java - Apache Camel: How to test for instance of Set<CustomObject> -


does know how test different types of collection in route?

// processor returns collection of 2 sets // 1. set<goodmessage> // 2. set<badmessage> .process(new mygoodbadmessageprocessor()) // split result list .split(body()).choice()     // how test set<goodmessage>??     .when(body().isinstanceof(set<goodmessage>)         .to("direct:good")     .otherwise()         .to("direct:bad") .endchoice() 

background: (in case can see better way of doing this) have processor works follows:

@override public void process(exchange exchange) throws exception {     message message = exchange.getin();     set<unknownmessage> unknownmessages = message.getbody(set.class);     set<goodmessage> goodmessages = new hashset<goodmessage>();      for(unknownmessage msg: unknownmessages) {         // simplified logic here         if (msg.isgood()) {             goodmessages.add(msg.getgoodmessage());         }     }      message.setbody(goodmessages); } 

i'd update include badmessage(s) reporting:

@override public void process(exchange exchange) throws exception {     message message = exchange.getin();     set<unknownmessage> unknownmessages = message.getbody(set.class);     set<goodmessage> goodmessages = new hashset<goodmessage>();     set<badmessage> badmessages = new hashset<badmessage>();      list result = new arraylist();      for(unknownmessage msg: unknownmessages) {         // simplified logic here         if (msg.isgood()) {             goodmessages.add(msg.getgoodmessage());         } else {             badmessages.add(msg.getbadmessage());         }     }      result.add(goodmessages)     result.add(badmessages)     message.setbody(result); } 

you cannot type of collection in way (nothing camel). way you've updated process method not need creating different end point bad messages.

one possible way send different end point based on message type add processor before choice inspects type of message , adds header. choice statement can work based on header.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -