Skip to content

Instantly share code, notes, and snippets.

Created November 18, 2013 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7534990 to your computer and use it in GitHub Desktop.
Save anonymous/7534990 to your computer and use it in GitHub Desktop.
package nl.hu.esb.nps.internal.route.exceptionflowtodlqs;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.cxf.binding.soap.SoapFault;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
public class TestClass extends CamelTestSupport {
@Override
public boolean isUseRouteBuilder() {
return false;
}
@Test
public void testBlaat() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Exception.class)
.log(LoggingLevel.INFO, "outer catch")
//.markRollbackOnly()
.handled(true)
;
from("direct:start")
.doTry()
.to("mock:exception")
.doCatch(Exception.class)
.log(LoggingLevel.INFO, "inner catch")
.to("mock:count")
.end();
}
});
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:exception").throwException(new Exception());
}
});
context.start();
template.sendBody("direct:start", "start");
MockEndpoint endpoint = getMockEndpoint("mock:count");
endpoint.expectedMessageCount(1);
assertMockEndpointsSatisfied();
}
}
@christian-posta
Copy link

change line 46-51 to this:

context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@OverRide
public void configure() throws Exception {
interceptSendToEndpoint("mock:exception").skipSendToOriginalEndpoint().
throwException(new Exception());
}
});

@christian-posta
Copy link

Scratch that. I just tried it myself. You should use the method explained in my mailing list response. Using a separate adviceWith route builder will create a new "route" channel http://camel.apache.org/message-channel.html and the channel at that point does not see a try/catch which is constructed in the original route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment