cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitry Kozlov (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-6297) JAX-RS BeanValidation feature fails with NPE in JAXRSBeanValidationOutInterceptor on sub-resource call
Date Wed, 25 Mar 2015 13:38:53 GMT

    [ https://issues.apache.org/jira/browse/CXF-6297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14379869#comment-14379869
] 

Dmitry Kozlov commented on CXF-6297:
------------------------------------

Hi, decided to double check to avoid confusion.

So, for sub-resource access the global filter (no name binding, just {{@Provider}}) is applied
once each way. Confirmed.

While double-response filter application seem to be a different Jersey related bug - it happens
when something fails inside Jersey response processing logic, when response has been already
successfully returned by business logic.

I'll probably attach code for this. But approach is simple - created resource with sub-resource
and added one global filter logging its invocation:
{code}
GET /myapp/groups/123/items/456 HTTP/1.1

06:31:14.049 [grizzly-nio-kernel(4) SelectorRunner] DEBUG o.g.g.nio.transport.TCPNIOTransport
- TCPNIOConnection (TCPNIOConnection{localSocketAddress={/127.0.0.1:8080}, peerSocketAddress={/127.0.0.1:63678}})
(allocated) read 567 bytes
06:31:14.050 [grizzly-http-server-3] INFO  r.k.e.j.t.w.f.GlobalContainerFilter - Invoking
request filter
06:31:14.051 [grizzly-http-server-3] INFO  r.k.e.j.t.w.f.GlobalContainerFilter - Invoking
response filter
06:31:14.052 [grizzly-http-server-3] DEBUG o.g.g.nio.transport.TCPNIOTransport - TCPNIOConnection
(TCPNIOConnection{localSocketAddress={/127.0.0.1:8080}, peerSocketAddress={/127.0.0.1:63678}})
(composite) write 177 bytes
{code}

> JAX-RS BeanValidation feature fails with NPE in JAXRSBeanValidationOutInterceptor on
sub-resource call
> ------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-6297
>                 URL: https://issues.apache.org/jira/browse/CXF-6297
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.4
>            Reporter: Dmitry Kozlov
>            Assignee: Sergey Beryozkin
>             Fix For: 3.1.0, 3.0.5
>
>
> With {{JAXRSBeanValidationFeature}} enabled CXF fails to process request to sub-resource
with exception like this:
> {code}
> 23:58:16.049 [qtp457732796-28] WARN  o.a.cxf.phase.PhaseInterceptorChain - Interceptor
for {http://example.com/}MainResource has thrown exception, unwinding now
> java.lang.NullPointerException: null
>     at org.apache.cxf.jaxrs.validation.ValidationUtils.getResourceInstance(ValidationUtils.java:39)
~[cxf-rt-frontend-jaxrs-3.0.4.jar:3.0.4]
>     at org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor.getServiceObject(JAXRSBeanValidationOutInterceptor.java:44)
~[cxf-rt-frontend-jaxrs-3.0.4.jar:3.0.4]
>     at org.apache.cxf.validation.AbstractValidationInterceptor.handleMessage(AbstractValidationInterceptor.java:60)
~[cxf-core-3.0.4.jar:3.0.4]
>     at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
[cxf-core-3.0.4.jar:3.0.4]
>     at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:83)
[cxf-core-3.0.4.jar:3.0.4]
>     at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
[cxf-core-3.0.4.jar:3.0.4]
>     at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
[cxf-core-3.0.4.jar:3.0.4]
>     at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)
[cxf-rt-transports-http-3.0.4.jar:3.0.4]
>     at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
[cxf-rt-transports-http-3.0.4.jar:3.0.4]
>     at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
[cxf-rt-transports-http-3.0.4.jar:3.0.4]
>     at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
[cxf-rt-transports-http-3.0.4.jar:3.0.4]
>     at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
[cxf-rt-transports-http-3.0.4.jar:3.0.4]
>     at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)
[cxf-rt-transports-http-3.0.4.jar:3.0.4]
>     at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:217)
[cxf-rt-transports-http-3.0.4.jar:3.0.4]
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) [javax.servlet-api-3.1.0.jar:3.1.0]
>     at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)
[cxf-rt-transports-http-3.0.4.jar:3.0.4]
>     ...
> {code}
> The example resource code:
> {code}
> @Path("/main")
> public interface MainResource {
>     @Path("/sub/{id}")
>     SubResource subResource(@PathParam @Size(min=3, max=255) String id);
> }
> -----
> public interface SubResource {
>     @GET
>     @Path("/items")
>     List<String> items();
> }
> GET http://example.com/main/sub/123/items
> {code}
> NPE happens at [ValidationUtils.java:39|https://github.com/apache/cxf/blob/c79696bfc1aee1d1204cbd592f6bc5c83c0d9dae/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationUtils.java#L39],
since {{resourceProvider}} retrieved on previous line is {{null}}:
> {code:java|firstline=33|highlight=39}
>     public static Object getResourceInstance(Message message) {
>         final OperationResourceInfo ori = message.getExchange().get(OperationResourceInfo.class);
>         if (ori == null) {
>             return null;
>         }
>         final ResourceProvider resourceProvider = ori.getClassResourceInfo().getResourceProvider();
>         if (!resourceProvider.isSingleton()) {
>             String error = "Service object is not a singleton, use a custom invoker to
validate";
>             LOG.warning(error);
>             return null;
>         } else {
>             return resourceProvider.getInstance(message);
>         }
> {code}
> This happens only during invocation of {{JAXRSBeanValidationOutInterceptor}} and only
when calling sub-resources as in example above.
> h3. Partial Workaround
> The partial workaround is to enable in-interceptor only. But this won't work for people
wishing to validate response entities as well.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message