geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jawar...@apache.org
Subject svn commit: r655505 - in /geronimo/samples/trunk/samples/async-http: http-local-app/src/main/java/org/apache/geronimo/ http-local-app/src/main/webapp/WEB-INF/ http-remote-app/src/main/java/org/apache/geronimo/
Date Mon, 12 May 2008 14:00:15 GMT
Author: jawarner
Date: Mon May 12 07:00:15 2008
New Revision: 655505

URL: http://svn.apache.org/viewvc?rev=655505&view=rev
Log:
GERONIMO-4007 : Fixes for errors when under heavy stress

Modified:
    geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/AsyncServlet.java
    geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java
    geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/Callback.java
    geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/Utils.java
    geronimo/samples/trunk/samples/async-http/http-local-app/src/main/webapp/WEB-INF/web.xml
    geronimo/samples/trunk/samples/async-http/http-remote-app/src/main/java/org/apache/geronimo/PageServlet.java

Modified: geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/AsyncServlet.java
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/AsyncServlet.java?rev=655505&r1=655504&r2=655505&view=diff
==============================================================================
--- geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/AsyncServlet.java
(original)
+++ geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/AsyncServlet.java
Mon May 12 07:00:15 2008
@@ -17,6 +17,7 @@
 package org.apache.geronimo;
 
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.net.URL;
 import java.util.concurrent.ExecutorService;
@@ -30,6 +31,7 @@
 
 import org.apache.ahc.AsyncHttpClient;
 import org.apache.ahc.codec.HttpRequestMessage;
+import org.apache.ahc.codec.HttpResponseMessage;
 import org.apache.ahc.codec.SessionCache;
 import org.apache.ahc.util.MonitoringEvent;
 import org.apache.ahc.util.TimeMonitor;
@@ -65,6 +67,7 @@
 
         threadPool = Executors.newCachedThreadPool();
         sessionCache = new SessionCache(); 
+
         ahc = new AsyncHttpClient(threadPool, null);
         // enable connection reuse
         ahc.setSessionCache(sessionCache); 
