I'm trying to get Mule to log the exception that my SOAP component throws in the following flow. For instance, if I pass it malformed xml as an input, in soapUI I get a meaningful output, but I want to be able to log this in either the console or to send it to a JMS queue.
<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 is just:
public class ExceptionService {
public void onException(ExceptionMessage e) {
System.err.println("EXCEPTION MESSAGE:::: " + e.getException().getMessage());
}
}
Define a <catch-exception-strategy>
before the CAB-Mule_WMBFlow1
ends like this and log and push the error message to JMS queue
<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>
Additionally, you may use message.getExceptionPayload().getMessage()
to get the exception message in java component and print it on console where message is of type MuleMessage
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.