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