我使用的是Mule Community Edition 3.4。 我有一個與UntilSuccessful組件有關的問題。該場景現已公開: 我有一個由UntilSuccessful組件構成的流程,其中有一個SOAP組件向Web服務發出請求。在這個流程中也有一個ExcpetionStrategy。我遇到的問題是,當UntilSuccessful內部發生異常(即在SOAP組件中)時,ExcpetionStrategy無法處理它,因爲它(Exception thrown)由UntilSuccessful組件內的某個機制處理。 因爲我需要在ExcpetionStrategy中處理異常,所以我想構建一個攔截SOAP響應的自定義出站攔截器(如果引發了異常,那麼它將引發異常以便觸發) ExcpetionStrategy。 任何人都可以幫助我解決這個問題嗎?我試圖閱讀文檔,但它很稀疏,並不能很好地解釋如何構建自定義出站異常。 我想要做的是保存某個地方的拋出異常的名稱(即如果服務器拋出一個NumberFormatException,我會保存它的名字以便在ExceptionStrategy中使用它)用SOAP Web Service構建自定義攔截器MULE
下面你可以看到一段代碼mule配置文件:
<flow name="ProvaClient" doc:name="ProvaClient">
<quartz:inbound-endpoint jobName="TalendJob" repeatInterval="5000" repeatCount="0" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job>
<quartz:payload>error</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<object-to-string-transformer doc:name="Object to String"/>
<until-successful objectStore-ref="OS_Bean" maxRetries="2" secondsBetweenRetries="2" doc:name="Until Successful" deadLetterQueue-ref="myQueue">
<processor-chain doc:name="Processor Chain: Wait For Web Service Response">
<processor-chain doc:name="Processor Chain: Web Service">
<cxf:jaxws-client operation="getCode" clientClass="it.aizoon.prova.client.ProvaService" port="ProvaPort" enableMuleSoapHeaders="true" doc:name="SOAP">
</cxf:jaxws-client>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="service/prova" method="POST" doc:name="HTTP"/>
</processor-chain>
<logger message="PAYLOAD: #[payload]" level="INFO" doc:name="Logger"/>
</processor-chain>
</until-successful>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<!-- <processor ref="myExceptionHandler_id"/> -->
<logger message="EXCEPTION STRATEGY" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</flow>
在這裏你可以看到它公開了一個Web服務的服務器:
<flow name="provaServer" doc:name="provaServer">
<http:inbound-endpoint exchange-pattern="request-response" doc:name="HTTP" host="localhost" path="service/prova" port="8081"/>
<logger message="SERVER" level="INFO" doc:name="Logger"/>
<cxf:jaxws-service serviceClass="it.aizoon.prova.Prova" doc:name="Process SOAP Request" />
<component class="it.aizoon.prova.ProvaImpl" doc:name="Java"/>
</flow>
而這裏是ProvaImpl.java,Web服務的實現。怎麼可以看到,如果字符串作爲參數中引用代碼()函數是錯誤時,拋出一個異常,我想,這是由客戶端定義的例外策略
@WebService(endpointInterface = "it.aizoon.prova.Prova",
serviceName = "Prova")
public class ProvaImpl implements Prova{
@Override
public String getCode(String code) throws NumberFormatException{
// TODO Auto-generated method stub
if(code.equals("error")) throw new NumberFormatException();
String str = "Andato a buon fine!";
return str;
}
}
首先感謝你爲重sponse。如果getCode()返回像NumberFormatException這樣的異常,那麼如何在異常策略中的消息中將此異常名稱設置爲負載?我的目標是發送帶有例外的郵件。我不想獲取SOAPFaultException,但NumberFormatException –
更新了答案,以及如何設置有效負載或異常等。 –
對不起Ryan,更新在哪裏? –