You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Mandy Warren <ma...@gmail.com> on 2013/06/22 17:00:34 UTC

How to intercept exceptions thrown by CXF servlet

I have developed a REST service using Apache CXF and notice that if I send invalid characters in the URL, the CXF servlet throws back the following exception before it gets to my code:

Servlet failed with Exception java.lang.IllegalArgumentException at java.net.URI.create(URI.java:841) at org.apache.cxf.transport.servlet.BaseUrlHelper.getBaseURL(BaseUrlHelper.java:49) at org.apache.cxf.transport.servlet.ServletController.getBaseURL(ServletController.java:73) at org.apache.cxf.transport.servlet.ServletController.updateDestination(ServletController.java:82) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:162) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137) at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:239) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:164) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:215)
This results in a 500 status code being returned to the client.

I would ideally like to intercept this exception and return a 400 Bad Request status code to the client but I am unable to work out how to do this.

Any help much appreciated!

Many thanks



Re: How to intercept exceptions thrown by CXF servlet

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 23/06/13 20:50, Mandy Warren wrote:
> Thanks very much for taking the time to reply..
>
> Ok so I am running on a weblogic 10.3 container and it does seem that the problem occurs when deploying to this environment but not when running on Tomcat 7. On Tomcat I do get a 400 status code returned.
>
> The 2 dodgy chars I am using in my url are \"
>
> Even reading the link below I still don't really understand quite what might be happening, would you mind explaining in a bit more detail so I can search for a possible fix in the weblogic forums?
>
I guess you may want to ask how to prevent WebLogic decoding \" characters
> Also, assuming weblogic has an issue, please could you explain how I write a filter to trap the exception and convert the response code manually? I have tried writing an Interceptor but the handleMessage method is never called (perhaps I specified the phase incorrectly - I used PRE_LOGICAL?).
>
I was referring to a servlet filter. which is where you'd catch it
Cheers, Sergey
> Many thanks
>
> Mandy
>
> On 23 Jun 2013, at 18:33, Sergey Beryozkin <sb...@gmail.com> wrote:
>
>> Hi
>> On 23/06/13 10:38, Andrei Shakirin wrote:
>>> Hi,
>>>
>>> Looks as defect for me. I will expect 400 Bad Request from CXF servlet in this case.
>>> Sergei, WDYT?
>>>
>> I think the reason for this particular exception is that the underlying container decodes request URI unexpectedly, there was a Windows specific issue to do with decoding %20, see
>> http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-Tomcat,
>>
>> but it could be caused by some other container specific issue.
>>
>> One can always add a filter can catch exceptions from there, but that would probably hide the container issue
>>
>> Cheers, Sergey
>>
>>
>>
>>> Regards,
>>> Andrei.
>>>
>>>> -----Original Message-----
>>>> From: Mandy Warren [mailto:mandys.inbox@gmail.com]
>>>> Sent: Samstag, 22. Juni 2013 17:01
>>>> To: users@cxf.apache.org
>>>> Subject: How to intercept exceptions thrown by CXF servlet
>>>>
>>>>
>>>> I have developed a REST service using Apache CXF and notice that if I send
>>>> invalid characters in the URL, the CXF servlet throws back the following
>>>> exception before it gets to my code:
>>>>
>>>> Servlet failed with Exception java.lang.IllegalArgumentException at
>>>> java.net.URI.create(URI.java:841) at
>>>> org.apache.cxf.transport.servlet.BaseUrlHelper.getBaseURL(BaseUrlHelper.j
>>>> ava:49) at
>>>> org.apache.cxf.transport.servlet.ServletController.getBaseURL(ServletContr
>>>> oller.java:73) at
>>>> org.apache.cxf.transport.servlet.ServletController.updateDestination(Servle
>>>> tController.java:82) at
>>>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.j
>>>> ava:162) at
>>>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.j
>>>> ava:137) at
>>>> org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpring
>>>> Servlet.java:158) at
>>>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Abstra
>>>> ctHTTPServlet.java:239) at
>>>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPS
>>>> ervlet.java:164) at
>>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at
>>>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPS
>>>> ervlet.java:215)
>>>> This results in a 500 status code being returned to the client.
>>>>
>>>> I would ideally like to intercept this exception and return a 400 Bad Request
>>>> status code to the client but I am unable to work out how to do this.
>>>>
>>>> Any help much appreciated!
>>>>
>>>> Many thanks
>>>>
>>>
>>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: How to intercept exceptions thrown by CXF servlet

Posted by Mandy Warren <ma...@gmail.com>.
Thanks very much for taking the time to reply..

Ok so I am running on a weblogic 10.3 container and it does seem that the problem occurs when deploying to this environment but not when running on Tomcat 7. On Tomcat I do get a 400 status code returned.

The 2 dodgy chars I am using in my url are \" 

Even reading the link below I still don't really understand quite what might be happening, would you mind explaining in a bit more detail so I can search for a possible fix in the weblogic forums?

Also, assuming weblogic has an issue, please could you explain how I write a filter to trap the exception and convert the response code manually? I have tried writing an Interceptor but the handleMessage method is never called (perhaps I specified the phase incorrectly - I used PRE_LOGICAL?).

Many thanks

Mandy 

On 23 Jun 2013, at 18:33, Sergey Beryozkin <sb...@gmail.com> wrote:

