Name: bsT130419 Date: 10/02/2001
1.4.0 Beta2 - b77
In addressing / closing a prior, related JDC bug:
http://developer.java.sun.com/developer/bugParade/bugs/4337876.html
The closing comment says something like "Fixed in most cases". It seems that
the properties are only useful when manual proxy config is used in the browser.
The properties that were added (javaplugin.proxy.config.*) contain static
information and there is no apparent way to discover the proxy IP/name or port
when auto config scripts are used.
It might be more useful to the developer of a plugin applet that needs proxy
knowledge (eg. tunneling through proxy w/3rd party SSL lib) if there was a
method to call with a sample URL that could return the proxy info used to
access that particular URL. Thus, the existing plug-in code that processes
proxy scripts, bypass lists, etc. could be relied upon by the developer.
An ugly, Sun internals-tied hack worked for proxy detection under 1.3.X and
does not under 1.4.X. This is no real suprise but no equivalent functionality
seems available under 1.4.X to replace the 1.3 hack below.
This applet & its HTML can be compiled & placed on a web server to illustrate
the problems. It will need rights (java.policy or signed JAR) to run. Under
1.3.X, the actual proxy info used to access the html file is displayed (under
IE & NN, manual or auto configs). Under 1.4, the static proxy info (if manual)
is around, but useful info is not available for auto config proxies (scripts).
Also, unless you get fancy (incorporating bypass list), you don't know if the
proxy is really used for any particular URL access.
DetectProxy.java - complie under 1.3.X w/JAWS.JAR access ==============
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;
import java.net.*;
// Attempt to read plugin proxy info (Sun internal 1.3 no-no classes)
import sun.plugin.protocol.PluginProxyHandler;
import sun.plugin.protocol.ProxyHandler;
import sun.plugin.protocol.ProxyInfo;
public class DetectProxy extends JApplet {
static URL sampleURL = null;
static boolean useProxy = false;
static String proxyIP = null;
static int proxyPort = -99;
static String startup = "Proxy detect results & view HTML";
// Attempt to read proxy info from plugin-specific methods. Taked from Hack
posted on ng...
ProxyHandler proxyHandler;
ProxyInfo proxyInfo;
public void init() {
try {
System.out.println("======== Applet Init ==========");
// Point to the HTML for this applet
sampleURL = new URL(getCodeBase()+"DetectProxy.html");
System.out.println("==== Plugin Properties =====");
Properties sysprops = System.getProperties();
Enumeration enum = sysprops.propertyNames();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
if (key.indexOf("plugin") > -1)
System.out.println(key+"("+sysprops.getProperty(key)+")");;
}
}
catch (Exception exc) {
startup = "Error in init:"+exc;
System.out.println(startup);
}
getContentPane().setLayout(new BorderLayout());
final JDesktopPane desktop = new JDesktopPane();
JInternalFrame makeFrame = new JInternalFrame("Frame
Maker",true,false,true,true);
JButton button = new JButton(startup);
button.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent event) {
final JInternalFrame internal = new JInternalFrame
("Frame",true,true,true,true);
proxyDetect();
JEditorPane epOutput = null;
try {
epOutput = new JEditorPane();
epOutput.setPage(sampleURL);
}
catch (Throwable eee) {
System.out.println("Unable to set editorpane to URL:"+eee);
}
internal.getContentPane().add(epOutput,BorderLayout.CENTER);
internal.setBounds(25,25,250,200);
internal.setVisible(true);
desktop.add(internal);
repaint();
}
});
makeFrame.getContentPane().add(button,BorderLayout.CENTER);
desktop.add(makeFrame);
makeFrame.setVisible(true);
getContentPane().add(desktop,BorderLayout.CENTER);
makeFrame.setBounds(300,50,300,100);
getContentPane().validate();
getContentPane().setVisible(true);
}
void proxyDetect() {
System.out.println("Entering proxyDetect...");
String results = null;
// Attempt to discover proxy info by asking internal plugin code to
locate path to (sampleURL)...
String javaVers = System.getProperties().getProperty("java.version");
// For 1.3 use Sun-specific internal plugin proxy classes... 1.4.0
nuked this method...
// if (javaVers.equals("1.3.0")) {
if (javaVers.substring(0,3).equals("1.3")) {
proxyHandler = PluginProxyHandler.getDefaultProxyHandler();
if (proxyHandler != null) {
try {
proxyInfo = proxyHandler.getProxyInfo (sampleURL);
if (proxyInfo != null) {
useProxy = (proxyInfo.getProxy() != null);
if (useProxy) {
proxyIP = proxyInfo.getProxy();
proxyPort = proxyInfo.getPort();
results = "1.3 proxy " + proxyIP+" port " +
proxyPort;
System.out.println(results);
}
else {
results = "JRE 1.3 with no proxy";
System.out.println(results);
}
}
else {
results = "1.3 NULL proxyInfo in proxy detection...";
System.out.println (results);
}
}
catch (Exception e) {
results = "1.3 Exception in proxydetect:"+e;
System.out.println (results);
}
}
else {
results = "JRE 1.3 with no proxyHandler";
System.out.println(results);
}
}
else {
// This code must be used in 1.4.0+ (internal plugin proxy classes
referenced above no longer around)
// BUT if configured with autoproxy / script, plugin properties
supply script name (useless),
// So only works with manual proxy config for now...
try {
String proxyList = ((String)System.getProperties().getProperty
("javaplugin.proxy.config.list")).toUpperCase();
results = "> 1.3 Plugin Proxy Config List:"+proxyList;
System.out.println(results);
useProxy = (proxyList != null);
if (useProxy) { // Using HTTP proxy as proxy for HTTP
proxy tunnelled SSL socket....
proxyIP = proxyList.substring(proxyList.indexOf("HTTP=")+5,
proxyList.indexOf(":"));
int endOfPort = proxyList.indexOf(",");
if (endOfPort < 1) endOfPort = proxyList.length();
proxyPort = Integer.parseInt(proxyList.substring
(proxyList.indexOf(":")+1,endOfPort));
results = "> 1.3 proxy " + proxyIP+" port " + proxyPort;
System.out.println (results);
}
}
catch (Exception e) {
results = "> 1.3 Exception in proxydetect:"+e;
System.out.println (results);
}
}
System.out.println("Exiting proxyDetect...");
JOptionPane.showMessageDialog(this.getRootPane(),results,"Detected
Proxy settings",JOptionPane.WARNING_MESSAGE);
}
}
DetectProxy.html ========
html>
<OBJECT id="DetectProxy" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH = 100% HEIGHT = 100%
codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-
win32.cab#Version=1,3,0,0">
<PARAM NAME = CODE VALUE = DetectProxy.class >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.3" java_CODE =
DetectProxy.class WIDTH = 100% HEIGHT = 100%
pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html">
<NOEMBED>
</COMMENT>
alt="Your browser understands the tag but isn't running the applet, for some
reason (Java Plug-In 1.3.0+ not available?)."
Your browser is completely ignoring the applet tag!
</NOEMBED>
</EMBED>
</OBJECT>
</html>
(Review ID: 131895)
======================================================================
- duplicates
-
JDK-4502810 require method to obtain proxy for a given URL
-
- Resolved
-