Search in sources :

Example 76 with CamelExecutionException

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

the class XmlJsonExceptionsTest method testMalformedJson.

@Test
public void testMalformedJson() throws Exception {
    String in = "{ \"a\": 123, \"b\": true, \"c\": true2 }";
    MockEndpoint mockXML = getMockEndpoint("mock:xml");
    mockXML.expectedMessageCount(0);
    MockEndpoint mockException = getMockEndpoint("mock:exception");
    mockException.expectedMessageCount(1);
    try {
        template.requestBody("direct:unmarshal", in);
        fail("Exception expected");
    } catch (CamelExecutionException e) {
        assertEquals("JSONException expected", JSONException.class, e.getCause().getClass());
    }
    List<Exchange> exchs = mockException.getExchanges();
    assertEquals("Only one exchange was expected in mock:exception", 1, exchs.size());
    Exception e = (Exception) exchs.get(0).getProperty(Exchange.EXCEPTION_CAUGHT);
    assertNotNull("Exception expected", e);
    assertEquals("JSONException expected", JSONException.class, e.getClass());
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) JSONException(net.sf.json.JSONException) CamelExecutionException(org.apache.camel.CamelExecutionException) JSONException(net.sf.json.JSONException) Test(org.junit.Test)

Example 77 with CamelExecutionException

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

the class CamelGreeterConsumerTest method testInvokeServers.

@Test
public void testInvokeServers() throws Exception {
    assertNotNull(camelContext);
    ProducerTemplate template = camelContext.createProducerTemplate();
    List<String> params = new ArrayList<String>();
    params.add("Willem");
    Object result = template.sendBodyAndHeader("cxf://bean:serviceEndpoint", ExchangePattern.InOut, params, CxfConstants.OPERATION_NAME, "greetMe");
    assertTrue("Result is a list instance ", result instanceof List);
    assertEquals("Get the wrong response", ((List<?>) result).get(0), "HelloWillem");
    try {
        template.sendBodyAndHeader("cxf://bean:serviceEndpoint", ExchangePattern.InOut, params, CxfConstants.OPERATION_NAME, "pingMe");
        fail("Expect exception here.");
    } catch (Exception ex) {
        assertTrue("Get a wrong exception.", ex instanceof CamelExecutionException);
        assertTrue("Get a wrong exception cause. ", ex.getCause() instanceof PingMeFault);
    }
    template.stop();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) ProducerTemplate(org.apache.camel.ProducerTemplate) PingMeFault(org.apache.hello_world_soap_http.PingMeFault) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CamelExecutionException(org.apache.camel.CamelExecutionException) Test(org.junit.Test)

Example 78 with CamelExecutionException

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

the class SpringAopClassLevelCamelBeanTest method testSpringAopException.

public void testSpringAopException() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    try {
        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "Damn");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
    }
    assertMockEndpointsSatisfied();
    ExceptionInterceptor ei = context.getRegistry().lookupByNameAndType("exceptionInterceptor", ExceptionInterceptor.class);
    IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, ei.getE());
    assertEquals("Foo has not expected value ABC but Damn", iae.getMessage());
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 79 with CamelExecutionException

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

the class HttpStreamCacheFileTest method testStreamCacheToFileShouldBeDeletedInCaseOfException.

@Test
public void testStreamCacheToFileShouldBeDeletedInCaseOfException() throws Exception {
    try {
        template.requestBody("direct:start", null, String.class);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        HttpOperationFailedException hofe = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
        String s = context.getTypeConverter().convertTo(String.class, hofe.getResponseBody());
        assertEquals("Response body", responseBody, s);
    }
    // the temporary files should have been deleted
    File file = new File("target/cachedir");
    String[] files = file.list();
    assertEquals("There should be no files", 0, files.length);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) HttpOperationFailedException(org.apache.camel.http.common.HttpOperationFailedException) File(java.io.File) Test(org.junit.Test)

Example 80 with CamelExecutionException

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

the class SimpleScheduledRoutePolicyTest method testScheduledResumeRoutePolicy.

@Test
public void testScheduledResumeRoutePolicy() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
    success.expectedMessageCount(1);
    context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long startTime = System.currentTimeMillis() + 3000L;
            policy.setRouteResumeDate(new Date(startTime));
            policy.setRouteResumeRepeatCount(1);
            policy.setRouteResumeRepeatInterval(3000);
            from("direct:start").routeId("test").routePolicy(policy).to("mock:success");
        }
    });
    context.start();
    ServiceHelper.suspendService(context.getRoute("test").getConsumer());
    try {
        template.sendBody("direct:start", "Ready or not, Here, I come");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        LOG.debug("Consumer successfully suspended");
    }
    Thread.sleep(4000);
    template.sendBody("direct:start", "Ready or not, Here, I come");
    context.getComponent("quartz", QuartzComponent.class).stop();
    success.assertIsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Date(java.util.Date) QuartzComponent(org.apache.camel.component.quartz.QuartzComponent) Test(org.junit.Test)

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