Reputation: 579
I'm trying to fetch www.dnb.no/portalfront/datafiles/miscellaneous/csv/kursliste_ws.xml and convert it to a Java object using xstrem.
I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/camel/spi/DataFormatName Caused by: java.lang.ClassNotFoundException: org.apache.camel.spi.DataFormatName
My code:
package route;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import mapper.CurrencyMapper;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.log4j.BasicConfigurator;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.*;
import java.net.URL;
public class CurrencyRoute {
public static void main(String args[]) throws Exception {
// Log 4j
BasicConfigurator.configure();
// Create camel context
CamelContext context = new DefaultCamelContext();
// New route
context.addRoutes(new RouteBuilder() {
public void configure() {
from("quartz://myTimer?trigger.repeatCount=0")
.log("### Quartz trigger ###")
.to("direct:readFile");
from("direct:readFile")
.log("### HTTP to XML ###")
.to("https4://www.dnb.no/portalfront/datafiles/miscellaneous/csv/kursliste_ws.xml")
.marshal()
.xstream()
.to("uri:activemq:queue:currency");
}
});
// start the route and let it do its work
context.start();
Thread.sleep(10000);
// stop the CamelContext
context.stop();
}
}
My pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>currencyProcessor</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<camel-version>2.15.1.redhat-621159</camel-version>
<jaxb2-maven-plugin-version>2.2</jaxb2-maven-plugin-version>
<maven-compiler-plugin-version>3.5.1</maven-compiler-plugin-version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.15.1.redhat-621159</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.8.0-alpha2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ftp</artifactId>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>2.19.3</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>spi-annotations</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http4</artifactId>
<version>2.15.1.redhat-621159</version>
<!-- use the same version as your Camel core version -->
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz</artifactId>
<version>2.15.1.redhat-621159</version>
<!-- use the same version as your Camel core version -->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xmljson</artifactId>
<version>${camel-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/xom/xom -->
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.camel/camel-xstream -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xstream</artifactId>
<version>2.20.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/xstream/xstream -->
<dependency>
<groupId>xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.activemq/activemq-camel -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.5.0</version>
</dependency>
</dependencies>
How I can convert it?
Upvotes: 0
Views: 1636
Reputation: 14591
Honestly I do not understand the purpose of XML to Java object conversion. If you read the XML using the Camel-Http component you can pipe it straight to ActiveMQ it works just fine.
What is the purpose of XStream in this context?
I have got the route actually to run on a toy project and got the XML injected into my ActiveMQ queue.
This is the working route:
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.log4j.BasicConfigurator;
import javax.jms.ConnectionFactory;
public class CurrencyRoute {
public static void main(String args[]) throws Exception {
// Log 4j
BasicConfigurator.configure();
// Create camel context
CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
// New route
context.addRoutes(new RouteBuilder() {
public void configure() {
from("quartz://myTimer?trigger.repeatCount=0")
.log("### Quartz trigger ###")
.to("direct:readFile");
from("direct:readFile")
.log("### HTTP to XML ###")
.to("https://www.dnb.no/portalfront/datafiles/miscellaneous/csv/kursliste_ws.xml")
.to("test-jms:queue:currency");
}
});
// start the route and let it do its work
context.start();
Thread.sleep(10000);
// stop the CamelContext
context.stop();
}
}
And this is the pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="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.onepointltd</groupId>
<artifactId>camel.activemq</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Dummy test project</name>
<url>http://www.onepointltd.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<log4j.version>2.7</log4j.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-parent</artifactId>
<version>2.17.3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
</dependency>
<!-- the ActiveMQ client with connection pooling -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.14.0</version>
</dependency>
<!-- the ActiveMQ broker is optional and can be removed if connecting to a remote broker only -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>5.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>5.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-kahadb-store</artifactId>
<version>5.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.7</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-1.2-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath</artifactId>
</dependency>
<!-- testing -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
</dependencies>
</project>
Upvotes: 1
Reputation: 1948
You are mixing versions of camel components in your pom.xml. Camel-xstream is 2.20 and camel core 2.15.1.redhat-621159.
The class DataFormatName
missing from the classpath has been introduced in 2.16.x release.
Update all your camel dependencies to the same version, preferably 2.20 and it should work
Upvotes: 1