eclipse-ee4j / eclipse-ee4j/jersey
WriterInterceptorContext does not provide resource method annotations
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
implementing and testing a WriterInterceptor I had to realize that WriterInterceptorContext as provided to aroundWriteTo() does not contain resource method annotations under all circumstances.
**In case the resource method call leads to an exception or if its return value is null, aroundWriteTo() is called with a WriterInterceptorContext whose array of annotations is empty.**
Investigating on this, I found that **"ResourceMethodInvoker.invoke()"** pushes a function to the context that only collects resource method metadata in case resource method response is not null and not "mapped from exception"
Actually I would expect complete context information in WriterInterceptorContext no matter what. If the behavior of the filter has to be based on information that is annotated on resource methods - how shall a "null-response" or an "exception-response" be computed in the desired manner?
Is there anybody around with deeper insight on this? Are there reasons I cannot see?
**I would suggest to remove this early return in ResourceMethodInvoker:**
```java
context.push(new Function() {
@Override
public ContainerResponse apply(final ContainerResponse response) {
// Need to check whether the response is null or mapped from exception. In these cases we don't want to modify
// response with resource method metadata.
if (response == null
|| response.isMappedFromException()) {
return response;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.