2017-09-04 102 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>