Created
November 18, 2013 20:45
-
-
Save anonymous/7534990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
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
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());
}
});