You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Andrew <su...@gmail.com> on 2011/02/04 22:53:09 UTC

Capturing CXF Exceptions

Hi,

I'm doing some basic stress testing of my JAX-RS service and getting back
some 500 responses, with body:

 JAXBException occurred : Read timed out. Read timed out.

and

 <ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring
xmlns:ns1="http://cxf.apache.org/bindings/xformat">java.net.SocketTimeoutException:
Read timed out</ns1:faultstring></ns1:XMLFault>

On the service side I see the exceptions logged at WARN:

2011-02-04 14:19:57,621 [http-8080-5] WARN
org.apache.cxf.phase.PhaseInterceptorChain[369] - Interceptor for {
http://foo.com/}CommandResourceImpl has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Read timed out
    at
org.apache.cxf.interceptor.LoggingInInterceptor.logging(LoggingInInterceptor.java:201)

2011-02-04 14:19:57,928 [http-8080-38] WARN
org.apache.cxf.jaxrs.provider.AbstractJAXBProvider[508] -
javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: Premature end of file.]

but I'd like to handle these exceptions myself.  Is there a way to capture
these exceptions on the service side?  I'm using CXF 2.2.11  Thanks,

Andrew

Re: Capturing CXF Exceptions

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Dan

On Mon, Feb 7, 2011 at 4:35 PM, Daniel Kulp <dk...@apache.org> wrote:

> On Sunday 06 February 2011 11:36:55 am Sergey Beryozkin wrote:
> > I believe using CXF interceptors has always been possible, alternatively,
> > registering a custom JAX-RS RuntimeException ExceptionMapper is a
> > possibility.
> >
> > The only thing I'm not sure about is why the uncaught exception is not
> > propagated to the servlet container, it's definitely a default on
> > 2.3.x/trunk, XMLBinding out fault interceptor will only report the
> > exception (as in this case) if the propagation has been disabled.
>
> Are you sure on that?   By default, at least with the soap cases,
> exceptions
> are NOT propogated up to the servlet container.   We handle them ourselves,
> map them to the appropriate 500 status code, create the soap fault, etc...
> Nothing is sent up to the container.
>
> The propagation of the uncaught exceptions is required by the JAX-RS spec
so I did a minor update the other day to the out fault interceptor - and I
even have 2 tests :-).
JAXRSClientServerBookTest#testPropogateException &
JAXRSClientServerBookTest#testPropogateException2 (with the typos in the
names of the tests).

JAXRSClientServerBookTest#testPropogateException2 will report an exception
text as formatted by XMLBinding - because the propagation has been disabled
by setting an "org.apache.cxf.propagate.exception" to false...

cheers, Sergey

Dan
>
>
>
> >
> > Cheers, Sergey
> >
> > > Dan
> > >
> > > On Friday 04 February 2011 4:53:09 pm Andrew wrote:
> > > > Hi,
> > > >
> > > > I'm doing some basic stress testing of my JAX-RS service and getting
> > > > back
> > > >
> > > > some 500 responses, with body:
> > > >  JAXBException occurred : Read timed out. Read timed out.
> > > >
> > > > and
> > > >
> > > >  <ns1:XMLFault
> > > >
> > > > xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring
> > > > xmlns:ns1="http://cxf.apache.org/bindings/xformat
> > >
> > > ">java.net.SocketTimeoutE
> > >
> > > > xception: Read timed out</ns1:faultstring></ns1:XMLFault>
> > > >
> > > > On the service side I see the exceptions logged at WARN:
> > > >
> > > > 2011-02-04 14:19:57,621 [http-8080-5] WARN
> > > > org.apache.cxf.phase.PhaseInterceptorChain[369] - Interceptor for {
> > > > http://foo.com/}CommandResourceImpl has thrown exception, unwinding
> now
> > > > org.apache.cxf.interceptor.Fault: Read timed out
> > > >
> > > >     at
> > >
> > >
> org.apache.cxf.interceptor.LoggingInInterceptor.logging(LoggingInIntercep
> > > to
> > >
> > > > r.java:201)
> > > >
> > > > 2011-02-04 14:19:57,928 [http-8080-38] WARN
> > > > org.apache.cxf.jaxrs.provider.AbstractJAXBProvider[508] -
> > > > javax.xml.bind.UnmarshalException
> > > >
> > > >  - with linked exception:
> > > > [org.xml.sax.SAXParseException: Premature end of file.]
> > > >
> > > > but I'd like to handle these exceptions myself.  Is there a way to
> > >
> > > capture
> > >
> > > > these exceptions on the service side?  I'm using CXF 2.2.11  Thanks,
> > > >
> > > > Andrew
> > >
> > > --
> > > Daniel Kulp
> > > dkulp@apache.org
> > > http://dankulp.com/blog
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: Capturing CXF Exceptions

Posted by Andrew <su...@gmail.com>.
Yeah, it does get handled by the container.  Here's the result of my test
(condensed):

2011-02-08 11:13:41,702 [http-8080-2] WARN
org.apache.cxf.phase.PhaseInterceptorChain[369] - Application {
http://controller.foo.com/}CommandResourceImpl has thrown exception,
unwinding now
org.apache.cxf.interceptor.Fault: unhandled
    at
org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
    at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
    at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:133)
    at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:82)
    at
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
Caused by: java.lang.RuntimeException: unhandled
    ... 30 more
