Search in sources :

Example 96 with RuntimeCamelException

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

the class FluentProducerTemplateTest method testRequestExceptionUsingBody.

public void testRequestExceptionUsingBody() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    try {
        DefaultFluentProducerTemplate.on(context).withBody("Hello World").to("direct:exception").request();
        fail("Should have thrown RuntimeCamelException");
    } catch (RuntimeCamelException e) {
        assertTrue(e.getCause() instanceof IllegalArgumentException);
        assertEquals("Forced exception by unit test", e.getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 97 with RuntimeCamelException

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

the class MyServiceProxyTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").choice().when(body().isEqualTo("Tiger in Action")).throwException(new MyApplicationException("No tigers", 9)).when(body().isEqualTo("Donkey in Action")).throwException(new RuntimeCamelException(new MyApplicationException("No donkeys", 8))).when(body().isEqualTo("Elephant in Action")).throwException(new MyCustomException("Damn", new MyApplicationException("No elephants", 7))).when(body().isEqualTo("Kaboom")).throwException(new IllegalArgumentException("Damn")).otherwise().transform(constant("Camel in Action"));
            from("direct:request").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    MyRequest request = exchange.getIn().getBody(MyRequest.class);
                    MyResponse response = new MyResponse();
                    response.id = request.id;
                    response.response = "Hi " + request.request;
                    // we need to setup the body as a response
                    exchange.getOut().setBody(response);
                }
            });
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 98 with RuntimeCamelException

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

the class TimerEndpointTest method testTimerEndpointNoProducer.

public void testTimerEndpointNoProducer() throws Exception {
    Endpoint te = context.getEndpoint("timer://foo");
    try {
        te.createProducer();
        fail("Should have thrown an exception");
    } catch (RuntimeCamelException e) {
    // expected
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 99 with RuntimeCamelException

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

the class ValidatingProcessorTest method testInvalidMessage.

public void testInvalidMessage() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:invalid");
    mock.expectedMessageCount(1);
    String xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + "<user xmlns=\"http://foo.com/bar\">" + "  <username>someone</username>" + "</user>";
    try {
        template.sendBody("direct:start", xml);
        fail("Should have thrown a RuntimeCamelException");
    } catch (RuntimeCamelException e) {
        assertTrue(e.getCause() instanceof SchemaValidationException);
    // expected
    }
    assertMockEndpointsSatisfied();
}
Also used : SchemaValidationException(org.apache.camel.processor.validation.SchemaValidationException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 100 with RuntimeCamelException

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

the class ValidatingProcessorTest method testNonWellFormedXml.

public void testNonWellFormedXml() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:invalid");
    mock.expectedMessageCount(1);
    String xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + "user xmlns=\"http://foo.com/bar\">" + "  <id>1</id>" + "  <username>davsclaus</username>";
    try {
        template.sendBody("direct:start", xml);
        fail("Should have thrown a RuntimeCamelException");
    } catch (RuntimeCamelException e) {
        assertTrue(e.getCause() instanceof SchemaValidationException);
    // expected
    }
    assertMockEndpointsSatisfied();
}
Also used : SchemaValidationException(org.apache.camel.processor.validation.SchemaValidationException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) 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