eclipse-ee4j / eclipse-ee4j/jersey

Accessing response metadata with jersey-client async

Open
#2,954 7 comments 0 reactions 0 assignees View on GitHub
Client Component: core Priority: Major Type: Improvement
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

Consider using jersey-client in async mode with an InvocationCallback. Order is a custom domain object for which we have a MessageBodyReader available.

```
Invocation invocation = client.target(someURL).request().buildGet();
invocation.submit(new InvocationCallback {
public void completed(Order order) {
// I want to access response metadata here
process(order);
}
public void failed(Throwable throwable) {
error();
}
});
```

I want to access the response metadata (available in javax.ws.rs.core.Response) when the response is successful. I might want to know the exact HTTP status code (200, 201 or 202), or read some HTTP response header (such as ETag, Location).

I can accomplish this by using InvocationCallback and then do readEntity() on the Response. But as far as I know, this won't be properly asynchronous since Response.readEntity() may block on reading the full response from the network.

This can be solved by either provide the Response object to the InvocationCallback.success() method, or to provide an asynchronous version of the Response.readEntity() method.
#### Affected Versions
[2.13]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.