Documentation Contents
Java Platform, Standard Edition Deployment Guide
Contents    Previous    Next

28 Networking

This topic provides information on setting up a proxy, and using the Pack200 tool for your Java applications.

This topic includes the following sections:

28.1 Proxy Configuration

For enterprise customers it is important to be able to set up secure computing environments within their companies, and proxy configuration is an essential part of doing that. Proxy configuration acts as a security barrier; it ensures that the proxy server monitors all traffic between the Internet and the intranet.

Proxy configuration is normally an integral part of security enforcement in corporate firewalls within intranets. Enterprise customers who want to use Java Plug-in to deploy applets, or Java Web Start to run applications on their intranet web pages can also set up proxy support. This support is required for Java Plug-in and Java Web Start to work in an intranet environment and can be set up through the Java Control Panel.

28.2 Java Control Panel

The Java Control Panel provides four proxy options through the Network Setting dialog, which is accessed by clicking Network Settings in the General tab:

28.2.1 Use browser settings

If Use browser settings is selected, then proxy information is obtained entirely through the browser. To change proxy information, see the documentation for your browser:

28.2.2 Use proxy Server

If you select Use proxy server in the Java Control Panel, you have two choices:

  1. Set the Address and the Port for a proxy server with the option to bypass it for local addresses.

  2. Individually set the proxy server for HTTP, Secure, FTP, and Socks connections. You can also provide a list of addresses for which you do not want to use a proxy server.

28.2.3 Use automatic proxy configuration script

If you select Use automatic proxy configuration script, then you must enter the URL for the location of the JavaScript method called FindProxyForURL(URL url) that returns the proxy server to be used for a URL. Support for this script is the same as described in Section 28.5, "Automatic Proxy Configuration."

28.2.4 Direct connection

Direct connection does not use a proxy. For certain situations, such as when mobile users connect to the company through a modem, direct connection to the intranet environment is required, and proxies should not be used in these cases.

28.3 How Java Plug-in and Java Web Start Obtain Proxy Information From the Browser

Because browsers on different platforms store proxy information differently, there is no generic mechanism to obtain proxy information. Here is how proxy information is obtained from Internet Explorer and Firefox on Windows:

Java Plug-in and Java Web Start obtain proxy information at startup time. If you change the proxy settings after Java Plug-in or Java Web Start have started, you may force reloading of the proxy information from the browser through the p option in the Java Console. Java Web Start is restarted for each application, so new proxy information will be used automatically on subsequent launches.

28.4 Manual Proxy Configuration

Internet Explorer, Firefox, and Chrome support manual proxy configuration. Users can specify the proxy server and port for each protocol. Users can also specify one proxy server and port for all protocols. To minimize the workload of the proxy server, some sites might bypass the proxy server completely when a machine is connecting to another machine inside the intranet environment. To do this, network administrators and users can specify a proxy server bypass list in the browser's proxy setting.

Internet Explorer: Java Plug-in and Java Web Start recognize and supports the proxy server and port setting associated with the protocol. IE supports various syntaxes in the proxy server bypass list, as follows:

For example, if you specify "203.0.113.0;*.eng;http://*.com" in the proxy server bypass list, then the browser bypasses the proxy whenever one of the following occurs:

Currently Java Plug-in and Java Web Start support the first two syntaxes in the proxy server bypass list in IE. IE also supports bypassing the proxy server for local (intranet) addresses without using the proxy server bypass list. Java Plug-in and Java Web Start support this option by bypassing the proxy server if the URL host name contains no dot (.).

Firefox: Java Plug-in and Java Web Start recognize and supports the proxy server and port setting associated with the protocol. For example, if you specify .eng,.sun.com in the proxy server bypass list in Firefox, it bypasses the proxy whenever the URL hostname ends with .eng or .sun.com. Java Plug-in and Java Web Start fully support this syntax in the proxy server bypass list in Firefox.

For more information about manual proxy configuration in your browser, consult the user guide for your browser.

28.5 Automatic Proxy Configuration

