Search in sources :

Example 1 with ExchangeTimedOutException

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

the class EtcdKeysProducer method processGet.

private void processGet(EtcdClient client, String path, Exchange exchange) throws Exception {
    EtcdKeyGetRequest request = client.get(path);
    setRequestTimeout(request, exchange);
    setRequestRecursive(request, exchange);
    try {
        exchange.getIn().setHeader(EtcdConstants.ETCD_NAMESPACE, getNamespace());
        exchange.getIn().setBody(request.send().get());
    } catch (TimeoutException e) {
        throw new ExchangeTimedOutException(exchange, configuration.getTimeout());
    }
}
Also used : EtcdKeyGetRequest(mousio.etcd4j.requests.EtcdKeyGetRequest) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ExchangeTimedOutException

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

the class EtcdKeysProducer method processDel.

private void processDel(EtcdClient client, String path, boolean dir, Exchange exchange) throws Exception {
    EtcdKeyDeleteRequest request = client.delete(path);
    setRequestTimeout(request, exchange);
    setRequestRecursive(request, exchange);
    if (dir) {
        request.dir();
    }
    try {
        exchange.getIn().setHeader(EtcdConstants.ETCD_NAMESPACE, getNamespace());
        exchange.getIn().setBody(request.send().get());
    } catch (TimeoutException e) {
        throw new ExchangeTimedOutException(exchange, configuration.getTimeout());
    }
}
Also used : EtcdKeyDeleteRequest(mousio.etcd4j.requests.EtcdKeyDeleteRequest) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with ExchangeTimedOutException

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

the class SetHeaderInDoCatchIssueTest method createRegistry.

protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = new JndiRegistry(createJndiContext());
    registry.bind("A", new Processor() {

        public void process(Exchange exchange) throws Exception {
            log.info("A headers " + exchange.getIn().getHeaders());
        }
    });
    registry.bind("B", new Processor() {

        public void process(Exchange exchange) throws Exception {
            log.info("B headers " + exchange.getIn().getHeaders());
            if ("ExchangeTimedOutException".equals(exchange.getIn().getBody(String.class))) {
                throw new ExchangeTimedOutException(exchange, 1);
            } else if ("Exception".equals(exchange.getIn().getBody(String.class))) {
                throw new Exception();
            }
        }
    });
    registry.bind("C", new Processor() {

        public void process(Exchange exchange) throws Exception {
            log.info("C headers " + exchange.getIn().getHeaders());
        }
    });
    return registry;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException)

Example 4 with ExchangeTimedOutException

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

the class SetHeaderInDoCatchIssueTest method testExchangeTimedOutException.

public void testExchangeTimedOutException() {
    Exchange exchange = template.request("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("ExchangeTimedOutException");
        }
    });
    assertEquals("TimeOut", exchange.getOut().getHeader("Status"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException)

Example 5 with ExchangeTimedOutException

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

the class VmInOutChainedTimeoutTest method testVmInOutChainedTimeout.

public void testVmInOutChainedTimeout() throws Exception {
    StopWatch watch = new StopWatch();
    try {
        template2.requestBody("vm:a?timeout=1000", "Hello World");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        // the chained vm caused the timeout
        ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
        assertEquals(200, cause.getTimeout());
    }
    long delta = watch.stop();
    assertTrue("Should be faster than 1 sec, was: " + delta, delta < 1100);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) StopWatch(org.apache.camel.util.StopWatch)

Aggregations

ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)23 Exchange (org.apache.camel.Exchange)11 CountDownLatch (java.util.concurrent.CountDownLatch)5 CamelExecutionException (org.apache.camel.CamelExecutionException)4 StopWatch (org.apache.camel.util.StopWatch)4 Test (org.junit.Test)4 TimeoutException (java.util.concurrent.TimeoutException)3 AsyncCallback (org.apache.camel.AsyncCallback)3 Processor (org.apache.camel.Processor)3 WaitForTaskToComplete (org.apache.camel.WaitForTaskToComplete)3 SynchronizationAdapter (org.apache.camel.support.SynchronizationAdapter)3 CamelExchangeException (org.apache.camel.CamelExchangeException)2 Endpoint (org.apache.camel.Endpoint)2 Producer (org.apache.camel.Producer)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 Session (javax.jms.Session)1 EtcdKeyDeleteRequest (mousio.etcd4j.requests.EtcdKeyDeleteRequest)1 EtcdKeyGetRequest (mousio.etcd4j.requests.EtcdKeyGetRequest)1