camel-cxf throwing a fault

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

camel-cxf throwing a fault

Marc Giger
Hi,

I'm trying to get the following camel route working where the
dataformat is MESSAGE.

<from uri="cxf:bean:routerEndpoint?dataFormat=MESSAGE"/>            
<process ref="decryptProcessor"/>
<choice>
    <when>
    <methodCall bean="endpointSelector" method="matches"/>
            <to uri="cxf:bean:serviceEndpoint?dataFormat=MESSAGE"/>
    </when>
    <otherwise>
    <to uri="cxf:bean:localEndpoint?dataFormat=MESSAGE"/>
    </otherwise>
</choice>

if the endpointSelector bean returns true the request is redirected to
a remote webservice.
otherwise the request is forwarded to a local cxf service (with
local-transport)

Now, if I invoke the routerEndpoint and somewhere in the pipeline
happens an exception (in my case in the decryptProcessor), I get the
following Exception in the outFault chain:

Mar 4, 2008 10:48:35 PM org.apache.cxf.phase.PhaseInterceptorChain
doIntercept INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault
        at
org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:43)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:77)
at
org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDestination.java:79)
at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:264)
at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:170)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:148)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
at
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:211)
at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313) at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
at
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644) at
org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381) at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
at
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
Caused by: java.lang.NullPointerException at
org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025) at
org.apache.commons.io.IOUtils.copy(IOUtils.java:999) at
org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:39) ...
28 more

This is because the InputStream is null in
RawMessageContentRedirectInterceptor:

public void handleMessage(Message message) throws Fault {

        InputStream is = message.getContent(InputStream.class);
        OutputStream os = message.getContent(OutputStream.class);
       
        try {            
            IOUtils.copy(is, os);
            is.close();
            os.flush();
        } catch (Exception e) {
            throw new Fault(e);
        }
    }

How can I return a custom soap-fault in a processor/filter?

Thanks,

Marc
Reply | Threaded
Open this post in threaded view
|

Re: camel-cxf throwing a fault

Willem.Jiang
Hi Marc,

It looks like camel-cxf component's issue which can't deal with the
exception message in MESSAGE dataFormat.
Could you fill a JIRA for it ? I will fix it later this week.
As usual ,you just need throw the exception from the processor , CXF
will try to marshal it into a soap fault.

Regards,
Willem

Marc Giger wrote:

> Hi,
>
> I'm trying to get the following camel route working where the
> dataformat is MESSAGE.
>
> <from uri="cxf:bean:routerEndpoint?dataFormat=MESSAGE"/>            
> <process ref="decryptProcessor"/>
> <choice>
>     <when>
>     <methodCall bean="endpointSelector" method="matches"/>
>    <to uri="cxf:bean:serviceEndpoint?dataFormat=MESSAGE"/>
>     </when>
>     <otherwise>
>     <to uri="cxf:bean:localEndpoint?dataFormat=MESSAGE"/>
>     </otherwise>
> </choice>
>
> if the endpointSelector bean returns true the request is redirected to
> a remote webservice.
> otherwise the request is forwarded to a local cxf service (with
> local-transport)
>
> Now, if I invoke the routerEndpoint and somewhere in the pipeline
> happens an exception (in my case in the decryptProcessor), I get the
> following Exception in the outFault chain:
>
> Mar 4, 2008 10:48:35 PM org.apache.cxf.phase.PhaseInterceptorChain
> doIntercept INFO: Interceptor has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault
>         at
> org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:43)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
> at
> org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
> at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:77)
> at
> org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDestination.java:79)
> at
> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:264)
> at
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
> at
> org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:170)
> at
> org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:148)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at
> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
> at
> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
> at
> org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
> at
> org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
> at
> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
> at
> org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
> at
> org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:211)
> at
> org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
> at
> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
> at org.mortbay.jetty.Server.handle(Server.java:313) at
> org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
> at
> org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
> at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644) at
> org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at
> org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381) at
> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
> at
> org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
> Caused by: java.lang.NullPointerException at
> org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025) at
> org.apache.commons.io.IOUtils.copy(IOUtils.java:999) at
> org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:39) ...
> 28 more
>
> This is because the InputStream is null in
> RawMessageContentRedirectInterceptor:
>
> public void handleMessage(Message message) throws Fault {
>
>         InputStream is = message.getContent(InputStream.class);
>         OutputStream os = message.getContent(OutputStream.class);
>        
>         try {            
>             IOUtils.copy(is, os);
>             is.close();
>             os.flush();
>         } catch (Exception e) {
>             throw new Fault(e);
>         }
>     }
>
> How can I return a custom soap-fault in a processor/filter?
>
> Thanks,
>
> Marc
>
>  

