ASF Bugzilla – Attachment 28407 Details for
Bug 51181
Add support for Web Sockets
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Introduce status code constants
introduce status code constants.patch (text/plain), 13.13 KB, created by
Johno Crawford
on 2012-02-29 15:12:41 UTC
(
hide
)
Description:
Introduce status code constants
Filename:
MIME Type:
Creator:
Johno Crawford
Created:
2012-02-29 15:12:41 UTC
Size:
13.13 KB
patch
obsolete
>Index: test/org/apache/catalina/websocket/TestWebSocket.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- test/org/apache/catalina/websocket/TestWebSocket.java (revision 1294992) >+++ test/org/apache/catalina/websocket/TestWebSocket.java (revision ) >@@ -31,6 +31,9 @@ > > import static org.junit.Assert.assertEquals; > import static org.junit.Assert.assertTrue; >+ >+import org.junit.After; >+import org.junit.Before; > import org.junit.Test; > > import org.apache.catalina.startup.Tomcat; >@@ -44,12 +47,16 @@ > > private static final String CRLF = "\r\n"; > >+ private Socket socket; > private OutputStream os; > private InputStream is; > private boolean isContinuation = false; > >- @Test >- public void testSimple() throws Exception { >+ @Override >+ @Before >+ public void setUp() throws Exception { >+ super.setUp(); >+ > Tomcat tomcat = getTomcatInstance(); > File appDir = new File(getBuildDirectory(), "webapps/examples"); > tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath()); >@@ -59,7 +66,7 @@ > // Open the socket > final String encoding = "ISO-8859-1"; > SocketAddress addr = new InetSocketAddress("localhost", getPort()); >- Socket socket = new Socket(); >+ socket = new Socket(); > socket.setSoTimeout(10000); > socket.connect(addr, 10000); > os = socket.getOutputStream(); >@@ -87,15 +94,22 @@ > while (!responseHeaderLine.equals("")) { > responseHeaderLine = reader.readLine(); > } >+ } > >- // Now we can do WebSocket >+ @Override >+ @After >+ public void tearDown() throws Exception { >+ super.tearDown(); >+ // Finished with the socket >+ socket.close(); >+ } >+ >+ @Test >+ public void testFragmentation() throws IOException { > sendMessage("foo", false); > sendMessage("foo", true); > > assertEquals("foofoo",readMessage()); >- >- // Finished with the socket >- socket.close(); > } > > private void sendMessage(String message, boolean finalFragment) >Index: java/org/apache/catalina/websocket/LocalStrings.properties >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>windows-1252 >=================================================================== >--- java/org/apache/catalina/websocket/LocalStrings.properties (revision 1294992) >+++ java/org/apache/catalina/websocket/LocalStrings.properties (revision ) >@@ -17,7 +17,7 @@ > frame.invalidUtf8=A sequence of bytes was received that did not represent valid UTF-8 > frame.notMasked=The client frame was not masked but all client frames must be masked > >-is.notContinutation=A frame with the OpCode [{0}] was recieved when a continuation frame was expected >+is.notContinuation=A frame with the OpCode [{0}] was received when a continuation frame was expected > is.unknownOpCode=A frame with the unrecognized OpCode [{0}] was received > > message.bufferTooSmall=The buffer is not big enough to contain the message currently being processed >\ No newline at end of file >Index: java/org/apache/catalina/websocket/WsInputStream.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- java/org/apache/catalina/websocket/WsInputStream.java (revision 1294992) >+++ java/org/apache/catalina/websocket/WsInputStream.java (revision ) >@@ -17,6 +17,7 @@ > 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; >@@ -27,7 +28,7 @@ > * makes the number of bytes declared in the payload length available for > * reading even if more bytes are available from the socket. > */ >-public class WsInputStream extends java.io.InputStream { >+public class WsInputStream extends InputStream { > > private static final StringManager sm = > StringManager.getManager(Constants.Package); >@@ -147,7 +148,7 @@ > nextFrame(true); > } > if (frame.getOpCode() != Constants.OPCODE_CONTINUATION) { >- error = sm.getString("is.notContinutation", >+ error = sm.getString("is.notContinuation", > Byte.valueOf(frame.getOpCode())); > throw new IOException(error); > } >Index: java/org/apache/catalina/websocket/StreamInbound.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- java/org/apache/catalina/websocket/StreamInbound.java (revision 1294992) >+++ java/org/apache/catalina/websocket/StreamInbound.java (revision ) >@@ -28,6 +28,8 @@ > import org.apache.coyote.http11.upgrade.UpgradeProcessor; > import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState; > >+import static org.apache.catalina.websocket.Constants.*; >+ > /** > * Base implementation of the class used to process WebSocket connections based > * on streams. Applications should extend this class to provide application >@@ -72,7 +74,7 @@ > try { > // TODO User defined extensions may define values for rsv > if (frame.getRsv() > 0) { >- getWsOutbound().close(1002, null); >+ getWsOutbound().close(STATUS_PROTOCOL_ERROR, null); > return SocketState.CLOSED; > } > >@@ -93,21 +95,21 @@ > // NO-OP > } else { > // Unknown OpCode >- getWsOutbound().close(1002, null); >+ getWsOutbound().close(STATUS_PROTOCOL_ERROR, null); > return SocketState.CLOSED; > } > } catch (MalformedInputException mie) { > // Invalid UTF-8 >- getWsOutbound().close(1007, null); >+ getWsOutbound().close(STATUS_BAD_DATA, null); > return SocketState.CLOSED; > } catch (UnmappableCharacterException uce) { > // Invalid UTF-8 >- getWsOutbound().close(1007, null); >+ getWsOutbound().close(STATUS_BAD_DATA, null); > return SocketState.CLOSED; > } catch (IOException ioe) { > // Given something must have gone to reach this point, this might > // not work but try it anyway. >- getWsOutbound().close(1002, null); >+ getWsOutbound().close(STATUS_PROTOCOL_ERROR, null); > return SocketState.CLOSED; > } > frame = wsIs.nextFrame(false); >Index: java/org/apache/catalina/websocket/Constants.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- java/org/apache/catalina/websocket/Constants.java (revision 1294992) >+++ java/org/apache/catalina/websocket/Constants.java (revision ) >@@ -29,4 +29,87 @@ > public static final byte OPCODE_CLOSE = 0x08; > public static final byte OPCODE_PING = 0x09; > public static final byte OPCODE_PONG = 0x0A; >+ >+ // Status Codes >+ >+ /* >+ * 1000 indicates a normal closure, meaning whatever purpose the >+ * connection was established for has been fulfilled. >+ */ >+ public static final int STATUS_CLOSE_NORMAL = 1000; >+ >+ /* >+ * 1001 indicates that an endpoint is "going away", such as a server >+ * going down, or a browser having navigated away from a page. >+ */ >+ public static final int STATUS_SHUTDOWN = 1001; >+ >+ /* >+ * 1002 indicates that an endpoint is terminating the connection due >+ * to a protocol error. >+ */ >+ public static final int STATUS_PROTOCOL_ERROR = 1002; >+ >+ /* >+ * 1003 indicates that an endpoint is terminating the connection >+ * because it has received a type of data it cannot accept (e.g. an >+ * endpoint that understands only text data MAY send this if it >+ * receives a binary message). >+ */ >+ public static final int STATUS_UNEXPECTED_DATA_TYPE = 1003; >+ >+ // 1004 is reserved. The specific meaning might be defined in the future. >+ >+ /* >+ * 1005 is a reserved value and MUST NOT be set as a status code in a >+ * Close control frame by an endpoint. It is designated for use in >+ * applications expecting a status code to indicate that no status >+ * code was actually present. >+ */ >+ public static final int STATUS_CODE_MISSING = 1005; >+ >+ /* >+ * 1006 is a reserved value and MUST NOT be set as a status code in a >+ * Close control frame by an endpoint. It is designated for use in >+ * applications expecting a status code to indicate that the >+ * connection was closed abnormally, e.g. without sending or >+ * receiving a Close control frame. >+ */ >+ public static final int STATUS_CLOSED_UNEXPECTEDLY = 1006; >+ >+ /* >+ * 1007 indicates that an endpoint is terminating the connection >+ * because it has received data within a message that was not >+ * consistent with the type of the message (e.g., non-UTF-8 [RFC3629] >+ * data within a text message). >+ */ >+ public static final int STATUS_BAD_DATA = 1007; >+ >+ /* >+ * 1008 indicates that an endpoint is terminating the connection >+ * because it has received a message that violates its policy. This >+ * is a generic status code that can be returned when there is no >+ * other more suitable status code (e.g. 1003 or 1009), or if there >+ * is a need to hide specific details about the policy. >+ */ >+ public static final int STATUS_POLICY_VIOLATION = 1008; >+ >+ /* >+ * 1009 indicates that an endpoint is terminating the connection >+ * because it has received a message which is too big for it to >+ * process. >+ */ >+ public static final int STATUS_MESSAGE_TOO_LARGE = 1009; >+ >+ /* >+ * 1010 indicates that an endpoint (client) is terminating the >+ * connection because it has expected the server to negotiate one or >+ * more extension, but the server didn't return them in the response >+ * message of the WebSocket handshake. The list of extensions which >+ * are needed SHOULD appear in the /reason/ part of the Close frame. >+ * Note that this status code is not used by the server, because it >+ * can fail the WebSocket handshake instead. >+ */ >+ public static final int STATUS_REQUIRED_EXTENSION = 1010; >+ > } >Index: java/org/apache/catalina/websocket/WsOutbound.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- java/org/apache/catalina/websocket/WsOutbound.java (revision 1294992) >+++ java/org/apache/catalina/websocket/WsOutbound.java (revision ) >@@ -26,6 +26,8 @@ > import org.apache.tomcat.util.buf.B2CConverter; > import org.apache.tomcat.util.res.StringManager; > >+import static org.apache.catalina.websocket.Constants.*; >+ > /** > * Provides the means to write WebSocket messages to the client. > */ >@@ -88,7 +90,7 @@ > * message started. If the buffer for textual data is full, the buffer will > * be flushed and a new textual continuation fragment started. > * >- * @param b The character to send to the client. >+ * @param c The character to send to the client. > * > * @throws IOException If a flush is required and an error occurs writing > * the WebSocket frame to the client >@@ -141,7 +143,7 @@ > * a WebSocket text message as a single frame with the provided buffer as > * the payload of the message. > * >- * @param msgBb The buffer containing the payload >+ * @param msgCb The buffer containing the payload > * > * @throws IOException If an error occurs writing to the client > */ >@@ -209,7 +211,7 @@ > close(status, frame.getPayLoad()); > } else { > // Invalid close code >- close(1002, null); >+ close(STATUS_PROTOCOL_ERROR, null); > } > } else { > // No status >@@ -220,9 +222,9 @@ > > private boolean validateCloseStatus(int status) { > >- if (status == 1000 || status == 1001 || status == 1002 || >- status == 1003 || status == 1007 || status == 1008 || >- status == 1009 || status == 1010 || status == 1011 || >+ if (status == STATUS_CLOSE_NORMAL || status == STATUS_SHUTDOWN || status == STATUS_PROTOCOL_ERROR || >+ status == STATUS_UNEXPECTED_DATA_TYPE || status == STATUS_BAD_DATA || status == STATUS_POLICY_VIOLATION || >+ status == STATUS_MESSAGE_TOO_LARGE || status == STATUS_REQUIRED_EXTENSION || status == 1011 || > (status > 2999 && status < 5000)) { > // Other 1xxx reserved / not permitted > // 2xxx reserved
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 51181
:
28264
|
28342
|
28396
| 28407 |
28408
|
28410
|
28411
|
28415
|
28416
|
28420
|
28426
|
28457