You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by "vs.souza" <vs...@gmail.com> on 2012/02/18 03:01:07 UTC
Process CSV using bindy and sending to JPA
Hello fellows.
I am creating a simple route to load data from a CSV using bindy and send it
to a JPA endpoint but it is not working. I'm trying to use the same bean for
Bindy and JPA entity. I tried a lot of different solutions but nothing
worked so far. Bellow I post my route, bean and log message:
Route:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="bindyDataFormat"
class="org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat">
<constructor-arg value="com.test.integration.camel.spring.poc.file"/>
</bean>
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="camelPU"/>
<property name="jpaVendorAdapter" ref="jpaAdapter"/>
</bean>
<bean id="jpaAdapter"
class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="databasePlatform"
value="org.apache.openjpa.jdbc.sql.MySQLDictionary" />
<property name="database" value="MYSQL"/>
</bean>
<bean id="transactionTemplate"
class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager">
<bean class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
</property>
</bean>
<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
<camel:package>com.test.integration.camel.spring.poc</camel:package>
<camel:route>
<camel:from
uri="file:/home/jedimaster/Java-Env/Sandbox/From?delete=true"/>
<camel:log message="Started unmarshalling file ${file:name}..."/>
<camel:split streaming="true" parallelProcessing="true">
<camel:tokenize token="\n"/>
<camel:unmarshal ref="bindyDataFormat"/>
<camel:to
uri="jpa:com.test.integration.camel.spring.poc.file.CSVEventRecordBean"/>
</camel:split>
<camel:log message="Finished unmarshalling file ${file:name}..."/>
</camel:route>
</camel:camelContext>
</beans>
Bean:
package com.test.integration.camel.spring.poc.file;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
import org.apache.camel.dataformat.bindy.annotation.DataField;
@Entity
@Table(name="file-event")
@CsvRecord(separator=",", quote="\"")
public class CSVEventRecordBean implements Serializable{
private static final long serialVersionUID = -8806841912643394977L;
@Column(name="event-date")
@DataField(pos=1)
private String eventDate;
@Column(name="user-id")
@DataField(pos=2)
private String userId;
@Column(name="system-id")
@DataField(pos=3)
private String systemId;
public String getEventDate() {
return eventDate;
}
public void setEventDate(String eventDate) {
this.eventDate = eventDate;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getSystemId() {
return systemId;
}
public void setSystemId(String systemId) {
this.systemId = systemId;
}
}
And this is my error message:
23:53:22,782 | INFO | Env/Sandbox/From | route1 |
90 - org.apache.camel.camel-core - 2.8.3 | Started unmarshalling file
AccessViolationGenDummy.csv...
23:53:23,105 | ERROR | hread #5 - Split | DefaultErrorHandler |
90 - org.apache.camel.camel-core - 2.8.3 | Failed delivery for exchangeId:
ID-deathstar-57412-1329529993318-0-5. Exhausted after delivery attempt: 1
caught: org.apache.camel.InvalidPayloadRuntimeException: No body available
of type: com.test.integration.camel.spring.poc.file.CSVEventRecordBean but
has value:
[{com.test.integration.camel.spring.poc.file.CSVEventRecordBean=com.test.integration.camel.spring.poc.file.CSVEventRecordBean@11c5c5c}]
of type: java.util.ArrayList on: Message:
[{com.test.integration.camel.spring.poc.file.CSVEventRecordBean=com.test.integration.camel.spring.poc.file.CSVEventRecordBean@11c5c5c}].
Caused by: No type converter available to convert from type:
java.util.ArrayList to the required type:
com.test.integration.camel.spring.poc.file.CSVEventRecordBean with value
[{com.test.integration.camel.spring.poc.file.CSVEventRecordBean=com.test.integration.camel.spring.poc.file.CSVEventRecordBean@11c5c5c}]
on the exchange: Exchange[Message:
[{com.test.integration.camel.spring.poc.file.CSVEventRecordBean=com.test.integration.camel.spring.poc.file.CSVEventRecordBean@11c5c5c}]]
org.apache.camel.InvalidPayloadRuntimeException: No body available of type:
com.test.integration.camel.spring.poc.file.CSVEventRecordBean but has value:
[{com.test.integration.camel.spring.poc.file.CSVEventRecordBean=com.test.integration.camel.spring.poc.file.CSVEventRecordBean@11c5c5c}]
of type: java.util.ArrayList on: Message:
[{com.test.integration.camel.spring.poc.file.CSVEventRecordBean=com.test.integration.camel.spring.poc.file.CSVEventRecordBean@11c5c5c}].
Caused by: No type converter available to convert from type:
java.util.ArrayList to the required type:
com.test.integration.camel.spring.poc.file.CSVEventRecordBean with value
[{com.test.integration.camel.spring.poc.file.CSVEventRecordBean=com.test.integration.camel.spring.poc.file.CSVEventRecordBean@11c5c5c}]
on the exchange: Exchange[Message:
[{com.test.integration.camel.spring.poc.file.CSVEventRecordBean=com.test.integration.camel.spring.poc.file.CSVEventRecordBean@11c5c5c}]]
at
org.apache.camel.component.jpa.JpaEndpoint$1.evaluate(JpaEndpoint.java:277)[219:org.apache.camel.camel-jpa:2.8.3]
at
org.apache.camel.impl.ExpressionAdapter.evaluate(ExpressionAdapter.java:36)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.component.jpa.JpaProducer.process(JpaProducer.java:49)[219:org.apache.camel.camel-jpa:2.8.3]
at
org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:114)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:284)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.SendProcessor.process(SendProcessor.java:109)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:90)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:318)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:209)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:306)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.Pipeline.process(Pipeline.java:116)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.Pipeline.process(Pipeline.java:79)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:318)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:209)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:139)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:106)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:104)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.MulticastProcessor.doProcessParallel(MulticastProcessor.java:704)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.MulticastProcessor.access$200(MulticastProcessor.java:79)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:294)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:279)[90:org.apache.camel.camel-core:2.8.3]
at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_26]
at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_26]
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_26]
at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_26]
at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_26]
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_26]
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_26]
at java.lang.Thread.run(Thread.java:662)[:1.6.0_26]
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type
converter available to convert from type: java.util.ArrayList to the
required type: com.test.integration.camel.spring.poc.file.CSVEventRecordBean
with value
[{com.test.integration.camel.spring.poc.file.CSVEventRecordBean=com.test.integration.camel.spring.poc.file.CSVEventRecordBean@11c5c5c}]
at
org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:144)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.core.osgi.OsgiTypeConverter.mandatoryConvertTo(OsgiTypeConverter.java:110)[94:org.apache.camel.camel-spring:2.8.3]
at
org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:100)[90:org.apache.camel.camel-core:2.8.3]
at
org.apache.camel.component.jpa.JpaEndpoint$1.evaluate(JpaEndpoint.java:274)[219:org.apache.camel.camel-jpa:2.8.3]
... 40 more
Do you guys have any tips about how I can solve this problem? This is
driving me nuts.
Cheers.
VinÃcius.
--
View this message in context: http://servicemix.396122.n5.nabble.com/Process-CSV-using-bindy-and-sending-to-JPA-tp5494547p5494547.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: Process CSV using bindy and sending to JPA
Posted by "vs.souza" <vs...@gmail.com>.
Hello fellows,
after some fight I got the solution for the problem described above.
I added a processor to get the value from ArrayList and set as the exchange
body. The processor is like this:
public class EventExchangeBodyProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
@SuppressWarnings("unchecked")
ArrayList<HashMap<String, Object>> body =
(ArrayList<HashMap<String, Object>>) exchange.getIn().getBody();
HashMap<String, Object> t = (HashMap<String, Object>) body.get(0);
exchange.getIn().setBody(t.get("com.test.integration.camel.spring.poc.file.CSVEventRecordBean"));
}
}
This is straight forward and by the time I didn't worried about Exception
Handling. Now I will fight with other problems to write to jpa endpoint.
Cheers.
--
View this message in context: http://servicemix.396122.n5.nabble.com/Process-CSV-using-bindy-and-sending-to-JPA-tp5494547p5502297.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.