> Hi
> On 23/06/13 10:38, Andrei Shakirin wrote:
>> Hi,
>> 
>> Looks as defect for me. I will expect 400 Bad Request from CXF servlet in this case.
>> Sergei, WDYT?
>> 
> I think the reason for this particular exception is that the underlying container decodes request URI unexpectedly, there was a Windows specific issue to do with decoding %20, see
> http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-Tomcat,
> 
> but it could be caused by some other container specific issue.
> 
> One can always add a filter can catch exceptions from there, but that would probably hide the container issue
> 
> Cheers, Sergey
> 
> 
> 
>> Regards,
>> Andrei.
>> 
>>> -----Original Message-----
>>> From: Mandy Warren [mailto:mandys.inbox@gmail.com]
>>> Sent: Samstag, 22. Juni 2013 17:01
>>> To: users@cxf.apache.org
>>> Subject: How to intercept exceptions thrown by CXF servlet
>>> 
>>> 
>>> I have developed a REST service using Apache CXF and notice that if I send
>>> invalid characters in the URL, the CXF servlet throws back the following
>>> exception before it gets to my code:
>>> 
>>> Servlet failed with Exception java.lang.IllegalArgumentException at
>>> java.net.URI.create(URI.java:841) at
>>> org.apache.cxf.transport.servlet.BaseUrlHelper.getBaseURL(BaseUrlHelper.j
>>> ava:49) at
>>> org.apache.cxf.transport.servlet.ServletController.getBaseURL(ServletContr
>>> oller.java:73) at
>>> org.apache.cxf.transport.servlet.ServletController.updateDestination(Servle
>>> tController.java:82) at
>>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.j
>>> ava:162) at
>>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.j
>>> ava:137) at
>>> org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpring
>>> Servlet.java:158) at
>>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Abstra
>>> ctHTTPServlet.java:239) at
>>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPS
>>> ervlet.java:164) at
>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at
>>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPS
>>> ervlet.java:215)
>>> This results in a 500 status code being returned to the client.
>>> 
>>> I would ideally like to intercept this exception and return a 400 Bad Request
>>> status code to the client but I am unable to work out how to do this.
>>> 
>>> Any help much appreciated!
>>> 
>>> Many thanks
>>> 
>> 
> 

Re: How to intercept exceptions thrown by CXF servlet

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 23/06/13 10:38, Andrei Shakirin wrote:
> Hi,
>
> Looks as defect for me. I will expect 400 Bad Request from CXF servlet in this case.
> Sergei, WDYT?
>
I think the reason for this particular exception is that the underlying 
container decodes request URI unexpectedly, there was a Windows specific 
issue to do with decoding %20, see
http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-Tomcat,

but it could be caused by some other container specific issue.

One can always add a filter can catch exceptions from there, but that 
would probably hide the container issue

Cheers, Sergey



> Regards,
> Andrei.
>
>> -----Original Message-----
>> From: Mandy Warren [mailto:mandys.inbox@gmail.com]
>> Sent: Samstag, 22. Juni 2013 17:01
>> To: users@cxf.apache.org
>> Subject: How to intercept exceptions thrown by CXF servlet
>>
>>
>> I have developed a REST service using Apache CXF and notice that if I send
>> invalid characters in the URL, the CXF servlet throws back the following
>> exception before it gets to my code:
>>
>> Servlet failed with Exception java.lang.IllegalArgumentException at
>> java.net.URI.create(URI.java:841) at
>> org.apache.cxf.transport.servlet.BaseUrlHelper.getBaseURL(BaseUrlHelper.j
>> ava:49) at
>> org.apache.cxf.transport.servlet.ServletController.getBaseURL(ServletContr
>> oller.java:73) at
>> org.apache.cxf.transport.servlet.ServletController.updateDestination(Servle
>> tController.java:82) at
>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.j
>> ava:162) at
>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.j
>> ava:137) at
>> org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpring
>> Servlet.java:158) at
>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Abstra
>> ctHTTPServlet.java:239) at
>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPS
>> ervlet.java:164) at
>> javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at
>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPS
>> ervlet.java:215)
>> This results in a 500 status code being returned to the client.
>>
>> I would ideally like to intercept this exception and return a 400 Bad Request
>> status code to the client but I am unable to work out how to do this.
>>
>> Any help much appreciated!
>>
>> Many thanks
>>
>


RE: How to intercept exceptions thrown by CXF servlet

Posted by Andrei Shakirin <as...@talend.com>.
Hi,

Looks as defect for me. I will expect 400 Bad Request from CXF servlet in this case.
Sergei, WDYT?

Regards,
Andrei.

> -----Original Message-----
> From: Mandy Warren [mailto:mandys.inbox@gmail.com]
> Sent: Samstag, 22. Juni 2013 17:01
> To: users@cxf.apache.org
> Subject: How to intercept exceptions thrown by CXF servlet
> 
> 
> I have developed a REST service using Apache CXF and notice that if I send
> invalid characters in the URL, the CXF servlet throws back the following
> exception before it gets to my code:
> 
> Servlet failed with Exception java.lang.IllegalArgumentException at
> java.net.URI.create(URI.java:841) at
> org.apache.cxf.transport.servlet.BaseUrlHelper.getBaseURL(BaseUrlHelper.j
> ava:49) at
> org.apache.cxf.transport.servlet.ServletController.getBaseURL(ServletContr
> oller.java:73) at
> org.apache.cxf.transport.servlet.ServletController.updateDestination(Servle
> tController.java:82) at
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.j
> ava:162) at
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.j
> ava:137) at
> org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpring
> Servlet.java:158) at
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Abstra
> ctHTTPServlet.java:239) at
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPS
> ervlet.java:164) at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPS
> ervlet.java:215)
> This results in a 500 status code being returned to the client.
> 
> I would ideally like to intercept this exception and return a 400 Bad Request
> status code to the client but I am unable to work out how to do this.
> 
> Any help much appreciated!
> 
> Many thanks
>