Tuesday 23 March 2010

java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String

What a weird title to start with. I have to say the caption needs to be pretty straight forward to address the related issue. So what is it? Apache CXF developers working on JAX-WS OR JAX-RS project on Maven and Java 6 are likely to experience this exception.


Exception in thread "main" java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String;
[java] at com.sun.xml.ws.model.RuntimeModeler.processExceptions(RuntimeModeler.java:1162)
[java] at com.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:898)
[java] at com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:666)
[java] at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:420)
[java] at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel

After digging around you'll realised the only option is to download the webservices-api.jar file, plus wack it onto C:\Program Files\Java\jdk1.6.0_18\jre\lib\endorsed directory to resolve it.

You might have probably ask yourself by now, where to grab webservices-api.jar easily from? two advice, download metro, unzip its content and the finally reach the lib directory to locate it OR right here.

Hold on! does it really resolves it? You are likely to enter into another annoyance when finally below exception spits onto your console log:

Exception in thread "main" java.lang.ClassCastException: $Proxy66 cannot be cast to com.sun.xml.internal.ws.developer.WSBindingProvider.

Like most people, the first thing that comes to mind is revisit and amend your service login object to see if it does the job. You are likely also to be told 'since you’re using CXF and not the JAX-WS reference implementation, the steps to set headers are probably going to be different and therefore Check the CXF docs', forgetting Apache CXF supports both JAX-WS OR JAX-RS implementations.

I tell you what don't explode yourself from annoyance, just take a close look at the Exception. You're referencing some of your object imports from com.sun.xml.internal.ws, and there is where your issue is.

Do NOT bombard yourself with new exceptions trying to regenerate your stubs with extra arguments as shown below, suggested by few people on the web.


-exsh
true


To resolve this Exception, just replace;

import com.sun.xml.internal.bind.api.JAXBRIContext;
import com.sun.xml.internal.ws.api.message.Header;
import com.sun.xml.internal.ws.api.message.Headers;
import com.sun.xml.internal.ws.developer.WSBindingProvider;

With

import com.sun.xml.bind.api.JAXBRIContext;
import com.sun.xml.ws.api.message.Header;
import com.sun.xml.ws.api.message.Headers;
import com.sun.xml.ws.developer.WSBindingProvider;


Job done! Now go grab a cuppa coffee and relax.

6 comments:

  1. Umm... You aren't likely to hit this with CXF. In ALL the above stack traces, you are using the JAX-WS RI built into the JDK. In none of the cases above is CXF involved. Anything in the com.sun.xml.ws.* (or "internal" versions) would be the JAX-WS RI, not CXF.

    ReplyDelete
  2. Got it! But when you find yourself generating stubs with cxf-codegen-plugin for maven, you're likely to end up building your consumers around JAX-WS RI built into JDK as you said, when this happens there's a likelihood.

    ReplyDelete
  3. I got the same issue. java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String

    I'm using netbeans 6.9.1, java 1.6.16 tomcat 6.x, metro 2.0, try copying "endorsed" folder with webservices-api.jar to you javahome\1.6.16\jre\lib\endorsed and restart netbeans. If it didn't fix, place the same endorsed folder in \endorsed or \endorsed where catalina-home is apache tomcat6.x home and catalina-base is tomcat instance. It should fix.

    ReplyDelete
  4. This blog post saved my life. Thanks!

    ReplyDelete
  5. Thank you!!, Exactly what my problem was.

    ReplyDelete
  6. Thanks! same problem I have. But i am unable to change it to import com.sun.xml.ws.developer.WSBindingProvider as it doesn't get resolved.

    Also, with "import com.sun.xml.internal.ws.developer.WSBindingProvider" , my standalone java application works fine. When I deploy it to the server , it returns '$Proxy50 cannot be cast to com.sun.xml.internal.ws.developer.WSBindingProvider'.

    ReplyDelete