Author: markt
Date: Mon Apr 29 19:49:24 2013
New Revision: 1477301

URL: http://svn.apache.org/r1477301
Log:
Remove unnecessary ActionCode.SET_READ_LISTENER
Add missing tests when setting a non-blocking ReadListener and use i18n for all 
exception messages if a test fails

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java
    tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties
    tomcat/trunk/java/org/apache/coyote/ActionCode.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java

Modified: tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java?rev=1477301&r1=1477300&r2=1477301&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java Mon Apr 29 
19:49:24 2013
@@ -22,6 +22,7 @@ import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.servlet.ReadListener;
 
@@ -252,9 +253,25 @@ public class InputBuffer extends Reader
 
     private volatile ReadListener listener;
     public void setReadListener(ReadListener listener) {
-        if (getReadListener()!=null) throw new IllegalStateException("Read 
listener already set.");
+        if (listener == null) {
+            throw new NullPointerException(
+                    sm.getString("inputBuffer.nullListener"));
+        }
+        if (getReadListener() != null) {
+            throw new IllegalStateException(
+                    sm.getString("inputBuffer.listenerSet"));
+        }
+        // Note: This class is not used for HTTP upgrade so only need to test
+        //       for async
+        AtomicBoolean result = new AtomicBoolean(false);
+        coyoteRequest.action(ActionCode.ASYNC_IS_ASYNC, result);
+        if (!result.get()) {
+            throw new IllegalStateException(
+                    sm.getString("inputBuffer.notAsync"));
+        }
+
         this.listener = listener;
-        coyoteRequest.action(ActionCode.SET_READ_LISTENER, listener);
+        coyoteRequest.setReadListener(listener);
     }
 
 

Modified: 
tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties?rev=1477301&r1=1477300&r2=1477301&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties Mon 
Apr 29 19:49:24 2013
@@ -13,10 +13,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+cometEvent.nullRequest=The event object has been recycled and is no longer 
associated with a request
+
+coyoteAdapter.parsePathParam=Unable to parse the path parameters using 
encoding [{0}]. The path parameters in the URL will be ignored.
+coyoteAdapter.debug=The variable [{0}] has value [{1}]
+coyoteAdapter.accesslogFail=Exception while attempting to add an entry to the 
access log
 
-#
-# CoyoteConnector
-#
 coyoteConnector.invalidPort=The connector cannot start since the specified 
port value of [{0}] is invalid
 coyoteConnector.protocolHandlerDestroyFailed=Protocol handler destroy failed
 coyoteConnector.protocolHandlerInitializationFailed=Protocol handler 
initialization failed
@@ -27,28 +29,9 @@ coyoteConnector.protocolHandlerPauseFail
 coyoteConnector.protocolHandlerResumeFailed=Protocol handler resume failed
 coyoteConnector.parseBodyMethodNoTrace=TRACE method MUST NOT include an entity 
(see RFC 2616 Section 9.6)
 
-#
-# CoyoteAdapter
-#
-coyoteAdapter.parsePathParam=Unable to parse the path parameters using 
encoding [{0}]. The path parameters in the URL will be ignored.
-coyoteAdapter.debug=The variable [{0}] has value [{1}]
-coyoteAdapter.accesslogFail=Exception while attempting to add an entry to the 
access log
-
-#
-# CoyoteResponse
-#
-coyoteResponse.getOutputStream.ise=getWriter() has already been called for 
this response
-coyoteResponse.getWriter.ise=getOutputStream() has already been called for 
this response
-coyoteResponse.reset.ise=Cannot call reset() after response has been committed
-coyoteResponse.resetBuffer.ise=Cannot reset buffer after response has been 
committed
-coyoteResponse.sendError.ise=Cannot call sendError() after the response has 
been committed
-coyoteResponse.sendRedirect.ise=Cannot call sendRedirect() after the response 
has been committed
-coyoteResponse.sendRedirect.note=<html><body><p>Redirecting to <a 
href="{0}">{0}</a></p></body></html>
-coyoteResponse.setBufferSize.ise=Cannot change buffer size after data has been 
written
+inputBuffer.listenerSet=The non-blocking read listener has already been set
+inputBuffer.nullListener=The listener passed to setReadListener() may not be 
null
 
-#
-# CoyoteRequest
-#
 coyoteRequest.getInputStream.ise=getReader() has already been called for this 
request
 coyoteRequest.getReader.ise=getInputStream() has already been called for this 
request
 coyoteRequest.sessionCreateCommitted=Cannot create a session after the 
response has been committed
@@ -65,10 +48,20 @@ coyoteRequest.sessionEndAccessFail=Excep
 coyoteRequest.sendfileNotCanonical=Unable to determine canonical name of file 
[{0}] specified for use with sendfile
 coyoteRequest.maxPostSizeExceeded=The multi-part request contained parameter 
data (excluding uploaded files) that exceeded the limit for maxPostSize set on 
the associated connector
 
-requestFacade.nullRequest=The request object has been recycled and is no 
longer associated with this facade
+coyoteResponse.getOutputStream.ise=getWriter() has already been called for 
this response
+coyoteResponse.getWriter.ise=getOutputStream() has already been called for 
this response
+coyoteResponse.reset.ise=Cannot call reset() after response has been committed
+coyoteResponse.resetBuffer.ise=Cannot reset buffer after response has been 
committed
+coyoteResponse.sendError.ise=Cannot call sendError() after the response has 
been committed
+coyoteResponse.sendRedirect.ise=Cannot call sendRedirect() after the response 
has been committed
+coyoteResponse.sendRedirect.note=<html><body><p>Redirecting to <a 
href="{0}">{0}</a></p></body></html>
+coyoteResponse.setBufferSize.ise=Cannot change buffer size after data has been 
written
 
-responseFacade.nullResponse=The response object has been recycled and is no 
longer associated with this facade
+inputBuffer.listenerSet=The non-blocking read listener has already been set
+inputBuffer.notAsync=It is only valid to switch to non-blocking IO within 
async processing or HTTP upgrade processing
+inputBuffer.nullListener=The listener passed to setReadListener() may not be 
null
+inputBuffer.streamClosed=Stream closed
 
-cometEvent.nullRequest=The event object has been recycled and is no longer 
associated with a request
+requestFacade.nullRequest=The request object has been recycled and is no 
longer associated with this facade
 
-inputBuffer.streamClosed=Stream closed
+responseFacade.nullResponse=The response object has been recycled and is no 
longer associated with this facade

Modified: tomcat/trunk/java/org/apache/coyote/ActionCode.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ActionCode.java?rev=1477301&r1=1477300&r2=1477301&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ActionCode.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ActionCode.java Mon Apr 29 19:49:24 2013
@@ -206,11 +206,6 @@ public enum ActionCode {
     UPGRADE,
 
     /**
-     * Callback to trigger setting the ReadListener
-     */
-    SET_READ_LISTENER,
-
-    /**
      * Callback to trigger setting the WriteListener
      */
     SET_WRITE_LISTENER,

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1477301&r1=1477300&r2=1477301&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Mon Apr 
29 19:49:24 2013
@@ -23,7 +23,6 @@ import java.nio.channels.SelectionKey;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.net.ssl.SSLEngine;
-import javax.servlet.ReadListener;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.WriteListener;
 
@@ -600,9 +599,6 @@ public class Http11NioProcessor extends 
             if (asyncStateMachine.asyncDispatch()) {
                 
((NioEndpoint)endpoint).dispatchForEvent(this.socket.getSocket(),SocketStatus.OPEN_READ,
 true);
             }
-        } else if (actionCode == ActionCode.SET_READ_LISTENER) {
-            ReadListener listener = (ReadListener)param;
-            request.setReadListener(listener);
         } else if (actionCode == ActionCode.SET_WRITE_LISTENER) {
             WriteListener listener = (WriteListener)param;
             response.setWriteListener(listener);



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

Reply via email to