Search in sources :

Example 1 with RuntimeCamelException

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

the class MailProducerUnsupportedCharsetTest method testSencUnsupportedCharsetDisabledOption.

@Test
public void testSencUnsupportedCharsetDisabledOption() throws Exception {
    Mailbox.clearAll();
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("pop3://jones@localhost?password=secret&delay=1000&ignoreUnsupportedCharset=false").to("mock:result");
        }
    });
    context.start();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    mock.allMessages().header("Content-Type").isEqualTo("text/plain");
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("To", "jones@localhost");
    headers.put("Content-Type", "text/plain");
    template.sendBodyAndHeaders("smtp://localhost?ignoreUnsupportedCharset=false", "Hello World", headers);
    headers.clear();
    headers.put("To", "jones@localhost");
    headers.put("Content-Type", "text/plain; charset=XXX");
    try {
        template.sendBodyAndHeaders("smtp://localhost?ignoreUnsupportedCharset=false", "Bye World", headers);
        fail("Should have thrown an exception");
    } catch (RuntimeCamelException e) {
        assertIsInstanceOf(UnsupportedEncodingException.class, e.getCause());
    }
    mock.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 2 with RuntimeCamelException

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

the class MinaNoResponseFromServerTest method testNoResponse.

@Test
public void testNoResponse() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    try {
        template.requestBody("mina:tcp://localhost:{{port}}?sync=true&codec=#myCodec", "Hello World");
        fail("Should throw a CamelExchangeException");
    } catch (RuntimeCamelException e) {
        assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        assertTrue(e.getCause().getMessage().startsWith("No response received from remote server"));
    }
    mock.assertIsSatisfied();
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Test(org.junit.Test)

Example 3 with RuntimeCamelException

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

the class Mina2NoResponseFromServerTest method testNoResponse.

@Test
public void testNoResponse() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    try {
        template.requestBody(String.format("mina2:tcp://localhost:%1$s?sync=true&codec=#myCodec", getPort()), "Hello World");
        fail("Should throw a CamelExchangeException");
    } catch (RuntimeCamelException e) {
        assertIsInstanceOf(CamelExchangeException.class, e.getCause());
    }
    mock.assertIsSatisfied();
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Test(org.junit.Test)

Example 4 with RuntimeCamelException

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

the class NettyHttpBridgeRouteUsingHttpClientTest method testBridge.

@Test
public void testBridge() throws Exception {
    String response = template.requestBodyAndHeader("http://localhost:" + port2 + "/test/hello", new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "application/xml", String.class);
    assertEquals("Get a wrong response", "/", response);
    response = template.requestBody("http://localhost:" + port1 + "/hello/world", "hello", String.class);
    assertEquals("Get a wrong response", "/hello/world", response);
    try {
        template.requestBody("http://localhost:" + port2 + "/hello/world", "hello", String.class);
        fail("Expect exception here!");
    } catch (Exception ex) {
        assertTrue("We should get a RuntimeCamelException", ex instanceof RuntimeCamelException);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Test(org.junit.Test)

Example 5 with RuntimeCamelException

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

the class Olingo2Consumer method poll.

@Override
protected int poll() throws Exception {
    // invoke the consumer method
    final Map<String, Object> args = new HashMap<String, Object>();
    args.putAll(endpoint.getEndpointProperties());
    // let the endpoint and the Consumer intercept properties
    endpoint.interceptProperties(args);
    interceptProperties(args);
    try {
        // create responseHandler
        final CountDownLatch latch = new CountDownLatch(1);
        final Object[] result = new Object[1];
        final Exception[] error = new Exception[1];
        args.put(Olingo2Endpoint.RESPONSE_HANDLER_PROPERTY, new Olingo2ResponseHandler<Object>() {

            @Override
            public void onResponse(Object response) {
                result[0] = response;
                latch.countDown();
            }

            @Override
            public void onException(Exception ex) {
                error[0] = ex;
                latch.countDown();
            }

            @Override
            public void onCanceled() {
                error[0] = new RuntimeCamelException("OData HTTP Request cancelled");
                latch.countDown();
            }
        });
        doInvokeMethod(args);
        // guaranteed to return, since an exception on timeout is expected!!!
        latch.await();
        if (error[0] != null) {
            throw error[0];
        }
        return ApiConsumerHelper.getResultsProcessed(this, result[0], isSplitResult());
    } catch (Throwable t) {
        throw ObjectHelper.wrapRuntimeCamelException(t);
    }
}
Also used : HashMap(java.util.HashMap) RuntimeCamelException(org.apache.camel.RuntimeCamelException) CountDownLatch(java.util.concurrent.CountDownLatch) 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