Search in sources :

Example 26 with CamelException

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;
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) 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) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException)

Example 27 with CamelException

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

Example 28 with CamelException

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());
    }
}
Also used : CamelException(org.apache.camel.CamelException) Lookup(org.xbill.DNS.Lookup)

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