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

Frank Ittermann commented on CXF-1730:
--------------------------------------

Okay i updated my local cxf project and now i got something new for you.

java.lang.NullPointerException
        at 
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:150)
        at 
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:61)
        at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
        at 
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
        at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
        at 
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)
        at 
org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92)
        at 
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:283)
        at 
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:128)
        at 
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:174)
        at 
org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFServlet.java:156)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)

I guess there is a deeper problem with that. With my local patched version of 
cxf 2.1.2 that i mentioned before all works fine and i wrote no new code i only 
change the order of the code a little bit. I looked in the trunk source code 
and what i see was that in the processResponse method of the 
JAXRSOutInterceptor class you but a lot of if checks for the 
OperationResourceInfo local variable. Because in my scenario see above this 
variable was never set.

So let me give you an advice set the OperationResourceInfo varaiable before the 
RequestHandler are called. With this solution the lot of null checks you are 
now performed not needed.

Last but not least you have forgot one of this null checks.

writer.writeTo(responseObj, targetType, invoked.getGenericReturnType(), 
                               invoked != null ? invoked.getAnnotations() : new 
Annotation[]{}, 
                               responseType, 
                               response.getMetadata(), 
                               out);

This line of code cause the trouble because the invoked variable is null and 
this code fragment invoked.getGenericReturnType() cause the 
NullPointerException.

Another thing about the RequestHandler feature is that i want used this 
possibility to write Authentication code. To do that i need the 
OperationResourceInfo variable setted in the Message instance. So please say if 
this is a bad idear.

Thanks for your attention

> The Exception handling if it is thrown from a RequestHandler is not correct i 
> guess.
> ------------------------------------------------------------------------------------
>
>                 Key: CXF-1730
>                 URL: https://issues.apache.org/jira/browse/CXF-1730
>             Project: CXF
>          Issue Type: Bug
>          Components: REST
>    Affects Versions: 2.1.2
>         Environment: Windows XP,  jdk1.6, Apache Tomcat 6.0.16
>            Reporter: Frank Ittermann
>
> Hello again
> i' ve used an implementation of RequestHandler to perform authentication 
> stuff. So
> if the Authentication failed a RuntimeException is thrown.  I've also wrote a 
> ExceptionMapper implementation to transform occurred Exception into Http 
> Status codes. If the RuntimeException from the Authentication was thrown than 
> this is translated to an HTTP 403 status code.
> But this Http status code is not send as response. This sends a 200 status 
> code. After a time of debugging i found the code that is responsible for 
> that. The processResponse method of the 
> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor work not correct is 
> guess. Because code with the following code block this methods ends.
> OperationResourceInfo operation = 
> (OperationResourceInfo)exchange.get(OperationResourceInfo.class
>             .getName());
>         if (operation == null) {
>             return;
>         }
> because the operation variable is null. The code after this is responsible to 
> but the Response from the ExceptionMapper class into the message object so 
> that i received a 403 http status code.
> I've searched the code again and i found the code block how put the 
> OperationResourceInfo into the Exchange object. That is done by the 
> processRequest method of the 
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor class. But before the 
> OperationResourceInfo object is putted in the registered ResourceHandler are 
> called see the code block below.
>  for (ProviderInfo<RequestHandler> sh : shs) {
>             Response response = sh.getProvider().handleRequest(message, 
> resource);
>             if (response != null) {
>                 message.getExchange().put(Response.class, response);
>                 return;
>             }
>         }
> I guess the code how put in the OperationresourceInfo object could be 
> performed before the RequestHandlers are called maybe? 
> Or it's forbidden to throw a Runtimeexception inside the RequestHandler ?
> I've also tried to return an Response object from the RequestHandler but the 
> effect was the same it never arrives the client. It received also the 
> Response object with http code 200.
> The CXF framework is great and very flexible good work. The opportunities to 
> register own code is very great.
> Good work.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to