tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r407671 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina: CometProcessor.java connector/CoyoteAdapter.java servlets/CometServlet.java
Date Fri, 19 May 2006 00:44:05 GMT
Author: remm
Date: Thu May 18 17:44:04 2006
New Revision: 407671

URL: http://svn.apache.org/viewvc?rev=407671&view=rev
Log:
- Add example read method.
- Return value for read errors (as an option compared with throwing an exception).
- Add some javadocs.

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometProcessor.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/CometServlet.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometProcessor.java?rev=407671&r1=407670&r2=407671&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometProcessor.java Thu May 18 17:44:04
2006
@@ -30,8 +30,10 @@
      * of the processing of the connection. It can be used to initialize any relevant 
      * fields using the request and response objects.
      * 
-     * @param request
-     * @param response
+     * @param request The HTTP servlet request instance, which can be accessed
+     *        asynchronously at any time until the end or error methods are called
+     * @param response The HTTP servlet response instance, which can be accessed
+     *        asynchronously at any time until the end or error methods are called
      * @throws IOException
      * @throws ServletException
      */
@@ -40,7 +42,9 @@
 
     /**
      * End may be called to end the processing of the request. Fields that have
-     * been initialized in the begin method should be reset.
+     * been initialized in the begin method should be reset. After this method has
+     * been called, the request and response objects, as well as all their dependent
+     * objects will be recycled and used to process other requests.
      * 
      * @param request
      * @param response
@@ -53,7 +57,9 @@
     /**
      * Error will be called by the container in the case where an IO exception
      * or a similar unrecoverable error occurs on the connection. Fields that have
-     * been initialized in the begin method should be reset.
+     * been initialized in the begin method should be reset. After this method has
+     * been called, the request and response objects, as well as all their dependent
+     * objects will be recycled and used to process other requests.
      * 
      * @param request
      * @param response
@@ -68,14 +74,19 @@
      * without blocking. The available and ready methods of the InputStream or
      * Reader may be used to determine if there is a risk of blocking: the servlet
      * should read while data is reported available, and can make one additional read
-     * without blocking.
+     * without blocking. When encountering a read error or an EOF, the servlet MUST
+     * report it by either returning null or throwing an exception such as an 
+     * IOException. 
      * 
      * @param request
      * @param response
-     * @throws IOException
+     * @throws IOException An IOException may be thrown to indicate an IO error, 
+     *         or that the EOF has been reached on the connection
      * @throws ServletException
+     * @return false if the read attempt returned an EOF; alternately, it is also
+     *         valid to throw an IOException
      */
-    public void read(HttpServletRequest request, HttpServletResponse response)
+    public boolean read(HttpServletRequest request, HttpServletResponse response)
         throws IOException, ServletException;
 
 }

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=407671&r1=407670&r2=407671&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Thu May 18
17:44:04 2006
@@ -128,7 +128,15 @@
                 if (error) {
                     servlet.error(request.getRequest(), response.getResponse());
                 } else {
-                    servlet.read(request.getRequest(), response.getResponse());
+                    if (!servlet.read(request.getRequest(), response.getResponse())) {
+                        error = true;
+                        request.removeAttribute("org.apache.tomcat.comet");
+                        try {
+                            servlet.error(request.getRequest(), response.getResponse());
+                        } catch (Throwable th) {
+                            log.error(sm.getString("coyoteAdapter.service"), th);
+                        }
+                    }
                 }
                 return (!error);
             } catch (Throwable t) {

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/CometServlet.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/CometServlet.java?rev=407671&r1=407670&r2=407671&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/CometServlet.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/CometServlet.java Thu May 18 17:44:04
2006
@@ -19,6 +19,7 @@
 
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -49,8 +50,20 @@
         end(request, response);
     }
     
-    public abstract void read(HttpServletRequest request, HttpServletResponse response)
-        throws IOException, ServletException;
+    public boolean read(HttpServletRequest request, HttpServletResponse response)
+        throws IOException, ServletException {
+        InputStream is = request.getInputStream();
+        byte[] buf = new byte[512];
+        do {
+            int n = is.read(buf);
+            if (n > 0) {
+                // Do something with the data
+            } else if (n < 0) {
+                return false;
+            }
+        } while (is.available() > 0);
+        return true;
+    }
 
     protected void service(HttpServletRequest request, HttpServletResponse response)
         throws IOException, ServletException {



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


Mime
View raw message