How To Authenticate Http Level Provided Web Service

In this post, I will give you a code for to consume web services with protected http basic authentication. I pretend that, there is a web service called SimpleWebService and it has a method that called getDummy. Here is the code:

public class Test {

	public static void main(String[] args) {
		SimpleWebServiceImplService service = new SimpleWebServiceImplService();

		SimpleWebService simpleWebService = service.getSimpleWebServicePort();

		((BindingProvider) simpleWebService).getRequestContext().put(BindingProvider.USERNAME_PROPERTY,"USERNAME");
		((BindingProvider) simpleWebService).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,"PASSWORD");

		SimpleWebServiceRequest request = new SimpleWebServiceRequest();
		SimpleWebServiceResponse response = simpleWebService.getDummy(request);


We just put necessary username and password parameters to our request context and that’s all. This the only operation that we have done different from regular web service call.

Developer’s rock!!!

This entry was posted in Java and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s