I did the following:

- Downloaded the zip file for Camel 2.12.3 (binary distribution)

- Added two java files to the example project "camel-example-ftp". The
files are called MyFileClient.java and MyFileClientRouteBuilder.java. Their
contents is embedded at the end of this mail.

- I started MyFileClient and dropped a file in the "target/in" directory.

- I get the exact same result as I described in my earlier post. I cannot
access the body contents of the original message.

Is this as designed or is it a bug (or have I misunderstood)?

/Bengt

*MyFileClient.java*
package org.apache.camel.example.ftp;

import org.apache.camel.main.Main;

public final class MyFileClient {

private MyFileClient() {
}

public static void main(String[] args) throws Exception {
Main main = new Main();
main.addRouteBuilder(new MyFileClientRouteBuilder());
main.enableHangupSupport();
main.run();
}
}


*MyFileClientRouteBuilder.java*
package org.apache.camel.example.ftp;

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;

public class MyFileClientRouteBuilder extends RouteBuilder {

@Override
public void configure() throws Exception {
// lets shutdown faster in case of in-flight messages stack up
getContext().getShutdownStrategy().setTimeout(10);

from("file:target/in").streamCaching().process(new Processor() {
  public void process(Exchange theExchange) {
  Message originalMessage =
theExchange.getUnitOfWork().getOriginalInMessage();
  System.out.println("Original message: " + originalMessage);
  System.out.println("Original body: " + originalMessage.getBody());
  System.out.println("Original body as string: " +
originalMessage.getBody(String.class));

  Message message = theExchange.getIn();
  System.out.println("Message: " + message);
  System.out.println("Body: " + message.getBody());
  System.out.println("Body as string: " + message.getBody(String.class));
  }
});
}
}



2014-03-12 16:51 GMT+01:00 Bengt Rodehav <[email protected]>:

> Thanks for your reply Claus.
>
> I changed my code to:
>
> from("file:in").streamcaching().process(new Processor() {
>   public void process(Exchange theExchange) {
>   Message originalMessage =
> theExchange.getUnitOfWork().getOriginalInMessage();
>   System.out.println(originalMessage); // 1
>   System.out.println("Body: " + originalMessage.getBody()); // 2
>   System.out.println("Body as string: " +
> originalMessage.getBody(String.class)); // 3
>   }
> });
>
> Unfortunately this makes no difference - I get the same result.
>
> Also, if I skip Step #2 above I still get "Body as string: null"  at step
> #3 so I don't think I'm reeading the body twice.
>
> /Bengt
>
>
>
> 2014-03-12 16:34 GMT+01:00 Claus Ibsen <[email protected]>:
>
> Hi
>>
>> No its streams playing tricks on you
>> http://camel.apache.org/why-is-my-message-body-empty.html
>>
>> So you get the body 2 times (at #2 and #3) and the 2nd time its empty.
>>
>> On Wed, Mar 12, 2014 at 4:29 PM, Bengt Rodehav <[email protected]> wrote:
>> > I'm using Camel 2.12.1.
>> >
>> > For error handling purposes I need access to the original message but
>> I'm
>> > having problems with that.
>> >
>> > In my error handler I do this:
>> >
>> >   Message originalMessage =
>> > theExchange.getUnitOfWork().getOriginalInMessage();
>> >   System.out.println(originalMessage); // 1
>> >   System.out.println("Body: " + originalMessage.getBody()); // 2
>> >   System.out.println("Body as string: " +
>> > originalMessage.getBody(String.class)); // 3
>> >
>> > The output at "1" is:
>> >
>> > TradeSet.xml
>> >
>> > The output at "2" is:
>> >
>> > Body:
>> >
>> GenericFile[C:\dev\karaf\connect-sts\head\apache-karaf2.3.4\bin\..\..\..\common\data\interfaces\ts2so\TradeSet.xml]
>> >
>> > The output at "3" is:
>> >
>> > Body as string: null
>> >
>> > I can reproduce this problem with a simple route that just uses the file
>> > component. Something like this:
>> >
>> > from("file:in").process(new Processor() {
>> >   public void process(Exchange theExchange) {
>> >   Message originalMessage =
>> > theExchange.getUnitOfWork().getOriginalInMessage();
>> >   System.out.println(originalMessage); // 1
>> >   System.out.println("Body: " + originalMessage.getBody()); // 2
>> >   System.out.println("Body as string: " +
>> > originalMessage.getBody(String.class)); // 3
>> >   }
>> > });
>> >
>> >
>> > Thus it seems like I can access the original message but I can't get the
>> > actual body content - at least not as a string. In my case the file
>> > contains an xml document that I need to get hold of. Is this a known
>> bug or
>> > have I misunderstood the purpose with the getOriginalMessage() method?
>> >
>> > /Bengt
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: [email protected]
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>> Make your Camel applications look hawt, try: http://hawt.io
>>
>
>

Reply via email to