users@glassfish.java.net

RE: JAXB in Glassfish

From: Larry Touve <ltouve_at_potomacfusion.com>
Date: Fri, 4 Jun 2010 12:30:14 -0500

But there is an ObjectFactory class. It was created when xjc compiled my XSD and created the classes. The code works fine in a standalone environment, but when it operates as a bundle in OSGi, the classloading is done differently so things don't work.

larry

From: Joe Bradley [mailto:gjoelbradley_at_netscape.net]
Sent: Friday, June 04, 2010 1:21 PM
To: users_at_glassfish.dev.java.net
Subject: Re: JAXB in Glassfish

You might want to try just coding an ObjectFactory class by hand. I had to do this recently when I was starting from annotated POJOs rather than an XML
schema. It's trivial to do: just provide an ObjectFactory class in each package with your POJOs. Sample follows.

I'm sure there is a Maven plugin to make JAXB generate the ObjectFactory but I couldn't find it.

package com.xxx;

import javax.xml.bind.annotation.XmlRegistry;

/**
 * Provides a JAXB Object Factory for the JAXB runtime to instantiate domain objects that can be marshalled to XML.
 *
 */
@XmlRegistry
public class ObjectFactory {

    public PriceChangedMessage createPriceChangedMessage() {
        return new PriceChangedMessage();
    }

    public OutOfStockMessage createOutOfStockMessage() {
        return new OutOfStockMessage();
    }
}

Joe

On Jun 4, 2010, at 12:38 PM, Larry Touve wrote:


Has anyone had success in using JAXB to marshal/unmarshall stuff in Glassfish? I'm using Glassfish V3.1-SNAPSHOT, and I'm running into tons of problems getting it to work from inside my bundles. I know it can work, because at one point in time I had deployed some combination of bundles that allowed it to work, but I can't get back to that state.

When I try to call JAXBContext.newInstance(<package-name>) I either get:

java.lang.RuntimeException: javax.xml.bind.JAXBException:
<package-name> doesn't contain ObjectFactory.class or jaxb.index

Or if I pass newInstance() a ClassLoader, I get:
javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory not found - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
                at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:146)
                at javax.xml.bind.ContextFinder.find(ContextFinder.java:289)
                at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:412)
                at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:375)
                at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:279)
                at Utils.unMarshall(Utils.java:215)
                at osgi.controller.JCMSController.publish(JCMSController.java:245)
                at osgi.controller.JCMSController.publishTrigger(JCMSController.java:320)
                at osgi.hscb.TcpThread.run(TcpThread.java:107)
                at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
                at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:744)
                at org.apache.felix.framework.ModuleImpl.access$100(ModuleImpl.java:61)
                at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1656)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
                at org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:604)
                at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1487)
                at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:897)
                at org.ops4j.pax.swissbox.core.BundleClassLoader.findClass(BundleClassLoader.java:176)
                at org.ops4j.pax.swissbox.core.BundleClassLoader.loadClass(BundleClassLoader.java:194)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
                at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:480)
                at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:112)
                ... 9 more

Glassfish uses version 2.2 of jaxb-api, and I've event tried using the DynamicJava version of JAXB (2.1).

Thanks,
 Larry



No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.819 / Virus Database: 271.1.1/2899 - Release Date: 06/04/10 02:25:00