2017-09-04 131 views
0

我有一個自定義的異常類customException,它在被調用時需要三個參數(兩個整數和字符串)。Apache駱駝:添加參數throwException語句

目前在我camel.xml文件我有:

<onException> 
    <exception>org.apache.camel.http.common.HttpOperationFailedException</exception> 
    <throwException exceptionType="package.path.of.customException" message="custom message" /> 
</onException> 

當異常被拋出,我想具體的變量(S)爲空。如何在Camel中設置該變量?可能嗎?

回答

2

您可以定義例外,因爲自定義構造函數參數和屬性值一個單獨的bean,並從throwException引用它:

<bean id="myException" class="package.path.of.customException"> 
    <constructor-arg index="0" value="Custom message"/> 
    <property name="someIntProperty" value="10"/> 
    <property name="anotherIntProperty" value="#{null}"/> 
</bean> 

<camelContext ...> 
    <onException> 
    <exception>org.apache.camel.http.common.HttpOperationFailedException.HttpOperationFailedException</exception> 
    <throwException ref="myException" /> 
    </onException> 
</camelContext>