Camel Route
package com.csv.xml;

import java.util.List;
import java.util.Map;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.DataFormat;

import com.csv.xml.model.EmployeeDTO;

public class ConvertorRoute implements RoutesBuilder {

                @Override
                public void addRoutesToCamelContext(CamelContext context) 
throws Exception {
                                context.addRoutes(new RouteBuilder() {
                                                public void configure() {
                                                                try {
                                                                                
DataFormat bindy = new BindyCsvDataFormat(
                                                                                
                                "com.csv.xml.model");
                                                                                
from("file://D:/Input?noop=true").log("${body}")
                                                                                
                                .unmarshal(bindy).process(new Processor() {
                                                                                
                                                @Override
                                                                                
                                                public void process(Exchange 
exchange)
                                                                                
                                                                                
throws Exception {
                                                                                
                                                                EmployeeDTO 
employeeDTO = (EmployeeDTO) (convertRecordDetails((List) 
exchange.getIn().getBody()));
                                                                                
                                                                
System.out.println(employeeDTO.toString());
                                                                                
                                                }

                                                                                
                                                private Object 
convertRecordDetails(
                                                                                
                                                                                
List<Map<String, Object>> orders) {
                                                                                
                                                                Object 
unmarshallObject = null;
                                                                                
                                                                for 
(Map<String, Object> order : orders) {
                                                                                
                                                                                
for (String key : order.keySet()) {
                                                                                
                                                                                
                unmarshallObject = (Object) order
                                                                                
                                                                                
                                                .get(key);
                                                                                
                                                                                
}
                                                                                
                                                                }
                                                                                
                                                                return 
unmarshallObject;
                                                                                
                                                }
                                                                                
                                });

                                                                                
// marshal().
                                                                                
//
                                                                                
// xstream().
                                                                                
// log("${body}").
                                                                                
// to("file://E:/OutPut?fileName=employee.xml");
                                                                } catch 
(Exception e) {
                                                                                
e.printStackTrace();
                                                                }
                                                }
                                });
                }

                public static void main(String[] args) {
                                try {
                                                CamelContext context = new 
DefaultCamelContext();
                                                ConvertorRoute route = new 
ConvertorRoute();
                                                
route.addRoutesToCamelContext(context);
                                                context.start();
                                                Thread.sleep(5000);
                                                context.stop();
                                } catch (Exception exe) {
                                                exe.printStackTrace();
                                }

                }
}
Bindy Model:
package com.csv.xml.model;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
import org.apache.camel.dataformat.bindy.annotation.DataField;

@XmlRootElement
@CsvRecord(separator = "\\|" )
public class EmployeeDTO implements Serializable {

       @Override
       public String toString() {
              return "EmployeeDTO [employeeId=" + employeeId + ", firstName="
                           + firstName + ", lastName=" + lastName + ", role1=" 
+ role1
                           + ", employeeId2=" + employeeId2 + ", firstName3=" + 
firstName3
                           + ", lastName4=" + lastName4 + ", role2=" + role2
                           + ", firstName2=" + firstName2 + ", lastName3=" + 
lastName3
                           + ", role4=" + role4 + "]";
       }

       /**
       *
        */
       private static final long serialVersionUID = 1L;

      @DataField(pos = 1,trim=true)
       private String employeeId;
      @DataField(pos = 2 )
       private String firstName;
      @DataField(pos = 3)
       private String lastName;
      @DataField(pos = 4,trim=true)
       private String role1;
      @DataField(pos = 5,trim=true)
       private String employeeId2;
      @DataField(pos = 6)
       private String firstName3;
      @DataField(pos = 7)
       private String lastName4;
      @DataField(pos = 8)
       private String role2;
       @DataField(pos =9)
       private String firstName2;
      @DataField(pos = 10)
       private String lastName3;
      @DataField(pos = 11)
       private String role4;



       public String getRole1() {
              return role1;
       }

       public void setRole1(String role1) {
              this.role1 = role1;
       }


       public String getFirstName3() {
              return firstName3;
       }

       public void setFirstName3(String firstName3) {
              this.firstName3 = firstName3;
       }

       public String getLastName4() {
              return lastName4;
       }

       public void setLastName4(String lastName4) {
              this.lastName4 = lastName4;
       }

       public String getRole2() {
              return role2;
       }

       public void setRole2(String role2) {
              this.role2 = role2;
       }

       public String getFirstName2() {
              return firstName2;
       }

       public void setFirstName2(String firstName2) {
              this.firstName2 = firstName2;
       }

       public String getLastName3() {
              return lastName3;
       }

       public void setLastName3(String lastName3) {
              this.lastName3 = lastName3;
       }

       public String getRole4() {
              return role4;
       }

       public void setRole4(String role4) {
              this.role4 = role4;
       }

       public static long getSerialversionuid() {
              return serialVersionUID;
       }


       public String getEmployeeId() {
              return employeeId;
       }

       public void setEmployeeId(String employeeId) {
              this.employeeId = employeeId;
       }

       public String getEmployeeId2() {
              return employeeId2;
       }

       public void setEmployeeId2(String employeeId2) {
              this.employeeId2 = employeeId2;
       }

       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 ;
       }


}

This is just a sample code which I did.
Anyway Thank you for replying me.
From: sergarci [via Camel] [mailto:[email protected]]
Sent: Friday, July 18, 2014 5:25 PM
To: Jayashankar C (WT01 - ENU)
Subject: Re: Bindy problem in reading the file

It seems a encodding error or something with the quote to me.
Can I see the code?
________________________________
If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/Bindy-problem-in-reading-the-file-tp5753989p5753998.html
To unsubscribe from Bindy problem in reading the file, click 
here<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5753989&code=amF5YXNoYW5rYXIuYzQzQHdpcHJvLmNvbXw1NzUzOTg5fDg0MDQxMzE4Mw==>.
NAML<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>

The information contained in this electronic message and any attachments to 
this message are intended for the exclusive use of the addressee(s) and may 
contain proprietary, confidential or privileged information. If you are not the 
intended recipient, you should not disseminate, distribute or copy this e-mail. 
Please notify the sender immediately and destroy all copies of this message and 
any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should 
check this email and any attachments for the presence of viruses. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email.

www.wipro.com




--
View this message in context: 
http://camel.465427.n5.nabble.com/Bindy-problem-in-reading-the-file-tp5753989p5753999.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to