-Dhttp.proxyHost=proxyname -Dhttp.proxyPort=portnumber
And to manage exceptions to proxy connection use:
-Dhttp.noProxyHosts="localhost|127.0.0.1
And finally if the proxy server requires authentication, before any call that use the connection through the proxy call this in your Java code:
Authenticator.setDefault(new SimpleAuthenticator(username,password));
where SimpleAuthenticator is:
public class SimpleAuthenticator extends Authenticator {
private String username, password;
public SimpleAuthenticator(String username, String password) {
this.username = username;
this.password = password;
}
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
}
private String username, password;
public SimpleAuthenticator(String username, String password) {
this.username = username;
this.password = password;
}
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
}
No comments:
Post a Comment