Hello!

In DefaultUnitOfWork (line 86 -93) we have the following code:

        if
(exchange.getIn().getClass().getSimpleName().equals("JmsMessage")) {
            this.originalInMessage = new DefaultMessage();
            this.originalInMessage.setBody(exchange.getIn().getBody());
            // cannot copy headers with a JmsMessage as the underlying
javax.jms.Message object goes nuts
        } else {
            this.originalInMessage = exchange.getIn().copy();
        }

Because of this, the following unit test will fail:
    @Test
    public void testUseOriginalMessage() throws Exception {
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                onException(Exception.class)
                    .useOriginalMessage()
                    .to(mockResult);

                from("jms:queue:foo")
                    .throwException(new Exception("forced exception for
test"));
            }
        });
        context.start();

        mockResult.expectedBodiesReceived("Hello World");
        mockResult.expectedHeaderReceived("header-key", "header-value"); //
will fail here

        template.sendBodyAndHeader("jms:queue:foo", "Hello World",
"header-key", "header-value");

        assertMockEndpointsSatisfied();
    }

I propose to change the DefaultUnitOfWork to also copy the headers in this
way:
        if
(exchange.getIn().getClass().getSimpleName().equals("JmsMessage")) {
            this.originalInMessage = new DefaultMessage();
            this.originalInMessage.setBody(exchange.getIn().getBody());

this.originalInMessage.setHeaders(exchange.getIn().getHeaders());
            // cannot copy headers with a JmsMessage as the underlying
javax.jms.Message object goes nuts
        } else {
            this.originalInMessage = exchange.getIn().copy();
        }

After this change the unit test passed. Also all unit tests in camel-core
and camel-jms passed. Any doubts for this change?

Best,
Christian

Reply via email to