I managed to solve the issue by using the JAXB implementation of Apache 
ServiceMix
Apache ServiceMix :: Bundles :: jaxb-impl (2.1.13.1) - 
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-impl/2.1.13_1

and its required dependencies:
Apache ServiceMix :: Specs :: Activation API 1.4 (1.7.0) - 
mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.activation-api-1.1/1.7.0
Apache ServiceMix :: Specs :: JAXB API 2.1 (1.7.0) - 
mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.1/1.7.0
Apache ServiceMix :: Specs :: Stax API 1.0 (1.7.0) - 
mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.stax-api-1.0/1.7.0

Kr Andrew
________________________________
From: Lindley Andrew [mailto:[email protected]]
Sent: Saturday, April 09, 2011 11:30 PM
To: [email protected]
Subject: RE: JAXB unmarshalling issue on karaf

Hi Achim, David

There are weird things going on. Indeed there seem to be issues with the 
JAXBContext.
When outputting the classes known to the JAXBContext in the JUnit-Test there 
are 5 classes of my package 'my.foo' on it.
When I look at the JAXBContext within the Karaf execution I receive in the case
a)JAXBContext.newInstance("my.foo",my.foo.MyRootElementType.class.getClassLoader());
 -->only one class of my package my.foo is on the context. That's the 
foo.bar.ObjectFactory
b)JAXBContext.newInstance(my.foo.MyRootElementType.class); -->3 classes of my 
package my.foo are on the context.

I've then tried to use the JAXBContext's  
newInstance<http://download.oracle.com/javase/6/docs/api/javax/xml/bind/JAXBContext.html#newInstance%28java.lang.Class...%29>(Class<http://download.oracle.com/javase/6/docs/api/java/lang/Class.html>...
 classesToBeBound) and added all of the 5 classes by hand, which worked out 
properly. However when I try to execute unmarshal the my.foo.MyRootElementType 
object is still returned with its fields s.getVersion==null and 
s.getDateCreated==null.

Kr Andrew

________________________________
From: Achim Nierbeck [mailto:[email protected]]
Sent: Saturday, April 09, 2011 8:11 PM
To: [email protected]
Subject: Re: JAXB unmarshalling issue on karaf

Hi guys,

my comments in-line

regards, Achim

Am 09.04.2011 19:15, schrieb David Jencks:
I ran into a similar but possibly opposite problem on karaf trunk.  For me, 
when I deployed a jaxb 2.2/stax 1.2 + geronimo specs for these set of bundles 
in karaf I got no contents to my top level jaxb object, but when I ran with the 
jvm versions jaxb worked properly.  At one point I got a setup where one of the 
two elements inside my top level element was unmarshalled into a java object 
and the other one wasn't.

I had similar issues where certain bundles did an import on a versioned jaxb 
spec and others didn't.
The way I solved parts of my problem was to set the package versions for the 
jaxb related packages in the jre.property file.
It was mainly a uses constraint violation. You might also take a look at the 
blog post of neil bartlet regarding the uses constraint violations and how to 
solve those :)


I haven't figured out what is going on yet, but I do wonder with the 
bootdelegation property set to include com.sun.* how any later sun jaxb 
implementation can be installed as a bundle and work -- I'd expect all the 
classes to be loaded from the vm no matter what you do.


the com.sun ones are always bootdelegated and shouldn't be imported by any 
bundle since those are internal classes :)
but sometimes you don't get around this, unfortunately :(

I may well have to actually solve this problem soon so I'm very interested in 
any clues about what is going on.

thanks
david jencks

On Apr 9, 2011, at 4:16 AM, Lindley Andrew wrote:

I've got a problem using JAXB unmarshalling within Karaf 2.1.0. I've got 
several JAXB annotated elements within the my.foo package along with e.g. 
package-info.java, ObjectFactory.java. They have been around for quite some 
time. However as I'm now porting this application to osgi and karaf I'm having 
problems unmarshalling.

you need to provide a classloader while creating the JAXBContext.
Since you didn't mention that you are using the ServiceMix Implementation of 
JAXB you need to set it yourself.
Because usually the Thread.currentContextLoader (or something that sounds the 
same just doing this out of my head without a
concrete example :)) is used and that point you need to make sure you are using 
the classloader that proveds the class you
want to un-/marshall. As far as I remember you need to provide that classloader 
- use my.foo.MyRootElement.class.getClassLoader() -
when using the un-/marshall methods.


The following JUnit test works perfectly as stand-alone - however when I try to 
execute the same calls from within a bundle on karaf I fail.
root.getValue() returns a my.foo.MyRootElement object however with it's fields 
s.getVersion==null and s.getDateCreated==null.
I already stepped in with the debugger and the JAXBContext instance contains 
the same references as within the standalone-JUnit test.

private static JAXBContext jc;
      private File fSigFile;

      @Before
      public void init() {
            fSigFile = new File("C:/TestFile.xml");
            try {
                  jc = JAXBContext.newInstance(my.foo.MyRootElementType.class);

            } catch (JAXBException e) {}
      }

      @Test
      public void testUnmarshalling (){
            try {
                  Assert.assertTrue(fSigFile.canRead());
                  JAXBElement<my.foo.MyRootElementType> root = 
jc.createUnmarshaller().unmarshal(newStreamSource((fSigFile).toURL().openStream()),my.foo.MyRootElementType.class);
                  my.foo.MyRootElement s = root.getValue();
                  Assert.assertNotNull(s);
                  Assert.assertNotNull(s.getVersion());
Assert.assertNotNull(s.getDateCreated());
            } catch (Exception e) {
                  Assert.assertTrue(false);
            }
    }

I haven't installed a JAXB impl bundle on karaf. The following system classes 
are used for parsing
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector
com.sun.org.apache.xerces.internal.parsers.XML11Configuration

I'm using the following karaf configuration:
org.osgi.framework.bootdelegation=sun.*,com.sun.*,javax.transaction,javax.transaction.*
org.osgi.framework.executionenvironment=J2SE-1.5,J2SE-1.4,J2SE-1.3

Thanks for your hints,
Kr Andrew


Reply via email to