在Mule ESB中记录SOAP错误

时间:2013-02-19 03:05:56

标签: logging soap error-handling mule

我正在尝试让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());
    }  
}

1 个答案:

答案 0 :(得分: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组件中获取异常消息,并将其打印在消息类型为MuleMessage的控制台上。