java - Camel AggregatonStrategy wrong result -


i using camel aggregate responses 2 sources, 1 being xml , other json. have stubbed responses , getting them file. goal aggregate responses both sources.

my aggregator route looks this

    from("direct:fetchprofile")     .multicast(new profileaggregationstrategy()).stoponexception()     .enrich("direct:xmlprofile")     .enrich("direct:jsonprofile")     .end(); 

my "direct:xmlprofile" route looks -

    from("direct:xmlprofile")     .process(new processor(){      @override         public void process(exchange exchange) throws exception {             string filename = "target/classes/xml/customerdetails.xml";              inputstream filestream = new fileinputstream(filename);             exchange.getin().setbody(filestream);          }      })     .split(body().tokenizexml("attributes", null))     .unmarshal(jaxbdataformat)     .process(new processor(){         @override         public void process(exchange exchange) throws exception {             profile legacyprofile = exchange.getin().getbody(profile.class);             // more processing here             exchange.getin().setbody(legacyprofile);         }      }); 

in above route reading xml file , using jaxb converter map elements of interest class denoted 'profile'. after calling route, camel calls profileaggregationstrategy. code -

    public class profileaggregationstrategy implements aggregationstrategy{        @override        public exchange aggregate(exchange oldexchange, exchange newexchange) {              // problematic line              profile newprofile = newexchange.getin().getbody(profile.class);              if (oldexchange == null){                  return newexchange;              } else {                  profile oldprofile = oldexchange.getin().getbody(profile.class);                  // code copy merge oldprofile newprofile                  return oldexchange;              }          }     } 

the issue line marked 'problematic line'. though in final phase of route 'direct:xmlprofile' have explicitly put object body of exchange, newexchange in profileaggregationstrategy still shows body of type iostream.

read documentation splitter eip.

as output of splitter input, unless specify aggregation strategy splitter can decide output should be. example if want use last splitted element, there uselastestaggregrationstrategy can use.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -