users@jersey.java.net

[Jersey] Re: Async client and Response.readEntity

From: Mikael Ståldal <mikael.staldal_at_appearnetworks.com>
Date: Mon, 12 Jan 2015 11:29:46 +0100

No, I did not get any answer to this. And neither to the JIRA issues I have
filed:

https://java.net/jira/browse/JERSEY-2682

To me, it seems like the async part of the JAX-RS 2.0 client API is flawed
(not to mention the default implementation in Jeresy:
https://java.net/jira/browse/JERSEY-2058).

It's a pity, since the synchronous client API in JAX-RS 2.0 (and its
implementation in Jersey) is really nice.

I am considering using something else for async REST client, such as
https://github.com/AsyncHttpClient/async-http-client or Jetty client.

On Wed, Dec 31, 2014 at 9:06 PM, Robert DiFalco <robert.difalco_at_gmail.com>
wrote:

> Did you ever get an answer to this?
>
> On Mon, Oct 6, 2014 at 7:45 AM, Mikael Ståldal <
> mikael.staldal_at_appearnetworks.com> wrote:
>
>> Consider using Jersey client in async mode with an
>> InvocationCallback<Response>, and then use readEntity() on the Response.
>> Order is a custom domain object for which we have a MessageBodyReader
>> available.
>>
>> Invocation invocation = client.target(someURL).request().buildGet();
>> invocation.submit(new InvocationCallback<Response> {
>> public void completed(Response response) {
>> int status = response.getStatus();
>> if (status == 200) {
>> Order order = response.readEntity(Order.class); // blocking ?
>> process(order);
>> } else {
>> error();
>> }
>> }
>> public void failed(Throwable throwable) {
>> error();
>> }
>> });
>>
>> Is the response.readEntity() call blocking? Is it I/O bound if the
>> response is large? Or is the whole response read from network before the
>> completed() callback is invoked?
>>
>> Will the asynchronicity be improved if I do InvocationCallback<Order>
>> instead? What if I want to get other information from the Response?
>>
>> --
>> Mikael Ståldal
>> Chief Software Architect
>> *Appear*
>> Phone: +46 8 545 91 572
>> Email: mikael.staldal_at_appearnetworks.com
>>
>
>


-- 
Mikael Ståldal
Chief Software Architect
*Appear*
Phone: +46 8 545 91 572
Email: mikael.staldal_at_appearnetworks.com