Search in sources :

Example 71 with RuntimeCamelException

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

the class HttpProducerSOTimeoutTest method testSendWithSOTimeoutTimeout.

@Test
public void testSendWithSOTimeoutTimeout() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    try {
        // we use a timeout of 1 second
        template.requestBody("http://localhost:{{port}}/myservice?httpClient.soTimeout=1000", null, String.class);
        fail("Should throw an exception");
    } catch (RuntimeCamelException e) {
        assertIsInstanceOf(SocketTimeoutException.class, e.getCause());
    }
    assertMockEndpointsSatisfied();
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Test(org.junit.Test)

Example 72 with RuntimeCamelException

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

the class HttpRedirectTest method testHttpRedirectFromCamelRoute.

@Test
public void testHttpRedirectFromCamelRoute() throws Exception {
    MockEndpoint errorEndpoint = context.getEndpoint("mock:error", MockEndpoint.class);
    errorEndpoint.expectedMessageCount(1);
    MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(0);
    try {
        template.requestBody("direct:start", "Hello World", String.class);
        fail("Should have thrown an exception");
    } catch (RuntimeCamelException e) {
        HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
        assertEquals(302, cause.getStatusCode());
    }
    errorEndpoint.assertIsSatisfied();
    resultEndpoint.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HttpOperationFailedException(org.apache.camel.http.common.HttpOperationFailedException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Test(org.junit.Test)

Example 73 with RuntimeCamelException

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

the class HttpsAsyncRouteTest method testEndpointWithoutHttps.

@Test
public void testEndpointWithoutHttps() throws Exception {
    // these tests does not run well on Windows
    if (isPlatform("windows")) {
        return;
    }
    MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
    try {
        template.sendBodyAndHeader("http://localhost:" + port1 + "/test", expectedBody, "Content-Type", "application/xml");
        fail("expect exception on access to https endpoint via http");
    } catch (RuntimeCamelException expected) {
    }
    assertTrue("mock endpoint was not called", mockEndpoint.getExchanges().isEmpty());
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Test(org.junit.Test)

Example 74 with RuntimeCamelException

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

the class EndpointMessageListener method onMessage.

@Override
public void onMessage(Message message, Session session) throws JMSException {
    LOG.trace("onMessage START");
    LOG.debug("{} consumer received JMS message: {}", endpoint, message);
    boolean sendReply;
    RuntimeCamelException rce;
    try {
        Object replyDestination = getReplyToDestination(message);
        // we can only send back a reply if there was a reply destination configured
        // and disableReplyTo hasn't been explicit enabled
        sendReply = replyDestination != null && !disableReplyTo;
        // we should also not send back reply to ourself if this destination and replyDestination is the same
        Destination destination = JmsMessageHelper.getJMSDestination(message);
        if (destination != null && sendReply && !endpoint.isReplyToSameDestinationAllowed() && destination.equals(replyDestination)) {
            LOG.debug("JMSDestination and JMSReplyTo is the same, will skip sending a reply message to itself: {}", destination);
            sendReply = false;
        }
        final Exchange exchange = createExchange(message, session, replyDestination);
        if (eagerLoadingOfProperties) {
            exchange.getIn().getHeaders();
        }
        String correlationId = message.getJMSCorrelationID();
        if (correlationId != null) {
            LOG.debug("Received Message has JMSCorrelationID [{}]", correlationId);
        }
        // process the exchange either asynchronously or synchronous
        LOG.trace("onMessage.process START");
        AsyncCallback callback = new EndpointMessageListenerAsyncCallback(message, exchange, endpoint, sendReply, replyDestination);
        // async is by default false, which mean we by default will process the exchange synchronously
        // to keep backwards compatible, as well ensure this consumer will pickup messages in order
        // (eg to not consume the next message before the previous has been fully processed)
        // but if end user explicit configure consumerAsync=true, then we can process the message
        // asynchronously (unless endpoint has been configured synchronous, or we use transaction)
        boolean forceSync = endpoint.isSynchronous() || endpoint.isTransacted();
        if (forceSync || !isAsync()) {
            // must process synchronous if transacted or configured to do so
            if (LOG.isTraceEnabled()) {
                LOG.trace("Processing exchange {} synchronously", exchange.getExchangeId());
            }
            try {
                processor.process(exchange);
            } catch (Exception e) {
                exchange.setException(e);
            } finally {
                callback.done(true);
            }
        } else {
            // process asynchronous using the async routing engine
            if (LOG.isTraceEnabled()) {
                LOG.trace("Processing exchange {} asynchronously", exchange.getExchangeId());
            }
            boolean sync = processor.process(exchange, callback);
            if (!sync) {
                // will be done async so return now
                return;
            }
        }
        // if we failed processed the exchange from the async callback task, then grab the exception
        rce = exchange.getException(RuntimeCamelException.class);
    } catch (Exception e) {
        rce = wrapRuntimeCamelException(e);
    }
    // the JMS listener will use the error handler to handle the uncaught exception
    if (rce != null) {
        LOG.trace("onMessage END throwing exception: {}", rce.getMessage());
        // on the JmsEndpoint to handle the exception
        throw rce;
    }
    LOG.trace("onMessage END");
}
Also used : Exchange(org.apache.camel.Exchange) Destination(javax.jms.Destination) AsyncCallback(org.apache.camel.AsyncCallback) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ObjectHelper.wrapRuntimeCamelException(org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RollbackExchangeException(org.apache.camel.RollbackExchangeException) JMSException(javax.jms.JMSException) ObjectHelper.wrapRuntimeCamelException(org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException)

Example 75 with RuntimeCamelException

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

the class KratiHelper method createDataSet.

/**
     * Creates a {@link krati.store.DynamicDataSet} with the given parameters.
     *
     * @param path            The directory which the set will use.
     * @param initialCapacity
     * @param segmentFactory  The segment factory, defaults to {@link krati.core.segment.ChannelSegmentFactory}.
     * @return
     */
public static DataSet<byte[]> createDataSet(String path, int initialCapacity, SegmentFactory segmentFactory) {
    DataSet<byte[]> result = null;
    File homeDir = new File(path);
    homeDir.mkdirs();
    try {
        result = new DynamicDataSet(homeDir, initialCapacity, segmentFactory);
    } catch (Exception e) {
        throw new RuntimeCamelException("Failed to create Krati DataSet. This exception is ignored.", e);
    }
    return result;
}
Also used : DynamicDataSet(krati.store.DynamicDataSet) RuntimeCamelException(org.apache.camel.RuntimeCamelException) File(java.io.File) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Aggregations

RuntimeCamelException (org.apache.camel.RuntimeCamelException)196 HashMap (java.util.HashMap)52 CamelContextAware (org.apache.camel.CamelContextAware)45 DataFormatFactory (org.apache.camel.spi.DataFormatFactory)45 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)45 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)45 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)45 Bean (org.springframework.context.annotation.Bean)45 IOException (java.io.IOException)36 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)32 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)11 Exchange (org.apache.camel.Exchange)11 InputStream (java.io.InputStream)9 GeneralSecurityException (java.security.GeneralSecurityException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 TimeoutException (java.util.concurrent.TimeoutException)7 QName (javax.xml.namespace.QName)7 Message (org.apache.camel.Message)7 Method (java.lang.reflect.Method)6