@@ -84,84 +87,107 @@
      * @throws ServletException
      */
     public void event(CometEvent event) throws IOException, ServletException {
+        
+        HttpServletResponse eventResponse = event.getHttpServletResponse();
         HttpServletRequest request = event.getHttpServletRequest();
-
-        String cometId = request.getSession(true).getId();
-        System.out.println("");
-        System.out.println("sessionId: " + cometId + " "
-                + event.getEventType().toString());
-
+        boolean debug = Boolean.parseBoolean(request.getParameter("debug"));
+        boolean shortCircuit = Boolean.parseBoolean(request.getParameter("shortCircuit"));
+        String cometId = null;
+        
         if (event.getEventType() == CometEvent.EventType.BEGIN) {
-            boolean dumpStats = request.getParameter("dump") != null;
-            if (dumpStats) {
-                dumpStats(event.getHttpServletResponse());
-                return;
-            }
-            
-            event.getHttpServletRequest().setAttribute(
-                    "org.apache.tomcat.comet.timeout", new Integer(5 * 1000));
-            event.setTimeout(5 * 1000);
-
-            // TODO this doesn't look thread safe...
-            if (request.getParameter("remoteUrl") != null) {
-                remoteUrl = request.getParameter("remoteUrl");        
-            }
-
-            String remoteUri = request.getParameter("remoteUri");
-            if (remoteUri == null) {
-                remoteUri = "/remoteApp/page";
-            }
-            
-            URL url_connect = new URL(remoteUrl + remoteUri);       
-            HttpServletResponse eventResponse = event.getHttpServletResponse();
-            eventResponse.flushBuffer();
-            Callback callback = new Callback(eventResponse, cometId);
-            HttpRequestMessage msgRequest = new HttpRequestMessage(url_connect, callback);
-
-            // If the file being served has other URIs in it, like say images,
-            // subsequent calls are made to the remote app to retrieve those.
-            // We don't want to set new delay times and status codes then.
-            if (remoteUri.endsWith("page")) {
-                msgRequest.setParameter("sessionId", cometId);
+            if (!shortCircuit) {
+    
+                cometId = request.getSession(true).getId();
+                if(debug) {
+                    System.out.println();
+                    System.out.println("Event type: " + event.getEventType().toString() +
" Session ID: " + cometId + "\n Request:" + request + " Response: " + eventResponse);
+                }
+                boolean dumpStats = request.getParameter("dump") != null;
+                if (dumpStats) {
+                    dumpStats(event.getHttpServletResponse());
+                    return;
+                }
                 
-                int delayInt = 0;
-                String delay = request.getParameter("delay");
-                if (delay != null) {
-                    delayInt = Integer.parseInt(delay);
-                } else {
-                    delayInt = Utils.generateRandomDelay();
-                    delay = String.valueOf(delayInt);
+                event.getHttpServletRequest().setAttribute(
+                        "org.apache.tomcat.comet.timeout", new Integer(15 * 1000));
+    
+                // TODO this doesn't look thread safe...
+                if (request.getParameter("remoteUrl") != null) {
+                    remoteUrl = request.getParameter("remoteUrl");        
+                }
+    
+                String remoteUri = request.getParameter("remoteUri");
+                if (remoteUri == null) {
+                    remoteUri = "/remoteApp/page";
                 }
                 
-                String code = request.getParameter("code") == null ?
-                        String.valueOf(Utils.generateRandomCode()) : 
-                        request.getParameter("code");
+                URL url_connect = new URL(remoteUrl + remoteUri);       
+                eventResponse.flushBuffer();
+                Callback callback = new Callback(eventResponse, cometId, debug);
+                //Callback callback = new Callback(event, cometId);
+                HttpRequestMessage msgRequest = new HttpRequestMessage(url_connect, callback);
+    
+                // If the file being served has other URIs in it, like say images,
+                // subsequent calls are made to the remote app to retrieve those.
+                // We don't want to set new delay times and status codes then.
+                if (remoteUri.endsWith("page")) {
+                    msgRequest.setParameter("sessionId", cometId);
+                    
+                    int delayInt = 0;
+                    String delay = request.getParameter("delay");
+                    if (delay != null) {
+                        delayInt = Integer.parseInt(delay);
+                    } else {
+                        delayInt = Utils.generateRandomDelay();
+                        delay = String.valueOf(delayInt);
+                    }
+                    
+                    String code = request.getParameter("code") == null ?
+                            String.valueOf(Utils.generateRandomCode()) : 
+                            request.getParameter("code");
+                    
+                    msgRequest.setParameter("delay", delay);
+                    msgRequest.setParameter("code", code);
+                    msgRequest.setTimeOut(delayInt + 15000);
+                    if (debug) {
+                        System.out.println("sessionId: " + cometId + "; delay: "
+                            + delay + "; code: " + code);
+                    }
+                } else {
+                    System.out.println("msg request is " + msgRequest.getPath());
+                }
+    
+                msgRequest.setRequestMethod(HttpRequestMessage.REQUEST_GET);            
                 
-                msgRequest.setParameter("delay", delay);
-                msgRequest.setParameter("code", code);
-                msgRequest.setTimeOut(delayInt + 1000);
-
-                System.out.println("sessionId: " + cometId + "; delay: "
-                        + delay + "; code: " + code);
-            } else {
-                System.out.println("msg request is " + msgRequest.getPath());
+                try {
+                    callback.setTime(System.nanoTime());
+                    ahc.sendRequest(msgRequest);
+                    //System.out.println("sessionId: " + cometId + " with request " + msgRequest
+ " sent");
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    // send an error response using the callback
+                    callback.onException(e);
+                    event.close();
+                }
+            } else {                
+                synchronized(eventResponse) {
+                    event.close();
+                }
             }
-
-            msgRequest.setRequestMethod(HttpRequestMessage.REQUEST_GET);            
-            
-            try {
-                callback.setTime(System.nanoTime());
-                ahc.sendRequest(msgRequest);
-            } catch (Exception e) {
-                e.printStackTrace();
-                // send an error response using the callback
-                callback.onException(e);
+        } else if (event.getEventType() == CometEvent.EventType.ERROR) {
+            if (debug) {    
+                System.out.println("Event type: " + event.getEventType().toString() + " Session
ID: " + cometId + "\n Request:" + request + " Response: " + eventResponse);
+            }
+            synchronized(eventResponse) {
                 event.close();
             }
-        } else if (event.getEventType() == CometEvent.EventType.ERROR) {
-            event.close();
         } else if (event.getEventType() == CometEvent.EventType.END) {
-            event.close();
+            if (debug) {
+                System.out.println("Event type: " + event.getEventType().toString() + " Session
ID: " + cometId + "\n Request:" + request + " Response: " + eventResponse);
+            }
+            synchronized(eventResponse) {
+                event.close();
+            }
         }
     }
     
@@ -179,5 +205,5 @@
         out.println("response time: " + monitor.getAverageResponseTime());
         out.println("connect time: " + monitor.getAverageConnectTime());
         out.close();
-    }
+    } 
 }

Modified: geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java?rev=655505&r1=655504&r2=655505&view=diff
==============================================================================
--- geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java
(original)
+++ geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java
Mon May 12 07:00:15 2008
@@ -19,6 +19,7 @@
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.net.URL;
 
@@ -56,52 +57,62 @@
      */
     public void doGet(HttpServletRequest request, HttpServletResponse response)
             throws IOException, ServletException {
-
-        System.out.println("");
-        System.out.println("Inside BlockingServlet.doGet()");
-
-        String sessionId = request.getSession(true).getId();
-
-        if (request.getParameter("remoteUrl") != null) {
-            remoteUrl = request.getParameter("remoteUrl");
+        
+        boolean debug = Boolean.parseBoolean(request.getParameter("debug"));
+        boolean shortCircuit = Boolean.parseBoolean(request.getParameter("shortCircuit"));
+        if (debug) {
+            System.out.println("");
+            System.out.println("Inside BlockingServlet.doGet()");
         }
-
-        String remoteUri = request.getParameter("remoteUri");
-        if (remoteUri == null) {
-            remoteUri = "/remoteApp/page";
-        }       
-
-        String delay = request.getParameter("delay") == null ?
-                String.valueOf(Utils.generateRandomDelay()) :
-                request.getParameter("delay");
         
-        String code = request.getParameter("code") == null ?
-                String.valueOf(Utils.generateRandomCode()) : 
-                request.getParameter("code");
-        System.out.println("sessionId: " + sessionId + "; delay: " + delay + "; code: " +
code);
+        String sessionId = request.getSession(true).getId();
 
-        String url_string = remoteUrl + remoteUri + "?sessionId=" + sessionId + "&delay="
+ delay + "&code=" + code;        
-        URL url_connect = new URL(url_string);
-        
-        try {
-            BufferedReader input = new BufferedReader(new InputStreamReader(url_connect.openStream()));
-            String line = "";                       
-            response.setContentType("text/html");
-            PrintWriter out = response.getWriter();         
-            while ((line = input.readLine()) != null) {             
-                out.println(line);
+
+        if (!shortCircuit) {
+            if (request.getParameter("remoteUrl") != null) {
+                remoteUrl = request.getParameter("remoteUrl");
             }
-            out.flush();
-            out.close();
-            input.close();
-        }
-        catch(IOException ex) {
-            response.sendError(Integer.parseInt(code));         
+    
+            String remoteUri = request.getParameter("remoteUri");
+            if (remoteUri == null) {
+                remoteUri = "/remoteApp/page";
+            }       
+    
+            String delay = request.getParameter("delay") == null ?
+                    String.valueOf(Utils.generateRandomDelay()) :
+                    request.getParameter("delay");
+            
+            String code = request.getParameter("code") == null ?
+                    String.valueOf(Utils.generateRandomCode()) : 
+                    request.getParameter("code");
+            if (debug) {        
+                System.out.println("sessionId:" + sessionId + "; delay:" + delay + "; code:"
+ code);
+            }
+            
+            String url_string = remoteUrl + remoteUri + "?sessionId=" + sessionId + "&delay="
+ delay + "&code=" + code;        
+            URL url_connect = new URL(url_string);
+            
+            try {
+                BufferedReader input = new BufferedReader(new InputStreamReader(url_connect.openStream()));
+                String line = "";                       
+                response.setContentType("text/html");
+                PrintWriter out = response.getWriter();         
+                while ((line = input.readLine()) != null) {             
+                    out.println(line);
+                }
+                out.flush();
+                out.close();
+                input.close();
+            }
+            catch(IOException ex) {
+                response.sendError(Integer.parseInt(code));         
+            }
+        } else {
+            return;
         }
         
-
-        System.out.println("doGet processed");
+        if (debug) {
+            System.out.println("doGet processed");
+        }
     }
-
-    
-}
+}
\ No newline at end of file

Modified: geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/Callback.java
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/Callback.java?rev=655505&r1=655504&r2=655505&view=diff
==============================================================================
--- geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/Callback.java
(original)
+++ geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/Callback.java
Mon May 12 07:00:15 2008
@@ -18,7 +18,6 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PrintWriter;
 import java.util.Date;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -30,6 +29,7 @@
 public class Callback implements AsyncHttpClientCallback {
     private final HttpServletResponse response;
     private final String sessionId;
+    private final boolean debug;
     
     private final AtomicBoolean handled = new AtomicBoolean(false);
     
@@ -39,9 +39,10 @@
     // in nanoseconds
     private volatile long time;
 
-    public Callback(HttpServletResponse response, String sessionId) {
+    public Callback(HttpServletResponse response, String sessionId, boolean debug) {
         this.response = response;
         this.sessionId = sessionId;
+        this.debug = debug;
         clear();
     }
     
@@ -56,33 +57,38 @@
     /* (non-Javadoc)
      * @see org.apache.ahc.AsyncHttpClientCallback#onResponse(org.apache.ahc.codec.HttpResponseMessage)
      */
-    public void onResponse(HttpResponseMessage msg) {
-        System.out.println("  onResponse()" + " - Status:" + msg.getStatusCode() + " - Length:"
+ msg.getContentLength() + " " + sessionId);
-        
+    public synchronized void onResponse(HttpResponseMessage msg) {
+        if (debug) {
+            System.out.println("  onResponse()" + " - Status:" + msg.getStatusCode() + "
- Length:" + msg.getContentLength() + " " + sessionId);
+        }
         if (!handled.compareAndSet(false, true)) {
             System.out.println("already responded to another callback method " + sessionId);
             return;
         }
 
-        response.setStatus(msg.getStatusCode());
-        response.setContentType(msg.getContentType());
-        if (msg.getContentLength() > 0) {
-            response.setContentLength(msg.getContentLength());
-            OutputStream out = null;
-            try {
-                out = response.getOutputStream();
-                out.write(msg.getContent());
-                out.flush();
-                out.close();
-            } catch (IOException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
+        synchronized(response) {
+            response.setStatus(msg.getStatusCode());
+            response.setContentType(msg.getContentType());
+            if (msg.getContentLength() > 0) {
+                response.setContentLength(msg.getContentLength());
+                OutputStream out = null;
+                try {
+                    out = response.getOutputStream();
+                    out.write(msg.getContent());
+                    out.flush();
+                    out.close();
+                } catch (Exception e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
             }
         }
-        System.out.println("  Responded to " + sessionId + " in " + (System.nanoTime() -
this.time)/1000000);
+        if (debug) {
+            System.out.println("  Responded to " + sessionId + " in " + (System.nanoTime()
- this.time)/1000000);
+        }
     }
 
-    public void onException(Throwable cause) {
+    public synchronized void onException(Throwable cause) {
         throwable = cause;
         System.out.println("  Exception by " + sessionId + " in " + (System.nanoTime() -
this.time)/1000000);       
         cause.printStackTrace();    
@@ -94,7 +100,7 @@
         sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "exception occurred");
     }
 
-    public void onClosed() {
+    public synchronized void onClosed() {
         // if the response has not been received, this is an error: need to write a response
         if (!handled.get()) {
             sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Connection to the remote
URL unexpectedly closed");
@@ -102,7 +108,7 @@
         }
     }
 
-    public void onTimeout() {
+    public synchronized void onTimeout() {
         System.out.println("  Timed out " + sessionId + " in " + (System.nanoTime() - this.time)/1000000);
         if (!handled.compareAndSet(false, true)) {
             System.out.println("already responded to another callback method " + sessionId);
@@ -112,15 +118,22 @@
         sendError(HttpServletResponse.SC_REQUEST_TIMEOUT, "Request Timed out!\n" + new Date().toString());
     }
     
-    private void sendError(int status, String msg) {
-        try {
-            response.setContentType("text/plain");
-            response.setStatus(status);
-            PrintWriter out = response.getWriter();
-            out.println(msg);
-            out.close();
-        } catch (IOException e) {
-            e.printStackTrace();
+    private synchronized void sendError(int status, String msg) {
+        synchronized(response) {
+            try {
+                if (response.isCommitted()) {
+                    System.out.println("already responded to another callback method " +
sessionId);
+                    return;
+                }
+                response.setContentType("text/plain");
+                response.setStatus(status);
+                OutputStream out = response.getOutputStream();
+                out.write(msg.getBytes());
+                out.flush();
+                out.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
     }
 

Modified: geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/Utils.java
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/Utils.java?rev=655505&r1=655504&r2=655505&view=diff
==============================================================================
--- geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/Utils.java
(original)
+++ geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/Utils.java
Mon May 12 07:00:15 2008
@@ -1,5 +1,5 @@
 /**
- * Licensed to the Apache Software Foundation (ASF) under one or more
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You under the Apache License, Version 2.0

Modified: geronimo/samples/trunk/samples/async-http/http-local-app/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/async-http/http-local-app/src/main/webapp/WEB-INF/web.xml?rev=655505&r1=655504&r2=655505&view=diff
==============================================================================
--- geronimo/samples/trunk/samples/async-http/http-local-app/src/main/webapp/WEB-INF/web.xml
(original)
+++ geronimo/samples/trunk/samples/async-http/http-local-app/src/main/webapp/WEB-INF/web.xml
Mon May 12 07:00:15 2008
@@ -1,55 +1,55 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <web-app id="web-app_1" xmlns="http://java.sun.com/xml/ns/j2ee"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
-	version="2.4">
-	<display-name>ServerApp</display-name>
-	<distributable />
-
-	<servlet>
-		<display-name>AsyncServlet</display-name>
-		<servlet-name>AsyncServlet</servlet-name>
-		<servlet-class>org.apache.geronimo.AsyncServlet</servlet-class>
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+    version="2.4">
+    <display-name>ServerApp</display-name>
+    <distributable />
+
+    <servlet>
+        <display-name>AsyncServlet</display-name>
+        <servlet-name>AsyncServlet</servlet-name>
+        <servlet-class>org.apache.geronimo.AsyncServlet</servlet-class>
         <init-param>
-			<param-name>remoteUrl</param-name>
-			<param-value>http://festivus:8080</param-value>
-  	    </init-param>      
-	</servlet>
-
-	<servlet-mapping>
-		<servlet-name>AsyncServlet</servlet-name>
-		<url-pattern>/async</url-pattern>
-	</servlet-mapping>
+            <param-name>remoteUrl</param-name>
+            <param-value>http://festivus:8080</param-value>
+        </init-param>      
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>AsyncServlet</servlet-name>
+        <url-pattern>/async</url-pattern>
+    </servlet-mapping>
 
     <servlet>
-		<display-name>BlockingServlet</display-name>
-		<servlet-name>BlockingServlet</servlet-name>
-		<servlet-class>org.apache.geronimo.BlockingServlet</servlet-class>
+        <display-name>BlockingServlet</display-name>
+        <servlet-name>BlockingServlet</servlet-name>
+        <servlet-class>org.apache.geronimo.BlockingServlet</servlet-class>
         <init-param>
-			<param-name>remoteUrl</param-name>
-			<param-value>http://festivus:8080</param-value>
-  	    </init-param>      
-	</servlet>
-
-	<servlet-mapping>
-		<servlet-name>BlockingServlet</servlet-name>
-		<url-pattern>/sync</url-pattern>
-	</servlet-mapping>
+            <param-name>remoteUrl</param-name>
+            <param-value>http://festivus:8080</param-value>
+        </init-param>      
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>BlockingServlet</servlet-name>
+        <url-pattern>/sync</url-pattern>
+    </servlet-mapping>
 
      <servlet>
-		<display-name>NIOServlet</display-name>
-		<servlet-name>NIOServlet</servlet-name>
-		<servlet-class>org.apache.geronimo.NIOServlet</servlet-class>
+        <display-name>NIOServlet</display-name>
+        <servlet-name>NIOServlet</servlet-name>
+        <servlet-class>org.apache.geronimo.NIOServlet</servlet-class>
         <init-param>
-			<param-name>remoteUrl</param-name>
-			<param-value>festivus</param-value>
-  	    </init-param>      
-	</servlet>
-
-	<servlet-mapping>
-		<servlet-name>NIOServlet</servlet-name>
-		<url-pattern>/nio</url-pattern>
-	</servlet-mapping>
+            <param-name>remoteUrl</param-name>
+            <param-value>festivus</param-value>
+        </init-param>      
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>NIOServlet</servlet-name>
+        <url-pattern>/nio</url-pattern>
+    </servlet-mapping>
 
 </web-app>

Modified: geronimo/samples/trunk/samples/async-http/http-remote-app/src/main/java/org/apache/geronimo/PageServlet.java
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/async-http/http-remote-app/src/main/java/org/apache/geronimo/PageServlet.java?rev=655505&r1=655504&r2=655505&view=diff
==============================================================================
--- geronimo/samples/trunk/samples/async-http/http-remote-app/src/main/java/org/apache/geronimo/PageServlet.java
(original)
+++ geronimo/samples/trunk/samples/async-http/http-remote-app/src/main/java/org/apache/geronimo/PageServlet.java
Mon May 12 07:00:15 2008
@@ -16,53 +16,54 @@
  * 
  */
 public class PageServlet extends HttpServlet {
-	static final long serialVersionUID = 1L;
+    static final long serialVersionUID = 1L;
 
-	/* (non-Javadoc)
-	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
-	 */
-	protected void doGet(HttpServletRequest request,
-		HttpServletResponse response) throws ServletException, IOException {
-		
-		String cometId = request.getParameter("sessionId");
-		String delay = request.getParameter("delay");
-		String codeStr = request.getParameter("code");
-		System.out.println("sessionId:" + cometId + "; delay:" + delay + "; code:" + codeStr);
-
-		try {
-			Thread.sleep(Integer.parseInt(delay));
-		} catch (NumberFormatException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-
-		String uri = "dummy.html";	
-
-		int code = Integer.parseInt(codeStr);
-		switch (code) {
-		case 200: request.getRequestDispatcher(uri).forward(request, response); break;
-		
-		case 302: 
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
+    protected void doGet(HttpServletRequest request,
+        HttpServletResponse response) throws ServletException, IOException {
+        
+        String cometId = request.getParameter("sessionId");
+        String delay = request.getParameter("delay");
+        String codeStr = request.getParameter("code");
+        //Uncomment the following line to help with debugging
+        //System.out.println("sessionId:" + cometId + "; delay:" + delay + "; code:" + codeStr);
+
+        try {
+            Thread.sleep(Integer.parseInt(delay));
+        } catch (NumberFormatException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (InterruptedException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+
+        String uri = "dummy.html";  
+
+        int code = Integer.parseInt(codeStr);
+        switch (code) {
+        case 200: request.getRequestDispatcher(uri).forward(request, response); break;
+        
+        case 302: 
         response.sendRedirect("http://" + request.getServerName() + ":" + request.getLocalPort()
+ request.getContextPath() + "/" + uri);
-		    break;
-		
-		case 403:
-		case 404:
-		case 500: response.sendError(code, codeStr);
-			/*try  { 
-				int test = 1/0;
-			} 
-			catch (Exception e) {
-					throw new ServletException("Servlet caught a ServletException: " + e.getMessage());

-			}*/			
-			break;
-		}
-		
-		return;
-	}
+            break;
+        
+        case 403:
+        case 404:
+        case 500: response.sendError(code, codeStr);
+            /*try  { 
+                int test = 1/0;
+            } 
+            catch (Exception e) {
+                    throw new ServletException("Servlet caught a ServletException: " + e.getMessage());

+            }*/         
+            break;
+        }
+        
+        return;
+    }
 
 }
\ No newline at end of file



Mime
View raw message