The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

vs.souza (4) [Avatar] Offline
#1
Hello fellows,

I am creating a route using camel and trying to deploy in servicemix. Everything was fine untill I added bindy to the game. I already read the chapter that explains csv parsing from Camel in action a few times but couldn't find my error. Can you guys help me please? Another question I have is that I am passing a parameter to the BindyCsvDataFormat but couldn't find an explanation about what this parameter means to get the full understanding. Can someone explain it to me please?

My software versions is Apache ServiceMix 4.4.0 and the libraries looks like Camel 2.8.3 and JDK 1.6.0_26.

I have the following features installed:
karaf-framework
spring
spring-dm
spring-jms
spring-test
spring-tx
spring-web
config
jetty
http
war
cxf-specs
cxf-jaxb
cxf-abdera
opensaml
wss4j
cxf-saaj-impl
cxf-war-java5
cxf
camel-activemq
activemq-broker
activemq
activemq-spring
activemq-blueprint
activemq-web-console
camel
camel-core
camel-spring
camel-blueprint
camel-cxf
camel-jms
camel-bindy
camel-spring-javaconfig



My camel-context.xml is like this:


<?xml version="1.0" encoding="UTF-8"?>
<!-- <br /> Licensed to the Apache Software Foundation (ASF) under one or more <br /> contributor license agreements. See the NOTICE file distributed with <br /> this work for additional information regarding copyright ownership. <br /> The ASF licenses this file to You under the Apache License, Version 2.0 <br /> (the "License"); you may not use this file except in compliance with <br /> the License. You may obtain a copy of the License at <br /> <br /> http://www.apache.org/licenses/LICENSE-2.0 <br /> <br /> Unless required by applicable law or agreed to in writing, software <br /> distributed under the License is distributed on an "AS IS" BASIS, <br /> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br /> See the License for the specific language governing permissions and <br /> limitations under the License. <br /> -->

<!-- Configures the Camel Context-->

<beans xmlns="http://www.springframework.org/schema/beans" >
xmlnssmiliesi="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="csvBindyDataFormat" class="org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat">
<constructor-arg value="com.test.file.csv"/>
<property name="locale" value="en_US"/>
</bean>

<bean id="csvRecord" class="com.test.file.csv.CsvFileRecordBean"/>

<!-- Queuing engine - ActiveMQ - works locally in mode virtual memory -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="vm://localhost:61616"/>
</bean>

<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
<camel:package>com.test.file.csv</camel:package>
<camel:jmxAgent id="jmxAgent" disabled="true"/>
<camel:route>
<camel:from uri="file:/home/jedimaster/Java-Env/Sandbox/From?noop=true"/>
<camel:log message="Started parsing file ${file:name} to JMS Queue at ${date:now:hh:MM:ss:SSS}"/>
<!-- Start unmarshaling file to send to queue -->
<camel:unmarshal ref="csvBindyDataFormat"/>
<camel:to uri="bean:csvRecord"/>
<!-- End of file unmarshaling process -->
<camel:to uri="activemq:queue:file-message-input"/>
<camel:log message="Finished parsing file ${file:name} to JMS Queue at ${date:now:hh:MM:ss:SSS}"/>
</camel:route>
</camel:camelContext>
</beans>

My bean is inside the package com.test.file.csv and its name is CsvFileRecordBean. The bean code is this:


package com.test.file.csv;

/*
* Reference from camel.apache.org/bindy.html
*/

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

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

