Wednesday, January 26, 2011

caused by: javax.xml.ws.webserviceexception: wrong binding id: xxx

I noticed many (new getting started) people facing problem of wring binding id. exception cause look like  bellow
caused by: javax.xml.ws.webserviceexception: wrong binding id: http://jsonplugin.googlecode.com/json/ at com.sun.xml.ws.api.bindingid.parse(bindingid.java:260)" 

binding id can be any URL in above exception. It is surly caused by relevant jar (jsonwebservice-ri-jar in case of jsonwebservice) files not in class path of  webapp. Check you have jar in WEB-INF/lib or tomcat endorsed or other endorsed directory's. Or check is your downloaded jar file corrupted.

If your sure you have jar in path,
1) extract jar using any zip tool locate following file
/META-INF/services/com.sun.xml.ws.api.BindingIDFactory
2) Look content of above file. It contains codec binding ID provider.
3) In case of jsonwebservice binding id provider class is com.jaxws.json.codec.JSONBindingIDFactory
4) Provider specify binding URL. E.g : http://jsonplugin.googlecode.com/json/

If all above checks are true, relay something wrong.or it may bug from jax-ws or in coedc.

I will explain how actually it works.

Every web application developer aware of, your application starts with web.xml file. In JAX-WS your specifying listener class "com.sun.xml.ws.transport.http.servlet.WSServletContextListener" when loading this servlet listener, it look for sun-jaxws.xml file.
    private static final String JAXWS_RI_RUNTIME = "/WEB-INF/sun-jaxws.xml";

and start processing it.

sun-jaxws contains entry for endpoint, like

<endpoint name="ChartPortJSON"
implementation="com.googlecode.jsonwebservice.attachment.impl.ChartPortImpl"
binding="http://jsonplugin.googlecode.com/json/" url-pattern="/chart.json" />

Using binding id attribute, servlet listener look for binding provider using ServiceLocator pattern. If there is no such provider your getting exception.

You can simply check what are the provider available in your class path using Service locator.

for(BindingIDFactory provider : ServiceLoader.load(com.sun.xml.ws.api.BindingIDFactory.class)){
provider.parse("BindingId");// E.g: http://jsonplugin.googlecode.com/json/
System.out.println(provider.getClass());
}


Hope it helps.







1 comment:

  1. It really helped. Now I have this error while trying to deploy in to glassfish 4.1 running JDK 1.8u25.

    java.lang.NoSuchMethodError: com.sun.xml.ws.api.model.SEIModel.getJAXBContext()Lcom/sun/xml/bind/api/JAXBRIContext;

    Thanx in advance.

    ReplyDelete