users@jersey.java.net

[Jersey] Re: Monitoring progress on an asynchronous request

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Fri, 17 Jun 2011 15:49:17 +0200

Hi Marco,

On 06/15/2011 09:27 PM, marco.ocana_at_balboasystems.com wrote:
> Hi,
>
> How would I go about monitoring the progress of an asynchronous request
> using the Jersey client?
> I am aware of the ContainerListener mechanism using a
> ConnectionListenerFilter, but I could not find a straightforward way to
> associate a listener to a specific request.

The above listener should work the same way for async/non-async
requests. You are getting a concrete ClientRequest instance passed
to your OnStartConnectionListener.onStart method:

client.addFilter(new ConnectionListenerFilter(new
OnStartConnectionListener() {
   public ContainerListener onStart(ClientRequest clientRequest) {
      return createYourContainerListenerHereAwareOfThe(clientRequest);
   }
});

~Jakub

> I also found the FutureListener with the onComplete callback, but it
> does not provide information on the bytes sent/received like the
> ContainerListener does.
>
> I am currently on Jersey Client 1.5.
>
> Thanks
>
> Marco
>