Search in sources :

Example 6 with CamelExchangeException

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

the class CharlesSplitAndTryCatchRollbackIssueTest method testSplitWithTryCatchAndRollbacILEAndException.

public void testSplitWithTryCatchAndRollbacILEAndException() throws Exception {
    MockEndpoint split = getMockEndpoint("mock:split");
    MockEndpoint ile = getMockEndpoint("mock:ile");
    MockEndpoint exception = getMockEndpoint("mock:exception");
    split.expectedBodiesReceived("A", "B");
    ile.expectedMessageCount(1);
    exception.expectedMessageCount(1);
    try {
        template.sendBody("direct:start", "A,Forced,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 3."));
        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 7 with CamelExchangeException

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

the class FailOverLoadBalanceWrappedExceptionTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            from("direct:start").loadBalance().failover(IOException.class).to("direct:x", "direct:y", "direct:z");
            from("direct:x").to("mock:x").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    // socket exception is an io exception
                    throw new CamelExchangeException("foo", exchange, new SocketException("Forced"));
                }
            });
            from("direct:y").to("mock:y").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    throw new IOException("Forced");
                }
            });
            from("direct:z").to("mock:z");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) CamelExchangeException(org.apache.camel.CamelExchangeException) SocketException(java.net.SocketException) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) IOException(java.io.IOException) SocketException(java.net.SocketException) IOException(java.io.IOException) CamelExchangeException(org.apache.camel.CamelExchangeException)

Example 8 with CamelExchangeException

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

the class FailOverLoadBalanceMultipleExceptionTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            from("direct:start").loadBalance().failover(IllegalArgumentException.class, IOException.class, CamelException.class).to("direct:x", "direct:y", "direct:z");
            from("direct:x").to("mock:x").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    throw new CamelExchangeException("Forced", exchange);
                }
            });
            from("direct:y").to("mock:y").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    throw new IOException("Forced");
                }
            });
            from("direct:z").to("mock:z");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) CamelExchangeException(org.apache.camel.CamelExchangeException) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelException(org.apache.camel.CamelException) IOException(java.io.IOException) IOException(java.io.IOException) CamelExchangeException(org.apache.camel.CamelExchangeException) CamelException(org.apache.camel.CamelException)

Example 9 with CamelExchangeException

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

the class AggregateIgnoreInvalidCorrelationKeysTest method testAggregateNotIgnoreInvalidCorrelationKeys.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(2).to("mock:result");
        }
    });
    context.start();
    getMockEndpoint("mock:result").expectedBodiesReceived("A+C");
    template.sendBodyAndHeader("direct:start", "A", "id", 1);
    try {
        template.sendBodyAndHeader("direct:start", "B", "id", null);
        fail("Should throw an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(cause.getMessage().startsWith("Invalid correlation key"));
    }
    template.sendBodyAndHeader("direct:start", "C", "id", 1);
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException) RouteBuilder(org.apache.camel.builder.RouteBuilder) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException)

Example 10 with CamelExchangeException

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

the class ThrowExceptionProcessor method process.

public boolean process(Exchange exchange, AsyncCallback callback) {
    Exception cause = exception;
    try {
        if (message != null && type != null) {
            // create the message using simple language so it can be dynamic
            String text = simple.evaluate(exchange, String.class);
            // create a new exception of that type, and provide the message as
            Constructor<?> constructor = type.getDeclaredConstructor(String.class);
            cause = (Exception) constructor.newInstance(text);
            exchange.setException(cause);
        } else {
            exchange.setException(cause);
        }
    } catch (Throwable e) {
        exchange.setException(new CamelExchangeException("Error creating new instance of " + exception.getClass(), exchange, e));
    }
    callback.done(true);
    return true;
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) CamelExchangeException(org.apache.camel.CamelExchangeException)

Aggregations

CamelExchangeException (org.apache.camel.CamelExchangeException)82 IApplication (com.openshift.client.IApplication)23 Exchange (org.apache.camel.Exchange)17 IOException (java.io.IOException)10 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)8 IEnvironmentVariable (com.openshift.client.IEnvironmentVariable)5 InputStream (java.io.InputStream)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 AsyncCallback (org.apache.camel.AsyncCallback)5 CamelExecutionException (org.apache.camel.CamelExecutionException)5 Message (org.apache.camel.Message)5 File (java.io.File)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Processor (org.apache.camel.Processor)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 IEmbeddedCartridge (com.openshift.client.cartridge.IEmbeddedCartridge)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Serializable (java.io.Serializable)3 URI (java.net.URI)3 List (java.util.List)3