简体   繁体   中英

How to create a soap fault with apache camel spring-ws

The following scenario was working with apache camel 2.14.0, spring-ws 1.5.9 and axiom 1.2.9

Scenario - When our soap service is called, it should optional return an error - This error should be in the response as soap fault

Problem detection

I already detected the problem: - The org.springframework.ws.soap.axiom.AxiomHandler(2.3.0) of Spring-WS does not create SOAPFault objects - The org.apache.axiom.soap.impl.llom.SOAPBodyImpl (1.2.15) no longer checks the local name of the element

Question It there a better way to handle the soap faults with apache camel?

  • One possibility is to use throwException but than my log will contain a lot of stacktrace in case of a functional error

Snippet Below is snippet of the camel configuration

<camel:from uri="spring-ws:uri:/contextPath/soapServices?endpointMapping=#endpointMapping"/>
<camel:to uri="bean:someBean" />
<camel:choice>
<camel:when>
<camel:xpath>//error</camel:xpath>
<camel:to uri="xslt:transform_event_response_to_soapfault.xslt?saxon=true" />
</camel:when>
</camel:choice>
</camel:from>

The solution we're using no, is the following: Store the original message in the header and throw an exception. The spring-ws component will automatically transform it to a soap fault. Also add the CamelFailuerHandled so that the error message is not within the log files.

<camel:setHeader headerName="myErrorMessage">
  <camel:xpath>//error/text()</camel:xpath>
</camel:setHeader>                  

<camel:setProperty propertyName="CamelFailureHandled">
    <camel:constant>true</camel:constant>
</camel:setProperty>        

<camel:throwException exceptionType="java.lang.IllegalArgumentException" message="${header.myErrorMessage}"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM