Claus... It's me again. Sorry.
I moved the filter logic to the AggregateStrategy
I tried some variants to insert "end()" such as:


from("file:/Users/marcobettiol/IES/data?noop=true")

.split(body().tokenize("\n"), new TVCEOrderAggregateStrategy())

.end()

.to("file:/Users/marcobettiol/IES/copy?autoCreate=true");


but i get Route has no child Exception

--------------

failed to create route route1 at: >>> Split[{tokenize(body,

)} -> []] <<< in route:
Route[[From[file:/Users/marcobettiol/IES/data?noop=true]] ->... because of
Definition has no children on Split[{tokenize(body,

)} -> []]




2010/11/29 Claus Ibsen <claus.ib...@gmail.com>

> On Mon, Nov 29, 2010 at 10:26 AM, Marco Bettiol <jamiro...@gmail.com>
> wrote:
> > I'm using 2.5.0.
> > Ok I will try with your solution and let you know. :)
> > P.S.
> > Just for knowledge... Is my code right?
> >
>
> No the filter should not be in the split. Camel will always invoke the
> AggregationStrategy for each splitted message.
> So you should implement the logic here if you want to skip certain
> messages.
>
> And you should in essence use .end() in the route to denote when the
> filter / splitter ends.
>
> from
>  split
>     filter
>     end
>  end
>  to
>
> But you logic could simply be
>
> from
>  split
>  end
>  to
>
>
>
> > 2010/11/29 Claus Ibsen <claus.ib...@gmail.com>
> >
> >> Hi
> >>
> >> What version of Camel are you using?
> >>
> >> And you can also do your filter logic in the aggregator. Just return
> >> oldExchange if the newExchange should be skipped.
> >>
> >>
> >> On Sun, Nov 28, 2010 at 9:39 PM, Marco Bettiol <jamiro...@gmail.com>
> >> wrote:
> >> > Hi guys,
> >> >
> >> > I'm new to apache Camel. It sound really great.
> >> >
> >> > I was trying to build my first application. I got a file with entries
> of
> >> > different type and I want to generate a new file with only a subset of
> >> the
> >> > lines (in the final version I will have to build up a POJO and send it
> >> using
> >> > web-service).
> >> >
> >> >
> >> > The problem is that when I try to aggregate the lines the output file
> >> > contains only the last not filtered row
> >> >
> >> >
> >> > Thank you for your support :)
> >> >
> >> >    Marco
> >> >
> >> >
> >> >
> >> > Here is the code
> >> >
> >> > -------------------------------
> >> >
> >> > public class Test {
> >> >
> >> >  private DefaultCamelContext camel;
> >> >
> >> >  public static void main(String[] args) throws Exception{
> >> >
> >> >  new Test();
> >> >
> >> > }
> >> >
> >> >  public Test() throws Exception{
> >> >
> >> >  camel = new DefaultCamelContext();
> >> >
> >> >  camel.addRoutes(new RouteBuilder() {
> >> >
> >> >  public void configure() { from(
> >> > "file:/Users/marcobettiol/IES/data?noop=true")
> >> >
> >> >  .split(body().tokenize("\n"), new
> >> > TVCEOrderAggregateStrategy()).filter(newPredicate() {
> >> >
> >> >  @Override
> >> >
> >> >  public boolean matches(Exchange exchange) {
> >> >
> >> >   String content =exchange.getIn().getBody(String.class);
> >> >
> >> >   if(content.startsWith("vnboltes") || content.startsWith("vnbolcas"))
> >> >
> >> >   return true;
> >> >
> >> >   return true;
> >> >
> >> >   //keep everything for test
> >> >
> >> >  }
> >> >
> >> >  })
> >> >
> >> >  .to("file:/Users/marcobettiol/IES/copy?autoCreate=true");
> >> >
> >> >  }
> >> >
> >> >  });
> >> >
> >> >  camel.start();
> >> >
> >> >  Thread.sleep(5000);
> >> >
> >> >  camel.stop();
> >> >
> >> > }
> >> >
> >> >
> >> > }
> >> >
> >> > --------------------------
> >> >
> >> >   public class TVCEOrderAggregateStrategy implements
> AggregationStrategy{
> >> >
> >> >     public Exchange aggregate(Exchange oldExchange, Exchange
> newExchange)
> >> {
> >> >
> >> >        if (oldExchange == null) {
> >> >
> >> >            return newExchange;
> >> >
> >> >        }
> >> >
> >> >        String oldBody = oldExchange.getIn().getBody(String.class);
> >> >
> >> >        String newBody = newExchange.getIn().getBody(String.class);
> >> >
> >> >        String concatBody = oldBody.concat(newBody);
> >> >
> >> >        oldExchange.getIn().setBody(concatBody);
> >> >
> >> >        return oldExchange;
> >> >
> >> >
> >> >  }
> >> >
> >> >
> >> > }
> >> >
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> FuseSource
> >> Email: cib...@fusesource.com
> >> Web: http://fusesource.com
> >> Twitter: davsclaus
> >> Blog: http://davsclaus.blogspot.com/
> >> Author of Camel in Action: http://www.manning.com/ibsen/
> >>
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cib...@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>

Reply via email to