Reply | Threaded
Open this post in threaded view
|

Re: camel-cxf throwing a fault

Marc Giger
Hi Willem,

On Wed, 05 Mar 2008 16:26:41 +0800
Willem Jiang <[hidden email]> wrote:

> Hi Marc,
>
> It looks like camel-cxf component's issue which can't deal with the
> exception message in MESSAGE dataFormat.
> Could you fill a JIRA for it ? I will fix it later this week.
> As usual ,you just need throw the exception from the processor , CXF
> will try to marshal it into a soap fault.

Hmm, yesterday I tryied to return a custom-soap-fault without specifying the
dataFormat. The result was the same. I always get the following soap-fault:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Fault occurred while processing.</faultstring></soap:Fault></soap:Body></soap:Envelope>

Perhaps I did something wrong yesterday. Will try it again...

Thanks,

Marc


>
> Regards,
> Willem
>
> Marc Giger wrote:
> > Hi,
> >
> > I'm trying to get the following camel route working where the
> > dataformat is MESSAGE.
> >
> > <from uri="cxf:bean:routerEndpoint?dataFormat=MESSAGE"/>            
> > <process ref="decryptProcessor"/>
> > <choice>
> >     <when>
> >     <methodCall bean="endpointSelector" method="matches"/>
> >    <to uri="cxf:bean:serviceEndpoint?dataFormat=MESSAGE"/>
> >     </when>
> >     <otherwise>
> >     <to uri="cxf:bean:localEndpoint?dataFormat=MESSAGE"/>
> >     </otherwise>
> > </choice>
> >
> > if the endpointSelector bean returns true the request is redirected to
> > a remote webservice.
> > otherwise the request is forwarded to a local cxf service (with
> > local-transport)
> >
> > Now, if I invoke the routerEndpoint and somewhere in the pipeline
> > happens an exception (in my case in the decryptProcessor), I get the
> > following Exception in the outFault chain:
> >
> > Mar 4, 2008 10:48:35 PM org.apache.cxf.phase.PhaseInterceptorChain
> > doIntercept INFO: Interceptor has thrown exception, unwinding now
> > org.apache.cxf.interceptor.Fault
> >         at
> > org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:43)
> > at
> > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
> > at
> > org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
> > at
> > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
> > at
> > org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:77)
> > at
> > org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDestination.java:79)
> > at
> > org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:264)
> > at
> > org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
> > at
> > org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:170)
> > at
> > org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:148)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at
> > org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
> > at
> > org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
> > at
> > org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
> > at
> > org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
> > at
> > org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
> > at
> > org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
> > at
> > org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:211)
> > at
> > org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
> > at
> > org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
> > at org.mortbay.jetty.Server.handle(Server.java:313) at
> > org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
> > at
> > org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
> > at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644) at
> > org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at
> > org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381) at
> > org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
> > at
> > org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
> > Caused by: java.lang.NullPointerException at
> > org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025) at
> > org.apache.commons.io.IOUtils.copy(IOUtils.java:999) at
> > org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:39) ...
> > 28 more
> >
> > This is because the InputStream is null in
> > RawMessageContentRedirectInterceptor:
> >
> > public void handleMessage(Message message) throws Fault {
> >
> >         InputStream is = message.getContent(InputStream.class);
> >         OutputStream os = message.getContent(OutputStream.class);
> >        
> >         try {            
> >             IOUtils.copy(is, os);
> >             is.close();
> >             os.flush();
> >         } catch (Exception e) {
> >             throw new Fault(e);
> >         }
> >     }
> >
> > How can I return a custom soap-fault in a processor/filter?
> >
> > Thanks,
> >
> > Marc
> >
> >  


--

itServe AG
Marc Giger
Länggassstrasse 26
3000 Bern 9
Tel.: +41 31 305 16 16
Fax:  +41 31 305 16 17

Direkt +41 31 305 43 27
Email [hidden email]

