eclipse-ee4j / eclipse-ee4j/jersey
NPE in ClientBinder when receiving response from server
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
An exception was thrown when we are firing async call from 2.23.1 client to 2.23.1 server.
Please find the attached response from 2.22.1 and 2.23.1 (2.23.1 NPE is the same even we are using 2.23.2)
Client side code:
```
client = ClientBuilder.newClient(clientConfig);
baseTarget = client.target(urlBase);
CacheBuilder.newBuilder().build(new CacheLoader() {
public WebTarget load(String path) {
return baseTarget.path(path);
}
});
public void testTing(ValidationRequest valReq) throws Exception {
try {
cachedWebTargets.get("/validate/position/eee").request().accept(mediaType)
.property(ClientProperties.READ_TIMEOUT, 1000000) // Overridden timeout value for this request, null will use default to defaultChunkedResponseTimeout
.async().post(Entity.entity(valReq, mediaType), new InvocationCallback>() {
@Override
public void completed(ChunkedInput response) {
response.setParser(ChunkedInput.createParser(CommonConsts.CHUNKED_DELIMITER));
String chunk;
while ((chunk = response.read()) != null) {
LOG.info(chunk);
}
}
@Override
public void failed(Throwable throwable) {
LOG.error(throwable, throwable);
}
});
} catch (Exception e) {
throw handleException(e);
}
}
Server side:
@Path("/position")
public Class validateOrder() {
return PositionValidatorSubResource.class;
}
Code Sniplet in PositionValidatorSubResource.class:
@POST
@Path("/eee")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
public ChunkedOutput validatePositionsWorkflowTest(com.ml.elt.vs.request.obj.ValidationRequest valReq) {
final ChunkedOutput output = new ChunkedOutput<>(String.class, CommonConsts.CHUNKED_DELIMITER);
try {
output.write("Testing001");
Thread.sleep(5000);
output.write("Testing002");
output.write(null);
}
catch (Exception e) {
LOG.error(e, e);
}
return output;
}
```
So in 2.22.1 we are working perfectly fine in calling async with chunked response, but it failed with such a strange error in 2.23.1\. If we send the request without using async() call, then the return can be recieved successfully and object binding are all fine.
It looks like something has changed in 2.23.1 that break the async call which is expecting chunked return
all the dependencies are pulled from maven central
#### Affected Versions
[2.23.2]
Contributor guide
Research direction
Start by reproducing the async call in ClientBuilder with InvocationCallback>, comparing Jersey 2.22.1 with 2.23.1/2.23.2 and the synchronous request. Inspect ClientBinder and the ClientBuilder async path while using the supplied server endpoint and chunked response. Done means the async callback receives and reads both chunks without an NPE.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100