Author: fhanik
Date: Fri Jul 17 21:14:13 2009
New Revision: 795229

URL: http://svn.apache.org/viewvc?rev=795229&view=rev
Log:
very simple async example

Added:
    tomcat/trunk/webapps/examples/WEB-INF/classes/async/
    tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java   (with 
props)
    tomcat/trunk/webapps/examples/jsp/async/
    tomcat/trunk/webapps/examples/jsp/async/async1.jsp   (with props)
    tomcat/trunk/webapps/examples/jsp/async/index.jsp   (with props)
Modified:
    tomcat/trunk/webapps/examples/WEB-INF/web.xml

Added: tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java?rev=795229&view=auto
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java (added)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java Fri Jul 17 
21:14:13 2009
@@ -0,0 +1,59 @@
+/*
+* 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
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package async;
+
+import java.io.IOException;
+
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+public class Async1 extends HttpServlet {
+    protected static Log log = LogFactory.getLog(Async1.class);
+    public Async1() {
+    }
+
+    @Override
+    protected void service(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
+        final AsyncContext actx = req.startAsync();
+        Runnable run = new Runnable() {
+            public void run() {
+                try {
+                    String path = "/jsp/async/async1.jsp";
+                    Thread.currentThread().setName("Async1-Thread");
+                    log.info("Putting AsyncThread to sleep");
+                    Thread.sleep(10*1000);
+                    log.info("Dispatching to "+path);
+                    actx.dispatch(path);
+                }catch (InterruptedException x) {
+                    log.error("Async1",x);
+                }catch (IllegalStateException x) {
+                    log.error("Async1",x);
+                }
+            }
+        };
+        Thread t = new Thread(run);
+        t.start();
+    }
+    
+
+}

Propchange: tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/webapps/examples/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/web.xml?rev=795229&r1=795228&r2=795229&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/web.xml (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/web.xml Fri Jul 17 21:14:13 2009
@@ -295,4 +295,13 @@
       <env-entry-value>10</env-entry-value>
     </env-entry>
 
+    <!-- Async examples -->
+    <servlet>
+      <servlet-name>async1</servlet-name>
+      <servlet-class>async.Async1</servlet-class>
+    </servlet>
+    <servlet-mapping>
+      <servlet-name>async1</servlet-name>
+      <url-pattern>/async/async1</url-pattern>
+    </servlet-mapping>
 </web-app>

Added: tomcat/trunk/webapps/examples/jsp/async/async1.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/jsp/async/async1.jsp?rev=795229&view=auto
==============================================================================
--- tomcat/trunk/webapps/examples/jsp/async/async1.jsp (added)
+++ tomcat/trunk/webapps/examples/jsp/async/async1.jsp Fri Jul 17 21:14:13 2009
@@ -0,0 +1,8 @@
+<%...@page session="false"%>
+Output from async1.jsp
+<%
+System.out.println("Inside Async 1");
+  if (request.isAsyncStarted()) {
+    request.getAsyncContext().complete();
+  }
+%>

Propchange: tomcat/trunk/webapps/examples/jsp/async/async1.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/webapps/examples/jsp/async/index.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/jsp/async/index.jsp?rev=795229&view=auto
==============================================================================
--- tomcat/trunk/webapps/examples/jsp/async/index.jsp (added)
+++ tomcat/trunk/webapps/examples/jsp/async/index.jsp Fri Jul 17 21:14:13 2009
@@ -0,0 +1,2 @@
+<%...@page session="false"%>
+<a href="<%=response.encodeURL("/examples/async/async1")%>"> Async 1 </a>

Propchange: tomcat/trunk/webapps/examples/jsp/async/index.jsp
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to