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(_*_new_*_StreamSource((__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
>