Search in sources :

Example 6 with CamelException

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

the class NettyProducer method openChannel.

protected Channel openChannel(ChannelFuture channelFuture) throws Exception {
    // blocking for channel to be done
    if (LOG.isTraceEnabled()) {
        LOG.trace("Waiting for operation to complete {} for {} millis", channelFuture, configuration.getConnectTimeout());
    }
    // here we need to wait it in other thread
    final CountDownLatch channelLatch = new CountDownLatch(1);
    channelFuture.addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture cf) throws Exception {
            channelLatch.countDown();
        }
    });
    try {
        channelLatch.await(configuration.getConnectTimeout(), TimeUnit.MILLISECONDS);
    } catch (InterruptedException ex) {
        throw new CamelException("Interrupted while waiting for " + "connection to " + configuration.getAddress());
    }
    if (!channelFuture.isDone() || !channelFuture.isSuccess()) {
        ConnectException cause = new ConnectException("Cannot connect to " + configuration.getAddress());
        if (channelFuture.getCause() != null) {
            cause.initCause(channelFuture.getCause());
        }
        throw cause;
    }
    Channel answer = channelFuture.getChannel();
    // to keep track of all channels in use
    allChannels.add(answer);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating connector to address: {}", configuration.getAddress());
    }
    return answer;
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) SucceededChannelFuture(org.jboss.netty.channel.SucceededChannelFuture) CamelException(org.apache.camel.CamelException) Channel(org.jboss.netty.channel.Channel) CountDownLatch(java.util.concurrent.CountDownLatch) ChannelFutureListener(org.jboss.netty.channel.ChannelFutureListener) CamelException(org.apache.camel.CamelException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ConnectException(java.net.ConnectException) CamelExchangeException(org.apache.camel.CamelExchangeException) ConnectException(java.net.ConnectException)

Example 7 with CamelException

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

the class ProtobufMarshalAndUnmarshallTest method testMarshalAndUnmarshalWithDSL3.

@Test
public void testMarshalAndUnmarshalWithDSL3() throws Exception {
    try {
        context.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("direct:unmarshalC").unmarshal().protobuf(new CamelException("wrong instance")).to("mock:reverse");
            }
        });
        fail("Expect the exception here");
    } catch (Exception ex) {
        assertTrue("Expect FailedToCreateRouteException", ex instanceof FailedToCreateRouteException);
        assertTrue("Get a wrong reason", ex.getCause() instanceof IllegalArgumentException);
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelException(org.apache.camel.CamelException) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) CamelException(org.apache.camel.CamelException) Test(org.junit.Test)

Example 8 with CamelException

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

the class RedeliveryErrorHandlerLogHandledTest method testRedeliveryErrorHandlerLogExhaustedDefault.

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

        @Override
        public void configure() throws Exception {
            errorHandler(defaultErrorHandler());
            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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelException(org.apache.camel.CamelException) CamelExecutionException(org.apache.camel.CamelExecutionException) CamelException(org.apache.camel.CamelException)

Example 9 with CamelException

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

the class RedeliveryErrorHandlerLogHandledTest method testRedeliveryErrorHandlerDoNotLogExhausted.

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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelException(org.apache.camel.CamelException) CamelExecutionException(org.apache.camel.CamelExecutionException) CamelException(org.apache.camel.CamelException)

Example 10 with CamelException

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

the class AvroDataFormat method loadSchema.

protected Schema loadSchema(String className) throws CamelException, ClassNotFoundException {
    // must use same class loading procedure to ensure working in OSGi
    Class<?> instanceClass = camelContext.getClassResolver().resolveMandatoryClass(className);
    Class<?> genericContainer = camelContext.getClassResolver().resolveMandatoryClass(GENERIC_CONTAINER_CLASSNAME);
    if (genericContainer.isAssignableFrom(instanceClass)) {
        try {
            Method method = instanceClass.getMethod("getSchema");
            return (Schema) method.invoke(camelContext.getInjector().newInstance(instanceClass));
        } catch (Exception ex) {
            throw new CamelException("Error calling getSchema on " + instanceClass, ex);
        }
    } else {
        throw new CamelException("Class " + instanceClass + " must be instanceof " + GENERIC_CONTAINER_CLASSNAME);
    }
}
Also used : CamelException(org.apache.camel.CamelException) Schema(org.apache.avro.Schema) Method(java.lang.reflect.Method) CamelException(org.apache.camel.CamelException)

Aggregations

CamelException (org.apache.camel.CamelException)28 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)6 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CamelExecutionException (org.apache.camel.CamelExecutionException)3 SyncResponseCallback (org.apache.camel.component.salesforce.internal.client.SyncResponseCallback)3 PushTopic (org.apache.camel.component.salesforce.internal.dto.PushTopic)3 QueryRecordsPushTopic (org.apache.camel.component.salesforce.internal.dto.QueryRecordsPushTopic)3 XMLReader (org.xml.sax.XMLReader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringWriter (java.io.StringWriter)2 ConnectException (java.net.ConnectException)2 Exchange (org.apache.camel.Exchange)2 Message (org.apache.camel.Message)2 Message (org.cometd.bayeux.Message)2 ClientSessionChannel (org.cometd.bayeux.client.ClientSessionChannel)2 Channel (org.jboss.netty.channel.Channel)2 ChannelFuture (org.jboss.netty.channel.ChannelFuture)2 Test (org.junit.Test)2