Java 类org.apache.camel.CamelExecutionException 实例源码

项目:Camel    文件:BindySimpleCsvMandatoryFieldsUnmarshallTest.java   
@DirtiesContext
@Test
public void testTooMuchFields() throws Exception {

    String record6 = ",,,,,,,,,,,,,,"; // too much data in the record (only
    // 11 are accepted by the model

    resultEndpoint1.expectedMessageCount(0);

    try {
        template1.sendBody(record6);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        // expected
        Assert.isInstanceOf(IllegalArgumentException.class, e.getCause());
    }

    resultEndpoint1.assertIsSatisfied();
}
项目:Camel    文件:RmiDamnExceptionTest.java   
@Test
public void tesDamn() throws Exception {
    if (classPathHasSpaces()) {
        return;
    }

    getMockEndpoint("mock:result").expectedMessageCount(0);

    try {
        template.sendBody("direct:echo", "Hello World");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(DamnException.class, e.getCause());
        assertEquals("Damn this did not work", e.getCause().getMessage());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:JettyAsyncContinuationTimeoutTest.java   
@Test
public void testJettyAsyncTimeout() throws Exception {
    getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");

    StopWatch watch = new StopWatch();
    try {
        template.requestBody("http://localhost:{{port}}/myservice", null, String.class);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        log.info("Timeout hit and client got reply with failure status code");

        long taken = watch.stop();

        HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
        assertEquals(503, cause.getStatusCode());

        // should be approx 3-4 sec.
        assertTrue("Timeout should occur faster than " + taken, taken < 4500);
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java   
@Test
public void testBasicAuth() throws Exception {
    try {
        template.requestBody("netty-http:http://localhost:{{port}}/foo", "Hello World", String.class);
        fail("Should send back 401");
    } catch (CamelExecutionException e) {
        NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
        assertEquals(401, cause.getStatusCode());
    }

    getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");

    // username:password is scott:secret
    String auth = "Basic c2NvdHQ6c2VjcmV0";
    String out = template.requestBodyAndHeader("netty-http:http://localhost:{{port}}/foo", "Hello World", "Authorization", auth, String.class);
    assertEquals("Bye World", out);

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:BeanComponentMissingParenthesisTest.java   
public void testMissing() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                .to("bean:myBean?method=concat(${body}, ${header.foo}")
                .to("mock:result");
        }
    });
    context.start();

    try {
        template.sendBodyAndHeader("direct:start", "Hello", "foo", "Camel");
        fail("Should throw exception");
    } catch (CamelExecutionException e) {
        IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("Method should end with parenthesis, was concat(${body}, ${header.foo}", iae.getMessage());
    }
}
项目:Camel    文件:SpringFinallyNestedFailTest.java   
public void testFailAgain() throws Exception {
    getMockEndpoint("mock:bar").expectedMessageCount(0);
    getMockEndpoint("mock:donkey").expectedMessageCount(1);
    getMockEndpoint("mock:catch").expectedMessageCount(1);
    getMockEndpoint("mock:kong").expectedMessageCount(1);
    getMockEndpoint("mock:finally").expectedMessageCount(1);
    getMockEndpoint("mock:finallyEnd").expectedMessageCount(0);
    getMockEndpoint("mock:end").expectedMessageCount(0);

    try {
        template.sendBody("direct:start", "Donkey Kong");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(IllegalStateException.class, e.getCause());
        assertEquals("Damn Kong", e.getCause().getMessage());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:DirectVmNoConsumerTest.java   
public void testInOut() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct-vm:start").to("direct-vm:foo");
        }
    });

    context.start();

    try {
        template.requestBody("direct-vm:start", "Hello World");
        fail("Should throw an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(DirectVmConsumerNotAvailableException.class, e.getCause());
    }
}
项目:Camel    文件:AsyncEndpointFailedAfterTest.java   
public void testAsyncEndpoint() throws Exception {
    getMockEndpoint("mock:before").expectedBodiesReceived("Hello Camel");
    getMockEndpoint("mock:after").expectedBodiesReceived("Bye Camel");
    getMockEndpoint("mock:result").expectedMessageCount(0);

    try {
        template.requestBody("direct:start", "Hello Camel", String.class);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("Damn", e.getCause().getMessage());
    }

    assertMockEndpointsSatisfied();

    assertFalse("Should use different threads", beforeThreadName.equalsIgnoreCase(afterThreadName));
}
项目:Camel    文件:RmiIllegalArgumentExceptionTest.java   
@Test
public void tesIllegal() throws Exception {
    if (classPathHasSpaces()) {
        return;
    }

    getMockEndpoint("mock:result").expectedMessageCount(0);

    try {
        template.sendBody("direct:echo", "Hello World");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(RemoteException.class, e.getCause());
        // wrapped far down
        IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause().getCause().getCause());
        assertEquals("Illegal", iae.getMessage());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:NotifyBuilderTest.java   
public void testTwoWereSentToDoneAndFailed() throws Exception {
    // we expect 2+ done messages which were sent to mock:bar
    // and 1+ failed message which were sent to mock:fail
    NotifyBuilder notify = new NotifyBuilder(context)
            .whenDone(2).wereSentTo("mock:bar")
            .and()
            .whenFailed(1).wereSentTo("mock:fail")
            .create();

    template.sendBody("direct:bar", "Hello World");
    assertEquals(false, notify.matches());

    template.sendBody("direct:bar", "Hello World");
    assertEquals(false, notify.matches());

    template.sendBody("direct:foo", "Hello World");
    assertEquals(false, notify.matches());

    try {
        template.sendBody("direct:fail", "Bye World");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        // expected
    }
    assertEquals(true, notify.matches());
}
项目:Camel    文件:RestRestletPostJsonPojoOnExceptionTest.java   
@Test
public void testRestletPostPojoError() throws Exception {
    getMockEndpoint("mock:input").expectedMessageCount(0);
    getMockEndpoint("mock:error").expectedMessageCount(1);

    String body = "This is not json";
    try {
        template.sendBody("http://localhost:" + portNum + "/users/new", body);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
        assertEquals(400, cause.getStatusCode());
        assertEquals("Invalid json data", cause.getResponseBody());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:RouteScopedErrorHandlerAndOnExceptionTest.java   
public void testOnException() throws Exception {
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("seda:*")
                .skipSendToOriginalEndpoint()
                .throwException(new ConnectException("Forced"));
        }
    });

    getMockEndpoint("mock:local").expectedMessageCount(0);
    getMockEndpoint("mock:seda").expectedMessageCount(0);
    // we fail all redeliveries so after that we send to mock:exhausted
    getMockEndpoint("mock:exhausted").expectedMessageCount(1);

    try {
        template.sendBody("direct:start", "Hello World");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        ConnectException cause = assertIsInstanceOf(ConnectException.class, e.getCause());
        assertEquals("Forced", cause.getMessage());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:XPathLanguageSingleNodeListTest.java   
/**
 * Regression test to ensure that a NodeList of length > 1 is not processed by the new converters.
 * @throws Exception
 */
@Test
public void testMultipleNodeList() throws Exception {
    getMockEndpoint("mock:found").expectedMessageCount(0);
    getMockEndpoint("mock:found").setResultWaitTime(500);
    getMockEndpoint("mock:notfound").expectedMessageCount(0);
    getMockEndpoint("mock:notfound").setResultWaitTime(500);

    try {
        template.requestBody("direct:doTest", XML_INPUT_MULTIPLE, String.class);
        fail("NoTypeConversionAvailableException expected");
    } catch (CamelExecutionException ex) {
        assertEquals(RuntimeCamelException.class, ex.getCause().getClass());
        assertEquals(NoTypeConversionAvailableException.class, ex.getCause().getCause().getClass());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:BeanNoTypeConvertionPossibleWhenHeaderTest.java   
public void testBeanHeaderNoTypeConvertionPossibleFail() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);

    // we send in a bar string as header which cannot be converted to a number so it should fail
    try {
        template.requestBodyAndHeader("direct:start", "Hello World", "foo", 555);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        ParameterBindingException pbe = assertIsInstanceOf(ParameterBindingException.class, e.getCause());
        assertEquals(1, pbe.getIndex());
        assertTrue(pbe.getMethod().getName().contains("hello"));
        assertEquals(555, pbe.getParameterValue());

        NoTypeConversionAvailableException ntae = assertIsInstanceOf(NoTypeConversionAvailableException.class, e.getCause().getCause());
        assertEquals(Integer.class, ntae.getFromType());
        assertEquals(Document.class, ntae.getToType());
        assertEquals(555, ntae.getValue());
        assertNotNull(ntae.getMessage());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:SimpleTest.java   
public void testBodyAs() throws Exception {
    assertExpression("${bodyAs(String)}", "<hello id='m123'>world!</hello>");
    assertExpression("${bodyAs('String')}", "<hello id='m123'>world!</hello>");

    exchange.getIn().setBody(null);
    assertExpression("${bodyAs('String')}", null);

    exchange.getIn().setBody(456);
    assertExpression("${bodyAs(Integer)}", 456);
    assertExpression("${bodyAs(int)}", 456);
    assertExpression("${bodyAs('int')}", 456);

    try {
        assertExpression("${bodyAs(XXX)}", 456);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
    }
}
项目:Camel    文件:RestUndertowHttpBindingModeJsonTest.java   
@Test
public void testBindingModeWrong() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:input");
    mock.expectedMessageCount(0);

    // we bind to json, but send in xml, which is not possible
    String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
    try {
        template.sendBody("http://localhost:" + getPort() + "/users/new", body);
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        // expected
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:OnCompletionAndInterceptTest.java   
public void testSynchronizeFailure() throws Exception {
    getMockEndpoint("mock:intercept").expectedMessageCount(4);
    getMockEndpoint("mock:sync").expectedMessageCount(1);
    getMockEndpoint("mock:sync").expectedPropertyReceived(Exchange.ON_COMPLETION, true);

    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();
}
项目:Camel    文件:BeanOverloadedMethodFQNTest.java   
public void testOrderFQNUnknown() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                .bean(MyBean.class, "order(org.apache.camel.component.bean.BeanOverloadedMethodFQNTest$Unknown)")
                .to("mock:result");

        }
    });
    context.start();

    try {
        template.sendBody("direct:start", new MyOrder());
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        NoTypeConversionAvailableException cause = assertIsInstanceOf(NoTypeConversionAvailableException.class, e.getCause().getCause());
        assertEquals("org.apache.camel.component.bean.BeanOverloadedMethodFQNTest$Unknown", cause.getValue());
    }
}
项目:Camel    文件:BeanOverloadedMethodTest.java   
public void testHelloOverloadedStringInt() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                .bean(MyBean.class, "hello(String,int)")
                .to("mock:result");

        }
    });
    context.start();

    try {
        template.sendBodyAndHeader("direct:start", "Claus", "country", "Denmark");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        AmbiguousMethodCallException cause = assertIsInstanceOf(AmbiguousMethodCallException.class, e.getCause());
        assertEquals(2, cause.getMethods().size());
    }
}
项目:Camel    文件:EnricherAsyncUnhandledExceptionTest.java   
@Test
public void testInOutWithRequestBody() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:pickedUp");
    mock.expectedMessageCount(1);
    // this direct endpoint should receive an exception
    try {
        Future<Object> obj = template.asyncRequestBody("direct:in", "Hello World");
        // wait five seconds at most; else, let's assume something went wrong
        obj.get(5000, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        // if we receive an exception, the async routing engine is working correctly
        // before the Enricher was fixed for cases where routing was async and the AggregationStrategy 
        // threw an exception, the call to requestBody would stall indefinitely
        // unwrap the exception chain
        assertTrue(e instanceof ExecutionException);
        assertTrue(e.getCause() instanceof CamelExecutionException);
        assertTrue(e.getCause().getCause() instanceof CamelExchangeException);
        assertTrue(e.getCause().getCause().getCause() instanceof RuntimeException);
        assertTrue(e.getCause().getCause().getCause().getMessage().equals("Bang! Unhandled exception"));
        mock.assertIsSatisfied();
        return;
    }
    fail("Expected an RuntimeException");
}
项目:Camel    文件:PollEnricherAggregateOnExceptionTest.java   
public void testEnrichFalseKaboom() throws Exception {
    template.send("seda:foo", new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.setException(new IllegalArgumentException("I cannot do this"));
        }
    });

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);

    try {
        template.sendBody("direct:start2", "Kaboom");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("I cannot do this", e.getCause().getMessage());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:AdviceWithTest.java   
public void testAdvisedThrowException() throws Exception {
    context.getRouteDefinitions().get(0).adviceWith(context, new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("mock:foo")
                .to("mock:advised")
                .throwException(new IllegalArgumentException("Damn"));
        }
    });

    getMockEndpoint("mock:foo").expectedMessageCount(0);
    getMockEndpoint("mock:advised").expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedMessageCount(0);

    try {
        template.sendBody("direct:start", "Hello World");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("Damn", e.getCause().getMessage());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:DisruptorInOutChainedTimeoutTest.java   
@Test
public void testDisruptorInOutChainedTimeout() throws Exception {
    // time timeout after 2 sec should trigger a immediately reply
    final StopWatch watch = new StopWatch();
    try {
        template.requestBody("disruptor:a?timeout=5000", "Hello World");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        final ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class,
                e.getCause());
        assertEquals(2000, cause.getTimeout());
    }
    final long delta = watch.stop();

    assertTrue("Should be faster than 4000 millis, was: " + delta, delta < 4000);
}
项目:Camel    文件:ValidateRegExpTest.java   
public void testSendNotMatchingMessage() throws Exception {
    resultEndpoint.expectedMessageCount(0);

    try {
        template.sendBody(startEndpoint, "1.1.2010");
        fail("CamelExecutionException expected");
    } catch (CamelExecutionException e) {
        // expected
        PredicateValidationException cause = assertIsInstanceOf(PredicateValidationException.class, e.getCause());

        // as the Expression could be different between the DSL and simple language, here we just check part of the message 
        assertTrue("Get a wrong exception message", cause.getMessage().startsWith("Validation failed for Predicate"));
        assertTrue(cause.getMessage().contains("^\\d{2}\\.\\d{2}\\.\\d{4}$"));

        String body = cause.getExchange().getIn().getBody(String.class);
        assertEquals("1.1.2010", body);
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:RedeliveryErrorHandlerLogHandledTest.java   
public void testRedeliveryErrorHandlerDoNotLogExhausted() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            errorHandler(defaultErrorHandler().logExhausted(false));

            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();
}
项目:Camel    文件:BindySimpleCsvMandatoryFieldsUnmarshallTest.java   
@DirtiesContext
@Test
public void testEmptyRecord() throws Exception {

    String record1 = ""; // empty records

    resultEndpoint1.expectedMessageCount(0);

    try {
        template1.sendBody(record1);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        Assert.isInstanceOf(Exception.class, e.getCause());
        // LOG.info(">> Error : " + e);
    }

    resultEndpoint1.assertIsSatisfied();
}
项目:Camel    文件:OnExceptionRouteTest.java   
public void testErrorWhileHandlingException() throws Exception {
    // DLC does not handle the exception as we failed during processing in onException
    MockEndpoint error = getMockEndpoint("mock:error");
    error.expectedMessageCount(0);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);

    try {
        template.sendBody("direct:start", "<order><type>myType</type><user>FuncError</user></order>");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        // the myOwnHandlerBean throw exception while handling an exception
        IOException cause = assertIsInstanceOf(IOException.class, e.getCause());
        assertEquals("Damn something did not work", cause.getMessage());
    }

    assertMockEndpointsSatisfied();

    // should not handle it
    assertNull(myOwnHandlerBean.getPayload());
}
项目:Camel    文件:DirectNoConsumerTest.java   
public void testInOut() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("direct:foo");
        }
    });

    context.start();

    try {
        template.requestBody("direct:start", "Hello World");
        fail("Should throw an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(DirectConsumerNotAvailableException.class, e.getCause());
    }
}
项目:Camel    文件:SplitterStopOnExceptionTest.java   
public void testSplitStopOnExceptionStop() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:split");
    // we do stop so we stop splitting when the exception occurs and thus we only receive 1 message
    mock.expectedBodiesReceived("Hello World");

    try {
        template.sendBody("direct:start", "Hello World,Kaboom,Bye World");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(cause.getMessage().startsWith("Sequential processing failed for number 1."));
        assertEquals("Forced", cause.getCause().getMessage());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:FileRollbackOnCompletionTest.java   
public void testRollback() throws Exception {
    try {
        template.sendBodyAndHeader("direct:confirm", "bumper", "to", "FATAL");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("Simulated fatal error", e.getCause().getMessage());
    }

    oneExchangeDone.matchesMockWaitTime();

    // onCompletion is async so we gotta wait a bit for the file to be deleted
    assertTrue("Should countdown the latch", LATCH.await(5, TimeUnit.SECONDS));

    File file = new File("target/mail/backup/");
    String[] files = file.list();
    assertEquals("There should be no files", 0, files.length);
}
项目:Camel    文件:BeanOverloadedMethodTest.java   
public void testHelloOverloadedAmbiguousStringStringString() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                .bean(MyBean.class, "hello(String,String,String)")
                .to("mock:result");

        }
    });
    context.start();

    try {
        template.sendBodyAndHeader("direct:start", "Claus", "country", "Denmark");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        AmbiguousMethodCallException cause = assertIsInstanceOf(AmbiguousMethodCallException.class, e.getCause());
        assertEquals(2, cause.getMethods().size());
    }
}
项目:Camel    文件:ComponentConfigurationIntegrationTest.java   
@Test
public void testGetComment() throws Exception {
    final Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelLinkedIn.comment_id", "123");
    // parameter type is String
    headers.put("CamelLinkedIn.fields", "");

    try {
        requestBodyAndHeaders("direct://GETCOMMENT", null, headers);
        fail("Bad client Id must cause an exception on first message");
    } catch (CamelExecutionException e) {
        Throwable t = e;
        while (t.getCause() != null && t.getCause() != t) {
            t = t.getCause();
        }
        if (!(t instanceof IllegalArgumentException)) {
            throw e;
        }
    }
}
项目:Camel    文件:RecipientListRedeliverTest.java   
public void testThrowExceptionAtB() throws Exception {
    counter = 0;

    getMockEndpoint("mock:a").expectedMessageCount(1);
    getMockEndpoint("mock:b").expectedMessageCount(1);
    getMockEndpoint("mock:c").expectedMessageCount(0);

    try {
        template.sendBodyAndHeader("direct:start", "Hello World", "mySlip", "mock:a,mock:b,direct:b,mock:c");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertEquals("Forced", e.getCause().getCause().getMessage());
    }

    assertMockEndpointsSatisfied();

    assertEquals(1 + 3, counter); // first call + 3 redeliveries
}
项目:Camel    文件:FailOverNotCatchedExceptionTest.java   
public void testExceptionNotCatched() throws Exception {
    x.expectedMessageCount(1);
    y.expectedMessageCount(1);
    z.expectedMessageCount(0);

    // to test that if a processor throw an exception that the failover loadbalancer
    // do not catch then the exception is propagated back

    try {
        template.sendBody("direct:start", "Hello World");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertEquals("Illegal", e.getCause().getMessage());
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:OnCompletionMoreGlobalRouteCompletionTest.java   
public void testSynchronizeFailure() throws Exception {
    getMockEndpoint("mock:complete").expectedMessageCount(0);
    getMockEndpoint("mock:failure").expectedMessageCount(1);
    getMockEndpoint("mock:two").expectedMessageCount(1);
    getMockEndpoint("mock:sync").expectedMessageCount(1);
    getMockEndpoint("mock:sync").expectedPropertyReceived(Exchange.ON_COMPLETION, true);

    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();
}
项目:Camel    文件:BeanComponentMissingParenthesisTest.java   
public void testInvalidName() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                .to("bean:myBean?method=--concat(${body}, ${header.foo})")
                .to("mock:result");
        }
    });
    context.start();

    try {
        template.sendBodyAndHeader("direct:start", "Hello", "foo", "Camel");
        fail("Should throw exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(MethodNotFoundException.class, e.getCause());
    }
}
项目:Camel    文件:SplitterParallelNoStopOnExceptionTest.java   
public void testSplitParallelNoStopOnExceptionStop() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:split");
    mock.expectedMinimumMessageCount(0);
    // we do NOT stop so we receive all messages except the one that goes kaboom
    mock.allMessages().body().isNotEqualTo("Kaboom");
    mock.expectedBodiesReceivedInAnyOrder("Hello World", "Goodday World", "Bye World", "Hi World");

    try {
        template.sendBody("direct:start", "Hello World,Goodday World,Kaboom,Bye World,Hi World");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("Forced", cause.getMessage());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:MulticastStopOnExceptionTest.java   
public void testMulticastStopOnExceptionStop() throws Exception {
    getMockEndpoint("mock:foo").expectedBodiesReceived("Kaboom");
    getMockEndpoint("mock:bar").expectedMessageCount(0);
    // we do stop so we should NOT continue and thus baz do not receive any message
    getMockEndpoint("mock:baz").expectedMessageCount(0);
    getMockEndpoint("mock:result").expectedMessageCount(0);

    try {
        template.sendBody("direct:start", "Kaboom");
        fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(cause.getMessage().startsWith("Sequential processing failed for number 1."));
        assertEquals("Forced", cause.getCause().getMessage());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:SpringJettyNoConnectionTest.java   
@Test
public void testConnectionNotOk() throws Exception {
    // stop Jetty route so there should not be a connection
    context.stopRoute("jetty");

    try {
        template.requestBody("direct:start", "Moon", String.class);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(ConnectException.class, e.getCause());
    }
}
项目:Camel    文件:MessageValidatorTest.java   
@Test(expected = CamelExecutionException.class)
public void testCustomValidationContext() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:test2");
    mock.expectedMessageCount(0);
    Message msg = createADT01Message();
    template.sendBody("direct:test2", msg);
    assertMockEndpointsSatisfied();
}