tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1354477 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/catalina/websocket/ test/org/apache/catalina/websocket/ webapps/docs/ webapps/examples/WEB-INF/classes/websocket/chat/ webapps/examples/WEB-INF/classes/websocket/echo/ webapps/examples...
Date Wed, 27 Jun 2012 12:50:39 GMT
Author: markt
Date: Wed Jun 27 12:50:37 2012
New Revision: 1354477

URL: http://svn.apache.org/viewvc?rev=1354477&view=rev
Log:
Make the request available when the WebSocket connection is being created

Added:
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/WsHttpServletRequestWrapper.java
      - copied, changed from r1354469, tomcat/trunk/java/org/apache/catalina/websocket/WsHttpServletRequestWrapper.java
Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/LocalStrings.properties
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/websocket/TestWebSocket.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
    tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatWebSocketServlet.java
    tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoMessage.java
    tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoStream.java
    tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeWebSocketServlet.java

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1354469

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/LocalStrings.properties?rev=1354477&r1=1354476&r2=1354477&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/LocalStrings.properties (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/LocalStrings.properties Wed Jun
27 12:50:37 2012
@@ -26,4 +26,6 @@ message.bufferTooSmall=The buffer is not
 
 servlet.reqUpgradeFail=Unable to cast to the Tomcat internal request class in order to complete
HTTP upgrade
 
-outbound.closed=The WebSocket connection has been closed
\ No newline at end of file
+outbound.closed=The WebSocket connection has been closed
+
+wrapper.invalid=An attempt was made to access the request object passed to WebSocketServlet.createWebSocketInbound()
outside of that method
\ No newline at end of file

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java?rev=1354477&r1=1354476&r2=1354477&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java Wed Jun
27 12:50:37 2012
@@ -117,7 +117,9 @@ public abstract class WebSocketServlet e
             // TODO
         }
 
-        StreamInbound inbound = createWebSocketInbound(subProtocol);
+        WsHttpServletRequestWrapper wrapper = new WsHttpServletRequestWrapper(req);
+        StreamInbound inbound = createWebSocketInbound(subProtocol, wrapper);
+        wrapper.invalidate();
 
         // Small hack until the Servlet API provides a way to do this.
         ServletRequest inner = req;
@@ -234,6 +236,13 @@ public abstract class WebSocketServlet e
      *
      * @param subProtocol   The sub-protocol agreed between the client and
      *                      server or <code>null</code> if none was agreed
+     * @param request       The HTTP request that initiated this WebSocket
+     *                      connection. Note that this object is <b>only</b>
+     *                      valid inside this method. You must not retain a
+     *                      reference to it outside the execution of this
+     *                      method. If Tomcat detects such access, it will throw
+     *                      an IllegalStateException
      */
-    protected abstract StreamInbound createWebSocketInbound(String subProtocol);
+    protected abstract StreamInbound createWebSocketInbound(String subProtocol,
+            HttpServletRequest request);
 }

Copied: tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/WsHttpServletRequestWrapper.java
(from r1354469, tomcat/trunk/java/org/apache/catalina/websocket/WsHttpServletRequestWrapper.java)
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/WsHttpServletRequestWrapper.java?p2=tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/WsHttpServletRequestWrapper.java&p1=tomcat/trunk/java/org/apache/catalina/websocket/WsHttpServletRequestWrapper.java&r1=1354469&r2=1354477&rev=1354477&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsHttpServletRequestWrapper.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/websocket/WsHttpServletRequestWrapper.java
Wed Jun 27 12:50:37 2012
@@ -38,7 +38,6 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 import javax.servlet.http.Part;
-import javax.servlet.http.ProtocolHandler;
 
 import org.apache.tomcat.util.res.StringManager;
 
@@ -95,11 +94,6 @@ public class WsHttpServletRequestWrapper
     }
 
     @Override
-    public long getContentLengthLong() {
-        return getRequest().getContentLengthLong();
-    }
-
-    @Override
     public String getContentType() {
         return getRequest().getContentType();
     }
@@ -407,9 +401,4 @@ public class WsHttpServletRequestWrapper
     public Part getPart(String name) throws IOException, ServletException {
         return getRequest().getPart(name);
     }
