From 2d5fa0a3bc8eb17518bcda1eb1e09c2aa69aec4c Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Mon, 2 Jul 2012 16:06:43 -0500 Subject: [PATCH] close short to int --- jetty-websocket/pom.xml | 2 +- .../jetty/websocket/api/CloseException.java | 10 +++---- .../jetty/websocket/api/StatusCode.java | 26 +++++++++---------- .../jetty/websocket/frames/ControlFrame.java | 5 ++-- .../parser/ClosePayloadParserTest.java | 6 ++--- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/jetty-websocket/pom.xml b/jetty-websocket/pom.xml index 4dd8817c856..0501bf303f6 100644 --- a/jetty-websocket/pom.xml +++ b/jetty-websocket/pom.xml @@ -14,7 +14,7 @@ websocket-core - websocket-client + websocket-server diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/CloseException.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/CloseException.java index aa3c41a191a..fdfe9d0e4c5 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/CloseException.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/CloseException.java @@ -3,27 +3,27 @@ package org.eclipse.jetty.websocket.api; @SuppressWarnings("serial") public class CloseException extends WebSocketException { - private short statusCode; + private int statusCode; - public CloseException(short closeCode, String message) + public CloseException(int closeCode, String message) { super(message); this.statusCode = closeCode; } - public CloseException(short closeCode, String message, Throwable cause) + public CloseException(int closeCode, String message, Throwable cause) { super(message,cause); this.statusCode = closeCode; } - public CloseException(short closeCode, Throwable cause) + public CloseException(int closeCode, Throwable cause) { super(cause); this.statusCode = closeCode; } - public short getStatusCode() + public int getStatusCode() { return statusCode; } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/StatusCode.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/StatusCode.java index 78e3559e326..89906c5cba5 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/StatusCode.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/StatusCode.java @@ -10,53 +10,53 @@ public class StatusCode *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short NORMAL = 1000; + public final static int 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. *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short SHUTDOWN = 1001; + public final static int SHUTDOWN = 1001; /** * 1002 indicates that an endpoint is terminating the connection due to a protocol error. *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short PROTOCOL = 1002; + public final static int PROTOCOL = 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). *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short BAD_DATA = 1003; + public final static int BAD_DATA = 1003; /** * Reserved. The specific meaning might be defined in the future. *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short UNDEFINED = 1004; + public final static int UNDEFINED = 1004; /** * 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. *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short NO_CODE = 1005; + public final static int NO_CODE = 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. *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short NO_CLOSE = 1006; + public final static int NO_CLOSE = 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). *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short BAD_PAYLOAD = 1007; + public final static int BAD_PAYLOAD = 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 @@ -64,13 +64,13 @@ public class StatusCode *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short POLICY_VIOLATION = 1008; + public final static int POLICY_VIOLATION = 1008; /** * 1009 indicates that an endpoint is terminating the connection because it has received a message that is too big for it to process. *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short MESSAGE_TOO_LARGE = 1009; + public final static int 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 that are needed SHOULD appear in the /reason/ part @@ -78,18 +78,18 @@ public class StatusCode *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short REQUIRED_EXTENSION = 1010; + public final static int 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. *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short SERVER_ERROR = 1011; + public final static int SERVER_ERROR = 1011; /** * 1015 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 due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified). *

* See RFC 6455, Section 7.4.1 Defined Status Codes. */ - public final static short FAILED_TLS_HANDSHAKE = 1015; + public final static int FAILED_TLS_HANDSHAKE = 1015; } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java index 9326f1e4209..96d9141e02b 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java @@ -4,7 +4,6 @@ import java.nio.ByteBuffer; import org.eclipse.jetty.websocket.api.OpCode; import org.eclipse.jetty.websocket.api.ProtocolException; -import org.eclipse.jetty.websocket.api.WebSocketException; public abstract class ControlFrame extends BaseFrame { @@ -40,9 +39,9 @@ public abstract class ControlFrame extends BaseFrame @Override public void setPayload(byte[] buf) { - if ( buf.length > 125 ) + if (buf.length > MAX_PAYLOAD) { - throw new WebSocketException("Control Payloads can not exceed 125 bytes in length."); + throw new ProtocolException("Control Payloads can not exceed 125 bytes in length."); } super.setPayload(buf); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/parser/ClosePayloadParserTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/parser/ClosePayloadParserTest.java index 6280a3b4e0c..bee74aadb87 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/parser/ClosePayloadParserTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/parser/ClosePayloadParserTest.java @@ -1,6 +1,6 @@ package org.eclipse.jetty.websocket.parser; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; import java.nio.ByteBuffer; @@ -22,7 +22,7 @@ public class ClosePayloadParserTest byte utf[] = expectedReason.getBytes(StringUtil.__UTF8_CHARSET); ByteBuffer payload = ByteBuffer.allocate(utf.length + 2); - payload.putShort(StatusCode.NORMAL); + payload.putChar((char)StatusCode.NORMAL); payload.put(utf,0,utf.length); payload.flip(); @@ -42,7 +42,7 @@ public class ClosePayloadParserTest capture.assertNoErrors(); capture.assertHasFrame(CloseFrame.class,1); CloseFrame close = (CloseFrame)capture.getFrames().get(0); - Assert.assertThat("CloseFrame.statusCode",(short)close.getStatusCode(),is(StatusCode.NORMAL)); + Assert.assertThat("CloseFrame.statusCode",close.getStatusCode(),is(StatusCode.NORMAL)); Assert.assertThat("CloseFrame.data",close.getReason(),is(expectedReason)); } }