views:

47

answers:

2

I have written a java webservice, deployed it on my tomcat and accessed the service WSDL via my webbrowser, all looks okay. The next step was to generate proxy class which can be used by client to communicate with the website. This is what I did next:

Lets assume my wsdl is accessible via: http://localhost:8080/testSvc/testSvc?wsdl

Using the wsimport tool, I generate the proxy by using the following command: $>wsimport http://localhost:8080/testSvc/testSvc?wsdl

The problem is that localhost:8080 gets hardcoded in the generated classes and if I deploy the service on a port other than 8080 then the client cannot reach it as the client will still try to access the service on port 8080.

Is there anyway of developing proxy classes in a way that port number is not hardcoded? So that we can deploy the service on any port?

I have tried updating ENDPOINT_ADDRESS_PROPERTY but that isn't useful since the code fails the moment it instanties an instance of the proxy class. It never really reaches to a point where I can overwrite ENDPOINT_ADDRESS that it has ready from the proxy class.

A: 

Use the -keep parameter to retain the source files that wsimport generates. From there, you can change the endpoint url in the wsimport-generated source code as you wish.

Catchwa
A: 

One way is to use the wsimport parameter

-wsdllocation <location>

and point it to your new WSDL.

Or you can use the

-catalog option.

To change the address dynamically use code like:

service = new Service();
port = service.getxxxPort();

((BindingProvider) port).getRequestContext().putBindingProvider.ENDPOINT_ADDRESS_PROPERTY, newUrl);
nzpcmad