eclipse-ee4j / eclipse-ee4j/jersey

WriterInterceptorContext does not provide resource method annotations

Open
#3,759 1 comment 0 reactions 0 assignees View on GitHub
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

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.