Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2015-08-27 22:34:45 +0000
committerJoakim Erdfelt2015-08-27 22:34:45 +0000
commit5312f2c0d7ff7a7926e1c2d6105007a5d58751c3 (patch)
tree84805f788a1bb1596451a214b89fcf5a1450a1b6 /jetty-websocket/websocket-api/src
parentcb0852c53cc242116c4a4c9937ec2e3b402d8282 (diff)
parent25cfffbe1ee0eb5cdb43ab394e354d1102c6ee51 (diff)
downloadorg.eclipse.jetty.project-5312f2c0d7ff7a7926e1c2d6105007a5d58751c3.tar.gz
org.eclipse.jetty.project-5312f2c0d7ff7a7926e1c2d6105007a5d58751c3.tar.xz
org.eclipse.jetty.project-5312f2c0d7ff7a7926e1c2d6105007a5d58751c3.zip
Merge branch 'jetty-9.2.x'
Conflicts: jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
Diffstat (limited to 'jetty-websocket/websocket-api/src')
-rw-r--r--jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/CloseStatus.java23
-rw-r--r--jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java9
-rw-r--r--jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/WebSocket.java4
3 files changed, 27 insertions, 9 deletions
diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/CloseStatus.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/CloseStatus.java
index 417221e926..e6a3e895aa 100644
--- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/CloseStatus.java
+++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/CloseStatus.java
@@ -18,33 +18,38 @@
package org.eclipse.jetty.websocket.api;
+import java.nio.charset.StandardCharsets;
+
public class CloseStatus
{
private static final int MAX_CONTROL_PAYLOAD = 125;
- private static final int MAX_REASON_PHRASE = MAX_CONTROL_PAYLOAD - 2;
+ public static final int MAX_REASON_PHRASE = MAX_CONTROL_PAYLOAD - 2;
/**
- * Convenience method for trimming a long reason phrase at the maximum reason phrase length.
+ * Convenience method for trimming a long reason phrase at the maximum reason phrase length of 123 UTF-8 bytes (per WebSocket spec).
*
* @param reason
* the proposed reason phrase
* @return the reason phrase (trimmed if needed)
+ * @deprecated use of this method is strongly discouraged, as it creates too many new objects that are just thrown away to accomplish its goals.
*/
+ @Deprecated
public static String trimMaxReasonLength(String reason)
{
if (reason == null)
{
return null;
}
-
- if (reason.length() > MAX_REASON_PHRASE)
- {
- return reason.substring(0,MAX_REASON_PHRASE);
- }
- else
+
+ byte[] reasonBytes = reason.getBytes(StandardCharsets.UTF_8);
+ if (reasonBytes.length > MAX_REASON_PHRASE)
{
- return reason;
+ byte[] trimmed = new byte[MAX_REASON_PHRASE];
+ System.arraycopy(reasonBytes,0,trimmed,0,MAX_REASON_PHRASE);
+ return new String(trimmed,StandardCharsets.UTF_8);
}
+
+ return reason;
}
private int code;
diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java
index 39e3c97b48..990253fb1b 100644
--- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java
+++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java
@@ -153,6 +153,15 @@ public interface RemoteEndpoint
BatchMode getBatchMode();
/**
+ * Set the batch mode with which messages are sent.
+ *
+ * @param mode
+ * the batch mode to use
+ * @see #flush()
+ */
+ void setBatchMode(BatchMode mode);
+
+ /**
* Flushes messages that may have been batched by the implementation.
*
* @throws IOException
diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/WebSocket.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/WebSocket.java
index 25d1001e7b..111e3a9fa2 100644
--- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/WebSocket.java
+++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/WebSocket.java
@@ -24,6 +24,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.eclipse.jetty.websocket.api.BatchMode;
+
/**
* Tags a POJO as being a WebSocket class.
*/
@@ -40,4 +42,6 @@ public @interface WebSocket
int maxIdleTime() default -2;
int maxTextMessageSize() default -2;
+
+ BatchMode batchMode() default BatchMode.AUTO;
}

Back to the top