Search code examples
javaspringapache-camelquartz

Strange trouble with Camel and Quartz2 and some machines


I have a WAR file with the following Camel Route:

qtz.expression read from property file and set value as: 0/30+*+*+*+*+?

    from("quartz2://schedulerVigenciaClienteEnvase?cron={{qtz.expression}}")
            .handleFault()
            .log("Testing job")
            .process("testProcessor");

It uses Camel 2.20, and Camel Quartz2. The following are the dependencies inside the POM file.

<dependencies>
    <!-- ${camel.version} contains 2.20.2 value -->
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
       <version>${camel.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-spring</artifactId>
      <version>${camel.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-servlet</artifactId>
      <version>${camel.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-quartz2</artifactId>    
      <version>${camel.version}</version>   
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jms</artifactId>
        <version>${camel.version}</version>
    </dependency>  
</dependencies>

The trouble is in some machines using the same Java version produces the following exception each Quartz triggering moment.

2018-03-22 18:54:00,005 JobRunShell ERROR Job Camel_camel-1.schedulerVigenciaClienteEnvase threw an unhandled Exception: 
**java.lang.NoSuchMethodError: org.apache.camel.impl.DefaultMessage.<init>(Lorg/apache/camel/CamelContext;)V**
    at org.apache.camel.component.quartz2.QuartzMessage.<init>(QuartzMessage.java:33) ~[camel-quartz2-2.20.2.jar:2.20.2]
    at org.apache.camel.component.quartz2.CamelJob.execute(CamelJob.java:57) ~[camel-quartz2-2.20.2.jar:2.20.2]
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [quartz-2.3.0.jar:?]
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.3.0.jar:?]
2018-03-22 18:54:00,006 ErrorLogger                    ERROR Job (Camel_camel-1.schedulerVigenciaClienteEnvase threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
    at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [quartz-2.3.0.jar:?]
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) **[quartz-2.3.0.jar:?]**
**Caused by: java.lang.NoSuchMethodError: org.apache.camel.impl.DefaultMessage.<init>(Lorg/apache/camel/CamelContext;)V
    at org.apache.camel.component.quartz2.QuartzMessage.<init>**(QuartzMessage.java:33) ~[camel-quartz2-2.20.2.jar:2.20.2]
    at org.apache.camel.component.quartz2.CamelJob.execute(CamelJob.java:57) ~[camel-quartz2-2.20.2.jar:2.20.2]
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.3.0.jar:?]

java.lang.NoSuchMethodError: org.apache.camel.impl.DefaultMessage.(Lorg/apache/camel/CamelContext;)V

Why the method are not complaining in all the machines, using same JVM version and OS.

Any suggestions are appreciated.


Solution

  • Found the problem and the solution, in the project we are using ActiveMQ, so, there was a dependency called activemq-all, that inside includes an internal Camel implementation that collides at classloading (sometimes, not always). Final solution was replacing this dependency with the following list:

    <!-- Apache Active MQ Jars -->
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-broker</artifactId>
            <version>${activemq.version}</version>     
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-client</artifactId>
            <version>${activemq.version}</version>     
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-pool</artifactId>
            <version>${activemq.version}</version>      
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-camel</artifactId>
            <version>${activemq.version}</version>      
        </dependency>