Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » DynamicJAXBContextFactory.createContextFromXSD fails to load SchemaMetadata (Fails if deployed in glassfish 4 works in junit-test)
DynamicJAXBContextFactory.createContextFromXSD fails to load SchemaMetadata [message #1241023] Fri, 07 February 2014 11:08 Go to next message
Greger Sernemar is currently offline Greger SernemarFriend
Messages: 1
Registered: July 2009
Junior Member
Hi,

I'm using the DynamicJAXBContextFactory.createContextFromXSD method to create a jaxbcontext from an xsd.

It works find when I instansiate all classes from a junit test, but when I call the same classes deployed on a glassfish 4 server, the class org.eclipse.persistence.jaxb.dynamic.metadata.SchemaMetadata can't be found!
Running GlassFish Server Open Source Edition 4.0 (build 89) with Eclipselink 2.5.0
I have tested with nightly build glassfish-4.0.1-b04-02_04_2014-ml with Eclipselink 2.5.1, it's the same fault there.

I downloaded the sourcecode and during debug I could set a log.debugflag to 4 and got a detailed description of the cause:

java.lang.ClassNotFoundException: *** Class 'org.eclipse.persistence.jaxb.dynamic.metadata.SchemaMetadata' was not found because bundle org.eclipse.persistence.core [211] does not import 'org.eclipse.persistence.jaxb.dynamic.metadata' even though bundle org.eclipse.persistence.moxy [216] does export it. Additionally, the class is also available from the system class loader. There are two fixes: 1) Add an import for 'org.eclipse.persistence.jaxb.dynamic.metadata' to bundle org.eclipse.persistence.core [211]; imports are necessary for each class directly touched by bundle code or indirectly touched, such as super classes if their methods are used. 2) Add package 'org.eclipse.persistence.jaxb.dynamic.metadata' to the 'org.osgi.framework.bootdelegation' property; a library or VM bug can cause classes to be loaded by the wrong class loader. The first approach is preferable for preserving modularity. ***

I added 'org.eclipse.persistence.jaxb.dynamic.metadata' to the 'org.osgi.framework.bootdelegation' property;
then the class loaded, but now it't can't find the constructor!

I debug the org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getConstructorFor method, (see code below), but it can't find the constructor even if they looks the same to me!
The parameterType is class org.eclipse.persistence.dynamic.DynamicClassLoader
the argType is class org.eclipse.persistence.dynamic.DynamicClassLoader
but somehow the methods parameterType.isAssignableFrom(argType)) && (!argType.isAssignableFrom(parameterType) fails if the code runs i glassfish 4 but works if run from a junit-test.

I don't know why it don't work, can someone help me please?

And the detailed message suggest that the number 1) sulotion should be used, i.e
1) Add an import for 'org.eclipse.persistence.jaxb.dynamic.metadata' to bundle org.eclipse.persistence.core [211];
Is this a bug in eclipselink, if so can someone fix it?

Regards,
Greger Sernemar
Stockholm, Sweden

Here is the code for the method:
public static Constructor getConstructorFor(final Class javaClass, final Class[] args, final boolean shouldSetAccessible) throws NoSuchMethodException {
Constructor result = null;
try {
result = javaClass.getConstructor(args);
} catch (NoSuchMethodException missing) {
// Search for any constructor with the same number of arguments and assignable types.
for (Constructor constructor : javaClass.getConstructors()) {
if (constructor.getParameterTypes().length == args.length) {
boolean found = true;
for (int index = 0; index < args.length; index++) {
Class parameterType = Helper.getObjectClass(constructor.getParameterTypes()[index]);
Class argType = Helper.getObjectClass(args[index]);
if ((!parameterType.isAssignableFrom(argType))
&& (!argType.isAssignableFrom(parameterType))) {
found = false;
break;
}
}
if (found) {
result = constructor;
break;
}
}
}
if (result == null) {
throw missing;
}
}
if (shouldSetAccessible) {
result.setAccessible(true);
}
return result;
}

Re: DynamicJAXBContextFactory.createContextFromXSD fails to load SchemaMetadata [message #1243277 is a reply to message #1241023] Mon, 10 February 2014 19:30 Go to previous message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

MOXy's support for bootstrapping a dynamic JAXB model from an XML Schema does not currently work in an OSGi environment.

For this feature MOXy leverages code from the JAXB reference implementation. Part of the code that is responsible for generating Java classes from an XML Schema. This code gave us problems when we tried to OSFi-ify it, therefore we couldn't expose the code that depended on it though OSGi.
Previous Topic:Eclipse AspectJ vs. EclipseLink DynamicWeaving
Next Topic:NOT NULL FK nullification problem
Goto Forum:
  


Current Time: Thu Apr 18 00:18:28 GMT 2024

Powered by FUDForum. Page generated in 0.03212 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top