apachecamel:向throwexception语句添加参数

pieyvz9o  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(280)

我有一个自定义的异常类customexception,调用它时需要三个参数(两个整数和字符串)。
目前在camel.xml文件中,我有:

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

抛出异常时,我想要的特定变量为null。如何在camel中设置该变量?有可能吗?

mw3dktmi

mw3dktmi1#

您可以将异常定义为具有自定义构造函数参数和属性值的单独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>

相关问题