Search in sources :

Example 86 with CamelExecutionException

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

the class SimpleScheduledRoutePolicyTest method testScheduledSuspendAndResumeRoutePolicy.

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

        public void configure() {
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long suspendTime = System.currentTimeMillis() + 1000L;
            policy.setRouteSuspendDate(new Date(suspendTime));
            policy.setRouteSuspendRepeatCount(0);
            policy.setRouteSuspendRepeatInterval(3000);
            long resumeTime = System.currentTimeMillis() + 4000L;
            policy.setRouteResumeDate(new Date(resumeTime));
            policy.setRouteResumeRepeatCount(1);
            policy.setRouteResumeRepeatInterval(3000);
            from("direct:start").routeId("test").routePolicy(policy).to("mock:success");
        }
    });
    context.start();
    Thread.sleep(1000);
    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("quartz2", 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.quartz2.QuartzComponent) Test(org.junit.Test)

Example 87 with CamelExecutionException

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

the class SimpleScheduledRoutePolicyTest method testScheduledStopRoutePolicy.

@Test
public void testScheduledStopRoutePolicy() throws Exception {
    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long startTime = System.currentTimeMillis() + 3000;
            policy.setRouteStopDate(new Date(startTime));
            policy.setRouteStopRepeatCount(1);
            policy.setRouteStopRepeatInterval(3000);
            from("direct:start").routeId("test").routePolicy(policy).to("mock:unreachable");
        }
    });
    context.start();
    Thread.sleep(4000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Stopped);
    boolean consumerStopped = false;
    try {
        template.sendBody("direct:start", "Ready or not, Here, I come");
    } catch (CamelExecutionException e) {
        consumerStopped = true;
    }
    assertTrue(consumerStopped);
    context.getComponent("quartz2", QuartzComponent.class).stop();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) Date(java.util.Date) QuartzComponent(org.apache.camel.component.quartz2.QuartzComponent) Test(org.junit.Test)

Example 88 with CamelExecutionException

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

the class RabbitMQInOutIntTest method partiallySerializeTest.

@Test
public void partiallySerializeTest() throws InterruptedException, IOException {
    TestPartiallySerializableObject foo = new TestPartiallySerializableObject();
    foo.setName("foobar");
    try {
        TestPartiallySerializableObject reply = template.requestBodyAndHeader("direct:rabbitMQ", foo, RabbitMQConstants.EXCHANGE_NAME, EXCHANGE, TestPartiallySerializableObject.class);
    } catch (CamelExecutionException e) {
    // expected
    }
    // Make sure we didn't crash the one Consumer thread
    String reply2 = template.requestBodyAndHeader("direct:rabbitMQ", "partiallySerializeTest1", RabbitMQConstants.EXCHANGE_NAME, EXCHANGE, String.class);
    assertEquals("partiallySerializeTest1 response", reply2);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) TestPartiallySerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestPartiallySerializableObject) Test(org.junit.Test)

Example 89 with CamelExecutionException

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

the class RestApiIntegrationTest method testRetryFailure.

@Test
public void testRetryFailure() throws Exception {
    final SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
    final String accessToken = sf.getSession().getAccessToken();
    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext(context));
    final HttpClient httpClient = new HttpClient(sslContextFactory);
    httpClient.setConnectTimeout(60000);
    httpClient.start();
    final String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
    final Request logoutGet = httpClient.newRequest(uri).method(HttpMethod.GET).timeout(1, TimeUnit.MINUTES);
    final ContentResponse response = logoutGet.send();
    assertEquals(HttpStatus.OK_200, response.getStatus());
    // set component config to bad password to cause relogin attempts to fail
    final String password = sf.getLoginConfig().getPassword();
    sf.getLoginConfig().setPassword("bad_password");
    try {
        testGetGlobalObjects();
        fail("Expected CamelExecutionException!");
    } catch (final CamelExecutionException e) {
        if (e.getCause() instanceof SalesforceException) {
            final SalesforceException cause = (SalesforceException) e.getCause();
            assertEquals("Expected 400 on authentication retry failure", HttpStatus.BAD_REQUEST_400, cause.getStatusCode());
        } else {
            fail("Expected SalesforceException!");
        }
    } finally {
        // reset password and retries to allow other tests to pass
        sf.getLoginConfig().setPassword(password);
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) Request(org.eclipse.jetty.client.api.Request) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters) Test(org.junit.Test)

Example 90 with CamelExecutionException

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

the class BeanNoTypeConvertionPossibleWhenHeaderTest method testBeanHeaderNoTypeConvertionPossibleFail.

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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException) Document(org.w3c.dom.Document)

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