geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pra...@apache.org
Subject svn commit: r575038 - in /geronimo/samples/trunk/samples/async-http/http-local-app/src/main: java/org/apache/geronimo/BlockingServlet.java webapp/WEB-INF/web.xml
Date Wed, 12 Sep 2007 18:43:47 GMT
Author: prasad
Date: Wed Sep 12 11:43:47 2007
New Revision: 575038

URL: http://svn.apache.org/viewvc?rev=575038&view=rev
Log:
* added a BlockingServlet for comparison

Added:
    geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java
  (with props)
Modified:
    geronimo/samples/trunk/samples/async-http/http-local-app/src/main/webapp/WEB-INF/web.xml

Added: 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=575038&view=auto
==============================================================================
--- geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java
(added)
+++ geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java
Wed Sep 12 11:43:47 2007
@@ -0,0 +1,111 @@
+package org.apache.geronimo;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.util.Random;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Servlet implementation class for Servlet: AsyncServlet
+ * 
+ * @web.servlet name="AsyncServlet" display-name="AsyncServlet"
+ * 
+ * @web.servlet-mapping url-pattern="/async"
+ * 
+ */
+public class BlockingServlet extends HttpServlet {
+	static final long serialVersionUID = 1L;
+
+	private String remoteUrl;
+
+	public void init() throws ServletException {
+		getServletContext().log("getinit init");
+		// Get the value of an initialization parameter
+		remoteUrl = getServletConfig().getInitParameter("remoteUrl");
+	}
+
+	/**
+	 * Process the given Comet event.
+	 * 
+	 * @param event
+	 *            The Comet event that will be processed
+	 * @throws IOException
+	 * @throws ServletException
+	 */
+	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");
+		}
+
+		String remoteUri = request.getParameter("remoteUri");
+		if (remoteUri == null) {
+			remoteUri = "/remoteApp/page";
+		}		
+
+		Integer[] params = generateRandomParams();
+		System.out.println("sessionId:" + sessionId + "; delay:" + params[0]
+				+ "; code:" + params[1]);
+
+		String url_string = remoteUrl + remoteUri + "?sessionId=" + sessionId + "&delay=" +
params[0] + "&code=" + params[1];		
+		URL url_connect = new URL(url_string);
+		
+		response.setContentType("text/html");
+		PrintWriter out = response.getWriter();
+		try {
+			BufferedReader input = new BufferedReader(new InputStreamReader(url_connect.openStream()));
+			String line = "";						
+			while ((line = input.readLine()) != null) {				
+				out.println(line);
+			}
+			out.flush();			
+			input.close();
+		}
+		catch(IOException ex) {			
+			out.println ("<html>");
+			out.println("<title>Error" + params[1] + "</title>");
+			out.println("<body bgcolor=FFFFFF>");
+
+			out.println("<h2>Error " + params[1] + "</h2>");
+			
+			out.println("</body>");
+			out.println("</html>");					
+		}
+		finally {
+			out.close();
+		}
+
+		System.out.println("doGet processed");
+	}
+
+	protected Integer[] generateRandomParams() {
+		Integer[] params = new Integer[2];
+		final int[] codes = new int[] { 200, 302, 403, 404, 500 };
+
+		Random generator = new Random();
+
+		// generate a random delay between 10ms and 250 ms
+		int delay = generator.nextInt(2500) + 10;
+		params[0] = new Integer(delay);
+
+		// generate randomly one of http status codes.
+		int index = generator.nextInt(codes.length);
+		params[1] = new Integer(codes[index]);
+
+		return params;
+	}
+
+}
\ No newline at end of file

Propchange: geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/BlockingServlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=575038&r1=575037&r2=575038&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
Wed Sep 12 11:43:47 2007
@@ -23,5 +23,20 @@
 		<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>
+        <init-param>
+			<param-name>remoteUrl</param-name>
+			<param-value>http://puffyshirt:8080</param-value>
+  	    </init-param>      
+	</servlet>
+
+
+	<servlet-mapping>
+		<servlet-name>BlockingServlet</servlet-name>
+		<url-pattern>/sync</url-pattern>
+	</servlet-mapping>
 
 </web-app>



Mime
View raw message