I have a SOAP web service that I am trying to call inside an application. I use cxf-codegen-plugin (3.1.10) to generate sources from WSDL.
Using the generated client, if I call the web service in the application, it works fine. However, I also use a different instance of JAXB against the same package in the application that causes the problem.
For example, the following works fine:
OutboundServicePortType service = new OutboundService().getOutboundServicePort(); service.sendMessage(message);
However, initializing a new JAXB instance right before calling getOutboundServicePort()
to fail:
JAXBContext.newInstance(SendMessageRequest.class); OutboundServicePortType service = new OutboundService().getOutboundServicePort(); service.sendMessage(message);
Using the following stacktrace command:
Caused by: java.lang.ClassCastException: outbound.model.standard.StandardOutboundMessage$JaxbAccessorF_messageUUId cannot be cast to com.sun.xml.internal.bind.v2.runtime.reflect.Accessor at com.sun.xml.internal.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.instanciate(OptimizedAccessorFactory.java:190) at com.sun.xml.internal.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.java:179) at com.sun.xml.internal.bind.v2.runtime.reflect.Accessor$FieldReflection.optimize(Accessor.java:271) at com.sun.xml.internal.bind.v2.runtime.property.SingleElementLeafProperty.<init>(SingleElementLeafProperty.java:77) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:113) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:166) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:488) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:153) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:488) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:305) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:124) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1123) at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:147) at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:152) at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:96) at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:98) at com.sun.xml.internal.ws.db.glassfish.JAXBRIContextFactory.newContext(JAXBRIContextFactory.java:79) ... 25 more
Things I've tried so far:
JAXB classes from Marshalling Webservice error
- I do not have approved jars in the JDK folder, so this answer does not apply
- Jaxb-impl jar (2.2.11) comes from camel-jaxb in my application, so it seems to be very inclusive and not like this answer .
- This answer seems to describe the problem well, but the solution they made seems confusing to me.
Problems creating JAXBContext to marshal an object as XML
- This question seems identical to me, but the solution they ended up with cannot work for my situation (see below).
Netbeans with JAXB Random exception ClassCastException .. will not be passed to com.sun.xml.bind.v2.runtime.reflect.Accessor
- I tried the solution
System.setProperty( "com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize", "true");
that works. However, setting this property is not an option for me, unfortunately, in my environment. Plus, it seems like it's a bit of a hack that doesn't address the real problem (if I don't understand it).
I'm going to hang myself with the little rope that I left. What am I missing here?
source share