HTTP error 407 – Proxy Authentication Required


Hello All,

We had a tough time resolving connecting to a hosted webservice using the client’s internal proxy server

Standard methods of setting proxy details using System Properties / command line doesn’t work. It always gave HTTP error 407 – Proxy Authentication Required

But this code worked…

import java.net.Authenticator;

class ProxyAuthenticator extends Authenticator {

private String user, password;

public ProxyAuthenticator(String user, String password) {

this.user = user;

this.password = password;

}

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(user, password.toCharArray());

}

}

Followed by call from your program like this

Authenticator.setDefault(new ProxyAuthenticator(“user”, “password”));

System.setProperty(“http.proxyHost”, “proxy host”);

System.setProperty(“http.proxyPort”, “port”);

After the above you can initiate the actual WS (HTTP/HTTPS) calls to go through the proxy

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s