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;
}
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);
}
}
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();
}
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();
}
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);
}
}
Aggregations