我正在从 Mule 进行 SOAP 调用。我正在使用默认异常策略来捕获异常。发生异常时,如何发送我自己的故障代码和故障字符串而不是通用的肥皂故障消息?谢谢
这是 mule xml、java 代码、实际输出和预期输出的片段
骡子xml
<flow name="addressSearchFlow1" doc:name="addressSearchFlow1">
<invoke object-ref="InvoiceManager" method="completeSearchObject"
methodArguments="#[message.payload]"></invoke>
<logger level="INFO" doc:name="Logger" />
<processor-chain doc:name="Search Processor Chain">
<cxf:jaxws-client operation="doSearch"
clientClass="com.invoice.web_2007_09.ProWeb" port="InvoicePortType"
wsdlLocation="proweb.wsdl" enableMuleSoapHeaders="true" doc:name="SOAP">
</cxf:jaxws-client>
<http:outbound-endpoint exchange-pattern="request-response"
method="POST" ref="InvoiceEndPoint" doc:name="HTTP" />
</processor-chain>
<default-exception-strategy>
<processor-chain>
<logger message="Exception_logger" level="INFO" doc:name="Exception_logger" />
<custom-transformer class="com.managers.CustomExceptionHandler" />
<logger message="Exception_logger" level="INFO" doc:name="Exception_logger" />
</processor-chain>
</default-exception-strategy>
</flow>
Java 代码
package com.managers;
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.getPayload();
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 \"" + exceptionMessage.getException() + "\""+ "</faultstring> " + "</soap:Fault>";
return outputMessage;
}
}
实际输出
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring> dt-invoice. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: PostMethod</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
预期产出
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring> An unexpected error has occured. Please contact your service desk and quote this error "org.mule.api.transport.DispatchException: dt-invoice. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: PostMethod"
</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>