-
1. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
concombremasqué Mar 29, 2010 2:08 PM (in response to concombremasqué)Solved. (Classloading issue)
CM
-
2. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
konrad.garlikowski Apr 13, 2010 9:00 PM (in response to concombremasqué)Hey,
currently I'm facing the same problem when trying to deploy some rest service using cxf and JAXB (servicemix 4.2.0). Could somebody explain how to overcome the class loading problems?
Thanks in advance,
Konrad.
-
3. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
michael.wengle Apr 19, 2010 4:28 AM (in response to konrad.garlikowski)We face the same problem with FUSE 4.2 and Java(TM) SE Runtime Environment (build 1.6.0_20-b02). We are NOT using CXF (Only Camel and ActiveMQ).
-
4. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
davsclaus Apr 19, 2010 4:59 AM (in response to michael.wengle)What OS are you using?
And did it work before? eg did you upgrade JDK or something, and then it stopped working?
-
5. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
michael.wengle Apr 20, 2010 7:55 AM (in response to davsclaus)Thank you for the quick reply.
I'm using Windows Vista but that is probably not crucial since I don't get the same error with all my bundles. Other bundles work successfully with JAXB and Camel on the same FUSE 4.2 installation.
The problem occurs when I deploy the bundles that I attached to this reply. The attachment also contains a log file.
This is not a blocking issue for me but this is an error I saw in the past from time to time and I would like to know how I can avoid it.
Edit: The problem appears only on startup and not when I deploy the bundles on a running instance.
Edited by: michael.wengle on Apr 20, 2010 11:53 AM
-
LogAndBundles.zip 16.0 KB
-
-
6. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
flume Jun 11, 2010 1:35 AM (in response to michael.wengle)How does one solve this classloading problem?
I get the same error when using the marshalling function of camel-jaxb:
Caused by: javax.xml.bind.JAXBException: Unable to create context
- with linked exception:
at javax.xml.bind.ContextFinder.find(ContextFinder.java:72)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
at org.apache.camel.converter.jaxb.JaxbDataFormat.createContext(JaxbDataFormat.java:242)
at org.apache.camel.converter.jaxb.JaxbDataFormat.getContext(JaxbDataFormat.java:183)
at org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:76)
... 69 more
Caused by: java.lang.NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String, java.lang.ClassLoader)
at java.lang.Class.getMethod(Class.java:1605)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:69)
... 75 more
I decompiled the class in bundle Apache ServiceMix Specs :: JAXB API 2.1 (1.4.0) -> ContextFinder.java:
if(className == null)
className = "com.sun.xml.bind.v2.ContextFactory";
spi = loadSpi(className, classLoader);
Method m = spi.getMethod("createContext", new Class[] {
java/lang/String, java/lang/ClassLoader, java/util/Map
});
return (JAXBContext)m.invoke(null, new Object[] {
contextPath, classLoader, properties
});
Throwable t;
t;
t = spi.getMethod("createContext", new Class[] {
java/lang/String, java/lang/ClassLoader
});
return (JAXBContext)t.invoke(null, new Object[] {
contextPath, classLoader
});
t;
throw new JAXBException("Unable to create context", t);
If I check the bundle Apache ServiceMix Bundles: jaxb-impl-2.1.12 (2.1.12.1) -> ContextFactory for the specific method with arguments java/lang/String, java/lang/ClassLoader I can't find it since this is JAXB 1.0.
Why didn't the first JAXB 2.0 method result in a success? I find this quite odd.
Method m = spi.getMethod("createContext", new Class[] {
java/lang/String, java/lang/ClassLoader, java/util/Map
});
This thread/question is marked as answered but I can't find a helpful thing in here. Can someone push me in the right direction?
-
7. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
gertv Jun 16, 2010 10:02 AM (in response to flume)L.S.,
Could you attach a sample bundle or some instructions on how to reproduce this issue? It looks like it's recurring now and then for people, so if we can get some extra input to get it fixed, that would be nice.
Regards,
Gert Vanthienen
-
8. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
michael.wengle Dec 7, 2010 3:50 AM (in response to gertv)I had the same exception when I wanted to load a Camel route from a XML file.
This solved the problem for me: Add the imports that are defined in "Constants.JAXB_CONTEXT_PACKAGES" to the OSGi bundle:
Bundle Plugin for Maven:
Edited by: michael.wengle on Dec 6, 2010 11:05 AM
Edited by: michael.wengle on Dec 7, 2010 8:47 AM
-
9. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
dustin_dustin.schultz Jun 18, 2010 9:48 AM (in response to concombremasqué)I keep seeing this error pop up and I solve it and then I forget how I solved it. It's definitely a classpath issue ... the bundle seeing the wrong jaxb api or impl.
Right now, the way it occurs for me is on an OSGi service that's imported into another bundle that uses the client's classloader. If I switch the classloader to service-provider I don't see the error.
-
10. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
dustin_dustin.schultz Jun 18, 2010 12:27 PM (in response to concombremasqué)Ok, with help from a coworker, the problem likely results from not being able to find a jaxb.index or ObjectFactory. You may have these but make sure that the OSGi classpath is seeing them.
In ContextFactory:
Method m = spiClass.getMethod("createContext",String.class,ClassLoader.class,Map.class);
context = m.invoke(null,contextPath,classLoader,properties);
// Context will == null if you don't have a jaxb.index or ObjectFactory
if(context==null) {
createContext method.
Method m = spiClass.getMethod("createContext",String.class,ClassLoader.class);
context = m.invoke(null,contextPath,classLoader);
}
Then you get the NoSuchMethodException from the second call.
-
11. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
dustin_dustin.schultz Jun 18, 2010 5:02 PM (in response to concombremasqué)More inspection on this shows that the jaxb-api used by FUSE has
try {
Method m = spi.getMethod("createContext", new Class[] { String.class, ClassLoader.class, Map.class });
return (JAXBContext) m.invoke(null, new Object[] { contextPath, classLoader, properties });
} catch (Throwable t) {
// Ignored
}
Other implementations have
} catch (NoSuchMethodException e) {
// it's not an error for the provider not to have this method.
}
The throwable swallows the real exception if an ObjectFactory or a jaxb.index is not found:
if( !(foundObjectFactory || foundJaxbIndex) ) {
throw new JAXBException( Messages.BROKEN_CONTEXTPATH.format(pkg));
}
Edit: sources here:
Edited by: dustin on Jun 18, 2010 8:59 PM
-
12. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
ffang Sep 27, 2010 8:50 AM (in response to dustin_dustin.schultz)Hi,
FYI, SMX4-580[1] tracked this issue and already get fixed.
https://issues.apache.org/activemq/browse/SMX4-580
Freeman
-
13. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
sharma_arun_se1 Nov 16, 2010 11:03 AM (in response to ffang)Hi,
I hope somebody have solved this problem, as I can see there are number of posting for the problem but no real and satisfactory common solution to the problem.
Let me discuss my issue:
I have created jaxb bean as :
In my routeBuilder.java Class, I have create route as :
from(quartzUri)
.to(DataextracterUri)
.marshal(myjaxb)
.to(ftpServerURI);
Now for your concern, I verify you that my jaxb generated classes are in package: com.xyz.abc.xa.jaxb.generated. This include ObjectFactory.class. But there is nothing like jaxb.index inside it.
Why classloader not picking up the class ObjectFactory, although it is there in com.xyz.abc.xa.jaxb.generated package.
FYI: I am deploying my bundle using feature in ServiceMix 4.3--2.0
Error Log:
Caused by: javax.xml.bind.JAXBException: Unable to create context
- with linked exception:
http://java.lang.reflect.InvocationTargetException
at javax.xml.bind.ContextFinder.find(ContextFinder.java:68)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
at com.vzb.ram.bind.ns.XmlPoJoUtil.toPoJo(XmlPoJoUtil.java:185)
... 54 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method):1.6.0_18
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39):1.6.0_18
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25):1.6.0_18
at java.lang.reflect.Method.invoke(Method.java:597):1.6.0_18
at javax.xml.bind.ContextFinder.find(ContextFinder.java:63)
... 58 more
Caused by: javax.xml.bind.JAXBException: "com.xyz.abc.xa.jaxb.generated" doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197)
... 63 more
Thank you,
Arun Kumar (sharma_arun_se)
Edited by: sharma_arun_se on Nov 16, 2010 4:02 PM
-
14. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
sharma_arun_se1 Nov 20, 2010 7:45 AM (in response to sharma_arun_se1)Hi All,
I have found alternative solution of my problem. If anybody face same kind of problem, I will be more than happy to discuss the solution.
Regards,
Arun Kumar (sharma_arun_se)
Expert SOA (Fuse ESB, Camel, ActiveMQ, OSGi) and RESTful Solution Architect, Open Source Contributor.
linkedin: http://in.linkedin.com/in/aronkumar