petek, 18. september 2009

Ws and HTTP Basic authentication

If you want to create a client for a web service that uses HTTP Basic authentication, you can authenticate in two different ways:
- use your own Authenticator class:
public class SAPAuthenticator extends Authenticator
{
private String username;
private char[] password;

public SAPAuthenticator(String username, char[] password)
{
this.username = username;
this.password = password;
}

@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(username, password);
}
}

and then use it is you client like this:
Authenticator.setDefault(new SAPAuthenticator("username", "password".toCharArray()));

- in your client you can write something like this:
((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
Objavite komentar