14 Replies Latest reply on Sep 18, 2012 10:14 AM by sivaram pola

    JAXB and the system bundle

    Alexander Koledzhikov Newbie

      I have an osgi bundle, which imports javax.xml.bind from the system.bundle. I try to create a new JAXB context in its activator. However, the attempt fails with: java.lang.ClassCircularityError: javax/xml/bind/JAXBException.

      After some investigation, I think that this package isn't exported properly - when I get my bundles classloader and try to load the JAXBContext by name, I get a ClassNotFoundException. This can be seen with the attached osgi bundle.

      Is this a bug or am I doing something wrong?

      P.S. I've read here: http://docs.jboss.org/osgi/jboss-osgi-1.0.0.Beta8/userguide/html/ChapProvidedBundles.html#SecBundleJAXB that there is an osgi service providing initial contexts now. Should I use the jboss-osgi-jaxb.jar in place of the system.bundle?

      P.P.S. Forgot to mention it, but I'm using JBoss 7.1.0Final.



        • 1. Re: JAXB and the system bundle
          Alexander Koledzhikov Newbie

          Sorry for the double post, but since getting the JAXB to work properly in osgi environment is really important to me (they've threatened to fire me if I don't solve the problem until the end of the week, and in that case I'll have no choice but to sell my women and children into slavery and become a mule for the local drug lord ).

          I've tried to deploy a separate bundle containing the jaxb implementation, but since the system bundle starts first, almost everything else loads the package from it, leading to the result mentioned in the previous post. Any idea how I can modify the exports of the system bundle and remove javax.xml.bind from them?

          • 2. Re: JAXB and the system bundle
            Alexander Koledzhikov Newbie

            In case someone is interested, you can modify the modules included in the system bundle by adding the org.jboss.osgi.system.modules.extra property to the osgi subsystem. In it you can place a comma-separated list of the modules you need (in my case, javax.xml.bind.api). You can also modify the exports of the bundle by setting org.jboss.osgi.system.packages - please note that this will override the default exports, so make sure that you list everything you need there.

            • 3. Re: JAXB and the system bundle
              Xavier Courangon Newbie

              Hi Alexander,

               

              I've just read your interesting post and met the same issue.

               

              We are upgrading from JBoss 7.1.0CR1b to 7.1.1.Final and we have this issue too : ClassNotFound javax.xml.bind.JAXBContext

              This exception was not raised with 7.1.0.CR1b (but raised for you with the Final release... ???).

              We've tryed to add the org.jboss.osgi.system.modules.extra property

               

              <property name="org.jboss.osgi.system.modules.extra">

                   javax.xml.bind

              </property>

               

              without success

               

              17:34:51,728 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC00001: Failed to start service jbosgi.AutoInstallProvider.COMPLETE: org.jboss.msc.service.StartException in service jbosgi.AutoInstallProvider.COMPLETE: Failed to start service

                      at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

                      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_07]

                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_07]

                      at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_07]

              Caused by: java.lang.IllegalStateException: org.jboss.modules.ModuleNotFoundException: Module javax.xml.bind:main is not found in local module loader @71fd20 (r

              oots: C:\jboss-as-7.1.1.Final\modules)

               

              Have you moved to 7.1.1.Final (or eap) and have you met issues ?

               

              Thanks

              • 4. Re: JAXB and the system bundle
                Rico Neubauer Novice

                Hi Xavier,

                Alexander and me are working on the same product, so I can answer your question regarding the version with: Yes, we moved to 7.1.1.Final in the meantime.

                The following os the configuration we use atm and this works for us. You may need less entries (e.g. not org.apache.santuario), but I post it completely here:

                 

                <properties>
                    <property name="org.jboss.osgi.system.modules.extra">
                        javax.xml.bind.api,org.apache.santuario.xmlsec,javax.xml.soap.api
                    </property>
                    <property name="org.osgi.framework.system.packages.extra">
                        javax.activation;version=1.1.1,
                        javax.xml.bind;version=2.2,
                        sun.security.provider;version=1.0,
                        com.sun.org.apache.xerces.internal.dom;version=1.0,
                        com.sun.org.apache.xerces.internal.jaxp;version=1.0,
                        com.sun.org.apache.xerces.internal.util;version=1.0,
                    </property>
                </properties>
                
                
                • 5. Re: JAXB and the system bundle
                  Xavier Courangon Newbie

                  Hi Rico,

                   

                  It is a mistake from us !!

                  Our org.jboss.osgi.system.modules.extra property is not correct : javax.xml.bind ->  javax.xml.bind.api (it is expected the module name, not the exported package).

                   

                  Thank you very must for your help, really.

                   

                  By the way, do you know why these packages (javax.xml.bind, ...) seem to be exported by system.bundle and correctly imported by application bundles ??

                  Is it an inducement to use JAXB as a service ?

                  • 6. Re: JAXB and the system bundle
                    sivaram pola Newbie

                    Hi Rico,

                     

                    I am facing the same problem while creating the JAXB context instance in a osgi bundle in jboss as 7.1.1.  I have made changes as you mentioned above in the standalone.xml. But now i am getting the following exception while creating the JAXBContext instance

                     

                    java.lang.Error: Failed to initialize JAXP 1.3 DatatypeFactory class.

                        at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.init(RuntimeBuiltinLeafInfoImpl.java:905)

                        at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.<clinit>(RuntimeBuiltinLeafInfoImpl.java:899)

                        at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.<init>(RuntimeTypeInfoSetImpl.java:65)

                        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:133)

                        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:85)

                        at com.sun.xml.bind.v2.model.impl.ModelBuilder.<init>(ModelBuilder.java:156)

                    Caused by: javax.xml.datatype.DatatypeConfigurationException: Provider __redirected.__DatatypeFactory not found

                        at javax.xml.datatype.DatatypeFactory.newInstance(DatatypeFactory.java:137) [rt.jar:1.6.0_26]

                        at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.init(RuntimeBuiltinLeafInfoImpl.java:903)

                        ... 33 more

                    Caused by: java.lang.ClassNotFoundException: __redirected/__DatatypeFactory

                        at java.lang.Class.forName0(Native Method) [rt.jar:1.6.0_26]

                        at java.lang.Class.forName(Class.java:247) [rt.jar:1.6.0_26]

                     

                    Do i need to add any configuration to resolve this error. Please suggest me if you came around this error.

                     

                    Thanks in advance.

                    • 7. Re: JAXB and the system bundle
                      Rico Neubauer Novice

                      Hi sivaram,

                      The error you get is known to me, however is not directly related to the configuration as far as I can say.

                      Please check your code, whether you are doing the JAXBContext.newInstance() call inside a static-block or in a method called via a static initializer. Removing any access to JAXBContext during such static initialization resolved the issue for us. Instead you can use initialization on access or on object-creation.

                      The root cause is not really clear to me, but seems to be related to a race-condition during boot-phase, so it can happen that the needed resources are not yet available.

                       

                      Best Regards,

                      Rico

                      • 8. Re: JAXB and the system bundle
                        sivaram pola Newbie

                        Hi Rico,

                         

                        Thankyou for the response. I have created a staic jaxbcontext variable now i have removed the static modifer. But now i am getting the following exception.

                         

                        java.lang.NullPointerException

                        20:37:29,844 ERROR [stderr] (MSC service thread 1-1)     at javax.xml.bind.ContextFinder.find(ContextFinder.java:279)

                        20:37:29,844 ERROR [stderr] (MSC service thread 1-1)     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:412)

                        20:37:29,845 ERROR [stderr] (MSC service thread 1-1)     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:375)

                        20:37:29,845 ERROR [stderr] (MSC service thread 1-1)     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:279)

                        20:37:29,846 ERROR [stderr] (MSC service thread 1-1)     at com.cultagent.gr.hotelde.JaxbUtil.getJaxb(JaxbUtil.java:33)

                        20:37:29,846 ERROR [stderr] (MSC service thread 1-1)     at com.cultagent.gr.hotelde.JaxbUtil.getUnmarshaller(JaxbUtil.java:47)

                        20:37:29,847 ERROR [stderr] (MSC service thread 1-1)     at com.cultagent.gr.hotelde.Activator.start(Activator.java:25)

                        20:37:29,847 ERROR [stderr] (MSC service thread 1-1)     at org.jboss.osgi.framework.internal.HostBundleState.transitionToActive(HostBundleState.java:300)

                        20:37:29,848 ERROR [stderr] (MSC service thread 1-1)     at org.jboss.osgi.framework.internal.HostBundleState.startInternal(HostBundleState.java:223)

                        20:37:29,848 ERROR [stderr] (MSC service thread 1-1)     at org.jboss.osgi.framework.internal.AbstractBundleState.start(AbstractBundleState.java:494)

                        20:37:29,849 ERROR [stderr] (MSC service thread 1-1)     at org.jboss.as.osgi.deployment.BundleStartTracker$1.processService(BundleStartTracker.java:144)

                        20:37:29,849 ERROR [stderr] (MSC service thread 1-1)     at org.jboss.as.osgi.deployment.BundleStartTracker$1.transition(BundleStartTracker.java:119)

                        20:37:29,849 ERROR [stderr] (MSC service thread 1-1)     at org.jboss.msc.service.ServiceControllerImpl.invokeListener(ServiceControllerImpl.java:1416)

                        20:37:29,850 ERROR [stderr] (MSC service thread 1-1)     at org.jboss.msc.service.ServiceControllerImpl.access$2700(ServiceControllerImpl.java:49)

                        20:37:29,850 ERROR [stderr] (MSC service thread 1-1)     at org.jboss.msc.service.ServiceControllerImpl$ListenerTask.run(ServiceControllerImpl.java:1954)

                        20:37:29,851 ERROR [stderr] (MSC service thread 1-1)     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

                        20:37:29,851 ERROR [stderr] (MSC service thread 1-1)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

                        20:37:29,852 ERROR [stderr] (MSC service thread 1-1)     at java.lang.Thread.run(Thread.java:662)

                         

                         

                        The code is running perfectly in the eclipse osgi contaner. 

                         

                         

                        Kind Regards,

                        Siva Ram.

                        • 9. Re: JAXB and the system bundle
                          Alexander Koledzhikov Newbie

                          Hi Siva,

                          Actually, just making the static variable non-static won't help. You have to postpone the creation of JAXB context until after the bundle has finished starting (when your Activator has finished its job), so any jaxb objects will have to be lazily initialized (if possible).

                          If this is not possible (or will proove too much hassle), you can try passing this property to the jboss' jvm : "-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true", but it is not guaranteed to work (especially if you have plenty of bundles using jaxb objects in their activators).

                          Btw, do you get this error every time you start the bundle or only occasionally?

                           

                          Best regards,

                          Alex

                          • 10. Re: JAXB and the system bundle
                            sivaram pola Newbie

                            Hi Alex,

                             

                            Thank You for your response.  I have tried in first way specified by you. But still i am getting the following exception:

                             

                            java.lang.NullPointerException

                            15:32:06,848 ERROR [stderr] (Thread-69)     at javax.xml.bind.ContextFinder.find(ContextFinder.java:279)

                            15:32:06,848 ERROR [stderr] (Thread-69)     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:412)

                            15:32:06,849 ERROR [stderr] (Thread-69)     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:375)

                            15:32:06,850 ERROR [stderr] (Thread-69)     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:279)

                            15:32:06,851 ERROR [stderr] (Thread-69)     at com.helloworld.JContext.getJContext(JContext.java:12)

                            15:32:06,852 ERROR [stderr] (Thread-69)     at jboss_as_helloworld.osgi.Activator$1.run(Activator.java:29)

                            15:32:06,852 ERROR [stderr] (Thread-69)     at java.lang.Thread.run(Thread.java:662).

                             

                            Yes i am getting this exception every time when the bundle is started. Not getting any way to resolve this error . Can you spot where i am doing the mistake. I am attaching the code and jar files here.

                             

                            Kind Regards,

                            Siva Ram.

                            • 11. Re: JAXB and the system bundle
                              Alexander Koledzhikov Newbie

                              Hello,

                              Still not sure if this will  help, but when you create the JAXB context, can you pass the classloader of the bundle which contains the jaxb objects as a second argument to the method invocation? I think the problem is that unless provided with specific classloader, JAXB uses the current thread's CL, which is usually null.

                               

                              In JContext:

                              jxbc = javax.xml.bind.JAXBContext

                                                      .newInstance("la-la-la", getClass().getClassLoader());

                               

                              If your jaxb objects are in another bundle, you'll have to somehow get its classloader here so you can use it for the context.

                               

                              Best regards,

                              Alex

                              • 12. Re: JAXB and the system bundle
                                sivaram pola Newbie

                                Hello Alex,

                                 

                                Thank you for you response. I have already tried in the way by specifieng the class loader for the particular package. I this case i am getting the following error again:

                                 

                                java.lang.Error: Failed to initialize JAXP 1.3 DatatypeFactory class.

                                    at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.init(RuntimeBuiltinLeafInfoImpl.java:905)

                                    at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.<clinit>(RuntimeBuiltinLeafInfoImpl.java:899)

                                    at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.<init>(RuntimeTypeInfoSetImpl.java:65)

                                    at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:133)

                                    at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:85)

                                    at com.sun.xml.bind.v2.model.impl.ModelBuilder.<init>(ModelBuilder.java:156)

                                Caused by: javax.xml.datatype.DatatypeConfigurationException: Provider __redirected.__DatatypeFactory not found

                                    at javax.xml.datatype.DatatypeFactory.newInstance(DatatypeFactory.java:137) [rt.jar:1.6.0_26]

                                    at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.init(RuntimeBuiltinLeafInfoImpl.java:903)

                                    ... 33 more

                                Caused by: java.lang.ClassNotFoundException: __redirected/__DatatypeFactory

                                    at java.lang.Class.forName0(Native Method) [rt.jar:1.6.0_26]

                                    at java.lang.Class.forName(Class.java:247) [rt.jar:1.6.0_26

                                 

                                Regards,

                                Siva Ram.

                                • 13. Re: JAXB and the system bundle
                                  Alexander Koledzhikov Newbie

                                  Now this is getting strange...

                                  Are you sure that you're trying the correct classloader (the one from HelloWorld_1.0.0.... bundle) and that your application is properly packaged (which I think it is, but I'm no JAXB expert).

                                  If yes, I'd like you to expand the experiment a bit - instead of using new thread to wait 5 seconds and create the context, can you register an mbean which does the same? You can invoke it after the osgi bundle has deployed successfully - this way we'll be sure that no deployment race-conditions exist.

                                   

                                  Best regards,

                                  Alex

                                  • 14. Re: JAXB and the system bundle
                                    sivaram pola Newbie

                                    Yes i will try in the way and let you know about the result.

                                     

                                    I think there was a problem with the jaxb support for osgi bundles the jboss as 7.1.1 as they have added it in the features list :

                                     

                                    https://issues.jboss.org/browse/AS7-5531.