我想知道如何使用回滚异常策略向终端客户端显示我们自己的异常消息。我使用catch异常块显示了我自己的消息。代码如下所示
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule- tracking-ee.xsd">
<http:connector name="HTTP_HTTPS" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" proxyHostname="" proxyUsername="" proxyPassword="" doc:name="HTTP\HTTPS"/>
<flow name="TestExampleFlow1" doc:name="TestExampleFlow1">
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:3030/gdsLoginReqTest" doc:name="HTTP" />
<cxf:proxy-service namespace="http://tlocalhost:8080/gdsLogin" service="GBDSService" payload="body" wsdlLocation="service/GBDSService.wsdl" doc:name="SOAP" />
<cxf:proxy-client payload="body" doc:name="SOAP" />
<!-- <mulexml:dom-to-xml-transformer returnClass="java.lang.String" /> -->
<http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://uds-uat2.bankofamerica.com/uds/services/GBDSService" doc:name="HTTP" connector-ref="HTTP_HTTPS" />
<catch-exception-strategy doc:name="catch Exception Strategy">
<logger message="Exception_logger" level="INFO" doc:name="Exception_logger" />
<custom-transformer class="com.bac.gwb.credit.csb.exception.CustomExceptionHandler" doc:name="Java"/>
<logger message="Exception_logger" level="INFO" doc:name="Exception_logger" />
</catch-exception-strategy>
</flow>
类CustomExceptionHandler.java是
import org.mule.api.ExceptionPayload;
import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.message.ExceptionMessage;
import org.mule.transformer.AbstractMessageTransformer;
public class CustomExceptionHandler extends AbstractMessageTransformer {
public CustomExceptionHandler() {
setName("CustomExceptionHandler");
}
@Override
public Object transformMessage(MuleMessage message, String outputEncoding)
throws TransformerException {
/* ExceptionMessage exceptionMessage = (ExceptionMessage)message.getExceptionPayload();*/
ExceptionPayload exceptionMessage=message.getExceptionPayload();
String t=exceptionMessage.getMessage();
String outputMessage = "<soap:Fault xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> <faultcode>soap:Server</faultcode><faultstring>An unexpected error has occured. Please contact your service desk and quote this error </faultstring> </soap:Fault>";
return outputMessage;
}
}
这与catch异常策略有关。我想用回滚异常策略进行锻炼。
答案 0 :(得分:0)
以与catch异常策略相同的方式应用<rollback-exception-strategy />
。 http://www.mulesoft.org/documentation/display/current/Rollback+Exception+Strategy