Apache camel: Adding parameters to throwException statement

1.8k views Asked by At

I have a custom exception class, customException, which when called is needing three parameters (two integers and String).

Currently in my camel.xml file I have:

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

When the exception is thrown, specific variable(s) I want is null. How could set that variable within Camel? is it possible?

1

There are 1 answers

0
Andrew Lygin On

You can define your exception as a separate bean with custom constructor arguments and property values, and reference it from 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>