-
-    @Override
-    public void upgrade(ProtocolHandler handler) throws IOException {
-        getRequest().upgrade(handler);
-    }
 }

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/websocket/TestWebSocket.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/websocket/TestWebSocket.java?rev=1354477&r1=1354476&r2=1354477&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/websocket/TestWebSocket.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/websocket/TestWebSocket.java Wed Jun 27
12:50:37 2012
@@ -36,6 +36,7 @@ import java.util.List;
 
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.servlet.http.HttpServletRequest;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -296,7 +297,8 @@ public class TestWebSocket extends Tomca
         private static final long serialVersionUID = 1L;
 
         @Override
-        protected StreamInbound createWebSocketInbound(String subProtocol) {
+        protected StreamInbound createWebSocketInbound(String subProtocol,
+                HttpServletRequest request) {
             return new Bug53339WsInbound();
         }
     }

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1354477&r1=1354476&r2=1354477&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Jun 27 12:50:37 2012
@@ -86,6 +86,10 @@
         <bug>53465</bug>: Populate mapped-name property for resources defined
in
         web.xml. Based on a patch by Violeta Georgieva. (markt) 
       </add>
+      <add>
+        Make the request available when establishing a WebSocket connection.
+        (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">

Modified: tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatWebSocketServlet.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatWebSocketServlet.java?rev=1354477&r1=1354476&r2=1354477&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatWebSocketServlet.java
(original)
+++ tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatWebSocketServlet.java
Wed Jun 27 12:50:37 2012
@@ -23,6 +23,8 @@ import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.catalina.websocket.MessageInbound;
 import org.apache.catalina.websocket.StreamInbound;
 import org.apache.catalina.websocket.WebSocketServlet;
@@ -44,7 +46,8 @@ public class ChatWebSocketServlet extend
             new CopyOnWriteArraySet<ChatMessageInbound>();
 
     @Override
-    protected StreamInbound createWebSocketInbound(String subProtocol) {
+    protected StreamInbound createWebSocketInbound(String subProtocol,
+            HttpServletRequest request) {
         return new ChatMessageInbound(connectionIds.incrementAndGet());
     }
 

Modified: tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoMessage.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoMessage.java?rev=1354477&r1=1354476&r2=1354477&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoMessage.java
(original)
+++ tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoMessage.java
Wed Jun 27 12:50:37 2012
@@ -21,6 +21,7 @@ import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 
 import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
 
 import org.apache.catalina.websocket.MessageInbound;
 import org.apache.catalina.websocket.StreamInbound;
@@ -59,7 +60,8 @@ public class EchoMessage extends WebSock
 
 
     @Override
-    protected StreamInbound createWebSocketInbound(String subProtocol) {
+    protected StreamInbound createWebSocketInbound(String subProtocol,
+            HttpServletRequest request) {
         return new EchoMessageInbound(byteBufSize,charBufSize);
     }
 

Modified: tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoStream.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoStream.java?rev=1354477&r1=1354476&r2=1354477&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoStream.java (original)
+++ tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoStream.java Wed
Jun 27 12:50:37 2012
@@ -20,6 +20,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.catalina.websocket.StreamInbound;
 import org.apache.catalina.websocket.WebSocketServlet;
 import org.apache.catalina.websocket.WsOutbound;
@@ -30,7 +32,8 @@ public class EchoStream extends WebSocke
     private static final long serialVersionUID = 1L;
 
     @Override
-    protected StreamInbound createWebSocketInbound(String subProtocol) {
+    protected StreamInbound createWebSocketInbound(String subProtocol,
+            HttpServletRequest request) {
         return new EchoStreamInbound();
     }
 

Modified: tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeWebSocketServlet.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeWebSocketServlet.java?rev=1354477&r1=1354476&r2=1354477&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeWebSocketServlet.java
(original)
+++ tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeWebSocketServlet.java
Wed Jun 27 12:50:37 2012
@@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHa
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
 
 import org.apache.catalina.websocket.MessageInbound;
 import org.apache.catalina.websocket.StreamInbound;
@@ -148,7 +149,8 @@ public class SnakeWebSocketServlet exten
     }
 
     @Override
-    protected StreamInbound createWebSocketInbound(String subProtocol) {
+    protected StreamInbound createWebSocketInbound(String subProtocol,
+            HttpServletRequest request) {
         return new SnakeMessageInbound(connectionIds.incrementAndGet());
     }
 



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


Mime
View raw message