Automatic proxy configuration is supported in the browser by setting a particular URL that contains a JavaScript file with .pac or .js extension. This file contains a function called FindProxyForURL that contains the logic to determine which proxy server to use when the browser receives a connection request. This function is written by the system administrator for the particular intranet environment. When the browser starts up, it recognizes the URL of the JavaScript file and downloads the file to the local machine using direct connection. Then whenever it needs to make a new connection, the browser executes the JavaScript function FindProxyForURL in the file to obtain the proxy information to set up the connection.

Java Plug-in

Java Web Start

Notes on FindProxyForURL

Given a JavaScript engine, the following is applicable to Java Plug-in on all platforms and to Java Web Start on Windows only.

  1. There are a number of JavaScript helper functions which can be called from the JavaScript function FindProxyForURL. Java Plug-in and Java Web Start provide their own implementations of these functions to completely emulate automatic proxy configuration. Regarding the implementation of these helper function, note the following:

    • Function dnsResolve always returns an empty string if the host is not an IP address.

    • Function isResolvable always returns false if the host is not an IP address.

    • Function isInNet always returns false if the host is not an IP address.

  2. Executing the function FindProxyForURL always returns proxy information as a string. Java Plug-in and Java Web Start extract the setting in the following way:

    • If DIRECT is in the string, Java Plug-in and Java Web Start assume direct connection.

    • If PROXY is in the string, they use the first proxy setting for the connection.

    • If SOCKS is in the string, they use the SOCKS v4 for the connection.

    • Otherwise, the proxy information in the string is incorrect. In this case, Java Plug-in and Java Web Start assume direct connection.

28.6 java.net.ProxySelector API

Developers sometimes might need to determine the proxy configuration of a given host. By knowing the proxy configuration, they can write more intelligent code to connect to the host through the proper proxy server. The java.net.ProxySelector class provides configuration support. Here is a simple code example:

Example 28-1 ProxySelector Usage Example

private Proxy findProxy(URI uri)
{
     try
     {
          ProxySelector selector = ProxySelector.getDefault();
          List<Proxy> proxyList = selector.select(uri);
          if (proxyList.size() > 1)
               return proxyList.get(0);
     }
     catch (IllegalArgumentException e)
     {
     }
     return Proxy.NO_PROXY;
}

28.7 Deploying JAR Files Compressed with Pack200

When the Java system property jnlp.packEnabled is set to true in a JNLP file or an applet tag, Java Plug-in or Java Web Start downloads the JAR file compressed by the Pack200 tool. If the compressed version is not available, Java Plug-in or Java Web Start looks for the uncompressed version.


Note:

Pack200 compressed JAR files must have the extension pack.gz. For example, if your JAR file is named sampleApp.jar, then the Pack200 compressed version of this file must be named sampleApp.jar.pack.gz.


28.7.1 Usage in a JNLP File

Use the property tag to specify jnlp.packEnabled to true within the resources tags, for example:

<jnlp ...>
 ...
 <resources>
 <property name="jnlp.packEnabled" value="true"/>
 <java version="1.5+" href="http://javadl.sun.com/webapps/jawsautodl/AutoDL/j2se"/>
 <jar href="sampleApp.jar" main="true" download="eager"/> 
</resources>
 ...
</jnlp>

In this example, Java Web Start and the Java Plug-in first look for sampleApp.jar.pack.gz. If the file is not found, they look for the original, sampleApp.jar.

28.7.2 Usage in Applet Tag

Pass the -Djnlp.packEnabled VM argument by using java_arguments, for example:

<HTML>
 ...
 <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
 <PARAM NAME = "cache_archive" VALUE = "HelloWorld.jar"/>
 <PARAM NAME="java_arguments" VALUE="-Djnlp.packEnabled=true"/>
 </APPLET>
 ...
</HTML>

The Java Plug-in looks for HelloWorld.jar.pack.gz; if this file is not available, it looks for HelloWorld.jar.

Contents    Previous    Next

Oracle and/or its affiliates Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.
Contact Us