如何在Apache Camel中定义通过ref抛出的异常

时间:2011-04-30 04:50:50

标签: apache-camel

必须在XML中定义的camel路由中抛出异常。找到了Camel 2.3提供的throwException声明,如下所示:

 <throwException ref="forced"></throwException>

但是,我不知道如何定义要引发的forced异常类。由于可以使用不同的异常消息多次抛出相同的异常 - 最好知道throwException是否具有其他形式的定义,因此异常类和异常消息是就地定义的。

2 个答案:

答案 0 :(得分:18)

ref只是对a的引用,所以你可以做到

<bean id="forced" class="java.lang.IllegalArgumentException">
   <constructor-arg index="0" value="This is forced"/>
</bean>

<camelContext ...>
  ...
</camelContext>

答案 1 :(得分:8)

从版本2.16.0开始,有更优雅的方法,可选的异常消息:

<route>
     <throwException exceptionType="java.lang.IllegalArgumentException" message="illegal argument found"/>
</route>
相关问题