2011-02-08 11:13:41,703 [http-8080-2] WARN
org.apache.cxf.phase.PhaseInterceptorChain[369] - Application {
http://controller.foo.com/}CommandResourceImpl has thrown exception,
unwinding now
org.apache.cxf.interceptor.Fault: unhandled
2011-02-08 11:13:41,704 [http-8080-2] WARN
org.apache.cxf.phase.PhaseInterceptorChain[404] - Exception in handleFault
on interceptor
org.apache.cxf.binding.xml.interceptor.XMLFaultOutInterceptor@32b4376e
org.apache.cxf.interceptor.Fault: unhandled
2011-02-08 11:13:41,705 [http-8080-2] ERROR
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver[101] - Error
occurred during error handling, give up!
org.apache.cxf.interceptor.Fault: unhandled
2011-02-08 11:13:41,708 [http-8080-2] ERROR com.foo.servlet.class
org.apache.jsp.error_jsp[65] - Unhandled container exception:
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: unhandled
Caused by: java.lang.RuntimeException: unhandled

I would like to be able to catch this, log it and return an appropriate
response.  Currently I'm handling it with a container error handler, but I
have non-REST stuff going on in this webapp so would like to handle it in a
more specific way.  I'd appreciate any suggestions (e.g. what interface to
implement and how to inject it).  Thanks,

Andrew


On Mon, Feb 7, 2011 at 9:35 AM, Daniel Kulp <dk...@apache.org> wrote:

