camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mirko Caserta <mirko.case...@gmail.com>
Subject Re: choice when check BodyType:null, Body:null
Date Tue, 09 Aug 2011 18:57:42 GMT
I've never implemented a component myself, but I think you should
override the PollingConsumer implementation of your file component if
you want your component to be able to manipulate the exchange's
contents.

In your code your are simply creating a new blank exchange (which by
default has no body), then passing it to a processor which will print
its contents.

Are you sure you need a component to do that? Manipulating contents
can be easily done by plugging a custom processor in your route.

Mirko

On Tue, Aug 9, 2011 at 8:25 PM, Tereza Nedelescu <tnedelescu@tagged.com> wrote:
> Hi, I am trying to modify the contents of a file using a Camel processor in a
> Camel component that I created.
> When I do the routing from one file to another using my component, it works.
> However, when trying to modify the contents of the file using the processor
> and putting the modified text in the second file, it doesn't work, it says
> the contents are null. See the code below:
>
> public class ComponentStub extends DefaultComponent {
>            public Endpoint createEndpoint(String uri, String remaining,
> Map&lt;String, Object&gt; parameters) throws Exception {
>                          FileComponent fileComp = new FileComponent();
>                          fileComp.setCamelContext(this.getCamelContext());
>                          Collection<Endpoint> endpointCol =
> fileComp.getCamelContext().getEndpoints();
>                          Iterator endpointIt = endpointCol.iterator(); endpointIt.next();
> endpointIt.next(); endpointIt.next();
>                          Endpoint e4 = (Endpoint)endpointIt.next();
>
>                         Exchange inExchange = e4.createExchange();
>                         final Processor myProcessor = new Processor() {
>                             public void process(Exchange exchange) throws
Exception {
>                                     String body = (String) exchange.getIn().getBody();
>                                     System.out.println(exchange);
>
> System.out.println(exchange.getFromEndpoint());
>                             }
>                        }
>                        myProcessor.process(inExchange);
>
>                       FileEndpoint outEndPt = (FileEndpoint)
> fileComp.createEndpoint(uri);
>                       return outEndPt;
>        }
> }
>
> Output: Exchange[Message: [Body is null]]
>
> Endpoint[file:///home/tnedelescu/workspace/CurrentMavenProject/src/alogatr/src/data/input/Component?noop=true]
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/choice-when-check-BodyType-null-Body-null-tp4259599p4683052.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Mime
View raw message