eclipse-ee4j / eclipse-ee4j/jersey
Passing through responses by rethrowing WebApplicationExceptions truncates the entity
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Suppose you have
```
public class TestResource {
@Inject
Client client;
@POST
@Path("test")
public MyDTO test() {
TheirDTO dto = client.target("http://some.server/some/api").get(TheirDTO.class);
return convert(dto);
}
}
```
This code intends to convert the body of successful responses, but pass on error responses as is. And that works flawlessly. However, if I add some innocent-looking logging:
```
public MyDTO test() {
try {
TheirDTO dto = client.target("http://some.server/some/api").get(TheirDTO.class);
return convert(dto);
} catch (WebApplicationException e) {
log(e.getResponse());
throw e;
}
}
log(Response r) {
r.bufferEntity();
logger.log("Upstream error: " + r.readEntity(String.class));
}
```
Jersey truncates the error entity when writing the response.
Expected behaviour: Jersey faithfully transcribes the entire response, including an entity if present.
Contributor guide
Research direction
Start with the WebApplicationException rethrow path and the Response APIs shown in the reproducer, especially bufferEntity() and readEntity(String.class). Reproduce the logged upstream error response, then trace how Jersey writes that Response after the exception is rethrown. Done means the complete error entity is preserved when the response is sent.
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