camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: CSV file
Date Thu, 16 Jul 2015 10:20:42 GMT
Read the javadoc of those apis, the receiveBody uses a timeout if
there is no data, so it wait 5 sec and return null if no data.

On Thu, Jul 16, 2015 at 8:02 AM, viral069 <viral.patel69@gmail.com> wrote:
> Thanks For Reply,
>
>
> But it gives me null as a output. I am providing a source code for same,
> Please suggest me the changes.
>
> public class UnMarshallingTest {
>
>         public static void main(String[] args) throws Exception {
>                 DefaultCamelContext context = new DefaultCamelContext();
>                 // append the routes to the 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();
>
>                 Object data = ct.receiveBody("seda:foo", 5000);
>
>                 System.out.println("Return Value::::" + data);
>                 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()
>             .beanRef("csvToPerson", "process").to ("seda:foo") ;
>         }
> }
>
> public class CSVToPerson {
>
>         public List<Person> process(List<List> csvRows) {
>                 List<Person> oList = new ArrayList<Person>();
>                 System.out.println("called");
>                 for (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;
>         }
> }
>
> 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;
>         }
>
> }
>
> Please suggest me the changes
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/CSV-file-tp466057p5769376.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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

Mime
View raw message