camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim <che...@gmail.com>
Subject Re: Error in MessageSupport when using JMSMessage
Date Wed, 17 Nov 2010 20:59:05 GMT
BTW, this is an error in logic in MessageSupport when interoperating
with JMSMessage it seems. I'm not quite sure what the intention was
when having it copy the old body over on null.

Can a committer please either confirm this as a bug (and I can try to
patch that would fix this without breaking other intended
functionality) or explain to me why this is not a bug if it was
designed this way?

Thanks
-Tim

On Tue, Nov 16, 2010 at 6:25 PM, Tim <chengt@gmail.com> wrote:
> This is essentially a different incantation of CAMEL-2436
> (https://issues.apache.org/activemq/browse/CAMEL-2436)
> A test case that reproduces the issue is below.
> If you have a bean that returns null when processing the body of a
> JMSMessage you will not get the null in the next endpoint but rather
> the original message itself.
> One really hacky way around this bug is to replace the JMSMessage with
> a DefaultMessage by adding a processor
>
>                    .process(
>                        new Processor() {
>                            @Override
>                            public void process(@NotNull Exchange
> anExchange) throws Exception {
>                                final DefaultMessage myIn = new
> DefaultMessage();
>                                myIn.setBody(anExchange.getIn().getBody());
>                                anExchange.setIn(myIn);
>                            }
>                        }
>                    )
>
> Into the below code after the from()
>
>
> import org.apache.activemq.ActiveMQConnectionFactory;
> import org.apache.activemq.command.ActiveMQObjectMessage;
> import org.apache.camel.Exchange;
> import org.apache.camel.Processor;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.jms.JmsComponent;
> import org.apache.camel.component.jms.JmsMessage;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.jetbrains.annotations.NotNull;
> import org.jetbrains.annotations.Nullable;
> import org.junit.Test;
>
> import javax.jms.JMSException;
>
> public class C2436Test extends CamelTestSupport {
>    private static final String ENDPOINT1 = "jms:mock";
>    private static final String ENDPOINT2 = "mock:results";
>    private static final String TEST_CONTENT = "My Test Content";
>
>    @NotNull
>    @Override
>    protected RouteBuilder createRouteBuilder() throws Exception {
>        context.addComponent("jms", JmsComponent.jmsComponent(new
> ActiveMQConnectionFactory("vm://localhost")));
>
>        return new RouteBuilder() {
>            @Override
>            public void configure() throws Exception {
>                from(ENDPOINT1)
>                    .bean(new ReturnsNull())
>                    .filter(body().isNull())
>                        .log("stopping:${body}")
>                            .stop()
>                        .end()
>                    .log("not-stopping:${body}")
>                    .to(ENDPOINT2);
>            }
>        };
>    }
>
>    @Test
>    public void testRoutePassing() throws InterruptedException, JMSException {
>        final MockEndpoint myMockEndpoint = getMockEndpoint(ENDPOINT2);
>
>        myMockEndpoint.expectedMessageCount(1);
>        myMockEndpoint.allMessages().body().isNull();
>
>        final ActiveMQObjectMessage myMessage = new ActiveMQObjectMessage();
>        myMessage.setObject(TEST_CONTENT);
>
>        template.send(ENDPOINT1, new Processor() {
>            @Override
>            public void process(@NotNull Exchange anExchange) throws Exception {
>                anExchange.setIn(new JmsMessage(myMessage, null));
>            }
>        });
>
>        myMockEndpoint.assertIsSatisfied();
>    }
>
>    public class ReturnsNull {
>        @Nullable
>        public String processMessage(@NotNull String aMessage) {
>            return null;
>        }
>    }
> }
>

Mime
View raw message