[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xwt-patches
Subject:    [patches] Intranet launcher
From:       Emiliano <emile () iris-advies ! nl>
Date:       2003-04-03 8:21:57
[Download RAW message or body]

This are my changes for the intranet launcher, updated for shoehorn v3
(ran CVS update and fixed my stuff). Note that the patch below modifies
web.xml to set it up for autoconfig. I find this convenient, but whether
it should be the default is up for discussion. I included it as a
sample.

With the patch below, building the launcher (after running the
dist/update script) will result in a launcher.war that you should be
able to drop into your webapps directory, and it should Just Work (tm).
The resulting war is 7Megs; I could make it available through the XWT SF
files section if so desired.

This works for me. I hope some others will test too and report if I've
accidentally broken anything. Enjoy.



In addition to the patch below, you must make the directory 'dist' and
place the following script, named 'update' there:

--------------- SNIP -------------------
#!/bin/sh
wget -N http://dist.xwt.org/mappings.txt
for d in `grep : mappings.txt | awk '{print $2}'` ; do
    wget -N http://dist.xwt.org/xwt-$d.jar
    wget -N http://dist.xwt.org/xwt-$d.cab
    wget -N http://dist.xwt.org/xwt-$d.exe.gz
    wget -N http://dist.xwt.org/xwt-$d.linux.gz
    wget -N http://dist.xwt.org/shoehorn-$d.jar
done
wget -N http://dist.xwt.org/xwt.jar
wget -N http://dist.xwt.org/xwt.cab
wget -N http://dist.xwt.org/shoehorn.jar
--------------- SNIP -------------------

--------------- SNIP -------------------
Index: build.xml
===================================================================
RCS file: /cvs/launcher/build.xml,v
retrieving revision 1.2
diff -u -d -B -u -d -r1.2 build.xml
--- build.xml	29 Mar 2003 03:36:32 -0000	1.2
+++ build.xml	3 Apr 2003 08:10:21 -0000
@@ -12,6 +12,7 @@
     <target name="compile">
 
         <mkdir dir="bin/"/>
+        <mkdir dir="dist/"/>
 
         <echo message="compiling   .java -> .class [launcher]"/>
         <javac destdir="bin/" deprecation="no">
@@ -34,6 +35,9 @@
 
         <echo message="archiving  .class -> .war   [launcher]"/>
         <war zipfile="launcher.war" webxml="src/org/xwt/launcher/web.xml">
+            <zipfileset dir="dist" prefix="">
+                <exclude name="update"/>
+            </zipfileset>
             <classes dir="src">
                     <include name="org/xwt/launcher/launch.html"/>
             </classes>
Index: src/org/xwt/launcher/Launcher.java
===================================================================
RCS file: /cvs/launcher/src/org/xwt/launcher/Launcher.java,v
retrieving revision 1.8
diff -u -d -B -u -d -r1.8 Launcher.java
--- src/org/xwt/launcher/Launcher.java	1 Apr 2003 02:55:30 -0000	1.8
+++ src/org/xwt/launcher/Launcher.java	3 Apr 2003 08:10:22 -0000
@@ -70,7 +70,7 @@
 
         } catch (Exception e) {
             e.printStackTrace();
-            throw new RuntimeException(e);
+            throw new RuntimeException(e.getMessage());
         }
     }
 
@@ -91,6 +91,12 @@
     boolean isLinux = false;
     boolean isNetscape4 = false;
     
+    // Global config \
////////////////////////////////////////////////////////////////////////////// +    \
private static String stumpURL = "/"; +    private static String shoehornURL = \
"http://dist.xwt.org/"; +    private static String CABURLPrefix = \
"http://dist.xwt.org/xwt-"; +    private static String mappingsURL = \
"http://dist.xwt.org/mappings.txt"; +    private static String xwarUrlPrefix = null;
 
     // Main Dispatch Loop \
//////////////////////////////////////////////////////////////////////////  
@@ -99,9 +105,14 @@
 
     static {
         System.out.println("Loading mappings...");
+        //[eeh] This *will* cause a security violation in lots of
+        //      Tomcat setups.
         try {
             updateMappings();
             System.out.println("Mappings loaded.");
+        } catch (java.security.AccessControlException e) {
+            // ignore, assume the containing Servlet will call
+            // updateMappings from a resource
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -120,8 +131,84 @@
             }.start();
     }
 
