0

我试图让 Mule 记录我的 SOAP 组件在以下流程中引发的异常。例如,如果我将格式错误的 xml 作为输入传递,在soapUI 中我会得到一个有意义的输出,但我希望能够在控制台中记录它或将它发送到 JMS 队列。

<jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="CAB-Mule_WMBFlow1" doc:name="CAB-Mule_WMBFlow1">
    <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/DemoCustomer" doc:name="HTTP" mimeType="text/xml">
        <idempotent-redelivery-policy maxRedeliveryCount="3">
            <dead-letter-queue> 
                <vm:outbound-endpoint path="error-queue" /> 
            </dead-letter-queue>
        </idempotent-redelivery-policy>
    </http:inbound-endpoint>
    <cxf:jaxws-service port="80" serviceClass="com.mulesoft.demo.DemoCustomer" doc:name="SOAP"/>
    <component class="com.mulesoft.demo.DemoCustomerIntImpl" doc:name="Java"/>
    <jms:outbound-endpoint queue="StudioIN" connector-ref="Active_MQ" doc:name="JMS"/>
    <logger level="INFO" doc:name="Logger" message="Payload: #[payload]"/>
</flow>
<flow name="error" doc:name="error">
    <component class="com.mulesoft.demo.ExceptionService" doc:name="Java"/>
    <jms:outbound-endpoint queue="Error" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>

ExceptionService 只是:

public class ExceptionService {
    public void onException(ExceptionMessage e) {
        System.err.println("EXCEPTION MESSAGE:::: " + e.getException().getMessage());
    }  
}
4

1 回答 1

0

<catch-exception-strategy>像这样在结束之前定义一个CAB-Mule_WMBFlow1并记录错误消息并将其推送到 JMS 队列

<flow name="CAB-Mule_WMBFlow1" doc:name="CAB-Mule_WMBFlow1">
    <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/DemoCustomer" doc:name="HTTP" mimeType="text/xml">
        <idempotent-redelivery-policy maxRedeliveryCount="3">
            <dead-letter-queue> 
                <vm:outbound-endpoint path="error-queue" /> 
            </dead-letter-queue>
        </idempotent-redelivery-policy>
    </http:inbound-endpoint>
    <cxf:jaxws-service port="80" serviceClass="com.mulesoft.demo.DemoCustomer" doc:name="SOAP"/>
    <component class="com.mulesoft.demo.DemoCustomerIntImpl" doc:name="Java"/>
    <jms:outbound-endpoint queue="StudioIN" connector-ref="Active_MQ" doc:name="JMS"/>
    <logger level="INFO" doc:name="Logger" message="Payload: #[payload]"/>

    <catch-exception-strategy>
        <logger level="INFO" message="---->Exception payload is: #[payload]"/>
        <jms:outbound-endpoint queue="Error" />
    </catch-exception-strategy>
</flow>

此外,您可以使用message.getExceptionPayload().getMessage()在 java 组件中获取异常消息并将其打印在 message 类型为 的控制台上MuleMessage

于 2013-02-19T15:21:27.737 回答