Featured Posts

Integrating GlassFish Application server with Apache... A typical production topology for GlassFish will be a front ending GlassFish with Apache for serving the static files. To integrate GlassFish Application Server with Apache web server follow the below...

Readmore

Some Java, JEE and WebSphere stuffs Rss

Web service client with basic authentication

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

2

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
1,681 views

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/Bookmark

Read More

Comments (2)

Hi,

I am not very expert on web services but with my limited experience I learned that at least in Websphere I can set Id and Password for web service client in Port Qualified NameSpace Bindings. I don’t have much experience of other servers.
But other servers like Glasfish would have similar ability. Why do you think we need to hardcode Id and password in Proxy ? We used to do that some years back but now we don’t do it at all.
Thanks.

Thanks for the information. This is something I need to explore.

Write a comment