harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r518914 - in /harmony/enhanced/classlib/trunk: make/build-test.xml support/src/test/java/tests/support/Support_Jetty.java
Date Fri, 16 Mar 2007 10:16:07 GMT
Author: liangyx
Date: Fri Mar 16 03:15:58 2007
New Revision: 518914

URL: http://svn.apache.org/viewvc?view=rev&rev=518914
Log:
Apply patch for HARMONY-2096([classlib]wrap embedding jetty API to support start a web server
with document root)

Added:
    harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/make/build-test.xml

Modified: harmony/enhanced/classlib/trunk/make/build-test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/make/build-test.xml?view=diff&rev=518914&r1=518913&r2=518914
==============================================================================
--- harmony/enhanced/classlib/trunk/make/build-test.xml (original)
+++ harmony/enhanced/classlib/trunk/make/build-test.xml Fri Mar 16 03:15:58 2007
@@ -91,6 +91,11 @@
              manifest="support/META-INF/MANIFEST.MF">
             <fileset dir="${tests.support.output}" />
         </jar>
+        <copy todir="${hy.hdk}/build/test"> 
+        <fileset dir="${jetty.dir}">
+            <include name="*.jar" />
+        </fileset>
+        </copy>
     </target>
 
     <target name="compile-support" depends="copy-test-resources, check-support-jars"

Added: harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java?view=auto&rev=518914
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java
(added)
+++ harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java
Fri Mar 16 03:15:58 2007
@@ -0,0 +1,88 @@
+package tests.support;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.mortbay.jetty.HttpConnection;
+import org.mortbay.jetty.Request;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.AbstractHandler;
+import org.mortbay.jetty.handler.ResourceHandler;
+
+public class Support_Jetty {
+    public static Server DEFAULT_SERVER = null;
+    
+    public static int DEFAULT_PORT = 0;
+    
+    public static Server SERVER = null;
+    
+    public static int PORT = 0;
+    
+    static {
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            public void run() {
+                try {
+                    stopDefaultServer();
+                    stopServer();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+    }
+    
+    public static class HYDefaultHandler extends AbstractHandler
+    {
+        public void handle(String target, HttpServletRequest request, HttpServletResponse
response, int dispatch) throws IOException, ServletException
+        {
+            Request base_request = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();
+            base_request.setHandled(true);   
+            response.setContentType("text/html");
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.getWriter().println("<h1>Hello OneHandler</h1>");
+        }
+    }
+    
+    public static int startDefaultHttpServer() throws Exception{
+        if (DEFAULT_SERVER != null){
+            return DEFAULT_PORT;
+        }
+        DEFAULT_PORT = Support_PortManager.getNextPortForUDP();
+        DEFAULT_SERVER = new Server(DEFAULT_PORT);
+        DEFAULT_SERVER.setHandler(new HYDefaultHandler());
+        DEFAULT_SERVER.start();
+        return DEFAULT_PORT;
+    }
+
+    public static int startHttpServerWithDocRoot(String root)
+            throws Exception {
+        if (SERVER != null) {
+            SERVER.stop();
+            SERVER = null;
+        }
+        PORT = Support_PortManager.getNextPortForUDP();
+        SERVER = new Server(PORT);
+        ResourceHandler resource_handler = new ResourceHandler();
+        resource_handler.setResourceBase(root);
+        SERVER.setHandler(resource_handler);
+        SERVER.start();
+        return PORT;
+    }
+
+    private static void stopDefaultServer() throws Exception {
+        if (DEFAULT_SERVER != null) {
+            DEFAULT_SERVER.stop();
+            DEFAULT_SERVER = null;
+        }
+    }
+    
+    private static void stopServer() throws Exception {
+        if (SERVER != null) {
+            SERVER.stop();
+            SERVER = null;
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message