[prev in list] [next in list] [prev in thread] [next in thread]
List: tomcat-dev
Subject: svn commit: r1295284 - in /tomcat/trunk/java/org/apache/catalina/websocket: Constants.java LocalStri
From: markt () apache ! org
Date: 2012-02-29 21:24:19
Message-ID: 20120229212420.2D1E823888D2 () eris ! apache ! org
[Download RAW message or body]
Author: markt
Date: Wed Feb 29 21:24:19 2012
New Revision: 1295284
URL: http://svn.apache.org/viewvc?rev=1295284&view=rev
Log:
Use constants for close code and fix various typos.
Patch provided by Johno Crawford.
Modified:
tomcat/trunk/java/org/apache/catalina/websocket/Constants.java
tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties
tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java
tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java
Modified: tomcat/trunk/java/org/apache/catalina/websocket/Constants.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/Constants.java?rev=1295284&r1=1295283&r2=1295284&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/Constants.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/Constants.java Wed Feb 29 \
21:24:19 2012 @@ -29,4 +29,93 @@ public class Constants {
public static final byte OPCODE_CLOSE = 0x08;
public static final byte OPCODE_PING = 0x09;
public static final byte OPCODE_PONG = 0x0A;
+
+ // Status Codes
+ // Definitions as per RFC 6455 (http://tools.ietf.org/html/rfc6455)
+ /**
+ * 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;
+
+ /**
+ * 1011 indicates that a server is terminating the connection because it
+ * encountered an unexpected condition that prevented it from fulfilling the
+ * request.
+ */
+ public static final int STATUS_UNEXPECTED_CONDITION = 1011;
}
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=1295284&r1=1295283&r2=1295284&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties \
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties Wed Feb \
29 21:24:19 2012 @@ -17,7 +17,7 @@ frame.eos=The end of the stream was reac
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
Modified: tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java?rev=1295284&r1=1295283&r2=1295284&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java Wed Feb 29 \
21:24:19 2012 @@ -113,7 +113,8 @@ public abstract class StreamInbound impl
try {
// TODO User defined extensions may define values for rsv
if (frame.getRsv() > 0) {
- getWsOutbound().close(1002, null);
+ getWsOutbound().close(
+ Constants.STATUS_PROTOCOL_ERROR, null);
return SocketState.CLOSED;
}
@@ -134,21 +135,22 @@ public abstract class StreamInbound impl
// NO-OP
} else {
// Unknown OpCode
- getWsOutbound().close(1002, null);
+ getWsOutbound().close(
+ Constants.STATUS_PROTOCOL_ERROR, null);
return SocketState.CLOSED;
}
} catch (MalformedInputException mie) {
// Invalid UTF-8
- getWsOutbound().close(1007, null);
+ getWsOutbound().close(Constants.STATUS_BAD_DATA, null);
return SocketState.CLOSED;
} catch (UnmappableCharacterException uce) {
// Invalid UTF-8
- getWsOutbound().close(1007, null);
+ getWsOutbound().close(Constants.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);
+ // Given something must have gone to reach this point, this
+ // might not work but try it anyway.
+ getWsOutbound().close(Constants.STATUS_PROTOCOL_ERROR, null);
return SocketState.CLOSED;
}
frame = wsIs.nextFrame(false);
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=1295284&r1=1295283&r2=1295284&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java Wed Feb 29 \
21:24:19 2012 @@ -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 @@ import org.apache.tomcat.util.res.String
* 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 @@ public class WsInputStream extends java.
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);
}
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=1295284&r1=1295283&r2=1295284&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java Wed Feb 29 \
21:24:19 2012 @@ -96,7 +96,7 @@ public class WsOutbound {
* 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
@@ -151,7 +151,7 @@ public class WsOutbound {
* 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
*/
@@ -221,7 +221,7 @@ public class WsOutbound {
close(status, frame.getPayLoad());
} else {
// Invalid close code
- close(1002, null);
+ close(Constants.STATUS_PROTOCOL_ERROR, null);
}
} else {
// No status
@@ -232,9 +232,15 @@ public class WsOutbound {
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 == Constants.STATUS_CLOSE_NORMAL ||
+ status == Constants.STATUS_SHUTDOWN ||
+ status == Constants.STATUS_PROTOCOL_ERROR ||
+ status == Constants.STATUS_UNEXPECTED_DATA_TYPE ||
+ status == Constants.STATUS_BAD_DATA ||
+ status == Constants.STATUS_POLICY_VIOLATION ||
+ status == Constants.STATUS_MESSAGE_TOO_LARGE ||
+ status == Constants.STATUS_REQUIRED_EXTENSION ||
+ status == Constants.STATUS_UNEXPECTED_CONDITION ||
(status > 2999 && status < 5000)) {
// Other 1xxx reserved / not permitted
// 2xxx reserved
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic