You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by mo...@polarisFT.com on 2013/10/09 08:53:46 UTC
Async API call
Hi,
I am using this JUnit test( example from Apache HTTP Components as
it is ). I am sending JSON to a Netty server which is able to receive 2
POSTS
and also send responses. I believe Netty can receive more requests but
that might be a different issue.
Here even for the 2 POSTS that Netty receives and sends responses the
callback methods are not called. I was thinking this unit test will
complete and the JVM will exit. But it doesn't happen.
When does 'future.get' return ? Does it return as soon as it sends and
receives a response ?
Since I am a new user I could be making some minor mistakes but the code
is able to send and the server receives the JSON.
Thanks,
Mohan
@Test
public void testAsyncThread() throws InterruptedException {
// Use pool of two threads
ExecutorService threadpool = Executors.newFixedThreadPool(2);
Async async = Async.newInstance().use(threadpool);
Request[] requests = new Request[] {
Request.Post("http://localhost:9090/print"
).bodyString(getJSon(), ContentType.APPLICATION_JSON),
Request.Post("http://localhost:9090/print"
).bodyString(getJSon(), ContentType.APPLICATION_JSON),
};
Queue<Future<Content>> queue = new LinkedList<Future<Content>>();
// Execute requests asynchronously
for (final Request request: requests) {
Future<Content> future = async.execute(request, new
FutureCallback<Content>() {
public void failed(final Exception ex) {
logger.info(ex.getMessage() + ": " + request);
}
public void completed(final Content content) {
logger.info("Request completed: " + request);
}
public void cancelled() {
logger.info("Request cancelled: " + request);
}
});
queue.add(future);
}
while(!queue.isEmpty()) {
Future<Content> future = queue.remove();
try {
Content c = future.get();
logger.info( "Response " + c.asString() );
} catch (ExecutionException ex) {
logger.info( "ExecutionException [" +
getExceptionAsString( ex ) + "]" );
}
}
logger.info("Done");
threadpool.shutdown();
}
This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.
Visit us at http://www.polarisFT.com
Re: Async API call
Posted by mo...@polarisFT.com.
Hi,
I plan to capture it through Fiddler to check. This call
should route it through the Fiddler proxy. It didn't when I tried.
Request[] requests = new Request[] {
Request.Post("http://localhost:9090/print").
viaProxy(new HttpHost("127.0.0.1", 8888)).
bodyString(getJSon(), ContentType.
APPLICATION_JSON),
Request.Post("http://localhost:9090/print").
viaProxy(new HttpHost("127.0.0.1", 8888)).
bodyString(getJSon(), ContentType.
APPLICATION_JSON),
};
Thanks,
Mohan
From: Oleg Kalnichevski <ol...@apache.org>
To: HttpClient User Discussion <ht...@hc.apache.org>
Date: 10/09/2013 05:28 PM
Subject: Re: Async API call
On Wed, 2013-10-09 at 12:23 +0530, mohan.radhakrishnan@polarisFT.com
wrote:
> Hi,
> I am using this JUnit test( example from Apache HTTP Components
as
> it is ). I am sending JSON to a Netty server which is able to receive 2
> POSTS
> and also send responses. I believe Netty can receive more requests but
> that might be a different issue.
>
> Here even for the 2 POSTS that Netty receives and sends responses the
> callback methods are not called. I was thinking this unit test will
> complete and the JVM will exit. But it doesn't happen.
>
> When does 'future.get' return ? Does it return as soon as it sends and
> receives a response ?
>
> Since I am a new user I could be making some minor mistakes but the
code
> is able to send and the server receives the JSON.
>
> Thanks,
> Mohan
I ran your code with some minor modifications (I had to eliminate JSON
and Netty dependencies) and it worked just fine for me (both responses
correctly processed and the JVM terminated as expected). This seems to
point at the server side.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.
Visit us at http://www.polarisFT.com
Re: Async API call
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2013-10-09 at 12:23 +0530, mohan.radhakrishnan@polarisFT.com
wrote:
> Hi,
> I am using this JUnit test( example from Apache HTTP Components as
> it is ). I am sending JSON to a Netty server which is able to receive 2
> POSTS
> and also send responses. I believe Netty can receive more requests but
> that might be a different issue.
>
> Here even for the 2 POSTS that Netty receives and sends responses the
> callback methods are not called. I was thinking this unit test will
> complete and the JVM will exit. But it doesn't happen.
>
> When does 'future.get' return ? Does it return as soon as it sends and
> receives a response ?
>
> Since I am a new user I could be making some minor mistakes but the code
> is able to send and the server receives the JSON.
>
> Thanks,
> Mohan
I ran your code with some minor modifications (I had to eliminate JSON
and Netty dependencies) and it worked just fine for me (both responses
correctly processed and the JVM terminated as expected). This seems to
point at the server side.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org