4
我在Mule 3.2.1中有一個簡單的流程,它只能重新發布web服務。目標是瞭解異常處理在Mule中的工作方式。爲了測試這個,我使用了一個總是返回異常的Web服務(即從來沒有正確的或錯誤的響應),我想捕獲這個異常並對其進行處理(登錄到初始者的文件中)。Mule:異常策略不叫
的問題是例外的策略似乎並沒有在所有被稱爲...
我試過兩個版本 - 第一個默認的異常策略,第二個自定義的異常-戰略。流程是這樣的:
<flow name="LoginFlow">
<http:inbound-endpoint address="http://localhost:8081/WsFaultResponseMule" exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="aaa.bbb.Soap">
<cxf:features>
<spring:bean class="sandbox.StackTraceFeature" id="stackTraceService"/>
</cxf:features>
</cxf:jaxws-service>
</http:inbound-endpoint>
<http:outbound-endpoint
host="localhost"
port="8080"
path="WsFaultResponse/services/Soap"
exchange-pattern="request-response">
<cxf:jaxws-client
clientClass="aaa.bbb.SforceService"
port="Soap"
wsdlLocation="classpath:wsdl/partner.wsdl"
operation="login"
soapVersion="1.1"
enableMuleSoapHeaders="false">
</cxf:jaxws-client>
</http:outbound-endpoint>
<default-exception-strategy>
<processor-chain>
<object-to-string-transformer/>
<file:outbound-endpoint path="data/exception" outputPattern="#[function:datestamp:yyyyMMddHHmmss].err"/>
</processor-chain>
</default-exception-strategy>
<!-- <custom-exception-strategy class="exception.TestExceptionListener"/> -->
</flow>
在流動的註釋掉的部分中提到的定製策略是微不足道的(基本上相同,一個在其文檔中):
public class TestExceptionListener extends DefaultMessagingExceptionStrategy {
public TestExceptionListener(MuleContext muleContext) {
super(muleContext);
}
private MuleEvent handle(Exception ex, MuleEvent event, RollbackSourceCallback rollbackMethod) {
logger.warn("Exception: " + ex.getMessage());
Object payloadBefore = event.getMessage().getPayload();
MuleEvent result = super.handleException(ex, event, rollbackMethod);
result.getMessage().setPayload(payloadBefore);
return result;
}
@Override
public MuleEvent handleException(Exception ex, MuleEvent event) {
return handle(ex, event, null);
}
@Override
public MuleEvent handleException(Exception ex, MuleEvent event, RollbackSourceCallback rollbackMethod) {
return handle(ex, event, rollbackMethod);
}
}
當我用上面的配置運行Mule服務器,我沒有得到我期望的輸出。我的期望是,默認異常策略應該在異常目錄中生成一個文件,但這不會發生。 Java策略應該將消息記錄到控制檯中,但同樣,我看不到任何東西......放置在句柄方法中的斷點根本不會觸發。
在此先感謝您的幫助。
設法找出問題,所以我要問:做遠程的服務回報HTTP 5XX錯誤,將所有來電? –
是的,我正在測試的服務返回500. – minimal
最後問題是與Mule版本。我能夠在3.3.0-R3版本中使用它。我最終編寫了自己的簡單轉換器,從異常中獲取堆棧跟蹤,並能夠使用默認異常策略和自定義異常策略。 – minimal