You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by chanti <ch...@gmail.com> on 2017/03/10 02:32:22 UTC

how to aggregate multiple unmarshalled objects

Hi All, how to aggregate multiple unmarshalled objects , please check my
code.

DataFormat bindyForInsert = new BindyCsvDataFormat(User0001.class);
DataFormat bindyForDelete = new BindyCsvDataFormat(User0002.class);
DataFormat bindyForUpdate = new BindyCsvDataFormat(User0003.class);


from("file:{{filepath}}?noop=true") 
  split(body().tokenize("\n")) 
  .streaming() 
 
.when().body().startsWith("0001")).to("file:{{file_path}}?fileName={{insertfilename}}.ascii").unmarshal(bindyForInsert)
 
.when().body().startsWith("0002")).to("file:{{file_path}}?fileName={{defilename}}.ascii").unmarshal(bindyForDelete
)
 
.when().body().startsWith("0002")).to("file:{{file_path}}?fileName={{upfilename}}.ascii").unmarshal(bindyForUpdate)   
   .aggregate(constant(true), getFileAggregationStrategy()).end();



The below aggregation logic only gives the last unmarshall object
response(bindyForUpdate), I need all unmarshalled Objects in Exchange.


public Exchange aggregate(Exchange oldEx, Exchange newEx) {
            Message newIn = 	newEx.getIn();
            Object newBody = (Object)newEx.getIn().getBody();
            List list = null;
            if (oldEx == null) {
                    list = new ArrayList();
                    list.add(newBody);
                    newIn.setBody(list);
                    return newEx;
            } else {
                    Message in = oldEx.getIn();
                    list = in.getBody(ArrayList.class);
                    list.add(newBody);
                    return oldEx;
            }
    }



--
View this message in context: http://camel.465427.n5.nabble.com/how-to-aggregate-multiple-unmarshalled-objects-tp5795209.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to aggregate multiple unmarshalled objects

Posted by Claus Ibsen <cl...@gmail.com>.
See this EIP
http://camel.apache.org/composed-message-processor.html

with the _splitter only_ section, where you can put the aggregation
strategy on the splitter and do this fork/join pattern.

On Fri, Mar 10, 2017 at 3:32 AM, chanti <ch...@gmail.com> wrote:
>
> Hi All, how to aggregate multiple unmarshalled objects , please check my
> code.
>
> DataFormat bindyForInsert = new BindyCsvDataFormat(User0001.class);
> DataFormat bindyForDelete = new BindyCsvDataFormat(User0002.class);
> DataFormat bindyForUpdate = new BindyCsvDataFormat(User0003.class);
>
>
> from("file:{{filepath}}?noop=true")
>   split(body().tokenize("\n"))
>   .streaming()
>
> .when().body().startsWith("0001")).to("file:{{file_path}}?fileName={{insertfilename}}.ascii").unmarshal(bindyForInsert)
>
> .when().body().startsWith("0002")).to("file:{{file_path}}?fileName={{defilename}}.ascii").unmarshal(bindyForDelete
> )
>
> .when().body().startsWith("0002")).to("file:{{file_path}}?fileName={{upfilename}}.ascii").unmarshal(bindyForUpdate)
>    .aggregate(constant(true), getFileAggregationStrategy()).end();
>
>
>
> The below aggregation logic only gives the last unmarshall object
> response(bindyForUpdate), I need all unmarshalled Objects in Exchange.
>
>
> public Exchange aggregate(Exchange oldEx, Exchange newEx) {
>             Message newIn =     newEx.getIn();
>             Object newBody = (Object)newEx.getIn().getBody();
>             List list = null;
>             if (oldEx == null) {
>                     list = new ArrayList();
>                     list.add(newBody);
>                     newIn.setBody(list);
>                     return newEx;
>             } else {
>                     Message in = oldEx.getIn();
>                     list = in.getBody(ArrayList.class);
>                     list.add(newBody);
>                     return oldEx;
>             }
>     }
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-aggregate-multiple-unmarshalled-objects-tp5795209.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2