Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overriding or setting web service endpoint at runtime for code generated with wsimport

Tags:

java

jax-ws

Using code that was generated with wsimport, can the service endpoint be overridden without having to regenerate the code?

I have written a simple java webservice, following are the steps:

  1. I compile the java class and generate a war file
  2. Deploy the war file to my app server (tomcat)
  3. Access the WSDL via the URL e.g. localhost:8080/service/helloservice?wsdl
  4. use the URL with wsimport.bat to generate client classes for example: wsimport http://localhost:8080/service/helloservice?Wsdl
  5. I use those classes in my client app to call the service

The problem is that is the service is deployed on an app server running on port other than 8080, the communication between client and service never happens. I am trying to know what is the best way to create stubs that does not have server and port hardcoded in the stub used by the client.

like image 650
user363808 Avatar asked Aug 25 '10 18:08

user363808


People also ask

What is Wsimport explain different options of it?

The wsimport command-line tool processes an existing Web Services Description Language (WSDL) file and generates the required artifacts for developing Java™ API for XML-Based Web Services (JAX-WS) web service applications.

What is Wsimport in Java?

The wsimport tool generates JAX-WS portable artifacts, such as: Service Endpoint Interface (SEI) Service. Exception class mapped from wsdl:fault (if any) Async Reponse Bean derived from response wsdl:message (if any)

How do I generate stubs in Wsimport?

You can run wsimport command from any directory where you like to generate stubs. We have published a sample soap web service which we going to use in this example. You can use this sample service URL https://test.java4coding.com/core/service/service.php?wsdl to test the wsimport command.


1 Answers

Your client can set the end-point in the service "port" at runtime via the BindingProvider interface.

Consider the JAX-WS client in this JAX-WS tutorial. Another way to write this code would be:

HelloService service = new HelloService(); Hello port = service.getHelloPort(); BindingProvider bindingProvider = (BindingProvider) port; bindingProvider.getRequestContext().put(       BindingProvider.ENDPOINT_ADDRESS_PROPERTY,       "http://foo:8086/HelloWhatever"); String response = port.sayHello(name); 

Caveat: I haven't downloaded the tutorial code and tested this code against it.

like image 147
McDowell Avatar answered Oct 01 '22 03:10

McDowell