Author: markt
Date: Sat Nov 24 17:37:31 2012
New Revision: 1413214

URL: http://svn.apache.org/viewvc?rev=1413214&view=rev
Log:
First cut for WebSockets (untested)

Added:
    tomcat/trunk/java/org/apache/catalina/websocket/StreamHandler.java
      - copied, changed from r1413212, 
tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java
Removed:
    tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java
Modified:
    tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java
    tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java
    tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java
    tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
    tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java
    tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java
    
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatWebSocketServlet.java
    
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoMessage.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoStream.java
    
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeWebSocketServlet.java

Modified: 
tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties Sat 
Nov 24 17:37:31 2012
@@ -24,8 +24,6 @@ is.unknownOpCode=A frame with the unreco
 
 message.bufferTooSmall=The buffer is not big enough to contain the message 
currently being processed
 
-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
 
 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/trunk/java/org/apache/catalina/websocket/MessageInbound.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java Sat Nov 
24 17:37:31 2012
@@ -28,9 +28,9 @@ import org.apache.tomcat.util.res.String
  * Base implementation of the class used to process WebSocket connections based
  * on messages. Applications should extend this class to provide application
  * specific functionality. Applications that wish to operate on a stream basis
- * rather than a message basis should use {@link StreamInbound}.
+ * rather than a message basis should use {@link StreamHandler}.
  */
