Search in sources :

Example 21 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class VmInOutChainedTimeoutTest method testVmInOutChainedTimeout.

public void testVmInOutChainedTimeout() throws Exception {
    StopWatch watch = new StopWatch();
    try {
        template2.requestBody("vm:a?timeout=1000", "Hello World");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        // the chained vm caused the timeout
        ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
        assertEquals(200, cause.getTimeout());
    }
    long delta = watch.stop();
    assertTrue("Should be faster than 1 sec, was: " + delta, delta < 1100);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) StopWatch(org.apache.camel.util.StopWatch)

Example 22 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class RecipientListFineGrainedErrorHandlingTest method testRecipientListAsBeanError.

public void testRecipientListAsBeanError() throws Exception {
    counter = 0;
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            context.setTracing(true);
            onException(Exception.class).maximumRedeliveries(2);
            from("direct:start").to("mock:a").bean(MyRecipientBean.class);
        }
    });
    context.start();
    getMockEndpoint("mock:a").expectedMessageCount(1);
    getMockEndpoint("mock:foo").expectedMessageCount(1);
    getMockEndpoint("mock:bar").expectedMessageCount(1);
    getMockEndpoint("mock:baz").expectedMessageCount(0);
    try {
        template.sendBody("direct:start", "Hello World");
        fail("Should throw exception");
    } catch (CamelExecutionException e) {
        // expected
        assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
        assertEquals("Damn", e.getCause().getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
    assertEquals(3, counter);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException)

Example 23 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class OnCompletionAsyncTest method testAsyncFailureUseOriginalBody.

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

        @Override
        public void configure() throws Exception {
            onCompletion().useOriginalBody().parallelProcessing().to("mock:before").delay(1000).setBody(simple("OnComplete:${body}")).to("mock:after");
            from("direct:start").transform(body().prepend("Before:${body}")).process(new MyProcessor()).to("mock:result");
        }
    });
    context.start();
    getMockEndpoint("mock:before").expectedBodiesReceived("Kabom");
    getMockEndpoint("mock:before").expectedPropertyReceived(Exchange.ON_COMPLETION, true);
    getMockEndpoint("mock:after").expectedBodiesReceived("OnComplete:Kabom");
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    try {
        template.requestBody("direct:start", "Kabom");
        fail("Should throw exception");
    } catch (CamelExecutionException e) {
        assertEquals("Kabom", e.getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CamelExecutionException(org.apache.camel.CamelExecutionException)

Example 24 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class OnCompletionGlobalTraceTest method testSynchronizeFailure.

public void testSynchronizeFailure() throws Exception {
    getMockEndpoint("mock:sync").expectedMessageCount(1);
    getMockEndpoint("mock:sync").expectedPropertyReceived(Exchange.ON_COMPLETION, true);
    getMockEndpoint("mock:trace").expectedMessageCount(3);
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    try {
        template.sendBody("direct:start", "Kabom");
        fail("Should throw exception");
    } catch (CamelExecutionException e) {
        assertEquals("Kabom", e.getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
    TraceEventMessage msg1 = getMockEndpoint("mock:trace").getReceivedExchanges().get(0).getIn().getBody(TraceEventMessage.class);
    TraceEventMessage msg2 = getMockEndpoint("mock:trace").getReceivedExchanges().get(1).getIn().getBody(TraceEventMessage.class);
    TraceEventMessage msg3 = getMockEndpoint("mock:trace").getReceivedExchanges().get(2).getIn().getBody(TraceEventMessage.class);
    assertEquals("direct://start", msg1.getFromEndpointUri());
    assertEquals("ref:myProcessor", msg1.getToNode());
    assertTrue(msg2.getPreviousNode().startsWith("OnCompletion"));
    assertEquals("log://global", msg2.getToNode());
    assertEquals("log://global", msg3.getPreviousNode());
    assertEquals("mock://sync", msg3.getToNode());
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) TraceEventMessage(org.apache.camel.processor.interceptor.TraceEventMessage)

Example 25 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class RedeliveryErrorHandlerLogHandledTest method testRedeliveryErrorHandlerAllOptions.

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

        @Override
        public void configure() throws Exception {
            errorHandler(defaultErrorHandler().maximumRedeliveries(3).logExhausted(true).logHandled(true).logRetryStackTrace(true).logStackTrace(true).retryAttemptedLogLevel(LoggingLevel.WARN).retriesExhaustedLogLevel(LoggingLevel.ERROR));
            from("direct:bar").throwException(new CamelException("Camel rocks"));
        }
    });
    context.start();
    getMockEndpoint("mock:handled").expectedMessageCount(0);
    try {
        template.sendBody("direct:bar", "Hello World");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        CamelException cause = assertIsInstanceOf(CamelException.class, e.getCause());
        assertEquals("Camel rocks", cause.getMessage());
    }
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelException(org.apache.camel.CamelException) CamelExecutionException(org.apache.camel.CamelExecutionException) CamelException(org.apache.camel.CamelException)

Aggregations

CamelExecutionException (org.apache.camel.CamelExecutionException)140 RouteBuilder (org.apache.camel.builder.RouteBuilder)60 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)58 Test (org.junit.Test)48 Exchange (org.apache.camel.Exchange)23 Processor (org.apache.camel.Processor)17 CamelExchangeException (org.apache.camel.CamelExchangeException)13 IOException (java.io.IOException)12 Date (java.util.Date)11 StopWatch (org.apache.camel.util.StopWatch)10 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)7 QuartzComponent (org.apache.camel.component.quartz.QuartzComponent)5 File (java.io.File)4 Set (java.util.Set)4 ConstraintViolation (javax.validation.ConstraintViolation)4 CamelContext (org.apache.camel.CamelContext)4 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)4 QuartzComponent (org.apache.camel.component.quartz2.QuartzComponent)4 List (java.util.List)3 JSONException (net.sf.json.JSONException)3