+    public static String getXwarUrlPrefix() {
+        return xwarUrlPrefix;
+    }
+    public static void setXwarUrlPrefix(String prefix) {
+        xwarUrlPrefix = prefix;
+        if (prefix == null) return;
+
+        if (! xwarUrlPrefix.endsWith("/")) {
+            xwarUrlPrefix = prefix + "/";
+        }
+    }
+
+    public static String getStumpURL() {
+        return stumpURL;
+    }
+    public static void setStumpURL(String url) {
+        if (url == null) return;
+
+        if (url.endsWith("/")) {
+            stumpURL = url;
+        } else {
+            stumpURL = url + "/";
+        }
+    }
+
+    public static String getShoehornURL() {
+        return shoehornURL;
+    }
+    public static void setShoehornURL(String url) {
+        shoehornURL = url;
+    }
+
+    public static String getCABURLPrefix() {
+        return CABURLPrefix;
+    }
+    public static void setCABURLPrefix(String url) {
+        CABURLPrefix = url;
+    }
+
+    public static String getMappingsURL() {
+        return mappingsURL;
+    }
+    public static void setMappingsURL(String url) {
+        mappingsURL = url;
+        try { updateMappings(); } catch (IOException e) {}
+    }
+
     public static void main(String[] args) throws IOException {
-        int p = args.length == 0 ? 8080 : Integer.parseInt(args[0]);
+        int p = 8080;
+
+        if (args.length == 1) {
+            p = Integer.parseInt(args[0]);
+        } else {
+            int eq;
+            String key, value;
+            for (int i=0; i<args.length; i++) {
+                eq = args[i].indexOf('=');
+                if (eq >= 0) {
+                    key = args[i].substring(0, eq);
+                    value = args[i].substring(eq + 1);
+
+                    if (key.equals("port")) {
+                        p = Integer.parseInt(value);
+                    } else if (key.equals("shoehorn")) {
+                        shoehornURL = value;
+                    } else if (key.equals("cab")) {
+                        CABURLPrefix = value;
+                    } else if (key.equals("mappings")) {
+                        mappingsURL = value;
+                    } else if (key.equals("stump")) {
+                        stumpURL = value;
+                    } else if (key.equals("url")) {
+                        xwarUrlPrefix = value;
+                    }
+                }
+            }
+        }
+
         ServerSocket s = new ServerSocket(p);
         System.out.println("Ready to serve requests on port " + p);
         while (true) {
@@ -158,7 +245,7 @@
 
         if (path.equals("/shoehorn.jar")) {
             pw.print("HTTP/1.0 302 Found\r\n");
-            pw.print("Location: http://dist.xwt.org/shoehorn.jar\r\n");
+            pw.print("Location: " + shoehornURL + "shoehorn.jar\r\n");
             pw.print("\r\n");
             
         } else if (path.equals("/stump.jar")) {
@@ -211,18 +298,21 @@
             pw.println("<html><body><p>Error: invalid path: <tt>" + path + \
"</tt></p></body></html>");  return;
         }
+
         path = path.substring(1);
-        if (path.indexOf('/') == -1) {
-            pw.println("<html><body><p>Error: couldn't parse engine \
                name</p></body></html>");
-            return;
+
+        String engine = path.substring(0, path.indexOf('/'));
+
+        if (engine == null) {
+          pw.println("<html><body><p>Error: couldn't parse engine \
name</p></body></html>"); +          return;
         }
 
+        path = "http://" + path.substring(path.indexOf('/') + 1);
+
         // version routing
-        String engine = path.substring(0, path.indexOf('/'));
         if (mappings != null) build = (String)mappings.get(engine);
         if (build == null) build = engine;
-
-        path = "http://" + path.substring(path.indexOf('/') + 1);
     }
 
     void body() throws IOException {
@@ -271,23 +361,35 @@
             pw.println("    applets. XWT can only run if the browser honors its \
                signature. Please");
             pw.println("    contact the KDE project and encourage them to implement \
                support for");
             pw.println("    signed applets. In the meantime, you can install XWT \
                manually by");
-            pw.println("    downloading <a \
href=http://dist.xwt.org/shoehorn.jar><tt>shoehorn.jar</tt></a>"); +            \
pw.println("    downloading <a href=" + shoehornURL + \
                "shoehorn.jar<tt>shoehorn.jar</tt></a>");
             pw.println("    and putting it in \
<tt>$JAVA_HOME/jre/lib/ext/</tt>.</p>");  }
 
         pw.println("    <p><b>XWT is loading; please wait...</b>&nbsp;");
-        if (Integer.parseInt(build, 16) >= 0x026d) {
-            pw.println("    <form action=http://localhost:" + logPort + "/" + \
                randUrl + " method=GET>");
-            pw.println("        <input type=submit value='Show Log &gt;&gt;'>");
-            pw.println("    </form>");
-        }
+
+        try {
+          if (Integer.parseInt(build, 16) >= 0x026d) {
+              pw.println("    <form action=http://localhost:" + logPort + "/" + \
randUrl + " method=GET>"); +              pw.println("        <input type=submit \
value='Show Log &gt;&gt;'>"); +              pw.println("    </form>");
+          }
+        } catch (Exception e) {}
+
         pw.println("    </p>");
 
         if (isMSIE && !isMacintosh) {
+            String clsid;
+            if (build.length() == 4) {
+                clsid = "D605" + build + "-61B3-11d6-82FA-005056CA9250";
+            } else {
+                clsid = build;
+            }
+
+            pw.println("    <p><b>XWT is loading; please wait...</b></p>");
             pw.println("    <p>You should see a blue bar at the bottom of your \
                browser window indicating XWT's progress.</p>");
             pw.println("    <p>When asked if you want to run the application signed \
                by <b>The XWT Foundation</b>, click <b>YES</b>.</p>");
-            pw.println("    <object classid=clsid:D605" + build + \
                "-61B3-11d6-82FA-005056CA9250");
-            pw.println("            codebase=http://dist.xwt.org/xwt-" + build + \
".cab width=1 height=1>"); +            pw.println("    <object classid=clsid:" + \
clsid); +            pw.println("            codebase=" + CABURLPrefix + build + \
".cab width=1 height=1>");  pw.println("        <param name=xwar value='" + path + \
                "'>");
             pw.println("        <param name=log value='" + logPort + "/" + randUrl + \
"'>");  pw.println("    </object>");
@@ -295,11 +397,11 @@
         } else {
             pw.println("    <center>");
             if (isNetscape4) {
-                pw.println("        <applet code=org.xwt.shoehorn" + \
                shoehorn_version +
-			   ".ShoeHorn codebase=http://dist.xwt.org/ \
archive=http://dist.xwt.org/shoehorn.jar width=300 height=30>"); +                \
pw.println("        <applet code=org.xwt.shoehorn" + shoehorn_version + ".ShoeHorn" + \
+                           " codebase=" + shoehornURL + " archive=" + shoehornURL + \
"shoehorn.jar width=300 height=30>");  } else {
-                pw.println("        <applet code=org.xwt.shoehorn" + \
                shoehorn_version +
-			   ".ShoeHorn archive=/stump.jar width=300 height=30>");
+                pw.println("        <applet code=org.xwt.shoehorn" + \
shoehorn_version + ".ShoeHorn" + +                           " archive=" + stumpURL + \
"stump.jar width=300 height=30>");  }
             pw.println("            <param name=build value=" + build + ">");
             pw.println("            <param name=browser value='" + useragent + \
"'>"); @@ -324,10 +426,14 @@
 
     static Hashtable mappings;
 
-    /** loads the mappings for "stable", "testing", and "unstable" from dist.xwt.org \
*/ +    /** loads the mappings for "stable", "testing", and "unstable" from \
mappingsURL */  static void updateMappings() throws IOException {
+        updateMappings(new URL(mappingsURL).openStream());
+    }
+
+    /** loads the mappings for "stable", "testing", and "unstable" from the given \
InputStream */ +    static void updateMappings(InputStream is) throws IOException {
         Hashtable newMap = new Hashtable();
-        InputStream is = new URL("http://dist.xwt.org/mappings.txt").openStream();
         BufferedReader br = new BufferedReader(new InputStreamReader(is));
         String s = null;
         while((s = br.readLine()) != null) {
Index: src/org/xwt/launcher/Servlet.java
===================================================================
RCS file: /cvs/launcher/src/org/xwt/launcher/Servlet.java,v
retrieving revision 1.1
diff -u -d -B -u -d -r1.1 Servlet.java
--- src/org/xwt/launcher/Servlet.java	4 Nov 2002 02:39:32 -0000	1.1
+++ src/org/xwt/launcher/Servlet.java	3 Apr 2003 08:10:22 -0000
@@ -11,13 +11,51 @@
 
 /** adapter to make Launcher.java work as a servlet */
 public class Servlet extends HttpServlet {
+private boolean autoConfig = false;
+private boolean autoConfigInitialized = false;
+private ServletContext context = null;
+
+    public void init(javax.servlet.ServletConfig servletConfig) throws \
javax.servlet.ServletException { +        super.init(servletConfig);
+
+        String param;
+        param = servletConfig.getInitParameter("autoConfig");
+        if (param != null && param.equals("true")) {
+            autoConfig = true;
+            context = servletConfig.getServletContext();
+        } else {
+            param = servletConfig.getInitParameter("shoehornURL");
+            if (param != null) { Launcher.setShoehornURL(param); }
+            param = servletConfig.getInitParameter("CABURLPrefix");
+            if (param != null) { Launcher.setCABURLPrefix(param); }
+            param = servletConfig.getInitParameter("mappingsURL");
+            if (param != null) { Launcher.setMappingsURL(param); }
+            param = servletConfig.getInitParameter("stumpCodebase");
+            if (param != null) { Launcher.setStumpURL(param); }
+        }
+    }
 
     public void doGet(HttpServletRequest req, HttpServletResponse res) throws \
ServletException, IOException {  
-        if (req.getPathInfo().equals("/shoehorn.jar")) {
-            res.sendRedirect("http://dist.xwt.org/shoehorn.jar");
+        if (autoConfig && !autoConfigInitialized) {
+            autoConfigInitialized = true;
+            String path = req.getContextPath();
+            String base = "http://" + req.getServerName() + ":" + \
req.getServerPort() + path;  
-        } else if (req.getPathInfo().equals("/stump.jar")) {
+            Launcher.setShoehornURL(base + "/shoehorn.jar");
+            Launcher.setCABURLPrefix(base + "/xwt-");
+            Launcher.setStumpURL(path + "/" + req.getServletPath() + "/");
+
+            Launcher.updateMappings(context.getResourceAsStream("/mappings.txt"));
+        }
+
+        String pathInfo = req.getPathInfo();
+        if (pathInfo == null) { pathInfo = ""; }
+
+        if (pathInfo.equals("/shoehorn.jar")) {
+            res.sendRedirect(Launcher.getShoehornURL());
+
+        } else if (pathInfo.equals("/stump.jar")) {
             res.setContentType("text/plain");
             res.getOutputStream().write(Launcher.stump_jar);
 
@@ -26,7 +64,7 @@
             Launcher l = new Launcher();
             l.useragent = req.getHeader("User-Agent");
             l.referer = req.getHeader("Referer");
-            l.path = req.getPathInfo() + (req.getQueryString() == null ? "" : ("?" + \
req.getQueryString())); +            l.path = pathInfo + (req.getQueryString() == \
                null ? "" : ("?" + req.getQueryString()));
             l.pw = new PrintWriter(new OutputStreamWriter(res.getOutputStream()));
             l.launch();
             l.pw.flush();
Index: src/org/xwt/launcher/web.xml
===================================================================
RCS file: /cvs/launcher/src/org/xwt/launcher/web.xml,v
retrieving revision 1.2
diff -u -d -B -u -d -r1.2 web.xml
--- src/org/xwt/launcher/web.xml	31 Mar 2003 12:49:20 -0000	1.2
+++ src/org/xwt/launcher/web.xml	3 Apr 2003 08:10:22 -0000
@@ -9,11 +9,15 @@
     <servlet>
         <servlet-name> Launch </servlet-name>
         <servlet-class> org.xwt.launcher.Servlet </servlet-class>
+        <init-param>
+            <param-name>autoConfig</param-name>
+            <param-value>true</param-value>
+        </init-param>
     </servlet>
 
     <servlet-mapping>
         <servlet-name> Launch    </servlet-name>
-        <url-pattern>  /* </url-pattern>
+        <url-pattern>  /launch/* </url-pattern>
     </servlet-mapping>
 
 </web-app>
--------------- SNIP -------------------


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic