5 Replies Latest reply on Jul 25, 2011 9:05 PM by Willem Jiang

    java.lang.ClassNotFoundException error

    Rogelio Sevilla Novice

      Good day to everyone:

       

      I've already made this question on the camel forum but i think this is the right place to ask because of its nature (more fuse than camel).

       

       

      I have 2 osgi bundles installed on fuse esb 4.4,  bundle #1 has a camel route and a simple pojo, bundle #2 has a simple pojo that takes the camel route on bundle #1 and instantiates it.

       

      The deployment of the bundle #1 works pretty well, this is the route i have:

       

       

                         getContext().setHandleFault(true);

                         errorHandler(deadLetterChannel("file:data/log/capalerts")

                          .maximumRedeliveries(2)

                          .asyncDelayedRedelivery()

                          .redeliveryDelay(3000)

                          .useOriginalMessage()

                          .logStackTrace(true)

                          .logRetryStackTrace(true)

                          .retryAttemptedLogLevel(LoggingLevel.ERROR));

               

               

                          from("quartz://fetchUrl?cron=00/1+*?")

                          .bean(MyPojo.class,"getHtmlCode")

                          .wireTap("seda:auditorfeed")

                          .bean(MyPojo.class.class,"gettUrls")

                          .wireTap("seda:urlauditor")

                          .split(body(String.class).tokenize("\n"))

                          .to("seda:finaldest");

       

       

      As you can see, i'm using a class called MyPojo.class inside my route. this class is also deployed with the camel route on the same package inside bundle #1, by the way, every package on this bundle is exported through the pom file.

       

       

      After deploying it, i try to deploy bundle #2 which have a class with only 1 method:

       

      public void init(){

           MyRoute myroute = new MyRoute();

              BundleContext bundleContext = Activator.getBundleContext();

              CamelContextFactory camelContextFactory = new CamelContextFactory();

              camelContextFactory.setBundleContext(bundleContext);

               

              DefaultCamelContext defaultContext = camelContextFactory.createContext();

              defaultContext.addRoutes(miruta);

              defaultContext.start();

      }

       

       

      The moment i install and try to start the bundle #2, i get this exception:

       

       

      ERROR | rint Extender: 1 | BlueprintContainerImpl           | 10 - org.apache.aries.blueprint - 0.3.1 | Unable to start blueprint container for bundle my_routes_factory

      org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to intialize bean MyRoutesFactory

              at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:638)[10:org.apache.aries.blueprint:0.3.1]

              at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:724)[10:org.apache.aries.blueprint:0.3.1]

              at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)[10:org.apache.aries.blueprint:0.3.1]

              at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:219)[10:org.apache.aries.blueprint:0.3.1]

              at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:147)[10:org.apache.aries.blueprint:0.3.1]

              at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:640)[10:org.apache.aries.blueprint:0.3.1]

              at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:331)[10:org.apache.aries.blueprint:0.3.1]

              at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:227)[10:org.apache.aries.blueprint:0.3.1]

              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_25]

              at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_25]

              at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_25]

              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)[:1.6.0_25]

              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)[:1.6.0_25]

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_25]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_25]

              at java.lang.Thread.run(Thread.java:662)[:1.6.0_25]

      Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route5 at: >>> Bean[com.mycompany.my_main_route.MyPojo.class] <<< in route: Route[[From[quartz://fetchUrl?cron=00/1**+?]] -> [Bean[... because of java.lang.ClassNotFoundException: com.mycompany.my_main_route.MyPojo.class

              at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:818)

              at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:165)

              at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:708)

              at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1650)

              at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1439)

              at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1338)

              at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:67)

              at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:54)

              at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1316)

              at com.my_company.my_route_factory.MyRouteFactory.init(MyRouteFactory.java:39)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_25]

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_25]

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_25]

              at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_25]

              at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:226)[10:org.apache.aries.blueprint:0.3.1]

              at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:824)[10:org.apache.aries.blueprint:0.3.1]

              at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:636)[10:org.apache.aries.blueprint:0.3.1]

              ... 15 more

      Caused by: org.apache.camel.RuntimeCamelException: java.lang.ClassNotFoundException: com.mycompany.my_main_route.MiPojo

              at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1139)

              at org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:164)

              at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:433)

              at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:181)

              at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:815)

              ... 31 more

      Caused by: java.lang.ClassNotFoundException: com.flytecomm.noaa_atom_feed_consumer.AtomFeedMessageConversorBean

              at org.apache.camel.impl.DefaultClassResolver.resolveMandatoryClass(DefaultClassResolver.java:52)

              at org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:162)

              ... 34 more

       

       

       

      According to this, camel cannot find the class com.mycompany.my_main_route.MyPojo.class , but i really don't understand why, because i'm already exporting it. If i execute command osgi:header on the bundle that instantiates the camel route,  this is the result:

       

      Manifest-Version = 1.0

      Bnd-LastModified = 1311372596591

      Tool = Bnd-1.15.0

      Built-By = rogeliosevilla1

      Build-Jdk = 1.6.0_26

      Created-By = Apache Maven Bundle Plugin

       

      Bundle-Name = My Route Factory

      Bundle-SymbolicName = my_route_factory

      Bundle-Version = 1.0.0.SNAPSHOT

      Bundle-ManifestVersion = 2

       

      Import-Package =

              com.mycompany.my_main_route,

              org.apache.camel;version="[2.7,3)",

              org.apache.camel.builder;version="[2.7,3)",

              org.apache.camel.impl;version="[2.7,3)",

              org.apache.camel.osgi;version="[2.7,3)",

       

       

       

      After that,executing the command

      packages:exports | grep mycompany

       

      y get this:

       

         246 com.mycompany.my_main_route; version=0.0.0

         247 com.mycompany.my_saver_bundle; version=0.0.0

         248 com.mycompany.my_route_factory; version=0.0.0

       

      As you can see it is stated on my bundle that the package should be imported, also, according th the packages:exports command,  the package is exported.. but still, i keep getting the same error :-S , i'm honestly lost in here.

       

      Any advice would be really appreciated.

       

       

      Thanks a lot in advance.

        • 1. Re: java.lang.ClassNotFoundException error
          Willem Jiang Master
          from("quartz://fetchUrl?cron=0+0/1+*+?")
          .bean(MyPojo.class,"getHtmlCode")
          .wireTap("seda:auditorfeed")
          .bean(MyPojo.class.class,"gettUrls")
          .wireTap("seda:urlauditor")
          .split(body(String.class).tokenize("\n"))
          .to("seda:finaldest");
          

          Can you change the ".bean(MyPojo.class.class, "gettUrls")" to ".bean(MyPojo.class, "getUrls")" ?

          • 2. Re: java.lang.ClassNotFoundException error
            Rogelio Sevilla Novice

            Thanks mr. Willem, sorry, that was a typo on my part while pasting the code here on the forum. The method is written correctly on the real code :-S .  Do you see any other irregularity on the situation??

            • 3. Re: java.lang.ClassNotFoundException error
              Rogelio Sevilla Novice

              Mr. Willem I've seen your answer on the camel forum, again sorry for double posting, i will keep answering here:

               

              >Can you try to use the Spring instead of Blueprint to start your camel route?

               

              I'm creating and starting my instantiated routes directly from code, do you mean that i should try using spring to deploy the bundle where i create them??

               

               

              >And you should avoid to export the same package from different bundle.

               

              Sorry mr. Willem i didn't quite catch this one. On each of my bundles i'm exporting only the package that lives on that bundle, is this the correct usage?

               

               

              >BTW,  where is the Activator ?

              I'm importing the Activator from this package

               

              import org.apache.camel.osgi.Activator;

               

              And i'm using it directly on the code without any modification. Is this ok??

               

               

               

               

              Thanks A LOT in advance

              • 4. Re: java.lang.ClassNotFoundException error
                Rogelio Sevilla Novice

                THANKS A LOT MR. WILLEM!!

                 

                Your questions on the camel forum lead me to the answer, although i don't know if my solution  is the right way to do it.

                 

                My usage of the Activator class was totally wrong. To solve it, i created a class called Activator and implemented the org.osgi.framework.BundleActivator interface.

                 

                My stop method is empty and in my start method y save the bundle context on a class member of the Activator class. using this:

                 

                public static BundleContext bundleContext;

                 

                    public void start(BundleContext bc) {

                        bundleContext = bc;

                    }

                 

                 

                I also added the activator to my manifest file doing this:

                 

                Bundle-Activator: com.mycompany.my_route_factory.Activator

                 

                 

                And on my RouteFactory class i have this

                 

                        MyRoute myroute = new MyRoute();

                        CamelContextFactory camelContextFactory = new CamelContextFactory();

                        camelContextFactory.setBundleContext(bundleContext);

                        DefaultCamelContext defaultContext = camelContextFactory.createContext();

                        defaultContext.addRoutes(myroute);

                        defaultContext.start();

                 

                 

                 

                 

                This has solved my problem. Thanks again for the help mr. Willem, i owe you like 12 beers by now, you should publish an address or something like that so send them :-P

                • 5. Re: java.lang.ClassNotFoundException error
                  Willem Jiang Master

                  Camel creates a delegate class loader which is based on the bundle instance that is passed by the bundle context.

                  If you are using the Activator from the camel-core bundle, it's make senses that you get the complain of not finding the router class. That is because camel-core bundle know nothing about your camel route class.

                   

                  When you pass the bundle context from your bundle Activator, your route class is visible for the delegate class loader, and it works now.

                   

                  Willem