2
votes

I have a simple flow in which I call the external web service through HTTP:

 <flow name="RFQStatusChangeFlow">
    <jms:inbound-endpoint queue="${RFQStatusQueue}" connector-ref="Web_logic_JMS" doc:name="JMS">
        <jms:transaction action="ALWAYS_BEGIN"/>
    </jms:inbound-endpoint>
    <set-variable variableName="originalMessage" value="#[payload]" doc:name="Variable"/> 
    <set-variable variableName="rfqnum" value="#[xpath3('/m:PublishRFQSTRUCT/m:RFQSTRUCTSet/m:RFQSTD/m:RFQNUM')]" doc:name="Variable"/>
    <expression-filter expression="#[xpath3('/m:PublishRFQSTRUCT/m:RFQSTRUCTSet/m:RFQSTD[(m:STATUS/@changed=1 and m:STATUS=(\'SENT\')) or (m:EOIREISSUE/@changed=1 and m:EOIREISSUE=1)]')!=empty]" doc:name="Expression"/>
    <mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" doc:name="XSLT" xsl-file="rfq.xslt"/>
    <http:request config-ref="HTTP_Request_Configuration" path="${uploadTenderPath}" method="POST" doc:name="HTTP">
        <http:request-builder>
            <http:query-param paramName="Content-Type" value="text/xml; charset=utf-8"/>
            <http:header headerName="SOAPAction" value="${uploadTenderSOAPAction}"/>
        </http:request-builder>
    </http:request>
    <choice-exception-strategy doc:name="Choice Exception Strategy">
        <catch-exception-strategy doc:name="RFQ Catch Exception Strategy" when="#[message.inboundProperties['http.status']==500]">
            <logger level="ERROR" message="#[message.inboundProperties]" doc:name="Logger"/>    
            <set-payload value="#[['rfqnum':#[flowVars['rfqnum']], 'message':#[flowVars['originalMessage']], 'exceptions':#[exception]]]" doc:name="Set Payload"/>
            <jms:outbound-endpoint queue="${rfq.dead.letter}" connector-ref="Web_logic_JMS" doc:name="JMS">
                <jms:transaction action="ALWAYS_JOIN" />
            </jms:outbound-endpoint>
        </catch-exception-strategy>
        <rollback-exception-strategy doc:name="Rollback Exception Strategy"/>
    </choice-exception-strategy>
</flow>

What I want is to read the HTTP response body in the catch exception strategy and set it as a part of the payload, before sending the message to the Dead Letter Queue.
Any ideas how to achieve that?
Thanks

1

1 Answers

0
votes

Response is by default passed to catch exception block. Just create java transformer extending AbstractMessageTransformer and put at the beginning of exception processing.

    <catch-exception-strategy doc:name="Catch Exception Strategy">
        <custom-transformer class="com.class.YourTransformer" doc:name="Java"/>
    </catch-exception-strategy>

In transformer just do something like that:

        String response = message.getPayloadAsString();

Then mix it with initial request. Preferably you should keep initial request in a variable and then

@Override
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {

//Webservice response
 String response = message.getPayloadAsString();

//Initial request     
 message.getInvocationProperty("initialRequest");

//mix them both as you like