Thanks for your interest in Camel. The error: " Caused by: java.lang.ClassNotFoundException:" means that the right dependency (jsonpath in this case) is not on the Java classpath. How the dependencies are handled depends a bit on the runtime that Camel is running. ActiveMQ is not really a runtime. There are many options for Camel available:
https://raymondmeester.medium.com/apache-camel-runtimes-80e9e8f8bcc8 When you for example choose Spring Boot than dependencies are normally listed in a Maven or Gradle project file. Another thing is that the both the Camel and ActiveMQ version aren't supported anymore, if possible you can go to a newer version. btw I use my own runtime that contains both the latest ActiveMQ version, as latest Camel version (including jsonpath): https://github.com/assimbly/gateway/wiki/quick-start Good luck, Raymond On Wed, Dec 18, 2024 at 1:26 PM Zsuzsanna Sovarschi < zsuzsanna.sovars...@gmail.com> wrote: > Dear Camel User Support, > > We are using Apache ActiveMQ 5.16.7 in our project. It has Camel > 2.25.4 embedded. > We are running ActiveMQ/Camel from a Docker container with external > volumes. > Our services are written in .Net/C#. They are connecting to ActiveMQ > and sending messages back and forth. > We have very simple Camel routes with a selector on message type > defined in camel.xml which is then referenced from the activemq.xml. > They are working perfectly for the last couple of year now. > > A recent requirement made me to investigate content based routing in Camel. > I worked out how I can do it based on header information with > 'simple'. That is working OK. > This is working fine in XML DSL without any further settings: > > <route> > <description>Message4</description> > <from > uri="activemq:AsyncSendQueue?selector=(JMSType='Shared.Messages.Message4')&disableReplyTo=true" > /> > <choice> > <when> > <simple>${header.NotificationCode} == 'MSGSIM_RoBDischarged' or > ${header.NotificationCode} == > 'MSGSIM_OverlanderDischarged' or > ${header.NotificationCode} == > 'MSGSIM_ContainerLoadedToWrongPosition'</simple> > <inOnly > uri="activemq:AsyncReceiveQueue?preserveMessageQos=true" /> > </when> > </choice> > <log message="Pulled: ${header[JMSCorrelationID]} | > ${header[JMSType]} | ${header[JMSTimestamp]}" loggingLevel="INFO"/> > <inOnly uri="activemq:ANotification.Inbound?preserveMessageQos=true" /> > </route> > > I also saw that there is a possibility to do content based routing > based on body content with 'jsonpath'. > This is where I'm lost. It is not working. > > I could find no documentation or posts about how can I configure > jsonpath to be able to use it from XML DSL without pom file. > I found a lot of blogposts, stack overflow posts, youtube videos that > are only about creating a Java/Spring project where the routes are > defined, and add the dependency to jsonpath into the pom file. > But this is not how our setup looks like.We define our soutes in > camel.xml XML DSL and that's all. > > The symptom I'm facing is that when I start up ActiveMQ and when Camel > is reaching the point to load in jsonpath, Camel is shutting down, > then ActiveMQ follows. Then ActiveMQ restarts (well the docker > container makes it to restart). > See the route definition below where 'activemq' is defined separately > as a bean. Without doing any further settings, I've just used > <jsonpath> simply. > > <route> > <description>Message4</description> > <from > uri="activemq:AsyncSendQueue?selector=(JMSType='Shared.Messages.Message4')&disableReplyTo=true" > /> > <choice> > <when> > <jsonpath>$.store.book[?(@.price < 10)]</jsonpath> > <to uri="activemq:AsyncReceiveQueue" /> > </when> > </choice> > <log message="Pulled: ${header[JMSCorrelationID]} | > ${header[JMSType]} | ${header[JMSTimestamp]}" loggingLevel="INFO"/> > <inOnly uri="activemq:ANotification.Inbound?preserveMessageQos=true" /> > </route> > > <bean id="activemq" > class="org.apache.activemq.camel.component.ActiveMQComponent"> > <property name="connectionFactory"> > <bean class="org.apache.activemq.ActiveMQConnectionFactory"> > <property name="brokerURL" value="vm://localhost?create=false" > /> > <property name="userName" value="${activemq.username}" /> > <property name="password" value="${activemq.password}" /> > </bean> > </property> > </bean> > > I managed to turn on DEBUG level logging for Camel, and it is shutting > down when it is searching for languages 'jsonpath' and > 'jsonpath-language'. No ERROR message found for jsonpath. > It is a bit strange because the same log lines are there for 'simple', > and that is working OK. > Log fragments: > > 2024-12-18 11:48:34,256 | DEBUG | Lookup Language with name simple in > registry. Found: null | org.apache.camel.util.ResolverHelper | main > 2024-12-18 11:48:34,267 | DEBUG | Lookup Language with name > simple-language in registry. Found: null | > org.apache.camel.util.ResolverHelper | main > 2024-12-18 11:48:34,269 | DEBUG | Simple language predicate/expression > cache size: 1000 | org.apache.camel.language.simple.SimpleLanguage | > main > ... > 2024-12-18 11:48:34,379 | DEBUG | Lookup Language with name jsonpath > in registry. Found: null | org.apache.camel.util.ResolverHelper | main > 2024-12-18 11:48:34,380 | DEBUG | Lookup Language with name > jsonpath-language in registry. Found: null | > org.apache.camel.util.ResolverHelper | main > 2024-12-18 11:48:34,383 | INFO | Apache Camel 2.25.4 (CamelContext: > camel) is shutting down | org.apache.camel.spring.SpringCamelContext | > main > 2024-12-18 11:48:34,384 | DEBUG | Shutting down with no inflight > threads. | org.apache.camel.impl.DefaultAsyncProcessorAwaitManager | > main > > I then downloaded and copied camel-jsonpath 2.25.4 jar file inside the > docker container under opt/activemq/lib/camel folder because this is > the folder where I have the camel jar files. > It was not working. The same symptom of Camel and ActiveMQ shutting > down and docker container restarting them continuously. > I also downloaded camel-core-languages-3.10.0.jar file and copied to > the same location. I ended up with version 3.10.0 because I found no > 2.25.4 version for camel-core-languages and based on date 3.10.0 was > around the time when camel 2.25.4 was released. > It did not help. The same symptom of Camel and ActiveMQ shutting down > and docker container restarting them continuously. > > - activemq-camel-5.16.7.jar > - camel-core-2.25.4.jar > - camel-core-languages-3.10.0.jar > - camel-jms-2.25.4.jar > - camel-jsonpath-2.25.4.jar > - camel-spring-2.25.4.jar > > I thought then I need to reference it somewhere, example I was > thinking that I have to set it up as a bean. > I cloned down camel 2.25.4 from git and navigated through the code. > I see that languages 'simple' and 'xpath' are under camel-core > org.apache.camel.language namespace. > 'jsonpath' however is under camel components camel-jsonpath > org.apache.camel.jsonpath. > I tried to add the following bean to camel.xml but honestly I did not > know what properties to set up for it because I found no documentation > about it: > > <bean id="jsonpath" class="org.apache.camel.jsonpath.JsonPathLanguage"> > </bean> > > Having this bean in camel.xml caused a different error about not able > to find the class JsonPathLanguage and load it in. > > 2024-12-18 12:07:09,650 | ERROR | Failed to load: class path resource > [activemq.xml], reason: Failed to load type: > org.apache.camel.jsonpath.JsonPathLanguage. Reason: > java.lang.ClassNotFoundException: > org.apache.camel.jsonpath.JsonPathLanguage; nested exception is > java.lang.ClassNotFoundException: > org.apache.camel.jsonpath.JsonPathLanguage | > org.apache.activemq.xbean.XBeanBrokerFactory | main > org.springframework.beans.factory.BeanDefinitionStoreException: Failed > to load type: org.apache.camel.jsonpath.JsonPathLanguage. Reason: > java.lang.ClassNotFoundException: > org.apache.camel.jsonpath.JsonPathLanguage; nested exception is > java.lang.ClassNotFoundException: > org.apache.camel.jsonpath.JsonPathLanguage > at > org.apache.xbean.spring.context.v2c.XBeanQNameHelper.getBeanInfo(XBeanQNameHelper.java:75) > at > org.apache.xbean.spring.context.v2c.XBeanQNameHelper.coerceNamespaceAwarePropertyValues(XBeanQNameHelper.java:54) > at > org.apache.xbean.spring.context.v2c.XBeanBeanDefinitionParserDelegate.parseBeanDefinitionElement(XBeanBeanDefinitionParserDelegate.java:59) > at > org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:459) > at > org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:428) > at > org.apache.xbean.spring.context.v2.XBeanBeanDefinitionDocumentReader.processBeanDefinition(XBeanBeanDefinitionDocumentReader.java:188) > at > org.apache.xbean.spring.context.v2.XBeanBeanDefinitionDocumentReader.parseDefaultElement(XBeanBeanDefinitionDocumentReader.java:115) > at > org.apache.xbean.spring.context.v2.XBeanBeanDefinitionDocumentReader.parseBeanDefinitions(XBeanBeanDefinitionDocumentReader.java:95) > at > org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:142) > at > org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94) > at > org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508) > at > org.apache.xbean.spring.context.v2.XBeanXmlBeanDefinitionReader.registerBeanDefinitions(XBeanXmlBeanDefinitionReader.java:79) > at > org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392) > at > org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) > at > org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) > at > org.apache.xbean.spring.context.v2.XBeanBeanDefinitionDocumentReader.importBeanDefinitionResource(XBeanBeanDefinitionDocumentReader.java:143) > at > org.apache.xbean.spring.context.v2.XBeanBeanDefinitionDocumentReader.parseDefaultElement(XBeanBeanDefinitionDocumentReader.java:109) > at > org.apache.xbean.spring.context.v2.XBeanBeanDefinitionDocumentReader.parseBeanDefinitions(XBeanBeanDefinitionDocumentReader.java:95) > at > org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:142) > at > org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94) > at > org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508) > at > org.apache.xbean.spring.context.v2.XBeanXmlBeanDefinitionReader.registerBeanDefinitions(XBeanXmlBeanDefinitionReader.java:79) > at > org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392) > at > org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) > at > org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) > at > org.apache.xbean.spring.context.ResourceXmlApplicationContext.loadBeanDefinitions(ResourceXmlApplicationContext.java:116) > at > org.apache.xbean.spring.context.ResourceXmlApplicationContext.loadBeanDefinitions(ResourceXmlApplicationContext.java:104) > at > org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:126) > at > org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:614) > at > org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514) > at > org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:64) > at > org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:52) > at > org.apache.activemq.xbean.XBeanBrokerFactory$1.<init>(XBeanBrokerFactory.java:104) > at > org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:104) > at > org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:67) > at > org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71) > at > org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54) > at > org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:87) > at > org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:63) > at > org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:154) > at > org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:63) > at > org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104) > at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native > Method) > at > java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.base/java.lang.reflect.Method.invoke(Method.java:566) > at org.apache.activemq.console.Main.runTaskClass(Main.java:262) > at org.apache.activemq.console.Main.main(Main.java:115) > Caused by: java.lang.ClassNotFoundException: > org.apache.camel.jsonpath.JsonPathLanguage > at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476) > at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:594) > at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:527) > at > org.apache.xbean.spring.context.v2c.XBeanQNameHelper.loadClass(XBeanQNameHelper.java:107) > at > org.apache.xbean.spring.context.v2c.XBeanQNameHelper.getBeanInfo(XBeanQNameHelper.java:72) > > So my questions are: > Is there a way to make this work with XML DSL only (no Java/Spring > project with pom file)? > Or is this working only if we define our routes in a Java/Spring > project where we can add the dependency to jsonpath into the pom file? > > Your help would be very much appreciated! > Best Regards, > Zsuzsa. >