Skip to content

How to use ProxyManager

Mikle edited this page Apr 9, 2018 · 4 revisions

Available since: WebLaF v1.17 release
Required Java version: Java 6 update 30 or any later
Module: core


What is it for?

ProxyManager provides a quick way to install or remove global proxy settings in your Java application. It also supports system proxy settings detection option and some other useful features.

It might be useful for various Java client applications to have proper proxy settings automatically installed or to simplify their setup in case you want to specify them manually.

It also supports proxy authorization and can save and restore applied settings automatically using SettingsManager as the base for the stored settings.


How to use it?

By default ProxyManager is initialized with WebLaF or core managers, but is disabled and only loads some internal data (like XStream aliases) without affecting JVM proxy settings. So the first thing you have to do is to choose the way you want to use it - whether it will be automatic proxy detection or user-driven configuration.

Auto-detection

In case you want to automate the proxy initialization process you will need to configure ProxyManager before any kind of WebLaF initialization like this:

ProxyManager.setAutoDetectionEnabled ( true );

This will allow ProxyManager to scan the initial options available. In case proxy is not required it will be simply disabled, in case a system proxy detected user will be prompted (once if he will choose the save the choice) to accept system proxy settings.

Manual setup

If you want to setup proxy manually you will need to call one of setProxySettings methods after the ProxyManager initialization.

Here is a simple example:

ProxyManager.setProxySettings ( "localhost", "7878" );

Or with the authentication:

ProxyManager.setProxySettings ( "localhost", "7878", "user", "password" );

You can also install system proxy settings:

ProxyManager.setSystemProxySettings ()

Or disable proxy manually:

ProxyManager.setEmptyProxySettings ();
Proxy settings dialog

In case you are using full version of WebLaF and not just its core UIProxyAuthenticator will also be initialized with the UIProxyManager. It will prompt a dialog in case proxy is set but authentification is required and user will be able to fill in login and password.

This dialog is set as the default authenticator into java.net.Authenticator class and might be propmpted either at application start or later when any proxy connection is established.