How to define exception to be thrown through ref in Apache Camel

瘦欲@ 提交于 2021-01-21 12:10:29

问题


Have to throw an exception in my camel route defined in XML. Found throwException statement available from Camel 2.3 which looks like:

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

However, I don't know how to define forced exception class to be thrown. Since same exception could be thrown couple of times with different exception messages - would be good to know if throwException has some other form of definition so exception class and exception message are defined in-place.


回答1:


The ref is just a reference to a so you can do

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

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



回答2:


Since version 2.16.0 there is more elegant way to do it, with optional exception message:

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


来源:https://stackoverflow.com/questions/5839612/how-to-define-exception-to-be-thrown-through-ref-in-apache-camel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!