1
votes

I am new to camel (v 2.10.0) and searching for a problem that i have due to exceptions that we throw in routes which are called by wireTap().

PROBLEM: is that when exception are thrown from wiretap routes then error handling do not run for these exceptions. When we change calls to direct "to()" calls then we have proper error handling. WireTap as per my understanding should also use same ErrorHandlerBuilder that is working for other routes in same RouteBuilder class.

We have our ErrorHandlerBuilder, that is configured per camel context as (in OSGI blueprints)

<camelContext id="ourHandlerContext" trace="false" errorHandlerRef="ourErrorHandlerBuilder"
    xmlns="http://camel.apache.org/schema/blueprint">
 <routeBuilder ref="ourHandlerRouteBuilder"/>

</camelContext>

But our camel routes are in Java ourHandlerRouteBuilder class configure() method have something like this:

from("direct-vm:start").routeId("start")          
    .wireTap("direct-vm:wiretap_exception")
    .to("direct-vm:endroute_last");

    from("direct-vm:wiretap_exception").routeId("wiretap_exception")
    .process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            throw new Exception("I AM EXCEPTION");
        }
    })
    ;

    from("direct-vm:endroute_last").routeId("endroute_last")
    .process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            throw new Exception("I AM ALSO EXCEPTION");
        }
    })
    ;

The "I AM EXCEPTION" never caught alone when thrown but when i throw also "I AM ALSO EXCEPTION" then i can see it in ErrorHandler.

We have our some complex translators over these exceptions to translate to some http error code that i think not necessary here to share.

But from above scenario if some body can share his thoughts will be helping.

2

2 Answers

2
votes

wireTap runs asynchronously thus you cant wait to catch its exceptions. If you want to run it synchronously and wait for possible exceptions, you can use enrich instead.

Something like this:

    .enrich("direct-vm:wiretap_exception", new AggregationStrategy() {
        @Override
        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
            return oldExchange;
        }        
    })
0
votes

I am also experiencing a similar issue. If an exception throws inside the wiretapped subroute "anotherRoute", the onException block does not executed. What should be the solution to create custom error handling in the wiretapped route? Camel version: 3.1.0

from("rest:POST:/order")
  .wiretap("direct:anotherRoute");
  
from("direct:anotherRoute")
 .onException(Exception.class)
   .doErrorHandlingThings(...)
   .handled(true)
   .stop()
 .end()
 .process(dobusinessLogicNormally);

However when placing the onException() block outside of wiretapped route to a global scope it works as should.

 onException(Exception.class)
   .doErrorHandlingThings(...)
   .handled(true)
   .stop()
 .end();


from("rest:POST:/order")
  .wiretap("direct:anotherRoute");

from("direct:anotherRoute")
  .exceptionThrow()