When you get a JMS message initially, like:
from("activemq:SomeQueue").to("someProcessor");

the processor, "someProcessor" in this case, is invoked with a JmsExchange
that has an in message and no out message (i.e. out = null). The in message
is a JmsMessage, and that has the original JMS Message set in its jmsMessage
property. So far so good. When the processor attempts to use the out of the
JmsExchange something odd happens. Since out doesn't exist, it will be
lazily created, but when this happens, the original JMS Message isn't
transferred to the newly created JmsMessage object. The only way that the
out would get the Message is if you manually set it or some representation
of it in the body of the out JmsMessage.

I'm not sure whether this is a bug, but it seems odd behavior at least. I
observed the behavior in Camel 1.4, and the code doesn't seem to have
changed in 1.5. The relevant code is below.

JmsExchange.getOut(true):
    public JmsMessage getOut(boolean lazyCreate) {
        return (JmsMessage) super.getOut(lazyCreate);
    }

delegates to DefaultExchange for lazy creation:
    public Message getOut(boolean lazyCreate) {
        if (out == null && lazyCreate) {
            out = createOutMessage();
            configureMessage(out);
        }
        return out;
    }

which delegates back to JmsExchange for the create:
    protected JmsMessage createOutMessage() {
        return new JmsMessage();
    }

and then runs its own (DefaultMessage's) configure:
    protected void configureMessage(Message message) {
        if (message instanceof MessageSupport) {
            MessageSupport messageSupport = (MessageSupport)message;
            messageSupport.setExchange(this);
        }
    }

It seems that JmsExchange should have a line added to its getOut(boolean)
method like so:
    public JmsMessage getOut(boolean lazyCreate) {
        JmsMessage result = (JmsMessage) super.getOut(lazyCreate);
        result.setJmsMessage(((JmsMessage) getIn()).getJmsMessage());
        return result;
    }

-- 
View this message in context: 
http://www.nabble.com/JmsExchange.getOut%28%29-loses-the-original-JMS-Message-tp21586153s22882p21586153.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to