TOC PREV NEXT INDEX




Proxy Auto Configuration


The ICEbrowser SDK has support for Proxy Auto Configuration (PAC) scripts. A PAC script tells the browser to load its proxy configuration information from a specified JavaScript file, rather than from static information entered directly. For more information on PAC, see the specification at: http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html

A PAC script is a JavaScript script that is run for every URL the browser attempts to load. The script accepts the URL you want to load and returns zero or more connection routes (direct or proxy) that can be used. If several connection routes are specified and the first one does not work, the browser will try the next on the list, until the list is exhausted.

PAC is part of the HTTP protocol handler. To work, JavaScript support must also be present.

Usage

A possible implementation of PAC support could look like the following:

URLStreamHandlerFactory.addStreamHandler(

    "http", "ice.net.HttpURLStreamHandler");

URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory());

try {

    PacManager pacManager =

        new PacManager(

            new URL("file:///e:/proxy.pac"));

    HttpURLConnection.setGlobalProxyResolver(pacManager);

} catch (MalformedURLException exception) {

    exception.printStackTrace(System.err);

}


 

The preceding code instantiates a PacManager with the specified URL and sets it as the global ProxyResolver on the HttpURLConnection.

A PacCallback can be set on the PacManager using the following:

pacManager.setPacCallback(new MyPacCallback());


 

An implementation of the PacCallback interface could look like the following:

class MyPacCallback implements PacCallback {

    public boolean ignoreProxies() {

        return

            new ConfirmationDialog(

                "All proxies are down! " +

                "Do you want to temporarily " +

                "disable proxies and attempt " +

                "to use direct connections?").getResult();

    }
 
    public boolean retryProxies() {

        return

            new ConfirmationDialog(

                "Do you want to retry using proxies?").getResult();

    }
 
    private class ConfirmationDialog extends Dialog {

        private boolean result;
 
        private ConfirmationDialog(String question) {

            super(

                BrowserFrameManager.getInstance().getActiveBrowserFrame(
),

                "Ignore proxies",

                true);

            Panel controlPanel = new Panel(new FlowLayout());

            Button yesButton = new Button("Yes");

            yesButton.addActionListener(

                new ActionListener() {

                    public void actionPerformed(ActionEvent event) {

                        result = true;

                        dispose();

                    }

                });

            controlPanel.add(yesButton);

            Button noButton = new Button("No");

            noButton.addActionListener(

                new ActionListener() {

                    public void actionPerformed(ActionEvent event) {

                        result = false;

                        dispose();

                    }

                });

            controlPanel.add(noButton);

            add(new Label(question), BorderLayout.CENTER);

            add(controlPanel, BorderLayout.SOUTH);

            pack();

            setLocation(

                (int)(getParent().getLocation().getX() +

                    ((getParent().getWidth() - getWidth()) / 2)),

                (int)(getParent().getLocation().getY() +

                    ((getParent().getHeight() - getHeight()) / 2)));

            show();

        }
 
        private boolean getResult() {

            return result;

        }

    }

}


 

The source code for the preceding examples is available in ICEbrowserExamples/src/pac.

PAC in the Reference Implementations

The Swing RI supports PAC, and no system properties need to be set. You can specify the PAC URL in the Proxy Management dialog, available by selecting Options > Proxy Management.

The Generic RI has built-in PAC support. On the command line, you set the RI-specific property com.icesoft.pac to the URL of the PAC file. The option -m:autoproxy must also be specified:

java -Dcom.icesoft.pac=file:///c:/proxy.pac ice.browser.Main 

    -m:https -m:autoproxy


 

The Enhanced AWT RI also has built-in PAC support, but only requires setting the com.icesoft.pac property:

java -Dcom.icesoft.pac=file:///c:/proxy.pac 
ice.ri.enhancedawt.browser.Main
 

The com.icesoft.pac property is specific to the reference implementations. If the value is anything but null, PAC is used. The value is the URL of the PAC file. It is not a dynamic property.



Copyright 2005. ICEsoft Technologies, Inc.
http://www.icesoft.com

TOC PREV NEXT INDEX