eclipse-ee4j / eclipse-ee4j/jersey
DeclarativeLinkingFeature does not work with StreamingOutput
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
This code throws an exception[1]
```java
@GET
@Path("/reports/{id}")
@Produces(MediaType.APPLICATION_XML)
public Response retrieveReportXml(@NotNull @PathParam("id") UUID id) {
StreamingOutput result = outputStream -> {
this.reportXmlService.exportReport(id, outputStream);
outputStream.flush();
};
return Response.ok(result, MediaType.APPLICATION_XML_TYPE).build();
}
```
if the Response entity is changed so that the processLinks method short circuits
```java
if (instance.getClass().getName().startsWith("java.lang")) {
return;
}
```
using a byte[] then the method will return properly.
```java
@GET
@Path("/reports/{id}")
@Produces(MediaType.APPLICATION_XML)
public Response retrieveReportXml(@NotNull @PathParam("id") UUID id) {
byte[] result = null;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
this.reportXmlService.exportReport(id, outputStream);
result = outputStream.toByteArray();
}
return Response.ok(result, MediaType.APPLICATION_XML_TYPE).build();
}
```
[1]exception stack excerpt
```
java.lang.UnsupportedOperationException: null
at org.codehaus.plexus.context.ContextMapAdapter.entrySet(ContextMapAdapter.java:106)
at org.glassfish.jersey.linking.FieldProcessor.processLinks(FieldProcessor.java:169)
at org.glassfish.jersey.linking.FieldProcessor.processMember(FieldProcessor.java:198)
at org.glassfish.jersey.linking.FieldProcessor.processLinks(FieldProcessor.java:178)
```
[2] version
```xml
org.glassfish.jersey
jersey-bom
2.26
org.glassfish.jersey.ext
jersey-declarative-linking
```
Contributor guide
Assessment
This issue has not been assessed yet.