@CsvRecord(separator=",", quote=""")
public class CsvFileRecordBean implements Serializable{

private static final long serialVersionUID = -2801015097800960319L;

public CsvFileRecordBean() {
Calendar cal = Calendar.getInstance();
processDate = cal.getTime();
}

@DataField(pos=1, pattern="EEE MMM dd HH:mm:ss z yyyy")
private Date eventDate;

@DataField(pos=2)
private String sysId;

@DataField(pos=3)
private String userId;

private Date processDate;

public Date getEventDate() {
return eventDate;
}

public void setEventDate(Date eventDate) {
this.eventDate = eventDate;
}

public String getSysId() {
return sysId;
}

public void setSysId(String sysId) {
this.sysId = sysId;
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public Date getProcessDate() {
return processDate;
}
}

My pom file is this:


<?xml version="1.0" encoding="UTF-8"?>
<!-- <br /> <br /> Licensed to the Apache Software Foundation (ASF) under one or more <br /> contributor license agreements. See the NOTICE file distributed with <br /> this work for additional information regarding copyright ownership. <br /> The ASF licenses this file to You under the Apache License, Version 2.0 <br /> (the "License"); you may not use this file except in compliance with <br /> the License. You may obtain a copy of the License at <br /> <br /> http://www.apache.org/licenses/LICENSE-2.0 <br /> <br /> Unless required by applicable law or agreed to in writing, software <br /> distributed under the License is distributed on an "AS IS" BASIS, <br /> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br /> See the License for the specific language governing permissions and <br /> limitations under the License. <br /> <br /> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlnssmiliesi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.test</groupId>
<artifactId>csv2db-camel</artifactId>
<packaging>jar</packaging>
<version>0.0.1</version>

<name>PoC :: CSV file to JMS Bindy</name>
<url>http://www.myorganization.org</url>

<repositories>
<repository>
<id>release.fusesource.org</id>
<name>FuseSource Release Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>snapshot.fusesource.org</id>
<name>FuseSource Snapshot Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>release.fusesource.org</id>
<name>FuseSource Release Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>snapshot.fusesource.org</id>
<name>FuseSource Snapshot Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>

<dependencies>
<!-- version checked in repo.fusesource.com/nexus/content/releases/org/apache/camel -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bindy</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.9.0</version>
</dependency>

<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>

<build>
<defaultGoal>install</defaultGoal>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

<!-- allows the route to be ran via 'mvn camel:run' -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>2.7.3-fuse-00-53</version>
</plugin>
</plugins>
</build>
</project>

And when I deploy the jar file I get the following error from ServiceMix:

Exception in thread "SpringOsgiExtenderThread-10" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat] for bean with name 'csvBindyDataFormat' defined in URL [bundle://170.0:0/META-INF/spring/camel-context.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat not found from bundle [csv2db-camel]

I thank for your help.

Thanks mates.
vs.souza (4) [Avatar] Offline
#2
Re: Problems trying to unmarshal CSV to Bean
Hello my friends,

I got back here to post my solution. I didn't remember that I am creating an OSGi bundle so I needed to add Import-Package to the MANIFEST.MF.

I added the following lines to my MANIFEST file and the magic just happened... smilie

Import-Package: org.apache.camel.dataformat.bindy.csv,
org.apache.activemq.camel.component

Now that the problem is solved I will improve my manifest file to add the versions to imports and so on.

Thanks and my best regards.
davsclaus (413) [Avatar] Offline
#3
Re: Problems trying to unmarshal CSV to Bean
Glad you got it resolved.

However this forum is for discussing the Camel in Action book.

If you have questions regarding Fuse ESB then I suggest to use the FuseSource forum for that. At this forum we can only help about the book itself.

http://fusesource.com/forums/forum.jspa?forumID=1
vs.souza (4) [Avatar] Offline
#4
Re: Problems trying to unmarshal CSV to Bean
Ooops. I'm sorry for the bad post. I am using the book but building my own examples to make sure that I understand it. ServiceMix is just where I chose to deploy my routes because it seemed to me that would be easier.

I'm sorry for posting the question in the wrong comunity.

BTW... The book is really really good. I am using the BindyCsvData format and sending one parameter to it. The parameter has a package format but I can't find an explanation about what it means. Can someone explain it to me? And a suggestion is that it would be nice to write a book about servicemix (we already have camel and activemq in action) to make the full stack documented.

Cheers.
davsclaus (413) [Avatar] Offline
#5
Re: Problems trying to unmarshal CSV to Bean
The 1 parameter for bindy data format, is to tell Bindy which package to go scan for classes which has bindy annotations. So it automatic discover your bindy class.

Its kinda the same principle that JAXB also has, eg if you use the jaxb data format.

In the future we may improve this so instead of a package name you can refer to class type directly. That may help readers to better understand what is going on.

For example a la:
from("file:inbox").unmarshal().bindy(MyOrder.class)