use of org.apache.camel.CamelException in project camel by apache.
the class ClientModeTCPNettyServerBootstrapFactory 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();
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 SipSubscriptionListener method dispatchExchange.
private void dispatchExchange(Object response) throws CamelException {
LOG.debug("Consumer Dispatching the received notification along the route");
Exchange exchange = sipSubscriber.getEndpoint().createExchange(ExchangePattern.InOnly);
exchange.getIn().setBody(response);
try {
sipSubscriber.getProcessor().process(exchange);
} catch (Exception e) {
throw new CamelException("Error in consumer while dispatching exchange", e);
}
}
use of org.apache.camel.CamelException in project camel by apache.
the class DnsLookupProducer method process.
@Override
public void process(Exchange exchange) throws Exception {
String dnsName = exchange.getIn().getHeader(DnsConstants.DNS_NAME, String.class);
ObjectHelper.notEmpty(dnsName, "Header " + DnsConstants.DNS_NAME);
Object type = exchange.getIn().getHeader(DnsConstants.DNS_TYPE);
Integer dnsType = null;
if (type != null) {
dnsType = Type.value(String.valueOf(type));
}
Object dclass = exchange.getIn().getHeader(DnsConstants.DNS_CLASS);
Integer dnsClass = null;
if (dclass != null) {
dnsClass = DClass.value(String.valueOf(dclass));
}
Lookup lookup = (dnsClass == null) ? (dnsType == null ? new Lookup(dnsName) : new Lookup(dnsName, dnsType)) : new Lookup(dnsName, dnsType, dnsClass);
lookup.run();
if (lookup.getAnswers() != null) {
exchange.getIn().setBody(lookup.getAnswers());
} else {
throw new CamelException(lookup.getErrorString());
}
}
Aggregations