Search in sources :

Example 96 with CamelExecutionException

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

the class SedaNoConsumerTest method testInOut.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").to("seda:foo?timeout=1000");
        }
    });
    context.start();
    try {
        template.requestBody("direct:start", "Hello World");
        fail("Should throw an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) CamelExecutionException(org.apache.camel.CamelExecutionException)

Example 97 with CamelExecutionException

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

the class ExceptionThrownFromOnExceptionNoEndlessLoopTest method testExceptionThrownFromOnExceptionNoEndlessLoopTest.

public void testExceptionThrownFromOnExceptionNoEndlessLoopTest() throws Exception {
    RETRY.set(0);
    ON_EXCEPTION_RETRY.set(0);
    ON_EXCEPTION_2_RETRY.set(0);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            onException(IOException.class).maximumRedeliveries(3).to("mock:b").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    ON_EXCEPTION_RETRY.incrementAndGet();
                    // then go into endless loop
                    throw new IllegalArgumentException("Not supported");
                }
            }).to("mock:c");
            onException(IllegalArgumentException.class).to("mock:d").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    ON_EXCEPTION_2_RETRY.incrementAndGet();
                    throw new IOException("Some other IOException");
                }
            }).to("mock:e");
            from("direct:start").to("direct:intermediate").to("mock:result");
            from("direct:intermediate").to("mock:a").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    RETRY.incrementAndGet();
                    throw new IOException("IO error");
                }
            }).to("mock:end");
        }
    });
    context.start();
    getMockEndpoint("mock:a").expectedMessageCount(1);
    getMockEndpoint("mock:b").expectedMessageCount(1);
    getMockEndpoint("mock:c").expectedMessageCount(0);
    getMockEndpoint("mock:d").expectedMessageCount(0);
    getMockEndpoint("mock:e").expectedMessageCount(0);
    getMockEndpoint("mock:result").expectedMessageCount(0);
    getMockEndpoint("mock:end").expectedMessageCount(0);
    try {
        template.sendBody("direct:start", "Hello World");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("Not supported", cause.getMessage());
    }
    assertMockEndpointsSatisfied();
    assertEquals("Should try 4 times (1 first, 3 retry)", 4, RETRY.get());
    assertEquals("Should only invoke onException once", 1, ON_EXCEPTION_RETRY.get());
    assertEquals("Should not be invoked", 0, ON_EXCEPTION_2_RETRY.get());
}
Also used : Exchange(org.apache.camel.Exchange) CamelExecutionException(org.apache.camel.CamelExecutionException) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) IOException(java.io.IOException) CamelExecutionException(org.apache.camel.CamelExecutionException) IOException(java.io.IOException)

Example 98 with CamelExecutionException

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

the class ExceptionThrownFromOnExceptionTest method testExceptionThrownFromOnExceptionAndHandledWithDeadLetterChannel.

public void testExceptionThrownFromOnExceptionAndHandledWithDeadLetterChannel() throws Exception {
    RETRY.set(0);
    ON_EXCEPTION_RETRY.set(0);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // DLC
            deadLetterChannel("mock:error").redeliveryDelay(0).maximumRedeliveries(3);
            // on exception to catch all IO exceptions and handle them specially
            onException(IOException.class).maximumRedeliveries(3).handled(true).to("mock:b").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    ON_EXCEPTION_RETRY.incrementAndGet();
                    throw new IOException("Some other IOException");
                }
            }).to("mock:c");
            from("direct:start").to("direct:intermediate").to("mock:result");
            from("direct:intermediate").to("mock:a").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    RETRY.incrementAndGet();
                    throw new IOException("IO error");
                }
            }).to("mock:end");
        }
    });
    context.start();
    getMockEndpoint("mock:a").expectedMessageCount(1);
    getMockEndpoint("mock:b").expectedMessageCount(1);
    getMockEndpoint("mock:c").expectedMessageCount(0);
    getMockEndpoint("mock:result").expectedMessageCount(0);
    getMockEndpoint("mock:end").expectedMessageCount(0);
    // the error will not be handled by DLC since we had an onException, and that failed,
    // so the exchange will throw an exception
    getMockEndpoint("mock:error").expectedMessageCount(0);
    try {
        template.sendBody("direct:start", "Hello World");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        IOException cause = assertIsInstanceOf(IOException.class, e.getCause());
        assertEquals("Some other IOException", cause.getMessage());
    }
    assertMockEndpointsSatisfied();
    assertEquals("Should try 4 times (1 first, 3 retry)", 4, RETRY.get());
    assertEquals("Should only invoke onException once", 1, ON_EXCEPTION_RETRY.get());
}
Also used : Exchange(org.apache.camel.Exchange) CamelExecutionException(org.apache.camel.CamelExecutionException) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) IOException(java.io.IOException) CamelExecutionException(org.apache.camel.CamelExecutionException) IOException(java.io.IOException)

Example 99 with CamelExecutionException

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

the class CharlesSplitAndTryCatchRollbackIssueTest method testSplitWithTryCatchAndRollbackException.

public void testSplitWithTryCatchAndRollbackException() throws Exception {
    MockEndpoint split = getMockEndpoint("mock:split");
    MockEndpoint ile = getMockEndpoint("mock:ile");
    MockEndpoint exception = getMockEndpoint("mock:exception");
    split.expectedBodiesReceived("A", "B");
    ile.expectedMessageCount(0);
    exception.expectedMessageCount(1);
    try {
        template.sendBody("direct:start", "A,B,Kaboom,C");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException ee = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(ee.getMessage().startsWith("Sequential processing failed for number 2."));
        RollbackExchangeException re = assertIsInstanceOf(RollbackExchangeException.class, ee.getCause());
        assertTrue(re.getMessage().startsWith("Intended rollback"));
    }
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RollbackExchangeException(org.apache.camel.RollbackExchangeException)

Example 100 with CamelExecutionException

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

the class EvaluateExpressionProcessorTest method testFail.

public void testFail() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    try {
        template.sendBody("direct:fail", "World");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("Forced", e.getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Aggregations

CamelExecutionException (org.apache.camel.CamelExecutionException)156 RouteBuilder (org.apache.camel.builder.RouteBuilder)69 Test (org.junit.Test)64 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)59 Exchange (org.apache.camel.Exchange)23 CamelContext (org.apache.camel.CamelContext)20 Processor (org.apache.camel.Processor)17 ProducerTemplate (org.apache.camel.ProducerTemplate)17 CamelExchangeException (org.apache.camel.CamelExchangeException)13 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)13 IOException (java.io.IOException)12 Date (java.util.Date)11 StopWatch (org.apache.camel.util.StopWatch)10 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)7 Set (java.util.Set)6 Subject (javax.security.auth.Subject)6 ConstraintViolation (javax.validation.ConstraintViolation)6 FailedLoginException (javax.security.auth.login.FailedLoginException)5 QuartzComponent (org.apache.camel.component.quartz.QuartzComponent)5 File (java.io.File)4