3

I created a jaxws web service. I totally followed the url

The service was up perfectly without any error. But the server having errors when request hit it.

SEVERE: caught throwable
java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.bind.api.JAXBRIContext
    at com.sun.xml.ws.db.glassfish.JAXBRIContextFactory.newContext(JAXBRIContextFactory.java:74)
    at com.sun.xml.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:149)
    at com.sun.xml.ws.message.jaxb.JAXBMessage.create(JAXBMessage.java:160)
    at com.sun.xml.ws.fault.SOAPFaultBuilder.createSOAP11Fault(SOAPFaultBuilder.java:433)
    at com.sun.xml.ws.fault.SOAPFaultBuilder.createSOAPFaultMessage(SOAPFaultBuilder.java:210)

I checked through out stackoverflow and many other sites all says jar file conflict.
I use java-6-openjdk.
and below is my jar file list in the jetty server.

gmbal-api-only.jar
ha-api.jar
jaxb-core.jar
jaxb-impl.jar
jaxws-rt.jar
management-api.jar
policy-2.3.1.jar
stax-ex.jar
streambuffer-1.5.1.jar

Since above jars are not working I tried with
Go here
Download JAX-WS RI distribution.

But those jars gave the same error.

Chris
  • 5,584
  • 9
  • 40
  • 58
imesh
  • 123
  • 1
  • 2
  • 11
  • Showing us your code might help a bit. – AppleDash Jun 14 '13 at 17:32
  • Hi, the code is in there in the http://www.mkyong.com/webservices/jax-ws/jax-ws-java-web-application-integration-example/ I didn't add here, because everything is clear in that tutorial. I can start the service without any problem and can see the wsdl perfectly. – imesh Jun 14 '13 at 17:41
  • I has this exact same error - it turned out that it was caused by a NullPointerException on the server side. Fixing the NPE resolved the issue! – homaxto Apr 25 '19 at 10:26

3 Answers3

3

I have also came across same exception and little bit googling it confirmed that its because of classpath/jar issue.

I'm using Java 6.0 as build and runtime environment and my project setup having jaxb-api.jar and jaxb-impl.jar. I simply removed these two jars from classpath and it works.

As if we are having Java 6.0 we dont need to use explicitely JAX binding jars. It comes by default with Java 6.0.

Anupam Pawar
  • 231
  • 3
  • 16
1

Check this thread: web client for web service. The main problem I think is that you have several jaxb jars that differ in versions. For example, I think that jaxb is already part of jaxws-rt.jar which would mean you don't need jaxb-core.jar and jaxb-impl.jar.

Community
  • 1
  • 1
Xargos
  • 633
  • 8
  • 19
  • 3
    HI, I can't remove any of above jar and that gave different no class found errors. ie. if I remove the jar files u mentioned that gave me va.lang.NoClassDefFoundError: com/sun/istack/localization/Localizable Can any body give me working jar file set? That is the best solution I guess. – imesh Jun 15 '13 at 17:28
1

Same error occured on my Java 7 project. Removing com/sun/xml/bind/jaxb-impl-2.2.6.jar com/sun/xml/bind/jaxb-xjc-2.2.6.jar

dependencies solved the problem.

Alternative solution :

clientPort is an Interface with @WebService annotation.

    BindingProvider prov = (BindingProvider) clientPort;        
    prov.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
    prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, serviceUsername);
    prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, servicePassword);
  • And also System.setProperty("javax.xml.bind.JAXBContext", "com.sun.xml.internal.bind.v2.ContextFactory"); System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true"); – Pekmezli Dürüm Nov 04 '21 at 11:02