camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hans Orbaan <hans.orb...@docdata.eu>
Subject RE: null body after transform method exception
Date Mon, 15 Jun 2015 06:56:29 GMT
Testcase (attachment was removed):

package route;

import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.fest.assertions.api.Assertions;
import org.junit.Test;

public class ExceptionToErrorRouteTest extends CamelTestSupport {

    private static final String START = "direct://test.start";
    private static final String END = "mock://test.end";
    private static final String ERROR = "mock://errors.start";
    private static final String BODY = "body";

    @Test
    public void testBeanExceptionToErrorRoute() throws Exception {
        testExceptionToErrorRoute();
    }

    @Test
    public void testTransformExceptionToErrorRoute() throws Exception {
        testExceptionToErrorRoute();
    }


    private void testExceptionToErrorRoute() throws Exception {

        this.getMockEndpoint(ERROR).expectedMessageCount(1);
        this.getMockEndpoint(ERROR).whenAnyExchangeReceived(new Processor() {

            @Override
            public void process(Exchange exchange) throws Exception {
                Object body = exchange.getIn().getBody();
                Assertions.assertThat(body).isNotNull();
                Assertions.assertThat(body).isEqualTo(BODY);
            }
        });

        this.getMockEndpoint(END).expectedMessageCount(0);

        this.template.sendBody(START, BODY);

        assertMockEndpointsSatisfied();
    }


    @Override
    protected RouteBuilder[] createRouteBuilders() {
        RouteBuilder builder = new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                errorHandler(deadLetterChannel(ERROR).retryAttemptedLogLevel(LoggingLevel.WARN));
                if ("testTransformExceptionToErrorRoute".equals(getTestMethodName())) {
                    from(START)
                    .routeId("exception.test.transform")
                    .transform().method(ErrorBean.class, ErrorBean.METHOD)
                    .to(END);
                } else {
                    from(START)
                    .routeId("exception.test.bean")
                    .bean(ErrorBean.class, ErrorBean.METHOD)
                    .to(END);
                }
            }
        };
        return new RouteBuilder[] { builder };
    }

    public static class ErrorBean {
        private static final String METHOD = "throwException";
        public static void throwException(Exchange exchange) {
            String body = exchange.getIn().getBody(String.class);
            Assertions.assertThat(body).isEqualTo(BODY);
            throw new AssertionError();
        }
    }
}



Van: Hans Orbaan [mailto:hans.orbaan@docdata.eu]
Verzonden: Monday 15 June 2015 8:51
Aan: users@camel.apache.org
Onderwerp: null body after transform method exception

Hello all,

When an exception is thrown from a transform method I lose the content of the message body.
Is that intentional or a bug? Because it does not happen when an exception is thrown from
a bean call.

.bean(ErrorBean.class, ErrorBean.METHOD)

Vs.

.transform().method(ErrorBean.class, ErrorBean.METHOD)

I have attached a testcase to demonstrate the issue.

Thanks!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message