在mule中使用回滚异常策略向终端客户端显示用户定义的异常消息

在mule中使用回滚异常策略向终端客户端显示用户定义的异常消息,mule,Mule,我想知道如何使用回滚异常策略向终端客户端显示我们自己的异常消息。我已经使用catch exception block显示了我自己的消息。代码如下所示 <?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"

我想知道如何使用回滚异常策略向终端客户端显示我们自己的异常消息。我已经使用catch exception block显示了我自己的消息。代码如下所示

<?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;
}
}

这是使用捕获异常策略进行的。我想使用回滚异常策略进行训练。

应用与捕获异常策略相同的方法

我使用回滚异常策略完成了该过程。但在这种情况下它不起作用。据我所知,当入站端点是事务性的时,会使用回滚异常策略。事务性端点是vm、jms、jdbc。我需要一个使用vm事务性入站端点的简单工作示例您是对的,回滚异常策略通常用于事务。但是,如果打开我发送的链接,它也可以用于捕获未处理的异常。如果需要使用回滚策略捕获特定异常,请使用when属性。如果必须使用VM,请将它们插入HTTP入站和出站之间。谢谢Bernard。我需要一个关于VM端点的说明。我们可以将它们插入HTTP端点之间。是否有可能将HTTP端点替换为VM端点。根据您的建议,我已在HTTP入站端点之后插入VM。在另一个流中,我保留了具有相同队列路径的vm,并在其中添加了类型操作和时间等事务属性。在第二个流中,我添加了回滚异常块。当发生异常时,控件将回滚异常块,并从此处引发异常错误2014-02-13 15:51:51030[[simple_project].connector.http.mule.default.receiver.02]org.mule.exception.rollbackMessaginExceptionStrategy:处理失败后,未能将消息分派到错误队列。这可能会导致消息丢失。在此处记录消息:请帮助我如何解决此问题