I'm trying to deploy very simple ESB application to Apache ServiceMix (Fuse ESB) and all works fine up to the point where I'm trying to use 'AggregationStrategy' interface. I'm building a proof of concept using EIP and aggregator pattern in particular and cannot deploy my artifact due to NoClassDefFound Error. Looks like a typical class loading issue but I'm out of ideas on how to resolve it. I have tried both: adding and removing camel-core dependency to my service unit (servicemix-camel type).
The basis of the application can be found here. I have modified my routes definition to the following:
public void configure() {
from("activemq:test2").split(xpath("/notes/note")).parallelProcessing().process(new NoteProcessor()).to("activemq:test3");
from("activemq:test3").aggregate(header("id"), new MyAggregationStrategy()).completionTimeout(3000).to("activemq:test");
}
and my custom AggregationStrategy looks like this:
package com.softwarepassion.tutorial.camel;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.processor.aggregate.AggregationStrategy;
public class MyAggregationStrategy implements AggregationStrategy {
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
Message newIn = newExchange.getIn();
String oldBody = oldExchange.getIn().getBody(String.class);
String newBody = newIn.getBody(String.class);
newIn.setBody(oldBody + newBody);
return newExchange;
}
}
I got the following error on plain ServiceMix as well as on FuseESB:
07:50:49,625 | ERROR | use-01-11/deploy | DefaultComponent
| ? ? | 151 - servicemix-common - 2011.02.1.fuse-02-11 | Error creating bean with name 'template': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camel': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.softwarepassion.tutorial.camel.MyRouteBuilder': Resolution of declared constructors on bean Class [com.softwarepassion.tutorial.camel.MyRouteBuilder] from ClassLoader [[org.apache.xbean.classloader.JarFileClassLoader: name=org.apache.xbean.spring.context.FileSystemXmlApplicationContext@1c4d3b6 urls=[file:/home/kris/apache-servicemix-4.4.1-fuse-01-11/data/jbi/tutorial-camel-sa/sus/tutorial-camel-su/] parents=[[org.apache.xbean.classloader.JarFileClassLoader: name=SU parent class loader urls=[] parents=[231.0, BundleDelegatingClassLoader for [camel-spring (org.apache.camel.camel-spring)], BundleDelegatingClassLoader for [camel-cxf (org.apache.camel.camel-cxf)], BundleDelegatingClassLoader for [camel-cxf-transport (org.apache.camel.camel-cxf-transport)]]]]]] failed; nested exception is java.lang.NoClassDefFoundError: org/apache/camel/processor/aggregate/AggregationStrategy 07:50:49,627 | ERROR | use-01-11/deploy | ServiceAssemblyInstaller | ?
? | 147 - org.apache.servicemix.jbi.deployer - 1.5.1.fuse-01-11 | Error deploying SU tutorial-camel-su
Do not use JBI its a legacy/dead. http://gnodet.blogspot.com/2010/12/thoughts-about-servicemix.html
Use the Camel archetypes to create a new OSGi project to be deployed in ServiceMix. The list of archetypes is here http://camel.apache.org/camel-maven-archetypes.html
For example the camel-archetype-spring-dm or camel-archetype-blueprint