You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by MichaelAtSAG <me...@gmail.com> on 2012/02/09 16:38:01 UTC

Problem with printing In.message.body

I create a new class that simply prints out the contents of the message. I am
finding the println command is changing the contents of the body.

As this code demonstrates, 
<1> STEP1 prints out the body as string. 
<2> STEP2 contains no output, the body is gone.

Why is the body empty in STEP2?
Is there a better way to printout the body?

public class ConsumerScreen implements Consumer {

	public void process(Exchange exchange) throws Exception {
// STEP1 - GOOD - HAS  CONTENT
		System.out.println(lineSep + exchange.getIn().getBody(String.class));
// STEP2 - BAD - HAS NO CONTENT
		System.out.println(lineSep + exchange.getIn().getBody(String.class));

	}
}

Thanks,
Michael

--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-printing-In-message-body-tp5469798p5469798.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem with printing In.message.body

Posted by MichaelAtSAG <me...@gmail.com>.
Thanks Claus, that was it!

--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-printing-In-message-body-tp5469798p5470016.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem with printing In.message.body

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Your body is most likely stream based that do not support re-reading the stream.

So either enable stream-caching, or convert the message body to
something that is not a stream.
http://camel.apache.org/stream-caching.html

On Thu, Feb 9, 2012 at 4:38 PM, MichaelAtSAG <me...@gmail.com> wrote:
> I create a new class that simply prints out the contents of the message. I am
> finding the println command is changing the contents of the body.
>
> As this code demonstrates,
> <1> STEP1 prints out the body as string.
> <2> STEP2 contains no output, the body is gone.
>
> Why is the body empty in STEP2?
> Is there a better way to printout the body?
>
> public class ConsumerScreen implements Consumer {
>
>        public void process(Exchange exchange) throws Exception {
> // STEP1 - GOOD - HAS  CONTENT
>                System.out.println(lineSep + exchange.getIn().getBody(String.class));
> // STEP2 - BAD - HAS NO CONTENT
>                System.out.println(lineSep + exchange.getIn().getBody(String.class));
>
>        }
> }
>
> Thanks,
> Michael
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-with-printing-In-message-body-tp5469798p5469798.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/