Uploaded image for project: 'FUSE Mediation Router'
  1. FUSE Mediation Router
  2. MR-109

Camel DeadLetterChannel processor should set handled exception to "in" message header properties in order to propagate it to receiver service

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Major Major
    • 1.5.2.0-fuse
    • 1.5.0.0-fuse
    • None
    • None

      Please see attached test case that exposes described problem. The camel route from wsdl-first-cxf-camel-su\src\main\resources\camel-context.xml is defined as:

      <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
          <route errorHandlerRef="deadLetterErrorHandler">
              <from uri="jbi:service:http://servicemix.apache.org/samples/wsdl-first/PersonServiceProviderHandler" />
      	<onException>
                  <!-- Catch exception from in-only message exchange -->
      	    <exception>org.apache.servicemix.jbi.FaultException</exception>
      	    <!-- Catch exception from robust-in-only message exchange -->
      	    <exception>org.apache.camel.CamelException</exception>
      	    <redeliveryPolicy maximumRedeliveries="0"/>
      	    <handled>
      		<constant>true</constant>
      	    </handled>	   
      	    <to uri="jbi:service:http://servicemix.apache.org/samples/wsdl-first/async-bridge?mep=robust-in-only" />
      	</onException>
      	<interceptor ref="handleFaultProcessor">
      	    <to uri="jbi:service:http://servicemix.apache.org/samples/wsdl-first/pipeline?mep=robust-in-only" />
      	</interceptor>
          </route>
      </camelContext>
      

      So the fault will be caught and handled by DeadLetterChannel. However, the original exception was not propagated to the receiver service (here is "jbi:service:http://servicemix.apache.org/samples/wsdl-first/async-bridge?mep=robust-in-only") since the exception was only added to property FAILURE_HANDLED_PROPERTY of the Camel Exchange rather than "in" message header property so the Camel only sends "in" message of the Camel Exchange to the receiver service. Hence the original exception got lost.

      The source code for the org.apache.camel.builder.DeadLetterChannelBuilder setFailureHandled() function is as below:

      public static void setFailureHandled(Exchange exchange) {
          exchange.setProperty(FAILURE_HANDLED_PROPERTY, exchange.getException());
          exchange.setException(null);
      }
      

      So if we change it to something like:

      public static final String CAUGHT_EXCEPTION_PROPERTY = "caught.exception";
      ...
      public static void setFailureHandled(Exchange exchange) {
          exchange.setProperty(FAILURE_HANDLED_PROPERTY, exchange.getException());
          // set "caught.exception" property to "in" message header so we won't 
          // lose the original exception when sending it to receiver service
          exchange.getIn().setHeader(CAUGHT_EXCEPTION_PROPERTY, exchange.getException());
          exchange.setException(null);
      }
      

      The original exception will be maintained in the "in" message part header property of the Camel exchange and will be propagated to the receiver service if the receiver service is defined.

            janstey@redhat.com Jonathan Anstey
            rhn-support-qluo Joe Luo
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: