You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by contactreji <co...@gmail.com> on 2014/04/05 13:57:50 UTC

ReturnType of Bindy - CSV to JAva Obj

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.

Re: ReturnType of Bindy - CSV to JAva Obj

Posted by Charles Moulliard <ch...@gmail.com>.
This is because you will receive a HashMap from Bindy and in your code here

   listofResults = exchange.getIn().getBody(ArrayList.class);

you map what you get from Camel Exchange as Array


On Sun, Apr 6, 2014 at 2:17 PM, contactreji <co...@gmail.com> wrote:

> Hi Charles.
>
> Am not returning anything explicitly though. Am trying to send the java
> objects returned by Bindy to a seda/direct endpoint ..
>
> Can u help me in adjusting the code to make it work?
>
> Any ideas would be helpful .
>
> Cheers
> Reji
> On 06/04/2014 5:40 pm, "Charles Moulliard-2 [via Camel]" <
> ml-node+s465427n5749857h46@n5.nabble.com> wrote:
>
> > I don't see in the camel examples that you call your processor. Anyway,
> > your error is related to the fact that wrong type returned by a processor
> > that you call.
> >
> >
> > On Sat, Apr 5, 2014 at 1:57 PM, contactreji <[hidden email]<
> http://user/SendEmail.jtp?type=node&node=5749857&i=0>>
> > wrote:
> >
> > > 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.
> > >
> >
> >
> >
> > --
> > Charles Moulliard
> > Apache Committer / Architect @RedHat
> > Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io
> >
> >
> > ------------------------------
> >  If you reply to this email, your message will be added to the discussion
> > below:
> >
> >
> http://camel.465427.n5.nabble.com/ReturnType-of-Bindy-CSV-to-JAva-Obj-tp5749842p5749857.html
> >  To unsubscribe from ReturnType of Bindy - CSV to JAva Obj, click here<
> http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5749842&code=Y29udGFjdHJlamlAZ21haWwuY29tfDU3NDk4NDJ8MTAwNDkxODIzMw==
> >
> > .
> > 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
> >
> >
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/ReturnType-of-Bindy-CSV-to-JAva-Obj-tp5749842p5749858.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io

Re: ReturnType of Bindy - CSV to JAva Obj

Posted by contactreji <co...@gmail.com>.
Hi Charles.

Am not returning anything explicitly though. Am trying to send the java
objects returned by Bindy to a seda/direct endpoint ..

Can u help me in adjusting the code to make it work?

Any ideas would be helpful .

Cheers
Reji
On 06/04/2014 5:40 pm, "Charles Moulliard-2 [via Camel]" <
ml-node+s465427n5749857h46@n5.nabble.com> wrote:

> I don't see in the camel examples that you call your processor. Anyway,
> your error is related to the fact that wrong type returned by a processor
> that you call.
>
>
> On Sat, Apr 5, 2014 at 1:57 PM, contactreji <[hidden email]<http://user/SendEmail.jtp?type=node&node=5749857&i=0>>
> wrote:
>
> > 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.
> >
>
>
>
> --
> Charles Moulliard
> Apache Committer / Architect @RedHat
> Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/ReturnType-of-Bindy-CSV-to-JAva-Obj-tp5749842p5749857.html
>  To unsubscribe from ReturnType of Bindy - CSV to JAva Obj, click here<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5749842&code=Y29udGFjdHJlamlAZ21haWwuY29tfDU3NDk4NDJ8MTAwNDkxODIzMw==>
> .
> 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>
>




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

Re: ReturnType of Bindy - CSV to JAva Obj

Posted by Charles Moulliard <ch...@gmail.com>.
I don't see in the camel examples that you call your processor. Anyway,
your error is related to the fact that wrong type returned by a processor
that you call.


On Sat, Apr 5, 2014 at 1:57 PM, contactreji <co...@gmail.com> wrote:

> 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.
>



-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io