-public abstract class MessageInbound extends StreamInbound {
+public abstract class MessageInbound extends StreamHandler {
 
     private static final StringManager sm =
             StringManager.getManager(Constants.Package);

Copied: tomcat/trunk/java/org/apache/catalina/websocket/StreamHandler.java 
(from r1413212, 
tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java)
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/StreamHandler.java?p2=tomcat/trunk/java/org/apache/catalina/websocket/StreamHandler.java&p1=tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java&r1=1413212&r2=1413214&rev=1413214&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/StreamHandler.java Sat Nov 
24 17:37:31 2012
@@ -24,9 +24,9 @@ import java.nio.ByteBuffer;
 import java.nio.charset.MalformedInputException;
 import java.nio.charset.UnmappableCharacterException;
 
-import org.apache.coyote.http11.upgrade.UpgradeInbound;
-import org.apache.coyote.http11.upgrade.UpgradeOutbound;
-import org.apache.coyote.http11.upgrade.UpgradeProcessor;
+import javax.servlet.http.ProtocolHandler;
+import javax.servlet.http.WebConnection;
+
 import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
 
 /**
@@ -35,16 +35,16 @@ import org.apache.tomcat.util.net.Abstra
  * specific functionality. Applications that wish to operate on a message basis
  * rather than a stream basis should use {@link MessageInbound}.
  */
-public abstract class StreamInbound implements UpgradeInbound {
+public abstract class StreamHandler implements ProtocolHandler {
 
     private final ClassLoader applicationClassLoader;
-    private UpgradeProcessor<?> processor = null;
     private WsOutbound outbound;
+    private InputStream inputStream;
     private int outboundByteBufferSize = WsOutbound.DEFAULT_BUFFER_SIZE;
     private int outboundCharBufferSize = WsOutbound.DEFAULT_BUFFER_SIZE;
 
 
-    public StreamInbound() {
+    public StreamHandler() {
         applicationClassLoader = 
Thread.currentThread().getContextClassLoader();
     }
 
@@ -54,51 +54,12 @@ public abstract class StreamInbound impl
     }
 
 
-    /**
-     * This only applies to the {@link WsOutbound} instance returned from
-     * {@link #getWsOutbound()} created by a subsequent call to
-     * {@link #setUpgradeOutbound(UpgradeOutbound)}. The current
-     * {@link WsOutbound} instance, if any, is not affected.
-     *
-     * @param outboundByteBufferSize
-     */
-    public void setOutboundByteBufferSize(int outboundByteBufferSize) {
-        this.outboundByteBufferSize = outboundByteBufferSize;
-    }
-
-
     public int getOutboundCharBufferSize() {
         return outboundCharBufferSize;
     }
 
 
     /**
-     * This only applies to the {@link WsOutbound} instance returned from
-     * {@link #getWsOutbound()} created by a subsequent call to
-     * {@link #setUpgradeOutbound(UpgradeOutbound)}. The current
-     * {@link WsOutbound} instance, if any, is not affected.
-     *
-     * @param outboundCharBufferSize
-     */
-    public void setOutboundCharBufferSize(int outboundCharBufferSize) {
-        this.outboundCharBufferSize = outboundCharBufferSize;
-    }
-
-
-    @Override
-    public final void setUpgradeOutbound(UpgradeOutbound upgradeOutbound) {
-        outbound = new WsOutbound(upgradeOutbound, outboundByteBufferSize,
-                outboundCharBufferSize);
-    }
-
-
-    @Override
-    public final void setUpgradeProcessor(UpgradeProcessor<?> processor) {
-        this.processor = processor;
-    }
-
-
-    /**
      * Obtain the outbound side of this WebSocket connection used for writing
      * data to the client.
      */
@@ -107,11 +68,10 @@ public abstract class StreamInbound impl
     }
 
 
-    @Override
-    public final SocketState onData() throws IOException {
+    public final SocketState onData() {
         // Must be start the start of a message (which may consist of multiple
         // frames)
-        WsInputStream wsIs = new WsInputStream(processor, getWsOutbound());
+        WsInputStream wsIs = new WsInputStream(inputStream, getWsOutbound());
 
         try {
             WsFrame frame = wsIs.nextFrame(true);
@@ -149,16 +109,28 @@ public abstract class StreamInbound impl
             }
         } catch (MalformedInputException mie) {
             // Invalid UTF-8
-            closeOutboundConnection(Constants.STATUS_BAD_DATA, null);
+            try {
+                closeOutboundConnection(Constants.STATUS_BAD_DATA, null);
+            } catch (IOException e) {
+                // TODO
+            }
             return SocketState.CLOSED;
         } catch (UnmappableCharacterException uce) {
             // Invalid UTF-8
-            closeOutboundConnection(Constants.STATUS_BAD_DATA, null);
+            try {
+                closeOutboundConnection(Constants.STATUS_BAD_DATA, null);
+            } catch (IOException e) {
+                // TODO
+            }
             return SocketState.CLOSED;
         } catch (IOException ioe) {
             // Given something must have gone to reach this point, this
             // might not work but try it anyway.
-            closeOutboundConnection(Constants.STATUS_PROTOCOL_ERROR, null);
+            try {
+                closeOutboundConnection(Constants.STATUS_PROTOCOL_ERROR, null);
+            } catch (IOException e) {
+                // TODO
+            }
             return SocketState.CLOSED;
         }
         return SocketState.UPGRADED;
@@ -219,7 +191,18 @@ public abstract class StreamInbound impl
     }
 
     @Override
-    public final void onUpgradeComplete() {
+    public final void init(WebConnection webConnection) {
+
+        // TODO Make these buffer sizes configurable via the constructor
+        try {
+            inputStream = webConnection.getInputStream();
+            outbound = new WsOutbound(webConnection.getOutputStream(),
+                    outboundByteBufferSize, outboundCharBufferSize);
+        } catch (IOException ioe) {
+            // TODO i18n
+            throw new IllegalStateException(ioe);
+        }
+
         // Need to call onOpen using the web application's class loader
         Thread t = Thread.currentThread();
         ClassLoader cl = t.getContextClassLoader();
@@ -229,6 +212,8 @@ public abstract class StreamInbound impl
         } finally {
             t.setContextClassLoader(cl);
         }
+
+        onData();
     }
 
     /**
@@ -282,17 +267,4 @@ public abstract class StreamInbound impl
      *                      connection.
      */
     protected abstract void onTextData(Reader r) throws IOException;
-
-    /**
-     * This default implementation sets the read timeout to infinite and 
expects
-     * the WebSocket application to close the connection when it is no longer
-     * required. Applications wishing to set an explicit timeout may override
-     * this method and return a value of their choice.
-     *
-     * @return  The read timeout in milliseconds or -1 for infinite
-     */
-    @Override
-    public int getReadTimeout() {
-        return -1;
-    }
 }

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java Sat 
Nov 24 17:37:31 2012
@@ -27,16 +27,13 @@ import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletRequestWrapper;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.ProtocolHandler;
 
-import org.apache.catalina.connector.RequestFacade;
 import org.apache.catalina.util.Base64;
 import org.apache.tomcat.util.buf.B2CConverter;
-import org.apache.tomcat.util.res.StringManager;
 
 /**
  * Provides the base implementation of a Servlet for processing WebSocket
@@ -49,8 +46,6 @@ public abstract class WebSocketServlet e
     private static final byte[] WS_ACCEPT =
             "258EAFA5-E914-47DA-95CA-C5AB0DC85B11".getBytes(
                     B2CConverter.ISO_8859_1);
-    private static final StringManager sm =
-            StringManager.getManager(Constants.Package);
 
     private final Queue<MessageDigest> sha1Helpers =
             new ConcurrentLinkedQueue<>();
@@ -118,21 +113,11 @@ public abstract class WebSocketServlet e
         }
 
         WsHttpServletRequestWrapper wrapper = new 
WsHttpServletRequestWrapper(req);
-        StreamInbound inbound = createWebSocketInbound(subProtocol, wrapper);
+        ProtocolHandler wsHandler =
+                createWebSocketHandler(subProtocol, wrapper);
         wrapper.invalidate();
 
-        // Small hack until the Servlet API provides a way to do this.
-        ServletRequest inner = req;
-        // Unwrap the request
-        while (inner instanceof ServletRequestWrapper) {
-            inner = ((ServletRequestWrapper) inner).getRequest();
-        }
-        if (inner instanceof RequestFacade) {
-            ((RequestFacade) inner).doUpgrade(inbound);
-        } else {
-            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
-                    sm.getString("servlet.reqUpgradeFail"));
-        }
+        req.upgrade(wsHandler);
     }
 
 
@@ -243,6 +228,6 @@ public abstract class WebSocketServlet e
      *                      method. If Tomcat detects such access, it will 
throw
      *                      an IllegalStateException
      */
-    protected abstract StreamInbound createWebSocketInbound(String subProtocol,
-            HttpServletRequest request);
+    protected abstract ProtocolHandler createWebSocketHandler(
+            String subProtocol, HttpServletRequest request);
 }

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java Sat Nov 24 
17:37:31 2012
@@ -18,12 +18,12 @@ package org.apache.catalina.websocket;
 
 import java.io.EOFException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.charset.CoderResult;
 
 import org.apache.catalina.util.Conversions;
-import org.apache.coyote.http11.upgrade.UpgradeProcessor;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -56,14 +56,14 @@ public class WsFrame {
      *                      connection.
      */
     private WsFrame(byte first,
-            UpgradeProcessor<?> processor) throws IOException {
+            InputStream is) throws IOException {
 
         int b = first & 0xFF;
         fin = (b & 0x80) > 0;
         rsv = (b & 0x70) >>> 4;
         opCode = (byte) (b & 0x0F);
 
-        b = blockingRead(processor);
+        b = blockingRead(is);
         // Client data must be masked
         if ((b & 0x80) == 0) {
             throw new IOException(sm.getString("frame.notMasked"));
@@ -72,11 +72,11 @@ public class WsFrame {
         payloadLength = b & 0x7F;
         if (payloadLength == 126) {
             byte[] extended = new byte[2];
-            blockingRead(processor, extended);
+            blockingRead(is, extended);
             payloadLength = Conversions.byteArrayToLong(extended);
         } else if (payloadLength == 127) {
             byte[] extended = new byte[8];
-            blockingRead(processor, extended);
+            blockingRead(is, extended);
             payloadLength = Conversions.byteArrayToLong(extended);
         }
 
@@ -89,12 +89,12 @@ public class WsFrame {
             }
         }
 
-        blockingRead(processor, mask);
+        blockingRead(is, mask);
 
         if (isControl()) {
             // Note: Payload limited to <= 125 bytes by test above
             payload = ByteBuffer.allocate((int) payloadLength);
-            blockingRead(processor, payload);
+            blockingRead(is, payload);
 
             if (opCode == Constants.OPCODE_CLOSE && payloadLength > 2) {
                 // Check close payload - if present - is valid UTF-8
@@ -144,9 +144,9 @@ public class WsFrame {
     /*
      * Blocks until a aingle byte has been read
      */
-    private int blockingRead(UpgradeProcessor<?> processor)
+    private int blockingRead(InputStream is)
             throws IOException {
-        int result = processor.read();
+        int result = is.read();
         if (result == -1) {
             throw new IOException(sm.getString("frame.eos"));
         }
@@ -157,12 +157,13 @@ public class WsFrame {
     /*
      * Blocks until the byte array has been filled.
      */
-    private void blockingRead(UpgradeProcessor<?> processor, byte[] bytes)
+    private void blockingRead(InputStream is, byte[] bytes)
             throws IOException {
         int read = 0;
         int last = 0;
         while (read < bytes.length) {
-            last = processor.read(true, bytes, read, bytes.length - read);
+            // TODO Must block ????
+            last = is.read(bytes, read, bytes.length - read);
             if (last == -1) {
                 throw new IOException(sm.getString("frame.eos"));
             }
@@ -175,11 +176,11 @@ public class WsFrame {
      * Intended to read whole payload and blocks until it has. Therefore able 
to
      * unmask the payload data.
      */
-    private void blockingRead(UpgradeProcessor<?> processor, ByteBuffer bb)
+    private void blockingRead(InputStream is, ByteBuffer bb)
             throws IOException {
         int last = 0;
         while (bb.hasRemaining()) {
-            last = processor.read();
+            last = is.read();
             if (last == -1) {
                 throw new IOException(sm.getString("frame.eos"));
             }
@@ -206,13 +207,14 @@ public class WsFrame {
      *                      exception will trigger the closing of the WebSocket
      *                      connection.
      */
-    public static WsFrame nextFrame(UpgradeProcessor<?> processor,
+    public static WsFrame nextFrame(InputStream is,
             boolean block) throws IOException {
 
         byte[] first = new byte[1];
-        int read = processor.read(block, first, 0, 1);
+        // TODO Must block ?????
+        int read = is.read(first, 0, 1);
         if (read == 1) {
-            return new WsFrame(first[0], processor);
+            return new WsFrame(first[0], is);
         } else if (read == 0) {
             return null;
         } else if (read == -1) {

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java Sat Nov 
24 17:37:31 2012
@@ -19,7 +19,6 @@ package org.apache.catalina.websocket;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.coyote.http11.upgrade.UpgradeProcessor;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -34,7 +33,7 @@ public class WsInputStream extends Input
             StringManager.getManager(Constants.Package);
 
 
-    private final UpgradeProcessor<?> processor;
+    private final InputStream is;
     private final WsOutbound outbound;
 
     private WsFrame frame;
@@ -44,8 +43,8 @@ public class WsInputStream extends Input
     private String error = null;
 
 
-    public WsInputStream(UpgradeProcessor<?> processor, WsOutbound outbound) {
-        this.processor = processor;
+    public WsInputStream(InputStream is, WsOutbound outbound) {
+        this.is = is;
         this.outbound = outbound;
     }
 
@@ -65,7 +64,7 @@ public class WsInputStream extends Input
      * @throws IOException  If a problem occurs reading the data for the frame.
      */
     public WsFrame nextFrame(boolean block) throws IOException {
-        frame = WsFrame.nextFrame(processor, block);
+        frame = WsFrame.nextFrame(is, block);
         if (frame != null) {
             readThisFragment = 0;
             remaining = frame.getPayLoadLength();
@@ -88,7 +87,7 @@ public class WsInputStream extends Input
         remaining--;
         readThisFragment++;
 
-        int masked = processor.read();
+        int masked = is.read();
         if(masked == -1) {
             return -1;
         }
@@ -109,7 +108,8 @@ public class WsInputStream extends Input
         if (len > remaining) {
             len = (int) remaining;
         }
-        int result = processor.read(true, b, off, len);
+        // TODO Must block????
+        int result = is.read(b, off, len);
         if(result == -1) {
             return -1;
         }

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java Sat Nov 24 
17:37:31 2012
@@ -17,12 +17,12 @@
 package org.apache.catalina.websocket;
 
 import java.io.IOException;
+import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.CoderResult;
 
-import org.apache.coyote.http11.upgrade.UpgradeOutbound;
 import org.apache.tomcat.util.buf.B2CConverter;
 import org.apache.tomcat.util.res.StringManager;
 
@@ -38,7 +38,7 @@ public class WsOutbound {
             StringManager.getManager(Constants.Package);
     public static final int DEFAULT_BUFFER_SIZE = 8192;
 
-    private UpgradeOutbound upgradeOutbound;
+    private OutputStream outputStream;
     private ByteBuffer bb;
     private CharBuffer cb;
     private boolean closed = false;
@@ -46,14 +46,14 @@ public class WsOutbound {
     private boolean firstFrame = true;
 
 
-    public WsOutbound(UpgradeOutbound upgradeOutbound) {
-        this(upgradeOutbound, DEFAULT_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
+    public WsOutbound(OutputStream outputStream) {
+        this(outputStream, DEFAULT_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
     }
 
 
-    public WsOutbound(UpgradeOutbound upgradeOutbound, int byteBufferSize,
+    public WsOutbound(OutputStream outputStream, int byteBufferSize,
             int charBufferSize) {
-        this.upgradeOutbound = upgradeOutbound;
+        this.outputStream = outputStream;
         this.bb = ByteBuffer.allocate(byteBufferSize);
         this.cb = CharBuffer.allocate(charBufferSize);
     }
@@ -271,25 +271,25 @@ public class WsOutbound {
         }
         closed = true;
 
-        upgradeOutbound.write(0x88);
+        outputStream.write(0x88);
         if (status == 0) {
-            upgradeOutbound.write(0);
+            outputStream.write(0);
         } else if (data == null || data.position() == data.limit()) {
-            upgradeOutbound.write(2);
-            upgradeOutbound.write(status >>> 8);
-            upgradeOutbound.write(status);
+            outputStream.write(2);
+            outputStream.write(status >>> 8);
+            outputStream.write(status);
         } else {
-            upgradeOutbound.write(2 + data.limit() - data.position());
-            upgradeOutbound.write(status >>> 8);
-            upgradeOutbound.write(status);
-            upgradeOutbound.write(data.array(), data.position(),
+            outputStream.write(2 + data.limit() - data.position());
+            outputStream.write(status >>> 8);
+            outputStream.write(status);
+            outputStream.write(data.array(), data.position(),
                     data.limit() - data.position());
         }
-        upgradeOutbound.flush();
+        outputStream.flush();
 
         bb = null;
         cb = null;
-        upgradeOutbound = null;
+        outputStream = null;
     }
 
 
@@ -331,16 +331,16 @@ public class WsOutbound {
 
         doFlush(true);
 
-        upgradeOutbound.write(0x80 | opcode);
+        outputStream.write(0x80 | opcode);
         if (data == null) {
-            upgradeOutbound.write(0);
+            outputStream.write(0);
         } else {
-            upgradeOutbound.write(data.limit() - data.position());
-            upgradeOutbound.write(data.array(), data.position(),
+            outputStream.write(data.limit() - data.position());
+            outputStream.write(data.array(), data.position(),
                     data.limit() - data.position());
         }
 
-        upgradeOutbound.flush();
+        outputStream.flush();
     }
 
 
@@ -368,31 +368,30 @@ public class WsOutbound {
             }
         }
         // Continuation frame is OpCode 0
-        upgradeOutbound.write(first);
+        outputStream.write(first);
 
         if (buffer.limit() < 126) {
-            upgradeOutbound.write(buffer.limit());
+            outputStream.write(buffer.limit());
         } else if (buffer.limit() < 65536) {
-            upgradeOutbound.write(126);
-            upgradeOutbound.write(buffer.limit() >>> 8);
-            upgradeOutbound.write(buffer.limit() & 0xFF);
+            outputStream.write(126);
+            outputStream.write(buffer.limit() >>> 8);
+            outputStream.write(buffer.limit() & 0xFF);
         } else {
             // Will never be more than 2^31-1
-            upgradeOutbound.write(127);
-            upgradeOutbound.write(0);
-            upgradeOutbound.write(0);
-            upgradeOutbound.write(0);
-            upgradeOutbound.write(0);
-            upgradeOutbound.write(buffer.limit() >>> 24);
-            upgradeOutbound.write(buffer.limit() >>> 16);
-            upgradeOutbound.write(buffer.limit() >>> 8);
-            upgradeOutbound.write(buffer.limit() & 0xFF);
-
+            outputStream.write(127);
+            outputStream.write(0);
+            outputStream.write(0);
+            outputStream.write(0);
+            outputStream.write(0);
+            outputStream.write(buffer.limit() >>> 24);
+            outputStream.write(buffer.limit() >>> 16);
+            outputStream.write(buffer.limit() >>> 8);
+            outputStream.write(buffer.limit() & 0xFF);
         }
 
         // Write the content
-        upgradeOutbound.write(buffer.array(), 0, buffer.limit());
-        upgradeOutbound.flush();
+        outputStream.write(buffer.array(), 0, buffer.limit());
+        outputStream.flush();
 
         // Reset
         if (finalFragment) {

Modified: tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java Sat Nov 
24 17:37:31 2012
@@ -300,7 +300,7 @@ public class TestWebSocket extends Tomca
         private static final long serialVersionUID = 1L;
 
         @Override
-        protected StreamInbound createWebSocketInbound(String subProtocol,
+        protected StreamHandler createWebSocketInbound(String subProtocol,
                 HttpServletRequest request) {
             return new Bug53339WsInbound();
         }

Modified: 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatWebSocketServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatWebSocketServlet.java?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatWebSocketServlet.java
 (original)
+++ 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatWebSocketServlet.java
 Sat Nov 24 17:37:31 2012
@@ -26,7 +26,7 @@ import java.util.concurrent.atomic.Atomi
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.catalina.websocket.MessageInbound;
-import org.apache.catalina.websocket.StreamInbound;
+import org.apache.catalina.websocket.StreamHandler;
 import org.apache.catalina.websocket.WebSocketServlet;
 import org.apache.catalina.websocket.WsOutbound;
 
@@ -46,7 +46,7 @@ public class ChatWebSocketServlet extend
             new CopyOnWriteArraySet<>();
 
     @Override
-    protected StreamInbound createWebSocketInbound(String subProtocol,
+    protected StreamHandler createWebSocketHandler(String subProtocol,
             HttpServletRequest request) {
         return new ChatMessageInbound(connectionIds.incrementAndGet());
     }

Modified: 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoMessage.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoMessage.java?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoMessage.java 
(original)
+++ 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoMessage.java 
Sat Nov 24 17:37:31 2012
@@ -24,7 +24,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.catalina.websocket.MessageInbound;
-import org.apache.catalina.websocket.StreamInbound;
+import org.apache.catalina.websocket.StreamHandler;
 import org.apache.catalina.websocket.WebSocketServlet;
 
 
@@ -60,14 +60,14 @@ public class EchoMessage extends WebSock
 
 
     @Override
-    protected StreamInbound createWebSocketInbound(String subProtocol,
+    protected StreamHandler createWebSocketHandler(String subProtocol,
             HttpServletRequest request) {
-        return new EchoMessageInbound(byteBufSize,charBufSize);
+        return new EchoMessageHandler(byteBufSize,charBufSize);
     }
 
-    private static final class EchoMessageInbound extends MessageInbound {
+    private static final class EchoMessageHandler extends MessageInbound {
 
-        public EchoMessageInbound(int byteBufferMaxSize, int 
charBufferMaxSize) {
+        public EchoMessageHandler(int byteBufferMaxSize, int 
charBufferMaxSize) {
             super();
             setByteBufferMaxSize(byteBufferMaxSize);
             setCharBufferMaxSize(charBufferMaxSize);

Modified: 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoStream.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoStream.java?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoStream.java 
(original)
+++ 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoStream.java 
Sat Nov 24 17:37:31 2012
@@ -22,7 +22,7 @@ import java.io.Reader;
 
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.catalina.websocket.StreamInbound;
+import org.apache.catalina.websocket.StreamHandler;
 import org.apache.catalina.websocket.WebSocketServlet;
 import org.apache.catalina.websocket.WsOutbound;
 
@@ -32,12 +32,12 @@ public class EchoStream extends WebSocke
     private static final long serialVersionUID = 1L;
 
     @Override
-    protected StreamInbound createWebSocketInbound(String subProtocol,
+    protected StreamHandler createWebSocketHandler(String subProtocol,
             HttpServletRequest request) {
         return new EchoStreamInbound();
     }
 
-    private static final class EchoStreamInbound extends StreamInbound {
+    private static final class EchoStreamInbound extends StreamHandler {
 
         @Override
         protected void onBinaryData(InputStream is) throws IOException {

Modified: 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeWebSocketServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeWebSocketServlet.java?rev=1413214&r1=1413213&r2=1413214&view=diff
==============================================================================
--- 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeWebSocketServlet.java
 (original)
+++ 
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeWebSocketServlet.java
 Sat Nov 24 17:37:31 2012
@@ -33,7 +33,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.catalina.websocket.MessageInbound;
-import org.apache.catalina.websocket.StreamInbound;
+import org.apache.catalina.websocket.StreamHandler;
 import org.apache.catalina.websocket.WebSocketServlet;
 import org.apache.catalina.websocket.WsOutbound;
 import org.apache.juli.logging.Log;
@@ -149,7 +149,7 @@ public class SnakeWebSocketServlet exten
     }
 
     @Override
-    protected StreamInbound createWebSocketInbound(String subProtocol,
+    protected StreamHandler createWebSocketHandler(String subProtocol,
             HttpServletRequest request) {
         return new SnakeMessageInbound(connectionIds.incrementAndGet());
     }



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

Reply via email to