5

I am using Eclipselink Moxy Implementation of JAXB in my project to map complex XML to String Object using XmlAnyElement. For this I have implemented DomHandler named as LayoutHandler. I am using JAXB for resteasy web services deployed in JBoss 6.

I am facing Below issue intermittently -

    Exception [EclipseLink-50033] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): 
org.eclipse.persistence.exceptions.JAXBException
Exception Description: The DomHandlerConverter for DomHandler 
[com.**.LayoutHandler] set on property [layoutXml] could not be 
initialized.
Internal Exception: java.lang.ClassNotFoundException: 
com.**.LayoutHandler from 
BaseClassLoader@5c0b3ad0{vfs:///*/*/jboss-server/server/all/deployers/resteasy.deployer}
    While EclipseLink Moxy is instantiating JAXBContext using JAXBContext.newInstance(classes, properties)

After spending some time in debugging and analyzing the issue I could figure out that ClassLoader of resteasy is getting used to load LayoutHandler class instead of my application class loader(vfs://///jboss-server/server/all/deploy/app_name.ear/app_name.war/) which is causing the issue as its unable to find the LayoutHandler class.

When I bounce the server, issue is getting resolved so I am unable to find out the exact root cause. Any help will be appreciated.

Further debugging into org.eclipse.persistence.jaxb.JAXBContextFactory revealed that below two classes are getting passed to createContext() method of JAXBContextFactory -

org.jboss.resteasy.plugins.providers.jaxb.JaxbCollection
com.**.Model_class

public static javax.xml.bind.JAXBContext createContext(Class[] classesToBeBound, Map properties) throws JAXBException {
        ClassLoader loader = null;
        if (classesToBeBound.length > 0) {
            loader = classesToBeBound[0].getClassLoader();
        }
        return createContext(classesToBeBound, properties, loader);
    }

In above method classloader of first class is getting used to load the custom DomHandler later on. When first element in array is model class at that time code is working fine as application context class loader is getting used but when the first element in array is JaxbCollection rest easy context class loader is getting used and its throwing mentioned exception.

This issue is occurring intermittently as order of elements in array is varying which might be due to the use of HashSet to hold the elements of type Class by caller of this method which is passing the classesToBeBound array

Note: I have replaced actual package names with *.

Murli
  • 1,258
  • 9
  • 20

1 Answers1

0

I'm surprised it works on a bounce... all of your JAXB bits need to line up, you should be using the moxy jaxb provider at all times. If it's failing after initial deploy, then working after a bounce, I suspect that you want to specify the moxy jaxb provider in your system properties ( -Djavax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory ) and ensure that they're available to jboss when your app is not deployed.

lscoughlin
  • 2,327
  • 16
  • 23
  • @Iscoughlin I have specified moxy as jaxb provider in jaxb.properties. I have spent some more time in debugging it and drill down more into root cause of this. I have posted the detailed cause in eclipse link forum - https://www.eclipse.org/forums/index.php/t/1094667/ – Murli Aug 18 '18 at 09:27