java - Retrieve Response from Camel Session -


i working on csv object creation example use of camel.

i have create bean in have method operation, , method return list.

my question how able list outside camel.

source code:

public class person {     private string firstname;     private string lastname;      public string getfirstname() {         return firstname;     }      public void setfirstname(string firstname) {         this.firstname = firstname;     }      public string getlastname() {         return lastname;     }      public void setlastname(string lastname) {         this.lastname = lastname;     }      @override     public string tostring() {         // todo auto-generated method stub         return this.firstname + "===" + this.lastname;     } }    public class unmarshallingtest {      public static void main(string[] args) throws exception {         defaultcamelcontext context = new defaultcamelcontext();         // append routes context         context.addroutes(new unmarshallingtestroute());          csvtoperson csvtoperson = new csvtoperson();         simpleregistry reg = new simpleregistry();         reg.put("csvtoperson", csvtoperson);         context.setregistry(reg);         context.start();         thread.sleep(3000);         system.out.println("done");         context.stop();      }  }     public class unmarshallingtestroute extends routebuilder {       public void configure() throws exception {         from("file:/home/viral/projects/camel/cxfjavatest/src/data?noop=true")                        .unmarshal().csv()             .beanref("csvtoperson", "process");     } }    public class csvtoperson {      public list<person> process(list<list> csvrows) {         list<person> olist = new arraylist<person>();         system.out.println("called");         (list csvrow : csvrows) {             person person = new person();             person.setfirstname((string) csvrow.get(0));             person.setlastname((string) csvrow.get(1));             olist.add(person);             // dosomethingto(person);             system.out.println("++++++++++++++++++++++++++");             system.out.println(person);             system.out.println("++++++++++++++++++++++++++");         }         system.out.println("end");         return olist;     } } 

i have camel context object how able list context object.

i found 1 answer above question.

public class unmarshallingtest {      public static void main(string[] args) throws exception {         defaultcamelcontext context = new defaultcamelcontext();         // append routes context         context.addroutes(new unmarshallingtestroute());          //csvtoperson csvtoperson = new csvtoperson();         //simpleregistry reg = new simpleregistry();         //reg.put("csvtoperson", csvtoperson);         //context.setregistry(reg);          context.start();          consumertemplate ct = context.createconsumertemplate();          list data = (list<person>)ct.receivebody("seda:foo", 5000);          system.out.println("=================================");         system.out.println("return value::::" + data);         system.out.println("=================================");          thread.sleep(3000);          context.stop();      } }  public class unmarshallingtestroute extends routebuilder {       public void configure() throws exception {         from("file:/home/viral/projects/camel/cxfjavatest/src/data?noop=true")           .split(body().tokenize("\n")).streaming()             .unmarshal().csv()             .bean(csvtoperson.class).to ("seda:foo") ;     } } 

for consuming response have use seda. , after executing route have consume same, , list<person>.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -