clientgen generated PortType_Stub cannot be cast to javax.xml.ws.BindingProvider

user1096318 picture user1096318 · Mar 30, 2012 · Viewed 10.1k times · Source

While trying to access a webservice through a client, I am not able to get the requestContext. I am trying to access the requestContext like this:

QuerySysStatService querySystem=new QuerySysStatService_Impl(wsdl);
QuerySysStatPortType qport=querySystem.getQuerySysStatPortType();
Map<String, Object> rContext =((BindingProvider)qport).getRequestContext();

But when I execute:

((BindingProvider) qport)

I get:

java.lang.ClassCastException: com.demo.client.service.QuerySysStatPortType_Stub cannot be cast to javax.xml.ws.BindingProvider

Any suggestions / help is appreciated. Thanks in advance.

Answer

user1096318 picture user1096318 · Apr 1, 2012

I found that:

  • ((javax.xml.ws.BindingProvider) qport) can safely be called on WSDL interfaces generated with JAX-WS (by wsimport)
  • ((javax.xml.rpc.Stub) qport) can safely be called on JAX-RPC clients (created by clientgen)

In my case I created the WSDL interfaces with clientgen (JAX-RPC), so the properties could be set as below:

javax.xml.rpc.Stub stub = (javax.xml.rpc.Stub) qport;
stub._setProperty("KEY","Value");