• Entries (RSS)
  • Comments (RSS)

Setting endpoint url in web service proxy client

Posted by | Posted in Web service | Posted on 13-08-2009

Tagged Under : ,

One of our project was developed and supported by an external vendor and due to some reasons (of course not known to me) our company decided to do all the future enhancements and support by our self. The project uses WebSphere Process Server as the middle ware and WebSphere portal server as the front end. All the communications between the portal and process server was using web service export. During the knowledge transfer session I noticed that for setting the endpoint url for different environments in their proxy client, they were editing the ServieLocator class. So I just want to post a small note on how to set the endpoint URL without changing the generated proxy classes.

To change the endpoint url for a web service we have a setEndpoint method in our proxy class. By default I guess the endpoint url will be pointing to localhost. By passing the new endpoint url to the setEndpoint method we can change it to a new host. For eg: in our hello world web service client, to change the end point url, change the code as shown below.

	HelloWorldProxy proxy = new HelloWorldProxy();
	proxy.setEndpoint(endPointurl);

That’s it. We are done with changing the endpoint url. We can store this endpoint url as part of our properties file and read it from there. This will ensure that, we get different endpoint urls for different environments

Share

Web service client with basic authentication

Posted by | Posted in Web service | Posted on 23-06-2009

Tagged Under : ,

Configuring a web service client for basic authentication

How do we pass the username and password to a web service which is protected by basic authentication? The generated proxy client has no methods for setting the username and password.

The solution is to set the username and password inside the generated proxy client. To do this edits your proxy java file and set the username and password properties. The properties are javax.xml.rpc.Stub.USERNAME_PROPERTY and javax.xml.rpc.Stub.PASSWORD_PROPERTY. I did it inside my _initXXX method of proxy client. For eg: my code looked like the following

if (test_Request != null) {
	((javax.xml.rpc.Stub)test_Request)._setProperty(Stub.USERNAME_PROPERTY, "username");	
	((javax.xml.rpc.Stub)test_Request)._setProperty(Stub.PASSWORD_PROPERTY,"password");	
}

If you set any other property name you will get an exception

Exception in thread "main" javax.xml.rpc.JAXRPCException: WSWS3212E: Error: Property name javax.xml.rpc.Stub.XXX not supported.
	at com.ibm.ws.webservices.engine.client.Stub._setProperty(Stub.java:541)
Share

Invoking a web service using web service proxy client

Posted by | Posted in Web service, WebSphere | Posted on 15-09-2008

Tagged Under : , , ,

Invoking a web service using web service proxy client

Yesterday I got a comment on my post “Generating a web service proxy client” asking how do we invoke or test this web service using the webservice proxy client. So I thought of writing a post of how to use the generated proxy client to call a webservice. Here I am going to create a simple JSP file that is going to use the webservice proxy client to call or invoke the Hello World web service running in WebSphere.

Before you start, please make sure that you have generated the web service client as mentioned in Generate web service proxy client in java. If you do not have the Hello World web service running in your server, follow the tutorial at Creating a Hello World web service using RAD.

While generating the webservice proxy client I generated the Java files using no wrapped style.

One we have the java proxy files generated we can see some files named XXXProxy.java, XXX.java, XXXService.java, XXXServiceInformation.java, XXXServiceLocator.java etc in our workspace. Now create a new jsp file for calling the web service. Add the following code to invoke the Hello World webservice using our web service proxy client.

	com.test.HelloWorldProxy proxy = new com.test.HelloWorldProxy();
        proxy.setEndpoint("http://localhost:9081/WSTest/services/HelloWorld");
        String name = proxy.sayHello("Albin Joseph");
 
        System.out.println(name);

If everything works fine, we would see a ‘Hello Albin Joseph’ as the output in your console.

Our Hello World service was exposing a sayHello method as a webservice. The HelloWorldProxy class is the proxy client class for our webservice. If we are not setting the end point url (the url of the webservice), our proxy client would take the default one present in the wsdl file.

Share