Hey Guys

I was creating a POC which reads a CSV file with following content

*reji,mathews,2681,pass
jack,rose,261,fail
*
The class defined is as follows 
*
package com.poc.camel.csv.java.bindy;

import java.io.Serializable;

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 = ",",crlf="WINDOWS",generateHeaderColumns=false)
public class Result implements Serializable{
    
    @DataField(pos = 1)
    private String firstName; 
 
    @DataField(pos = 2)
    private String lastName;
 
    @DataField(pos = 3)
    private String rollNo;
 
    @DataField(pos = 4)
    private String result;

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

        public String getRollNo() {
                return rollNo;
        }

        public void setRollNo(String rollNo) {
                this.rollNo = rollNo;
        }

        public String getResult() {
                return result;
        }

        public void setResult(String result) {
                this.result = result;
        }
        
}

*

My CAMEL Route file looks like

*
        <bean id="bindyDataformat"
                
class="org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat">
                <constructor-arg value="com.poc.camel.csv.java.bindy" />
        </bean>

        <bean id="csv" class="com.poc.camel.csv.java.bindy.HandleOrderBean" />

        <camelContext xmlns="http://camel.apache.org/schema/spring";>

                <dataFormats>
                        <jaxb id="myJaxb" prettyPrint="true"
contextPath="com.poc.camel.csv.java.bindy" />
                </dataFormats>
                
                
                
                
                  <route streamCache="true">
            <from uri="file://C:/Users/Mathews/Desktop/in" />
            <unmarshal ref="bindyDataformat" />
            <to uri="bean:csv" />
         
        </route>
 
        <route>
            <from uri="seda:queue:in" />
            <to uri="log:reached route 2"/>
            <marshal ref="myJaxb" />
            <to uri="file://C:/Users/Mathews/Desktop/out" />
        </route>
                
        </camelContext>

</beans>
*

And my Java Processor looks like follows
*
package com.poc.camel.csv.java.bindy;

import java.util.ArrayList;
import java.util.List;

import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.DefaultProducerTemplate;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;

public class HandleOrderBean implements Processor {

        @SuppressWarnings("unchecked")
        @Override
        public void process(Exchange exchange) throws Exception {
                // TODO Auto-generated method stub

                CamelContext context = new DefaultCamelContext();
                ProducerTemplate template = context.createProducerTemplate();
                Result result = new Result();
                List<Result> listofResults = new ArrayList<Result>();
                listofResults = exchange.getIn().getBody(ArrayList.class);
                for (int i = 0; i < listofResults.size(); i++) {
                        result = listofResults.get(i);
                        
                        // send to a specific queue
                        template.sendBody("seda:queue:in", result);

                }

        }

}
*


But I get following error
*
[pache.camel.spring.Main.main()] DefaultStreamCachingStrategy   INFO 
StreamCaching in use with spool directory:
C:\Users\Mathews\AppData\Local\Temp\camel\camel-tmp-127025a0-28cb-44a3-9b80-be5cc749ee46
and rules: [Spool > 128K body size]
[pache.camel.spring.Main.main()] JaxbDataFormat                 INFO 
Creating JAXBContext with contextPath: com.poc.camel.csv.java.bindy and
ApplicationContextClassLoader: java.net.URLClassLoader@90b96e
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Route:
route1 started and consuming from:
Endpoint[file://C:/Users/Mathews/Desktop/in]
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Route:
route2 started and consuming from: Endpoint[seda://queue:in]
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Total
2 routes, of which 2 is started.
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Apache
Camel 2.12.2 (CamelContext: camel-1) started in 1.331 seconds
[://C:/Users/Mathews/Desktop/in] DefaultErrorHandler            ERROR Failed
delivery for (MessageId: ID-REJI-PC-49519-1396698959426-0-1 on ExchangeId:
ID-REJI-PC-49519-1396698959426-0-2). Exhausted after delivery attempt: 1
caught: java.lang.ClassCastException: java.util.HashMap cannot be cast to
com.poc.camel.csv.java.bindy.Result

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                             
                                          
Elapsed (ms)
[route1            ] [route1            ]
[file://C:/Users/Mathews/Desktop/in                                           
] [       130]
[route1            ] [unmarshal1        ] [unmarshal[ref:bindyDataformat]       
                                        
] [        83]
[route1            ] [to1               ] [bean:csv                             
                                        
] [        32]

Exchange
---------------------------------------------------------------------------------------------------------------------------------------
Exchange[
        Id                  ID-REJI-PC-49519-1396698959426-0-2
        ExchangePattern     InOnly
        Headers             {breadcrumbId=ID-REJI-PC-49519-1396698959426-0-1,
CamelFileAbsolute=true,
CamelFileAbsolutePath=C:\Users\Mathews\Desktop\in\test.txt,
CamelFileLastModified=1396688098196, CamelFileLength=50,
CamelFileName=test.txt, CamelFileNameConsumed=test.txt,
CamelFileNameOnly=test.txt, CamelFileParent=C:\Users\Mathews\Desktop\in,
CamelFilePath=C:\Users\Mathews\Desktop\in\test.txt,
CamelFileRelativePath=test.txt, CamelRedelivered=false,
CamelRedeliveryCounter=0}
        BodyType            java.util.ArrayList
        Body               
[{com.poc.camel.csv.java.bindy.Result=com.poc.camel.csv.java.bindy.Result@3a4f1},
{com.poc.camel.csv.java.bindy.Result=com.poc.camel.csv.java.bindy.Result@141f75b}]
]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
java.lang.ClassCastException: java.util.HashMap cannot be cast to
com.poc.camel.csv.java.bindy.Result
        at
com.poc.camel.csv.java.bindy.HandleOrderBean.process(HandleOrderBean.java:27)[file:/C:/Users/Mathews/workspace/camel-csv-java-bindy/target/classes/:]
        at
org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:97)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:67)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:103)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:401)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:201)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:165)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)[camel-core-2.12.2.jar:2.12.2]
        at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)[camel-core-2.12.2.jar:2.12.2]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown
Source)[:1.7.0_45]
        at java.util.concurrent.FutureTask.runAndReset(Unknown 
Source)[:1.7.0_45]
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown
Source)[:1.7.0_45]
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown
Source)[:1.7.0_45]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown
Source)[:1.7.0_45]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
Source)[:1.7.0_45]
        at java.lang.Thread.run(Unknown Source)[:1.7.0_45]
[://C:/Users/Mathews/Desktop/in] GenericFileOnCompletion        WARN 
Rollback file strategy:
org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy@4729ca
for file: GenericFile[C:\Users\Mathews\Desktop\in\test.txt]
[://C:/Users/Mathews/Desktop/in] DefaultErrorHandler            ERROR Failed
delivery for (MessageId: ID-REJI-PC-49519-1396698959426-0-3 on ExchangeId:
ID-REJI-PC-49519-1396698959426-0-4). Exhausted after delivery attempt: 1
caught: java.lang.ClassCastException: java.util.HashMap cannot be cast to
com.poc.camel.csv.java.bindy.Result

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                             
                                          
Elapsed (ms)
[route1            ] [route1            ]
[file://C:/Users/Mathews/Desktop/in                                           
] [         3]
[route1            ] [unmarshal1        ] [unmarshal[ref:bindyDataformat]       
                                        
] [         2]
[route1            ] [to1               ] [bean:csv                             
                                        
] [         1]

Exchange
---------------------------------------------------------------------------------------------------------------------------------------
Exchange[
        Id                  ID-REJI-PC-49519-1396698959426-0-4
        ExchangePattern     InOnly
        Headers             {breadcrumbId=ID-REJI-PC-49519-1396698959426-0-3,
CamelFileAbsolute=true,
CamelFileAbsolutePath=C:\Users\Mathews\Desktop\in\test.txt,
CamelFileLastModified=1396688098196, CamelFileLength=50,
CamelFileName=test.txt, CamelFileNameConsumed=test.txt,
CamelFileNameOnly=test.txt, CamelFileParent=C:\Users\Mathews\Desktop\in,
CamelFilePath=C:\Users\Mathews\Desktop\in\test.txt,
CamelFileRelativePath=test.txt, CamelRedelivered=false,
CamelRedeliveryCounter=0}
        BodyType            java.util.ArrayList
        Body               
[{com.poc.camel.csv.java.bindy.Result=com.poc.camel.csv.java.bindy.Result@33827c},
{com.poc.camel.csv.java.bindy.Result=com.poc.camel.csv.java.bindy.Result@1bba333}]
]

*


Can you help with this? Basically I am trying to create a java obj using CSV
data and later trying to print them as XML data. 





--
View this message in context: 
http://camel.465427.n5.nabble.com/ReturnType-of-Bindy-CSV-to-JAva-Obj-tp5749842.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to