13 Replies Latest reply on Nov 20, 2010 7:46 AM by Arun Sharma

    "Unable to create context" error while using jaxb in servicemix 4.3

    Gaurav Nigam Newbie

      Hi all,

      I have a bundle which calls a bean. That bean calls some methods from a jar (say MyUtility.jar) which in turn uses jaxb to convert an xml to PoJo(in a class in that jar). I have added the jaxb-api-2.0, camel-jaxb-2.4,camel-core-2.4 dependencies in pom.xml. I also tried defining a bean for the ObjectFactory.class(which is present in MyUtility.jar) in the src/main/resources/META-INF/spring/beans.xml. But still I am getting the following error while converting an xml to PoJo:

       

      Caused by: javax.xml.bind.JAXBException: Unable to create context

      - with linked exception:

      java.lang.NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String, java.lang.ClassLoader)

           at javax.xml.bind.ContextFinder.find(ContextFinder.java:72)

           at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)

           at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)

           at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)

           at com.vzb.ram.bind.ns.XmlPoJoUtil.toPoJo(XmlPoJoUtil.java:185)

           ... 56 more

      Caused by: java.lang.NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String, java.lang.ClassLoader)

           at java.lang.Class.getMethod(Class.java:1605)[:1.6.0_18]

           at javax.xml.bind.ContextFinder.find(ContextFinder.java:69)

           ... 60 more

       

      I understand that this error occurs when it is not able to find neither ObjectFactory.class nor jaxb.index. But MyUtility.jar has ObjectFactory.class. So I assume that it is a classloading issue.

       

      I found a related thread in fuse esb forum:

      http://fusesource.com/forums/thread.jspa?messageID=6943&#6943

      but I could not find a solution for this problem in this thread.

       

      Can anyone please help me with this.

       

      Thanks,

      Gaurav

        • 1. Re: "Unable to create context" error while using jaxb in servicemix 4.3
          Freeman(Yue) Fang Master

          Hi,

           

          I just added comment for http://fusesource.com/forums/thread.jspa?messageID=6943&#6943.

           

          I believe this issue is related to SMX4-580, which swallow exception hide the real problem, the real problem could be miss some package import from your bundle.

          The fix for SMX4-580 just throw such more meaningful exception for you to figure out the real problem.

           

          You need use jaxb-api-2.1 latest snapshot[2] to pick up this fix

           

          https://issues.apache.org/activemq/browse/SMX4-580

          https://repository.apache.org/content/groups/snapshots-group/org/apache/servicemix/specs/org.apache.servicemix.specs.jaxb-api-2.1/1.6-SNAPSHOT/

           

          Freeman

          • 2. Re: "Unable to create context" error while using jaxb in servicemix 4.3
            Gaurav Nigam Newbie

            Hi Freeman,

            Thanks for the response. I removed the dependency for jaxb-api-2.0 and replaced it with jaxb-api-2.1 which you have mentioned above, but I am still getting the same exception. Is there any other thing, I could be missing?

             

            Thanks,

            Gaurav

            • 3. Re: "Unable to create context" error while using jaxb in servicemix 4.3
              Freeman(Yue) Fang Master

              Hi Gaurav,

               

              Could you tell me how you replace jaxb-api-2.1 snapshot jar?

               

              We've shipped  jaxb-api-2.1 jar in

              $SMX_HOME/system/org/apache/servicemix/specs/org.apache.servicemix.specs.jaxb-api-2.1/1.5.0/org.apache.servicemix.specs.jaxb-api-2.1-1.5.0.jar

               

              You need copy the snapshot jar I pointed[1] to $SMX_HOME/system/org/apache/servicemix/specs/org.apache.servicemix.specs.jaxb-api-2.1/1.5.0/org.apache.servicemix.specs.jaxb-api-2.1-1.5.0.jar

               

              https://repository.apache.org/content/groups/snapshots-group/org/apache/servicemix/specs/org.apache.servicemix.specs.jaxb-api-2.1/1.6-SNAPSHOT/

               

               

              Freeman

              • 4. Re: "Unable to create context" error while using jaxb in servicemix 4.3
                Gaurav Nigam Newbie

                Hi Freeman,

                Thanks for clearing that up. I had just added it to the pom dependency. Now I replaced the older jar in servicemix system directory. Now I got the following error which I was afraid of:

                 

                Caused by: javax.xml.bind.JAXBException: Unable to create context

                - with linked exception:

                     at javax.xml.bind.ContextFinder.find(ContextFinder.java:68)

                     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)

                     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)

                     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)

                     at com.vzb.ram.bind.ns.XmlPoJoUtil.toPoJo(XmlPoJoUtil.java:185)

                     ... 54 more

                Caused by: java.lang.reflect.InvocationTargetException

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

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

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

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

                     at javax.xml.bind.ContextFinder.find(ContextFinder.java:63)

                     ... 58 more

                Caused by: javax.xml.bind.JAXBException: "com.mypackage" doesnt contain ObjectFactory.class or jaxb.index

                     at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197)

                     ... 63 more

                 

                MyUtility.jar contains the ObjectFactory.class in com.mypackage. But it is not able to find it. Can you suggest any way so that I can I make servicemix see that class file.

                 

                Thanks,

                Gaurav

                • 5. Re: "Unable to create context" error while using jaxb in servicemix 4.3
                  Freeman(Yue) Fang Master

                  Hi,

                   

                  Did you already export com.mypackage package from your bundle so that it's avaible for jaxb?

                   

                  Freeman

                  • 6. Re: "Unable to create context" error while using jaxb in servicemix 4.3
                    Gaurav Nigam Newbie

                    Hi Freeman,

                    I had installed MyUtil.jar in servicemix 4.3 using the following command:

                    osgi:install wrap:file:///C:/MyUtil.jar

                    and then I started this bundle.

                    When I say packages:exports for this bundle, com.mypackage is listed there. So I think, it should be available for jaxb.

                     

                    Thanks,

                    Gaurav

                    • 7. Re: "Unable to create context" error while using jaxb in servicemix 4.3
                      Freeman(Yue) Fang Master

                      Hi Gaurav,

                       

                      Could you use osgi:headers your_bundle_id and post the output here?

                       

                      Freeman

                      • 8. Re: "Unable to create context" error while using jaxb in servicemix 4.3
                        Gaurav Nigam Newbie

                        Hi Freeman,

                        Here is the output for 2 bundles, one is the wrapped jar file and other one is the bundle which is using that jar file.

                         

                        wrap_file____C__MyUtility.jar (171)

                        -


                        Bnd-LastModified = 1285598542345

                        Bundle-ManifestVersion = 2

                        Bundle-Name = wrap_file____C__MyUtility.jar

                        Bundle-SymbolicName = wrap_file____C__MyUtility.jar

                        Bundle-Version = 0

                        Created-By = 1.6.0_18 (Sun Microsystems Inc.)

                        Export-Package =

                        com.mylog;uses:="com.mypersist,com.mycommons,com.mypackage",com.mypersist;uses:="com.mypackage",com.mytest;uses:="com.mylog",com.mycommons;uses:="org.apache.log4j,javax.xml.bind,javax.xml.validation,gnu.getopt,org.xml.sax",com.mypackage;uses:="javax.xml.bind.annotation,javax.xml.bind,javax.xml.namespace,com.mycommons",gnu.getopt

                        Generated-By-Ops4j-Pax-From = wrap:file:///C:/MyUtility.jar

                        Import-Package =

                        com.mylog;resolution:=optional,com.mypersist;resolution:=optional,com.mytest;resolution:=optional,com.mycommons;resolution:=optional,com.mypackage;resolution

                        ;=optional,gnu.getopt;resolution:=optional,javax.xml.bind;resolution:=optional,javax.xml.bind.annotation;resolution:=optional,javax.xml.namespace;resolution:

                        =optional,javax.xml.validation;resolution:=optional,org.apache.log4j;resolution:=optional,org.xml.sax;resolution:=optional

                        Manifest-Version = 1.0

                        Originally-Created-By = 1.6.0_17 (Sun Microsystems Inc.)

                        Tool = Bnd-0.0.313

                         

                        ESB :: Common :: MyLog (172)

                        -


                        Bnd-LastModified = 1285644282449

                        Build-Jdk = 1.6.0_18

                        Built-By = gaurav.x.nigam

                        Bundle-ManifestVersion = 2

                        Bundle-Name = ESB :: Common :: MyLog

                        Bundle-SymbolicName = AuditLog

                        Bundle-Version = 0.0.0.main-SNAPSHOT

                        Created-By = Apache Maven Bundle Plugin

                        Export-Package = com.esb.common.mylog;uses:="org.apache.camel,com.mycommons,com.mylog"

                        Import-Package =

                        com.mylog,com.mycommons,com.mypackage,javax.xml.bind,javax.xml.bind.annotation,javax.xml.namespace,org.apache.camel;version="2.4",org.apache.camel.osgi

                        Manifest-Version = 1.0

                        Tool = Bnd-0.0.357

                         

                        -Gaurav

                        • 9. Re: "Unable to create context" error while using jaxb in servicemix 4.3
                          Freeman(Yue) Fang Master

                          Hi,

                           

                          I noticed that from MyUtility.jar bundle, there's also Import-Package com.mypackage, that would be a problem when other bundles(not MyUtility.jar) also export com.mypackage, could you remove Import-Package com.mypackage from MyUtility.jar?

                           

                          Freeman

                          • 10. Re: "Unable to create context" error while using jaxb in servicemix 4.3
                            Gaurav Nigam Newbie

                            Hi Freeman,

                            Thanks for bearing with me. Earlier I was using osgi:install wrap:file:///C:/MyUtility.jar to install the jar as osgi bundle. Now I wrote a pom to wrap that jar as an osgi bundle. Now MyUtility.jar bundle headers look like this:

                            ESB :: Common :: MyUtility-jar-osgi (177)

                            -


                            Bnd-LastModified = 1285653669363

                            Build-Jdk = 1.6.0_18

                            Built-By = gaurav.x.nigam

                            Bundle-Description = MyUtility-jar-osgi wrapper OSGi bundle.

                            Bundle-ManifestVersion = 2

                            Bundle-Name = ESB :: Common :: auditlog-jar-osgi

                            Bundle-SymbolicName = MyUtility-jar-osgi

                            Bundle-Version = 0.0.0.main-SNAPSHOT

                            Created-By = Apache Maven Bundle Plugin

                            Export-Package = com.mylog;uses:="com.mypersist,com.mycommons,com.mypackage",com.mypersist;uses:="com.mypackage",com.mytest;uses:="com.mylog",com.mycommons;uses:="org.apache.log4j,javax.xml.bind,javax.xml.validation,gnu.getopt,org.xml.sax",com.mypackage;uses:="javax.xml.bind.annotation,javax.xml.bind,javax.xml.namespace,com.mycommons",gnu.getopt

                            Import-Package = javax.xml.bind,javax.xml.bind.annotation,javax.xml.namespace,javax.xml.validation,org.apache.log4j,org.xml.sax

                            Manifest-Version = 1.0

                            Tool = Bnd-0.0.357

                             

                            But still I am getting the same exception. Am I missing anything here?

                             

                            Gaurav

                            • 11. Re: "Unable to create context" error while using jaxb in servicemix 4.3
                              Freeman(Yue) Fang Master

                              Hi Gaurav,

                               

                              Maybe you can set up remote debug for servicemix, and run the debug in Eclipse, step in the jaxb code, it would give you more idea what's going on there.

                               

                              Freeman

                              • 12. Re: "Unable to create context" error while using jaxb in servicemix 4.3
                                Arun Sharma Newbie

                                Hi,

                                 

                                I hope somebody have solved this problem, as I can see there are number of posting for the problem but no real and satisfactory common solution to the problem.

                                 

                                Let me discuss my issue:

                                 

                                I have created jaxb bean as :

                                   

                                 

                                In my routeBuilder.java Class, I have create route as :

                                 

                                     from(quartzUri)

                                      .to(DataextracterUri)

                                      .marshal(myjaxb)

                                      .to(ftpServerURI);

                                 

                                Now for your concern, I verify you that my jaxb generated classes are in package: com.xyz.abc.xa.jaxb.generated. This include ObjectFactory.class. But there is nothing like jaxb.index inside it.

                                 

                                Why classloader not picking up the class ObjectFactory, although it is there in com.xyz.abc.xa.jaxb.generated package.

                                 

                                 

                                FYI: I am deploying my bundle using feature in ServiceMix 4.3--2.0

                                 

                                 

                                Error Log:

                                 

                                Caused by: javax.xml.bind.JAXBException: Unable to create context

                                - with linked exception:

                                http://java.lang.reflect.InvocationTargetException

                                at javax.xml.bind.ContextFinder.find(ContextFinder.java:68)

                                at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)

                                at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)

                                at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)

                                at com.vzb.ram.bind.ns.XmlPoJoUtil.toPoJo(XmlPoJoUtil.java:185)

                                ... 54 more

                                Caused by: java.lang.reflect.InvocationTargetException

                                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method):1.6.0_18

                                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39):1.6.0_18

                                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25):1.6.0_18

                                at java.lang.reflect.Method.invoke(Method.java:597):1.6.0_18

                                at javax.xml.bind.ContextFinder.find(ContextFinder.java:63)

                                ... 58 more

                                Caused by: javax.xml.bind.JAXBException: "com.xyz.abc.xa.jaxb.generated" doesnt contain ObjectFactory.class or jaxb.index

                                at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197)

                                ... 63 more

                                 

                                 

                                Thank you,

                                 

                                Arun Kumar (sharma_arun_se)

                                 

                                Edited by: sharma_arun_se on Nov 16, 2010 2:40 PM

                                 

                                Edited by: sharma_arun_se on Nov 16, 2010 4:02 PM

                                • 13. Re: "Unable to create context" error while using jaxb in servicemix 4.3
                                  Arun Sharma Newbie

                                  Hi All,

                                   

                                  I have found alternative solution of my problem. If anybody face same kind of problem, I will be more than happy to discuss the solution.

                                   

                                   

                                  Regards,

                                   

                                  Arun Kumar (sharma_arun_se)

                                   

                                  Expert SOA (Fuse ESB, Camel, ActiveMQ, OSGi) and RESTful Solution Architect, Open Source Contributor.

                                  linkedin: http://in.linkedin.com/in/aronkumar

                                  twitter: https://twitter.com/#!/SharmaArunKumar

                                  blog: http://techiesweek.blogspot.com/