I recently received a JAX-WS client legacy code. I'm having a hard time debugging some of the issues such as thread safety in this code. The code has a stub class that was generated using JAX-WS RI,
@WebServiceClient(name = "Control", targetNamespace = "urn:Control", wsdlLocation = "file:/home/src/proj/Control.wsdl")
public class Control extends Service
{
private final static URL CONTROL_WSDL_LOCATION;
static {
URL url = null;
try {
url = new URL("file:/home/src/proj/Control.wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
CONTROL_WSDL_LOCATION = url;
}
public Control(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public Control() {
super(CONTROL_WSDL_LOCATION, new QName("urn:Control", "Control"));
}
@WebEndpoint(name = "Control")
public ControlPortType getControl() {
return (ControlPortType)super.getPort(new QName("urn:Control", "Control"), ControlPortType.class);
}
@WebEndpoint(name = "Control")
public ControlPortType getControl(WebServiceFeature... features) {
return (ControlPortType)super.getPort(new QName("urn:Control", "Control"), ControlPortType.class, features);
}
}
And there's another class that is building the webservice end point,
private final synchronized Control InitWSService() {
if (service == null) {
URL wsdl = Control.class.getResource("Control.wsdl");
if (wsdl != null) {
service = new Control(wsdl, new QName("urn:Control", "Control"));
} else {
service = new Control();
}
service.setExecutor(this);
}
return service;
}
This is used in building the Endpoint,
private void buildControlEndpoint() {
InitWSService();
ControlPortType control = service.getControl();
Map<String, Object> ctext = ((BindingProvider)control).getRequestContext();
URL address = getConnectionEndpoint();
ctext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,address.toString());
}
Now I am having a hard time connecting the dots between the three. These are my doubts:
1. If the author who wrote this code generated the stub using wsimport, why is the url hard coded as a file path? Is this making a difference to how the code works? The wsdl is available locally in a resource folder.
2. In InitWsService, why are we fetching it as a class resource again? Is the WSDL location defined in the right way? How are proxies exactly used in JAX-WS?
3. Is this thread safe?