Extreme Java When vanilla Java is not enough

29Apr/080

Configuring proxy in Java applications

If you have a Java application that needs to connect to Internet, and you are behind a proxy, you have two options:

  1. Add this to the application command line parameters:
    -Dhttp.proxyHost=[host.of.proxy] -Dhttp.proxyPort=[port.of.proxy]
  2. Or edit the net.properties file in the lib folder of your java home. It is self-explanatory, since you have to edit one or two lines and there's about 70 lines of comments on that file.

The bad news is if your proxy requires authentication. This means you will have to do something like:

Authenticator.setDefault(new Authenticator() {
  @Override
  protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication("username",
        new char[] { 49, 50, 51, 52, 53, 54 } );
  }
});

You can, of course, create a more complex Authenticator subclass, that will open a Popup asking for the proxy user and password.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)


*

No trackbacks yet.