Hello all again, Ok, I've found an alternative that I like it more: Instead of using the camel cxf component, I've tried using directly the CXF endpoint connected to a Camel Proxy:
<bean id="myBean" class="net.cristcost.MyBean" /> <jaxws:endpoint id="proxyCxfService" implementor="#myBeanProxy" address="http://0.0.0.0:8090/proxyCxfService" implementorClass="net.cristcost.MyBeanInterface"> </jaxws:endpoint> <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring "> <proxy id="myBeanProxy" serviceInterface="net.cristcost.MyBeanInterface" serviceUrl="bean:myBean" binding="false" /> </camelContext> This approach handles the Exceptions transparently (I don't know why, maybe it is the Camel Proxy which extracts the cause of a RuntimeCamelException). In this way I recognize I am not using the camel-cxf component, ad CXF and Camel are integrated via the java net.cristcost.MyBeanInterface interface. Do anyone has concerns or remarks about this approach? Thank you all, Cristiano PS. Note that I use the binding="false" because I was already using Camel Proxies before Camel 2.16.x, and I'm keeping the binding="false" for retro compatibility in processors where I manage exchanges with a BeanInvocation body - maybe it is not needed for most use cases) Il giorno mar 15 mar 2016 alle ore 18:25 Cristiano Costantini < [email protected]> ha scritto: > Hello All, > > I need to throw an "Fault" to a CXF service which is managed via a > cxf:bean:endpoint > > The fault exception is generated in a Bean, but the camel route wrap it in > org.apache.camel.RuntimeCamelException and when it is sent back to the > initial CXF endpoint it is not marshalled properly as CXF expects a Jax-WS > @WebFault > > The only solution that I've found is to extract the cause and set it as > the faultBody: > <setFaultBody> > <simple>${property.CamelExceptionCaught.cause}</simple> > </setFaultBody> > ... but I don't like this solution, it seems fragile to me. Do you have > any suggestion on how best to handle this use-case? > > > > Below a follow a more detailed example: > > consider the following Bean: > <bean id="myBean" class="net.cristcost.MyBean" /> > > I'm able to publish it as a Web Service with CXF in this way: > <jaxws:endpoint id="directCxfService" implementor="#myBean" > address="http://0.0.0.0:8090/directCxfService" > implementorClass="net.cristcost.MyBeanInterface"> > </jaxws:endpoint> > > > Now I need to some kind of processing between the request and the handling > by the bean, so I introduce Camel: > > <cxf:cxfEndpoint id="serviceViaCamel" > address="http://0.0.0.0:8090/serviceViaCamel" > serviceClass="net.cristcost.MyBeanInterface"> > </cxf:cxfEndpoint> > > and a route like this > > <route> > <from uri="cxf:bean:serviceViaCamel" /> > <!-- pre processing,filtering and routing of the requests here --> > <to uri="bean:myBean" /> > </route> > > > The problem happen when the service bean throws the exception. My solution > has been to handle the exception specifically by extracting the cause in > the following way: > > <camelContext id="camelContext" xmlns=" > http://camel.apache.org/schema/spring"> > > <onException> > <exception>net.cristcost.MyBeanFault</exception> > <handled> > <constant>true</constant> > </handled> > <setFaultBody> > <simple>${property.CamelExceptionCaught.cause}</simple> > </setFaultBody> > </onException> > > <route> > <from uri="cxf:bean:serviceViaCamel" /> > <!-- pre processing of the requests happen here --> > <to uri="bean:myBean" /> > </route> > </camelContext> > > > Could you suggest a more elegant solution to do this? > Thank you! > > Cristiano > > > >