http://www.itserve.ch
Reply | Threaded
Open this post in threaded view
|

Re: camel-cxf throwing a fault

Marc Giger
Hi Willem,

Today I figured out that the exception handling still does not work
as I would have expected.

When I throw a Fault from a processor like the following:

public void process(Exchange exchange) throws java.lang.Exception {
        SoapFault fault = new SoapFault("blabblabla",
        SoapFault.FAULT_CODE_CLIENT);
        Element detail = fault.getOrCreateDetail();
        Document doc = detail.getOwnerDocument();
        Text tn = doc.createTextNode("testTextNode");
        detail.appendChild(tn);
        throw fault;
}

I still get
 
Caused by: java.lang.NullPointerException
        at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025)
        at org.apache.commons.io.IOUtils.copy(IOUtils.java:999)
        at
org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:48)
        ... 28 more


but if I only set the message body and not throwing a fault
(you did the same in the TestCases):

public void process(Exchange exchange) throws java.lang.Exception {
        SoapFault fault = new SoapFault("blabblabla",
        SoapFault.FAULT_CODE_CLIENT);
        Element detail = fault.getOrCreateDetail();
        Document doc = detail.getOwnerDocument();
        Text tn = doc.createTextNode("testTextNode");
        detail.appendChild(tn);
        org.apache.camel.Message message = exchange.getFault();
        message.setBody(fault);
}

it works. Is it intended?
I had attached a patch if I knew how to solve it:-(

Thanks!

Cheers,

Marc


On Wed, 5 Mar 2008 10:43:03 +0100
Marc Giger <[hidden email]> wrote:

> Hi Willem,
>
> On Wed, 05 Mar 2008 16:26:41 +0800
> Willem Jiang <[hidden email]> wrote:
>
> > Hi Marc,
> >
> > It looks like camel-cxf component's issue which can't deal with the
> > exception message in MESSAGE dataFormat.
> > Could you fill a JIRA for it ? I will fix it later this week.
> > As usual ,you just need throw the exception from the processor ,
> > CXF will try to marshal it into a soap fault.
>
> Hmm, yesterday I tryied to return a custom-soap-fault without
> specifying the dataFormat. The result was the same. I always get the
> following soap-fault:
>
> <soap:Envelope
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Fault
> occurred while
> processing.</faultstring></soap:Fault></soap:Body></soap:Envelope>
>
> Perhaps I did something wrong yesterday. Will try it again...
>
> Thanks,
>
> Marc
>
>
> >
> > Regards,
> > Willem
> >
> > Marc Giger wrote:
> > > Hi,
> > >
> > > I'm trying to get the following camel route working where the
> > > dataformat is MESSAGE.
> > >
> > > <from
> > > uri="cxf:bean:routerEndpoint?dataFormat=MESSAGE"/> <process
> > > ref="decryptProcessor"/> <choice>
> > >     <when>
> > >     <methodCall bean="endpointSelector" method="matches"/>
> > >    <to
> > > uri="cxf:bean:serviceEndpoint?dataFormat=MESSAGE"/> </when>
> > >     <otherwise>
> > >     <to uri="cxf:bean:localEndpoint?dataFormat=MESSAGE"/>
> > >     </otherwise>
> > > </choice>
> > >
> > > if the endpointSelector bean returns true the request is
> > > redirected to a remote webservice.
> > > otherwise the request is forwarded to a local cxf service (with
> > > local-transport)
> > >
> > > Now, if I invoke the routerEndpoint and somewhere in the pipeline
> > > happens an exception (in my case in the decryptProcessor), I get
> > > the following Exception in the outFault chain:
> > >
> > > Mar 4, 2008 10:48:35 PM org.apache.cxf.phase.PhaseInterceptorChain
> > > doIntercept INFO: Interceptor has thrown exception, unwinding now
> > > org.apache.cxf.interceptor.Fault
> > >         at
> > > org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:43)
> > > at
> > > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
> > > at
> > > org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
> > > at
> > > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
> > > at
> > > org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:77)
> > > at
> > > org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDestination.java:79)
> > > at
> > > org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:264)
> > > at
> > > org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
> > > at
> > > org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:170)
> > > at
> > > org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:148)
> > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at
> > > javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at
> > > org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
> > > at
> > > org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
> > > at
> > > org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
> > > at
> > > org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
> > > at
> > > org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
> > > at
> > > org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
> > > at
> > > org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:211)
> > > at
> > > org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
> > > at
> > > org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
> > > at org.mortbay.jetty.Server.handle(Server.java:313) at
> > > org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
> > > at
> > > org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
> > > at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644) at
> > > org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
> > > at
> > > org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
> > > at
> > > org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
> > > at
> > > org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
> > > Caused by: java.lang.NullPointerException at
> > > org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025) at
> > > org.apache.commons.io.IOUtils.copy(IOUtils.java:999) at
> > > org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:39) ...
> > > 28 more
> > >
> > > This is because the InputStream is null in
> > > RawMessageContentRedirectInterceptor:
> > >
> > > public void handleMessage(Message message) throws Fault {
> > >
> > >         InputStream is = message.getContent(InputStream.class);
> > >         OutputStream os = message.getContent(OutputStream.class);
> > >        
> > >         try {            
> > >             IOUtils.copy(is, os);
> > >             is.close();
> > >             os.flush();
> > >         } catch (Exception e) {
> > >             throw new Fault(e);
> > >         }
> > >     }
> > >
> > > How can I return a custom soap-fault in a processor/filter?
> > >
> > > Thanks,
> > >
> > > Marc
> > >
> > >  
>
>
> --
>
> itServe AG
> Marc Giger
> Länggassstrasse 26
> 3000 Bern 9
> Tel.: +41 31 305 16 16
> Fax:  +41 31 305 16 17
>
> Direkt +41 31 305 43 27
> Email [hidden email]
>
> http://www.itserve.ch
Reply | Threaded
Open this post in threaded view
|

