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