001: package com.sun.portal.proxylet.client.jwsdetect;
002:
003: /**
004: * @author amitosh
005: * Date: Apr 4, 2005
006: */
007: import java.applet.Applet;
008: import java.net.ServerSocket;
009: import java.net.Socket;
010: import java.lang.reflect.*;
011:
012: import netscape.javascript.JSObject;
013:
014: public class JWSDetectionApplet extends Applet {
015: StringBuffer buffer;
016: private String jwsInstalled;
017:
018: public void init() {
019: buffer = new StringBuffer();
020: addItem("initializing... ");
021: }
022:
023: public void start() {
024: RegReader registryReader = RegReader.getInstance();
025: boolean b = registryReader.detectJWSInstallation();
026: jwsInstalled = (new Boolean(b)).toString();
027:
028: try {
029:
030: // If "deployment.browser.path" is IE, start a temporary listener.
031: String browser = System.getProperty("java.library.path");
032: System.out.println("browser type " + browser);
033: if (browser != null
034: && browser.indexOf("Internet Explorer") != -1) {
035: try {
036: System.out.println("Starting listner on 58083...");
037: ServerSocket serverSocket = new ServerSocket(58083);
038: (new ServerSocketThread(serverSocket)).start();
039: } catch (Exception ignore) {
040: }
041: }
042:
043: JSObject win = JSObject.getWindow(this );
044: Object args[] = new Object[2];
045: args[0] = getJavaVersion();
046: args[1] = getJWSInstalled();
047: win.call("processJWSLaunch", args);
048: } catch (Exception e) {
049: e.printStackTrace();
050: }
051: }
052:
053: public String getJWSInstalled() {
054: return jwsInstalled;
055: }
056:
057: public String getJavaVersion() {
058: return System.getProperty("java.version");
059: }
060:
061: void addItem(String newWord) {
062: System.out.println(newWord);
063: buffer.append(newWord);
064: }
065:
066: /*
067: * This listerner class accepts a request and bounces the JVM proxy settings
068: */
069: class ServerSocketThread extends Thread {
070: private ServerSocket serverSocket = null;
071:
072: ServerSocketThread(ServerSocket socket) {
073: super ("ServerSocketThread");
074: this .serverSocket = socket;
075: }
076:
077: public void run() {
078: boolean running = true;
079: try {
080: while (running) {
081: Socket client = serverSocket.accept();
082:
083: System.out.println("process request for " + client);
084:
085: // Make JVM re-read proxy configuration
086: // This is only required incase of IE browser
087: Class CResetProxyManager = null;
088: Method reset = null;
089: try {
090: CResetProxyManager = Class
091: .forName("sun.plugin.net.proxy.PluginProxyManager");
092: } catch (ClassNotFoundException cnf) {
093: try {
094: CResetProxyManager = Class
095: .forName("com.sun.deploy.net.proxy.DynamicProxyManager");
096: } catch (ClassNotFoundException cnf1) {
097: System.out
098: .println("Unable to reset plugin proxy information for this JVM");
099: }
100: }
101:
102: if (CResetProxyManager != null) {
103: try {
104: reset = CResetProxyManager.getMethod(
105: "reset", null);
106: reset.invoke(null, null);
107: } catch (Exception e) {
108: System.out
109: .println("Unable to reset plugin proxy information for this JVM");
110: }
111: }
112:
113: client.close();
114: running = false;
115: serverSocket.close();
116: serverSocket = null;
117:
118: }
119: } catch (Exception e) {
120: running = false;
121: }
122: }
123: } // End of ServerSocketThread
124:
125: }
|