java - httpAsyncClient.execute() callback method not invoked -


package com.lt.uadb.app.resource.test;  import java.util.concurrent.future;  import org.apache.http.httpresponse; import org.apache.http.client.methods.httpget; import org.apache.http.concurrent.futurecallback; import org.apache.http.impl.nio.client.defaulthttpasyncclient; import org.apache.http.nio.client.httpasyncclient; import org.junit.test;  public class asyncsampleresourcetest {     private static final string path = "http://192.168.1.112:8080/uadb.app/rest/sample/async/get";      @test     public void testhttpasyncclientfuturecallback() throws exception {         final httpasyncclient httpasyncclient = new defaulthttpasyncclient();         httpasyncclient.start();         final httpget request = new httpget(path);         try {             (int = 0; < 5; i++) {                 system.out.println("*****get--------------");                 future<httpresponse> future = httpasyncclient.execute(request,                         new futurecallback<httpresponse>() {                             @override                             public void completed(httpresponse httpresponse) {                                 system.out                                         .println("*****completed--------------");                             }                              @override                             public void failed(exception e) {                                 system.out.println("*****failed--------------");                             }                              @override                             public void cancelled() {                                 system.out                                         .println("*****cancelled--------------");                             }                         });                 // if run code in try catch,the rest service invoke                 // try {                 // httpresponse result = future.get();                 // if (result != null) {                 // system.out.println("request executed");                 // } else {                 // system.out.println("request failed");                 // }                 // } catch (interruptedexception | executionexception e1) {                 // e1.printstacktrace();                 // }             }             system.out.println("*****loop--------------");         } catch (exception e) {             e.printstacktrace();         } {             system.out.println("shutting down");             httpasyncclient.getconnectionmanager().shutdown();         }      } } 

the above code not invoking rest service, below log -

    *****get--------------     2015-06-04 16:51:53,372 [main] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 1] start execution       2015-06-04 16:51:53,385 [main] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 1] request connection {}->http://192.168.1.112:8080       2015-06-04 16:51:53,389 [main] [org.apache.http.impl.nio.conn.poolingclientasyncconnectionmanager] [debug] - connection request: [route: {}->http://192.168.1.112:8080][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]       *****get--------------     2015-06-04 16:51:53,393 [main] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 2] start execution       2015-06-04 16:51:53,394 [main] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 2] request connection {}->http://192.168.1.112:8080       2015-06-04 16:51:53,394 [main] [org.apache.http.impl.nio.conn.poolingclientasyncconnectionmanager] [debug] - connection request: [route: {}->http://192.168.1.112:8080][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]       *****get--------------     2015-06-04 16:51:53,394 [main] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 3] start execution       2015-06-04 16:51:53,396 [main] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 3] request connection {}->http://192.168.1.112:8080       2015-06-04 16:51:53,396 [main] [org.apache.http.impl.nio.conn.poolingclientasyncconnectionmanager] [debug] - connection request: [route: {}->http://192.168.1.112:8080][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]       *****get--------------     2015-06-04 16:51:53,396 [main] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 4] start execution       2015-06-04 16:51:53,397 [main] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 4] request connection {}->http://192.168.1.112:8080       2015-06-04 16:51:53,397 [main] [org.apache.http.impl.nio.conn.poolingclientasyncconnectionmanager] [debug] - connection request: [route: {}->http://192.168.1.112:8080][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]       *****get--------------     2015-06-04 16:51:53,397 [main] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 5] start execution       2015-06-04 16:51:53,397 [main] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 5] request connection {}->http://192.168.1.112:8080       2015-06-04 16:51:53,397 [main] [org.apache.http.impl.nio.conn.poolingclientasyncconnectionmanager] [debug] - connection request: [route: {}->http://192.168.1.112:8080][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]       *****loop--------------     shutting down     2015-06-04 16:51:53,398 [main] [org.apache.http.impl.nio.conn.poolingclientasyncconnectionmanager] [debug] - connection manager shutting down       2015-06-04 16:51:53,401 [thread-0] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 1] cancelled       *****cancelled--------------     2015-06-04 16:51:53,402 [main] [org.apache.http.impl.nio.conn.poolingclientasyncconnectionmanager] [debug] - connection manager shut down       2015-06-04 16:51:53,402 [thread-0] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 2] cancelled       *****cancelled--------------     2015-06-04 16:51:53,402 [thread-0] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 3] cancelled       *****cancelled--------------     2015-06-04 16:51:53,402 [thread-0] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 4] cancelled       *****cancelled--------------     2015-06-04 16:51:53,403 [thread-0] [org.apache.http.impl.nio.client.defaulthttpasyncclient] [debug] - [exchange: 5] cancelled       *****cancelled-------------- 

the completed not getting logged.

if toggle comment of code shown below -

    try {   httpresponse result = future.get();   if (result != null) {     system.out.println("request executed");   } else {     system.out.println("request failed");   } } catch (interruptedexception | executionexception e1) {   e1.printstacktrace(); } 

then rest service invoked, shown below -

      *****get--------------        *****completed--------------     *****loop--------------      *****get--------------        *****completed--------------     *****loop--------------      *****get--------------        *****completed--------------     *****loop--------------      shutting down  

it seems async not getting invoked, if it's invoke async, logged -

      *****get--------------      *****loop--------------      *****get--------------      *****loop--------------      *****get--------------      *****loop--------------         *****completed--------------       *****completed--------------       *****completed--------------      shutting down  


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -