1

I'm testing my Mule(3.3.1) flow which sends a web service call to external vendor. My aim is to catch java.net.ConnectException and apply appropriate XSLT to original payload and send it to caller.

But the payload received in <catch-exception-strategy> is of type org.apache.commons.httpclient.methods.PostMethod@12b13004 and not original XML. Tried using <objexct-to-string-transformer> but didn't help.

Any suggestions how to retrieve the original payload in catch block?

Part of mule-config.xml is below:

    <flow name="orderRequirementsToVendor">
        <jms:inbound-endpoint queue="order.vendor" />   

        <set-property propertyName="SOAPAction" value="http://vendor.com/services/InterfacePoint/Call" /> 

        <cxf:proxy-client payload="body" enableMuleSoapHeaders="false">
            <cxf:inInterceptors>
                <spring:bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />                  
            </cxf:inInterceptors>
            <cxf:outInterceptors>
                <spring:bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
            </cxf:outInterceptors>
        </cxf:proxy-client>
        <outbound-endpoint address="${vendor.ws.url}" mimeType="text/xml" connector-ref="https.connector" />
        <byte-array-to-string-transformer />

         <choice-exception-strategy>
            <catch-exception-strategy when="#[exception.causedBy(java.net.ConnectException)]">
                <logger message="#[exception.causeException]" level="ERROR" />
                <object-to-string-transformer/>
                <transformer ref="vendorConnectExceptionTransformer" />
             </catch-exception-strategy>
            <catch-exception-strategy>
                <logger message="#[exception.causeException]" level="ERROR" />
                <transformer ref="generalErrorTransformer" />
            </catch-exception-strategy>
        </choice-exception-strategy> 

    </flow> 
Charu Khurana
  • 4,511
  • 8
  • 47
  • 81

1 Answers1

3
  • Store the original payload in a flow variable right after jms:inbound-endpoint with

    <set-variable variableName="originalPayload" value="#[message.payload]" />
    
  • Access it back in your exception strategy with a MEL expression like: #[flowVars.originalPayload].

David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • yes that's a good idea. But why is the payload getting lost. I read that Mule (3.3 onwards) preserves original payload when exception is thrown and doesn't replace it with exception payload – Charu Khurana Apr 23 '13 at 17:18
  • And that is the case: the payload you see is not the exception payload (which is in a property named `exception`) but the payload as it was ready to be sent by the `outbound-endpoint` when the failure occurred. – David Dossot Apr 23 '13 at 17:20
  • I see, yes agree that's the case. But is there not a way to extract xml out of that ready-to-be-sent payload – Charu Khurana Apr 23 '13 at 17:24
  • Actually: you could try: the payload is of type `org.apache.commons.httpclient.methods.PostMethod` so you could use `https://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/methods/EntityEnclosingMethod.html#getRequestEntity%28%29` to retrieve its content. But the caveat of this approach is that it ties you to the internals of the HTTP transport and I would discourage you to do so. – David Dossot Apr 23 '13 at 17:34