Search in sources :

Example 11 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class ErrorHandlerAdviceIssueTest method testErrorHandlerAdvice.

public void testErrorHandlerAdvice() throws Exception {
    RouteDefinition foo = context.getRouteDefinition("foo");
    foo.adviceWith(context, new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("seda:*").skipSendToOriginalEndpoint().throwException(new IllegalAccessException("Forced"));
        }
    });
    RouteDefinition error = context.getRouteDefinition("error");
    error.adviceWith(context, new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("file:*").skipSendToOriginalEndpoint().to("mock:file");
        }
    });
    getMockEndpoint("mock:error").expectedMessageCount(1);
    getMockEndpoint("mock:file").expectedMessageCount(1);
    // should be intercepted
    getMockEndpoint("mock:foo").expectedMessageCount(0);
    context.stopRoute("timer");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 12 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class AdviceWithIssueTest method testAdviceWithOnCompletion.

public void testAdviceWithOnCompletion() throws Exception {
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            onCompletion().to("mock:done");
        }
    });
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:done").expectedBodiesReceived("Hello World");
    template.sendBody("direct:start", "World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 13 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class AdviceWithIssueTest method testAdviceWithOnException.

public void testAdviceWithOnException() throws Exception {
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            onException(IllegalArgumentException.class).handled(true).to("mock:error");
        }
    });
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:error").expectedBodiesReceived("Kaboom");
    template.sendBody("direct:start", "World");
    template.sendBody("direct:start", "Kaboom");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 14 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class AdviceWithIssueTest method testAdviceWithErrorHandler.

public void testAdviceWithErrorHandler() throws Exception {
    RouteDefinition route = context.getRouteDefinitions().get(0);
    try {
        route.adviceWith(context, new AdviceWithRouteBuilder() {

            @Override
            public void configure() throws Exception {
                errorHandler(deadLetterChannel("mock:dead"));
            }
        });
        fail("Should have thrown exception");
    } catch (IllegalArgumentException e) {
        assertEquals("You can not advice with error handlers. Remove the error handlers from the route builder.", e.getMessage());
    }
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 15 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class AdviceWithInterceptSendToEndpointWithLoadbalancerTest method testInterceptSendToEndpoint.

public void testInterceptSendToEndpoint() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").loadBalance().failover().to("seda:end1", "seda:end2");
        }
    });
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new RouteBuilder() {

        public void configure() throws Exception {
            interceptSendToEndpoint("seda:end1").skipSendToOriginalEndpoint().to("mock:end");
        }
    });
    context.start();
    getMockEndpoint("mock:end").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) RouteDefinition(org.apache.camel.model.RouteDefinition)

Aggregations

RouteDefinition (org.apache.camel.model.RouteDefinition)102 AdviceWithRouteBuilder (org.apache.camel.builder.AdviceWithRouteBuilder)17 RouteBuilder (org.apache.camel.builder.RouteBuilder)17 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 FromDefinition (org.apache.camel.model.FromDefinition)9 HashMap (java.util.HashMap)6 Processor (org.apache.camel.Processor)6 ConnectException (java.net.ConnectException)5 Exchange (org.apache.camel.Exchange)5 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)5 IOException (java.io.IOException)4 Map (java.util.Map)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)4 HystrixConfigurationDefinition (org.apache.camel.model.HystrixConfigurationDefinition)4 HystrixDefinition (org.apache.camel.model.HystrixDefinition)4 LogDefinition (org.apache.camel.model.LogDefinition)4 ModelCamelContext (org.apache.camel.model.ModelCamelContext)4