use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithContextScopedErrorHandlerIssueTest method testAdviceWith.
public void testAdviceWith() throws Exception {
context.getRouteDefinition("route-a").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("direct:bar").skipSendToOriginalEndpoint().throwException(new IllegalArgumentException("Forced"));
}
});
getMockEndpoint("mock:error").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(0);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithInterceptTest method testAdviceIntercept.
public void testAdviceIntercept() throws Exception {
getMockEndpoint("mock:advice").expectedMessageCount(1);
context.getRouteDefinition("main").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveAddFirst().to("direct:advice");
}
});
template.sendBody("direct:main", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithWeaveFirstLastTest method testWeaveAddFirst.
public void testWeaveAddFirst() throws Exception {
// START SNIPPET: e1
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// insert at first the given piece of route to the existing route
weaveAddFirst().to("mock:a").transform(constant("Bye World"));
}
});
// END SNIPPET: e1
getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:foo").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithWeaveLastCBRTest method testWeaveAddLast.
public void testWeaveAddLast() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// insert at the end of the existing route, the given piece of route
weaveAddLast().to("mock:last");
}
});
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(0);
getMockEndpoint("mock:last").expectedMessageCount(1);
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "yeah");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTasksTest method testBefore.
public void testBefore() throws Exception {
// START SNIPPET: e3
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// weave the node in the route which has id = bar
// and insert the following route path before the adviced node
weaveById("bar").before().to("mock:a").transform(constant("Bye World"));
}
});
// END SNIPPET: e3
getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
Aggregations