我有一个简单的流程,我通过HTTP调用外部Web服务:
<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>
我想要的是在将消息发送到死信队列之前,在catch异常策略中读取HTTP响应主体并将其设置为有效负载的一部分。
任何想法如何实现?
感谢
答案 0 :(得分:0)
默认情况下,响应被传递给catch异常块。只需创建扩展AbstractMessageTransformer的java转换器并放在异常处理的开头。
<catch-exception-strategy doc:name="Catch Exception Strategy">
<custom-transformer class="com.class.YourTransformer" doc:name="Java"/>
</catch-exception-strategy>
在变压器中只需做类似的事情:
String response = message.getPayloadAsString();
然后将其与初始请求混合。您最好将初始请求保留在变量中,然后
@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