Re: camel-cxf throwing a fault

Willem.Jiang
Hi Marc,

You can't throw the exception from the processor, since the
PipeLineProcessor will try to call the process method several times to
resend the message when  the process throw the exception.  If you throw
the exception from the process method, the Message that

RawMessageContentRedirectInterceptor get will have not Exception class or InputStream class. So you got the NPE here.

I am sorry I gave you a wrong answer before , and just figured it out by writing the unit test.

Willem

Marc Giger wrote:

> Hi Willem,
>
> Today I figured out that the exception handling still does not work
> as I would have expected.
>
> When I throw a Fault from a processor like the following:
>
> public void process(Exchange exchange) throws java.lang.Exception {
>         SoapFault fault = new SoapFault("blabblabla",
> SoapFault.FAULT_CODE_CLIENT);
> Element detail = fault.getOrCreateDetail();
> Document doc = detail.getOwnerDocument();
> Text tn = doc.createTextNode("testTextNode");
>         detail.appendChild(tn);
>         throw fault;
> }
>
> I still get
>  
> Caused by: java.lang.NullPointerException
>         at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025)
>         at org.apache.commons.io.IOUtils.copy(IOUtils.java:999)
>         at
> org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:48)
>         ... 28 more
>
>
> but if I only set the message body and not throwing a fault
> (you did the same in the TestCases):
>
> public void process(Exchange exchange) throws java.lang.Exception {
>         SoapFault fault = new SoapFault("blabblabla",
> SoapFault.FAULT_CODE_CLIENT);
> Element detail = fault.getOrCreateDetail();
> Document doc = detail.getOwnerDocument();
> Text tn = doc.createTextNode("testTextNode");
>         detail.appendChild(tn);
>         org.apache.camel.Message message = exchange.getFault();
>         message.setBody(fault);
> }
>
> it works. Is it intended?
> I had attached a patch if I knew how to solve it:-(
>
> Thanks!
>
> Cheers,
>
> Marc
>
>
> On Wed, 5 Mar 2008 10:43:03 +0100
> Marc Giger <[hidden email]> wrote:
>
>  
>> Hi Willem,
>>
>> On Wed, 05 Mar 2008 16:26:41 +0800
>> Willem Jiang <[hidden email]> wrote:
>>
>>    
>>> Hi Marc,
>>>
>>> It looks like camel-cxf component's issue which can't deal with the
>>> exception message in MESSAGE dataFormat.
>>> Could you fill a JIRA for it ? I will fix it later this week.
>>> As usual ,you just need throw the exception from the processor ,
>>> CXF will try to marshal it into a soap fault.
>>>      
>> Hmm, yesterday I tryied to return a custom-soap-fault without
>> specifying the dataFormat. The result was the same. I always get the
>> following soap-fault:
>>
>> <soap:Envelope
>> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Fault
>> occurred while
>> processing.</faultstring></soap:Fault></soap:Body></soap:Envelope>
>>
>> Perhaps I did something wrong yesterday. Will try it again...
>>
>> Thanks,
>>
>> Marc
>>
>>
>>    
>>> Regards,
>>> Willem
>>>
>>> Marc Giger wrote:
>>>      
>>>> Hi,
>>>>
>>>> I'm trying to get the following camel route working where the
>>>> dataformat is MESSAGE.
>>>>
>>>> <from
>>>> uri="cxf:bean:routerEndpoint?dataFormat=MESSAGE"/> <process
>>>> ref="decryptProcessor"/> <choice>
>>>>     <when>
>>>>     <methodCall bean="endpointSelector" method="matches"/>
>>>>    <to
>>>> uri="cxf:bean:serviceEndpoint?dataFormat=MESSAGE"/> </when>
>>>>     <otherwise>
>>>>     <to uri="cxf:bean:localEndpoint?dataFormat=MESSAGE"/>
>>>>     </otherwise>
>>>> </choice>
>>>>
>>>> if the endpointSelector bean returns true the request is
>>>> redirected to a remote webservice.
>>>> otherwise the request is forwarded to a local cxf service (with
>>>> local-transport)
>>>>
>>>> Now, if I invoke the routerEndpoint and somewhere in the pipeline
>>>> happens an exception (in my case in the decryptProcessor), I get
>>>> the following Exception in the outFault chain:
>>>>
>>>> Mar 4, 2008 10:48:35 PM org.apache.cxf.phase.PhaseInterceptorChain
>>>> doIntercept INFO: Interceptor has thrown exception, unwinding now
>>>> org.apache.cxf.interceptor.Fault
>>>>         at
>>>> org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:43)
>>>> at
>>>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
>>>> at
>>>> org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
>>>> at
>>>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
>>>> at
>>>> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:77)
>>>> at
>>>> org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDestination.java:79)
>>>> at
>>>> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:264)
>>>> at
>>>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
>>>> at
>>>> org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:170)
>>>> at
>>>> org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:148)
>>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at
>>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at
>>>> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
>>>> at
>>>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
>>>> at
>>>> org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
>>>> at
>>>> org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
>>>> at
>>>> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
>>>> at
>>>> org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
>>>> at
>>>> org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:211)
>>>> at
>>>> org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
>>>> at
>>>> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
>>>> at org.mortbay.jetty.Server.handle(Server.java:313) at
>>>> org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
>>>> at
>>>> org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
>>>> at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644) at
>>>> org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
>>>> at
>>>> org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
>>>> at
>>>> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
>>>> at
>>>> org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
>>>> Caused by: java.lang.NullPointerException at
>>>> org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025) at
>>>> org.apache.commons.io.IOUtils.copy(IOUtils.java:999) at
>>>> org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor.handleMessage(RawMessageContentRedirectInterceptor.java:39) ...
>>>> 28 more
>>>>
>>>> This is because the InputStream is null in
>>>> RawMessageContentRedirectInterceptor:
>>>>
>>>> public void handleMessage(Message message) throws Fault {
>>>>
>>>>         InputStream is = message.getContent(InputStream.class);
>>>>         OutputStream os = message.getContent(OutputStream.class);
>>>>        
>>>>         try {            
>>>>             IOUtils.copy(is, os);
>>>>             is.close();
>>>>             os.flush();
>>>>         } catch (Exception e) {
>>>>             throw new Fault(e);
>>>>         }
>>>>     }
>>>>
>>>> How can I return a custom soap-fault in a processor/filter?
>>>>
>>>> Thanks,
>>>>
>>>> Marc
>>>>
>>>>  
>>>>        
>> --
>>
>> itServe AG
>> Marc Giger
>> Länggassstrasse 26
>> 3000 Bern 9
>> Tel.: +41 31 305 16 16
>> Fax:  +41 31 305 16 17
>>
>> Direkt +41 31 305 43 27
>> Email [hidden email]
>>
>> http://www.itserve.ch
>>    
>
>