> On Sunday 06 February 2011 11:36:55 am Sergey Beryozkin wrote:
> > I believe using CXF interceptors has always been possible, alternatively,
> > registering a custom JAX-RS RuntimeException ExceptionMapper is a
> > possibility.
> >
> > The only thing I'm not sure about is why the uncaught exception is not
> > propagated to the servlet container, it's definitely a default on
> > 2.3.x/trunk, XMLBinding out fault interceptor will only report the
> > exception (as in this case) if the propagation has been disabled.
>
> Are you sure on that?   By default, at least with the soap cases,
> exceptions
> are NOT propogated up to the servlet container.   We handle them ourselves,
> map them to the appropriate 500 status code, create the soap fault, etc...
> Nothing is sent up to the container.
>
> Dan
>
>
>
> >
> > Cheers, Sergey
> >
> > > Dan
> > >
> > > On Friday 04 February 2011 4:53:09 pm Andrew wrote:
> > > > Hi,
> > > >
> > > > I'm doing some basic stress testing of my JAX-RS service and getting
> > > > back
> > > >
> > > > some 500 responses, with body:
> > > >  JAXBException occurred : Read timed out. Read timed out.
> > > >
> > > > and
> > > >
> > > >  <ns1:XMLFault
> > > >
> > > > xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring
> > > > xmlns:ns1="http://cxf.apache.org/bindings/xformat
> > >
> > > ">java.net.SocketTimeoutE
> > >
> > > > xception: Read timed out</ns1:faultstring></ns1:XMLFault>
> > > >
> > > > On the service side I see the exceptions logged at WARN:
> > > >
> > > > 2011-02-04 14:19:57,621 [http-8080-5] WARN
> > > > org.apache.cxf.phase.PhaseInterceptorChain[369] - Interceptor for {
> > > > http://foo.com/}CommandResourceImpl has thrown exception, unwinding
> now
> > > > org.apache.cxf.interceptor.Fault: Read timed out
> > > >
> > > >     at
> > >
> > >
> org.apache.cxf.interceptor.LoggingInInterceptor.logging(LoggingInIntercep
> > > to
> > >
> > > > r.java:201)
> > > >
> > > > 2011-02-04 14:19:57,928 [http-8080-38] WARN
> > > > org.apache.cxf.jaxrs.provider.AbstractJAXBProvider[508] -
> > > > javax.xml.bind.UnmarshalException
> > > >
> > > >  - with linked exception:
> > > > [org.xml.sax.SAXParseException: Premature end of file.]
> > > >
> > > > but I'd like to handle these exceptions myself.  Is there a way to
> > >
> > > capture
> > >
> > > > these exceptions on the service side?  I'm using CXF 2.2.11  Thanks,
> > > >
> > > > Andrew
> > >
> > > --
> > > Daniel Kulp
> > > dkulp@apache.org
> > > http://dankulp.com/blog
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: Capturing CXF Exceptions

Posted by Daniel Kulp <dk...@apache.org>.
On Sunday 06 February 2011 11:36:55 am Sergey Beryozkin wrote:
> I believe using CXF interceptors has always been possible, alternatively,
> registering a custom JAX-RS RuntimeException ExceptionMapper is a
> possibility.
> 
> The only thing I'm not sure about is why the uncaught exception is not
> propagated to the servlet container, it's definitely a default on
> 2.3.x/trunk, XMLBinding out fault interceptor will only report the
> exception (as in this case) if the propagation has been disabled.

Are you sure on that?   By default, at least with the soap cases, exceptions 
are NOT propogated up to the servlet container.   We handle them ourselves, 
map them to the appropriate 500 status code, create the soap fault, etc...    
Nothing is sent up to the container.

Dan



> 
> Cheers, Sergey
> 
> > Dan
> > 
> > On Friday 04 February 2011 4:53:09 pm Andrew wrote:
> > > Hi,
> > > 
> > > I'm doing some basic stress testing of my JAX-RS service and getting
> > > back
> > > 
> > > some 500 responses, with body:
> > >  JAXBException occurred : Read timed out. Read timed out.
> > > 
> > > and
> > > 
> > >  <ns1:XMLFault
> > > 
> > > xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring
> > > xmlns:ns1="http://cxf.apache.org/bindings/xformat
> > 
> > ">java.net.SocketTimeoutE
> > 
> > > xception: Read timed out</ns1:faultstring></ns1:XMLFault>
> > > 
> > > On the service side I see the exceptions logged at WARN:
> > > 
> > > 2011-02-04 14:19:57,621 [http-8080-5] WARN
> > > org.apache.cxf.phase.PhaseInterceptorChain[369] - Interceptor for {
> > > http://foo.com/}CommandResourceImpl has thrown exception, unwinding now
> > > org.apache.cxf.interceptor.Fault: Read timed out
> > > 
> > >     at
> > 
> > org.apache.cxf.interceptor.LoggingInInterceptor.logging(LoggingInIntercep
> > to
> > 
> > > r.java:201)
> > > 
> > > 2011-02-04 14:19:57,928 [http-8080-38] WARN
> > > org.apache.cxf.jaxrs.provider.AbstractJAXBProvider[508] -
> > > javax.xml.bind.UnmarshalException
> > > 
> > >  - with linked exception:
> > > [org.xml.sax.SAXParseException: Premature end of file.]
> > > 
> > > but I'd like to handle these exceptions myself.  Is there a way to
> > 
> > capture
> > 
> > > these exceptions on the service side?  I'm using CXF 2.2.11  Thanks,
> > > 
> > > Andrew
> > 
> > --
> > Daniel Kulp
> > dkulp@apache.org
> > http://dankulp.com/blog

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

Re: Capturing CXF Exceptions

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On Fri, Feb 4, 2011 at 11:05 PM, Daniel Kulp <dk...@apache.org> wrote:

>
> I'm not sure with 2.2.11.   With 2.3.2 you can definitely stick an
> interceptor
> early in the "in" chain and in the handleFault method, you can grab the
> exception and change it to a different exception:
>
> Exception ex = msg.getContent(Exception.class);
> if (ex is Read timed out) {
>   msg.setContent(Exception.class, new ThisIsMyException());
> }
>
> or similar.  It would then output that exception usiing the normal fault
> chain.
>
> Obviously, youcan stick an interceptor out early in the FaultOut and
> accomplish that as well.
>
>
I believe using CXF interceptors has always been possible, alternatively,
registering a custom JAX-RS RuntimeException ExceptionMapper is a
possibility.

The only thing I'm not sure about is why the uncaught exception is not
propagated to the servlet container, it's definitely a default on
2.3.x/trunk, XMLBinding out fault interceptor will only report the exception
(as in this case) if the propagation has been disabled.

Cheers, Sergey



> Dan
>
>
>
> On Friday 04 February 2011 4:53:09 pm Andrew wrote:
> > Hi,
> >
> > I'm doing some basic stress testing of my JAX-RS service and getting back
> > some 500 responses, with body:
> >
> >  JAXBException occurred : Read timed out. Read timed out.
> >
> > and
> >
> >  <ns1:XMLFault
> > xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring
> > xmlns:ns1="http://cxf.apache.org/bindings/xformat
> ">java.net.SocketTimeoutE
> > xception: Read timed out</ns1:faultstring></ns1:XMLFault>
> >
> > On the service side I see the exceptions logged at WARN:
> >
> > 2011-02-04 14:19:57,621 [http-8080-5] WARN
> > org.apache.cxf.phase.PhaseInterceptorChain[369] - Interceptor for {
> > http://foo.com/}CommandResourceImpl has thrown exception, unwinding now
> > org.apache.cxf.interceptor.Fault: Read timed out
> >     at
> >
> org.apache.cxf.interceptor.LoggingInInterceptor.logging(LoggingInIntercepto
> > r.java:201)
> >
> > 2011-02-04 14:19:57,928 [http-8080-38] WARN
> > org.apache.cxf.jaxrs.provider.AbstractJAXBProvider[508] -
> > javax.xml.bind.UnmarshalException
> >  - with linked exception:
> > [org.xml.sax.SAXParseException: Premature end of file.]
> >
> > but I'd like to handle these exceptions myself.  Is there a way to
> capture
> > these exceptions on the service side?  I'm using CXF 2.2.11  Thanks,
> >
> > Andrew
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: Capturing CXF Exceptions

Posted by Daniel Kulp <dk...@apache.org>.
I'm not sure with 2.2.11.   With 2.3.2 you can definitely stick an interceptor 
early in the "in" chain and in the handleFault method, you can grab the 
exception and change it to a different exception:

Exception ex = msg.getContent(Exception.class);
if (ex is Read timed out) {
   msg.setContent(Exception.class, new ThisIsMyException());
}

or similar.  It would then output that exception usiing the normal fault 
chain.

Obviously, youcan stick an interceptor out early in the FaultOut and 
accomplish that as well.

Dan



On Friday 04 February 2011 4:53:09 pm Andrew wrote:
> Hi,
> 
> I'm doing some basic stress testing of my JAX-RS service and getting back
> some 500 responses, with body:
> 
>  JAXBException occurred : Read timed out. Read timed out.
> 
> and
> 
>  <ns1:XMLFault
> xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring
> xmlns:ns1="http://cxf.apache.org/bindings/xformat">java.net.SocketTimeoutE
> xception: Read timed out</ns1:faultstring></ns1:XMLFault>
> 
> On the service side I see the exceptions logged at WARN:
> 
> 2011-02-04 14:19:57,621 [http-8080-5] WARN
> org.apache.cxf.phase.PhaseInterceptorChain[369] - Interceptor for {
> http://foo.com/}CommandResourceImpl has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault: Read timed out
>     at
> org.apache.cxf.interceptor.LoggingInInterceptor.logging(LoggingInIntercepto
> r.java:201)
> 
> 2011-02-04 14:19:57,928 [http-8080-38] WARN
> org.apache.cxf.jaxrs.provider.AbstractJAXBProvider[508] -
> javax.xml.bind.UnmarshalException
>  - with linked exception:
> [org.xml.sax.SAXParseException: Premature end of file.]
> 
> but I'd like to handle these exceptions myself.  Is there a way to capture
> these exceptions on the service side?  I'm using CXF 2.2.11  Thanks,
> 
> Andrew

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog