0 Replies Latest reply on May 16, 2016 12:48 PM by vassilis spiliopoulos

    error while camel route starts in spring unit test

    vassilis spiliopoulos Newbie

      Hi all!

       

      I tried to run a Spring based unit test using camel version 2.15.1.redhat-621084 and I am getting:

       

      Caused by: java.lang.LinkageError: loader (instance of  sun/misc/Launcher$AppClassLoader): attempted  duplicate class definition for name: "org/apache/camel/spi/RestConfiguration$RestHostNameResolver"


      Any ideas where should I look are more than welcome!


      The same Camel Route is working fine in Fuse 2.6.1.GA runtime and has nothing to do with REST endpoints.


      Kind Regards,

      Vassilis


      -----

       

      Specifically I am using as a parent pom:

       

      <parent>

        <groupId>org.jboss.fuse.bom</groupId>

        <artifactId>jboss-fuse-parent</artifactId>

        <version>6.2.1.redhat-084</version>

      </parent>


      and for testing I am importing camel-test-spring3, as I am using spring 3 from the dependency management (2.15.1.redhat-621084):

       

        <dependency>

                  <groupId>org.apache.camel</groupId>

                  <artifactId>camel-test-spring3</artifactId>

         </dependency>

       

      My test outline is:

       

      @DisableJmx

      @RunWith(CamelSpringJUnit4ClassRunner.class)

      @ContextConfiguration(locations = {

              "classpath:/test-context.xml",

              "classpath:/db-datasource.xml",

              "classpath:/aries-tx-manager.xml",

              "classpath:META-INF/spring/application-context.xml",

              "classpath:META-INF/spring/camel-context.xml"

      })

      @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)

      @ShutdownTimeout(300)

      public class InboundRouteTest extends TestSupport {

       

      / ...

       

          @Test

          public void testJPAConsumer() throws InterruptedException{

       

          myMockedRouteEndpoint.expectedMessageCount(2);

       

              Thread.sleep(30000);

       

              myMockedRouteEndpoint.assertIsSatisfied();

       

              String policyXml = myMockedRouteEndpoint.getExchanges().get(0).getIn().getBody(String.class);

              LOG.info("policyXml: {}", policyXml);

              assertTrue("XML representation of policy object should contain the string 'destination'",

             policyXml.contains("destination"));

          }

       

      }

       

      Add I am getting the following exception stack trace:

       

      java.lang.IllegalStateException: Failed to load ApplicationContext

        at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:103)

        at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)

        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)

        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)

        at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)

        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)

        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)

        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)

        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)

        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)

        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)

        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)

        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)

        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)

        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'my-camel-context': Invocation of init method failed; nested exception is java.lang.LinkageError: loader (instance of  sun/misc/Launcher$AppClassLoader): attempted  duplicate class definition for name: "org/apache/camel/spi/RestConfiguration$RestHostNameResolver"

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1514)

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)

        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)

        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)

        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)

        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)

        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)

        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)

        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:636)

        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934)

        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)

        at org.apache.camel.test.spring.CamelSpringTestContextLoader.loadContext(CamelSpringTestContextLoader.java:147)

        at org.apache.camel.test.spring.CamelSpringTestContextLoader.loadContext(CamelSpringTestContextLoader.java:84)

        at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:69)

        at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:95)

        ... 26 more

      Caused by: java.lang.LinkageError: loader (instance of  sun/misc/Launcher$AppClassLoader): attempted  duplicate class definition for name: "org/apache/camel/spi/RestConfiguration$RestHostNameResolver"

        at java.lang.ClassLoader.defineClass1(Native Method)

        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)

        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)

        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)

        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)

        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)

        at java.security.AccessController.doPrivileged(Native Method)

        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)

        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

        at org.apache.camel.spi.RestConfiguration.<init>(RestConfiguration.java:45)

        at org.apache.camel.impl.DefaultCamelContext.<init>(DefaultCamelContext.java:194)

        at org.apache.camel.spring.SpringCamelContext.<init>(SpringCamelContext.java:69)

        at org.apache.camel.spring.CamelContextFactoryBean.newCamelContext(CamelContextFactoryBean.java:387)

        at org.apache.camel.spring.CamelContextFactoryBean.createContext(CamelContextFactoryBean.java:381)

        at org.apache.camel.spring.CamelContextFactoryBean.getContext(CamelContextFactoryBean.java:392)

        at org.apache.camel.spring.CamelContextFactoryBean.getContext(CamelContextFactoryBean.java:84)

        at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.getContext(AbstractCamelContextFactoryBean.java:599)

        at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.afterPropertiesSet(AbstractCamelContextFactoryBean.java:169)

        at org.apache.camel.spring.CamelContextFactoryBean.afterPropertiesSet(CamelContextFactoryBean.java:256)

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1573)

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511)

        ... 41 more

       

      My Dependency Hierarchy in case it is useful (filtered with 'camel-'):

       

      Screen Shot 2016-05-16 at 17.38.21.png