john.mcclain_at_homeq.com wrote:
> I have an EAR project. In the project I have a web app and an EJB. My goal
> is to have a REST webservice servlet that gets the XML payload, uses JAXB
> to unmarshal it into XJC generated classes, then pass those classes to an
> EJB for processing. What I have found is the following:
>
> scenario 1)
> here is the EAR fle structure:
> EAR
> bpo-lib.jar - holds the XJC generated classes
> bpo-ejb.jar - references bpo-lib.jar in its manifest.mf file
> bpo-webservice.war - holds the rest servlet that does the
> unmarshaling and passes unmarshaled objects to EJB
> - holds bpo-lib.jar in WEB-INF/lib - I did this
> because I saw in the FAQ that JAXBContext.newInstance tries to load
> classes using the same clasloader that the
> JAXBContext class is in
> - references bpo-lib.jar in its manifest.mf
> file
>
> The result is that I can unmarshal the data into the XJC classes, but
> after I pass them to the EJB, I try to cast the object into the expected
> types and get a class cast exception. this is possibly the behavior
> mentioned in https://jaxb.dev.java.net/faq/#classloader
If you successfully unmarshalled objects, then the above doesn't really
sound like a JAXB issue. How do you pass data from your web tier to EJBs?
>
>
> scenario 2)
> here is the EAR file structure:
> EAR
> bpo-lib.jar - holds the XJC generated classes
> bpo-ejb.jar - references bpo-lib.jar in its manifest.mf file
> bpo-webservice.war - holds the rest servlet that does the
> unmarshaling and passes unmarshaled objects to EJB
> - does NOT hold bpo-lib.jar in WEB-INF/lib - I
> did this because in theory, on JBOSS4.0.4GA,
> the EAR classes are accessible to the WAR
> context. I.E., I should NOT have to put the bpo-lib.jar file
> in both the WEB-INF/lib dir and the EAR file
> - references bpo-lib.jar in its manifest.mf file
> The result is that I can NOT unmarshal the data into the XJC classes.
I don't have any experience with EJB myself, so I don't know how class
loaders are set up there.
You mentioned that you saw in FAQ that"JAXBContext.newInstance tries to
load classes using the same clasloader that the JAXBContext class is
in", but that is incorrect. I believe it tries to load things from the
current thread context classloader.
> When it did not unmarshal data it had this set of classes:
> boolean
> byte
> char
> com.homeq.bpo.domain.FirstAmericanSchema.request.ObjectFactory
> com.sun.xml.bind.api.CompositeStructure
> double
> float
It's very unusual that ObjectFactory shows up like this. My suspicion is
that you somehow ended up loading multiple copies of jaxb-api.jar, and
@XmlRegistry annotation on the
com.homeq.bpo.domain.FirstAmericanSchema.request.ObjectFactory class is
not correctly recognized by the JAXB RI.
> Would I be correct in stating that using JAXB in a rest based web service
> on JBOSS4.0.4GA cannot be done, or am I missing something?
I think this is just a deployment problem, and not necessarily any
fundamental integration issue.
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com