0
votes

How can I log a raw SOAP exception response with Mule 3.3.1? When I add a <exception-strategy ref="myStrategy"/> at the end of the flow along with myStrategy defined like this:

<choice-exception-strategy name="myStrategy">
    <catch-exception-strategy when="exception.causedBy(com.example.ServiceException)">
        <logger message="Caught a service exception" level="INFO" />
        <!-- <logger message="what to put here to get SOAP response?" level="INFO"/> -->
    </catch-exception-strategy>
    <catch-exception-strategy doc:name="Catch Exception Strategy">
        <logger level="INFO" doc:name="Logger"/>
    </catch-exception-strategy>
</choice-exception-strategy>

I'd like to be able to output the raw SOAP response.

The message payload seems to be of the payload=org.apache.commons.httpclient.methods.PostMethod type. I can see the SOAP call details in OUTBOUND scoped properties.

The relevant part of the flow looks like this:

<https:outbound-endpoint exchange-pattern="request-response" host="hostAddress" port="portNumber" path="path/to/service" doc:name="HTTP" connector-ref="connector" responseTimeout="50000" >
    <cxf:jaxws-client clientClass="com.example.Service"
    enableMuleSoapHeaders="true" doc:name="SOAP" operation="methodName"
    port="PortName"
    wsdlLocation="wsdl/wsdlName.wsdl">
    </cxf:jaxws-client>
</https:outbound-endpoint>
<exception-strategy ref="myStrategy" doc:name="Reference Exception Strategy"/>
2
Are you receiving SOAP fault from the outbound call you are making? Or do you want o catch exception and give SOAP fault? - user1760178
I'd like to log the raw response from the service. I believe I am getting the appropriate com.example.ServiceException. - ipavlic
When you receive an exception from the service you are calling then there is no response to be logged. The paylaod contains the Post Request sent from your flow. If ever a SOAP fault is to returned then it should be prepared by you in the exception strategy based on the exception. - user1760178
If SOAP Fault is received as response from the service you called from your flow then it will not come to exception strategy. - user1760178

2 Answers

1
votes

Best way to get original payload in <catch-exception-strategy> is to store the original payload in a variable as the first thing in your flow and then access it in exception block.

<https:outbound-endpoint exchange-pattern="request-response" host="hostAddress" port="portNumber" path="path/to/service" doc:name="HTTP" connector-ref="connector" responseTimeout="50000" >
    <cxf:jaxws-client clientClass="com.example.Service"
    enableMuleSoapHeaders="true" doc:name="SOAP" operation="methodName"
    port="PortName"
    wsdlLocation="wsdl/wsdlName.wsdl">
    </cxf:jaxws-client>
</https:outbound-endpoint>

<xm:dom-to-xml-transformer/>
<set-variable variableName="originalPayload" value="#[payload]" />

<exception-strategy ref="myStrategy" doc:name="Reference Exception Strategy"/>

and then in your <catch-exception-strategy>, do this: <set-payload value="originalPayload"/> or access payload as #[originalPayload] and use it as needed.

This technique is very useful and I do pretty much almost in all flows irrespective of it has soap inbound or other, original payload will never be unaccessible

1
votes

Logging Interceptors can be used to log the Inbound and Outbound messages from a CXF client.

<cxf:inInterceptors>
     <spring:ref bean="cxfLoggingInInterceptor" />
</cxf:inInterceptors> 
<cxf:outInterceptors>
    <spring:ref bean="cxfLoggingOutInterceptor" />
</cxf:outInterceptors>


<bean id="cxfLoggingInInterceptor"  class="org.apache.cxf.interceptor.LoggingInInterceptor" />
<bean id="cxfLoggingOutInterceptor"  class="org.apache.cxf.interceptor.LoggingOutInterceptor" />

Hope this helps.