Jorge Cercas created CXF-8227:
---------------------------------

             Summary: Failure to comply with JAX-RS spec with 
ContainerRequestContext and WriterInterceptorContext
                 Key: CXF-8227
                 URL: https://issues.apache.org/jira/browse/CXF-8227
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 3.3.5
         Environment: * Linux and or Windows
 * Java 11.0.6
 * CXF 3.3.5
            Reporter: Jorge Cercas


The Javadoc for the ContainerRequestContext interface says:
{{[setProperty|https://docs.oracle.com/javaee/7/api/javax/ws/rs/container/ContainerRequestContext.html#setProperty-java.lang.String-java.lang.Object-]([String|http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true]
 name,           
[Object|http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true]
 object)}}
Binds an object to a given property name in the *current request/response 
exchange context*.
{{[getProperty|https://docs.oracle.com/javaee/7/api/javax/ws/rs/container/ContainerRequestContext.html#getProperty-java.lang.String-]([String|http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true]
 name)}}
Returns the property with the given name registered in the *current 
request/response exchange context*, or {{null}} if there is no property by that 
name.

And the Javadoc for the InterceptorContext interface and known sub-interfaces 
(ReaderInterceptorContext, WriterInterceptorContext) says:
{{[setProperty|https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/InterceptorContext.html#setProperty-java.lang.String-java.lang.Object-]([String|http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true]
 name,           
[Object|http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true]
 object)}}
Binds an object to a given property name in the *current request/response 
exchange context*.
{{[getProperty|https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/InterceptorContext.html#getProperty-java.lang.String-]([String|http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true]
 name)}}
Returns the property with the given name registered in the *current 
request/response exchange context*, or {{null}} if there is no property by that 
name.
 
However, given the code below for a resource that does provide an entity, the 
variable fooBar in the aroundWriteTo method is always null.
{code:java}
// code placeholder
@Provider
public class InterceptorBug implements ContainerRequestFilter, 
WriterInterceptor {    @Override
    public void filter(ContainerRequestContext requestContext) throws 
IOException {
        requestContext.setProperty("foo.bar", "baz");
    }    @Override
    public void aroundWriteTo(WriterInterceptorContext context) throws 
IOException, WebApplicationException {
        context.proceed();
        
        // ALWAYS NULL
        var fooBar = context.getProperty("foo.bar");
    }
}
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to