diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPolicy.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPolicy.java index 8a4732e13e4..fc15acef46c 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPolicy.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPolicy.java @@ -18,12 +18,13 @@ package org.eclipse.jetty.websocket.api; - /** * Settings for WebSocket operations. */ public class WebSocketPolicy { + private static final int KB = 1024; + public static WebSocketPolicy newClientPolicy() { return new WebSocketPolicy(WebSocketBehavior.CLIENT); @@ -34,45 +35,26 @@ public class WebSocketPolicy return new WebSocketPolicy(WebSocketBehavior.SERVER); } - /** - * Automatically fragment large frames. - *

- * If frames are encountered at size larger than {@link #maxPayloadSize} then they are automatically fragmented into pieces fitting within the - * maxPayloadSize. - *

- * Default: false - */ - private boolean autoFragment = false; - /** * The maximum allowed payload size (validated in both directions) *

* Default: 65536 (64K) */ - private int maxPayloadSize = 65536; + private int maxPayloadSize = 64 * KB; /** * The maximum size of a text message during parsing/generating. *

* Default: 16384 (16 K) */ - private int maxTextMessageSize = 16384; + private int maxTextMessageSize = 64 * KB; /** * The maximum size of a binary message during parsing/generating. *

* Default: -1 (no validation) */ - private int maxBinaryMessageSize = -1; - - /** - * Maximum Message Buffer size, which is also the max frame byte size. - *

- * Default: 65536 (64 K) - */ - private int bufferSize = 65536; - - // TODO: change bufferSize to windowSize for FrameBytes logic? + private int maxBinaryMessageSize = 64 * KB; /** * The time in ms (milliseconds) that a websocket may be idle before closing. @@ -127,9 +109,7 @@ public class WebSocketPolicy public WebSocketPolicy clonePolicy() { WebSocketPolicy clone = new WebSocketPolicy(this.behavior); - clone.autoFragment = this.autoFragment; clone.idleTimeout = this.idleTimeout; - clone.bufferSize = this.bufferSize; clone.maxPayloadSize = this.maxPayloadSize; clone.maxBinaryMessageSize = this.maxBinaryMessageSize; clone.maxTextMessageSize = this.maxTextMessageSize; @@ -141,11 +121,6 @@ public class WebSocketPolicy return behavior; } - public int getBufferSize() - { - return bufferSize; - } - public int getIdleTimeout() { return idleTimeout; @@ -166,21 +141,6 @@ public class WebSocketPolicy return maxTextMessageSize; } - public boolean isAutoFragment() - { - return autoFragment; - } - - public void setAutoFragment(boolean autoFragment) - { - this.autoFragment = autoFragment; - } - - public void setBufferSize(int bufferSize) - { - this.bufferSize = bufferSize; - } - public void setIdleTimeout(int idleTimeout) { this.idleTimeout = idleTimeout; @@ -193,9 +153,9 @@ public class WebSocketPolicy public void setMaxPayloadSize(int maxPayloadSize) { - if (maxPayloadSize < bufferSize) + if (maxPayloadSize < 0) { - throw new IllegalStateException("Cannot have payload size be smaller than buffer size"); + throw new IllegalStateException("Cannot have payload size be a negative number"); } this.maxPayloadSize = maxPayloadSize; } @@ -204,5 +164,4 @@ public class WebSocketPolicy { this.maxTextMessageSize = maxTextMessageSize; } - } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java index 1dfd67dea15..8c69d65f349 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java @@ -176,7 +176,6 @@ public class WebSocketClientTest try { int bufferSize = 512; - factSmall.getPolicy().setBufferSize(512); TrackingSocket wsocket = new TrackingSocket(); WebSocketClient client = factSmall.newWebSocketClient(wsocket); diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AnnotatedEventDriver.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AnnotatedEventDriver.java index 3bf95a5457e..566403b1354 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AnnotatedEventDriver.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AnnotatedEventDriver.java @@ -49,10 +49,6 @@ public class AnnotatedEventDriver extends EventDriver WebSocket anno = websocket.getClass().getAnnotation(WebSocket.class); // Setup the policy - if (anno.maxBufferSize() > 0) - { - this.policy.setBufferSize(anno.maxBufferSize()); - } if (anno.maxBinarySize() > 0) { this.policy.setMaxBinaryMessageSize(anno.maxBinarySize()); diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/RFC6455ExamplesParserTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/RFC6455ExamplesParserTest.java index 3f3114e9f50..ff8958329c9 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/RFC6455ExamplesParserTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/RFC6455ExamplesParserTest.java @@ -175,7 +175,6 @@ public class RFC6455ExamplesParserTest buf.flip(); WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER); - policy.setBufferSize(80000); Parser parser = new UnitParser(policy); IncomingFramesCapture capture = new IncomingFramesCapture(); parser.setIncomingFramesHandler(capture); diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java index 5f78106aa62..c130388173c 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java @@ -38,7 +38,6 @@ public class TextPayloadParserTest { WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER); // Artificially small buffer/payload - policy.setBufferSize(512); policy.setMaxPayloadSize(1024); byte utf[] = new byte[2048]; Arrays.fill(utf,(byte)'a'); @@ -89,7 +88,6 @@ public class TextPayloadParserTest buf.flip(); WebSocketPolicy policy = WebSocketPolicy.newServerPolicy(); - policy.setBufferSize(100000); policy.setMaxPayloadSize(100000); Parser parser = new UnitParser(policy); IncomingFramesCapture capture = new IncomingFramesCapture(); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABServlet.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABServlet.java index b3c0da7bc3c..58d07f7cf79 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABServlet.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABServlet.java @@ -36,7 +36,6 @@ public class ABServlet extends WebSocketServlet // Test cases 9.x uses BIG frame sizes, let policy handle them. int bigFrameSize = 20 * MBYTE; - factory.getPolicy().setBufferSize(bigFrameSize); factory.getPolicy().setMaxPayloadSize(bigFrameSize); factory.getPolicy().setMaxTextMessageSize(bigFrameSize); factory.getPolicy().setMaxBinaryMessageSize(bigFrameSize); diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java index 1f08ab8c496..c1deddecabd 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java @@ -66,10 +66,6 @@ import org.eclipse.jetty.websocket.api.annotations.WebSocket; * basis. * *

- *
bufferSize
- *
can be used to set the buffer size, which is also the max frame byte size
- * Default: 8192
- * *
maxIdleTime
*
set the time in ms that a websocket may be idle before closing
* Default:
@@ -104,12 +100,7 @@ public abstract class WebSocketServlet extends HttpServlet { try { - String bs = getInitParameter("bufferSize"); WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER); - if (bs != null) - { - policy.setBufferSize(Integer.parseInt(bs)); - } String max = getInitParameter("maxIdleTime"); if (max != null) @@ -129,15 +120,18 @@ public abstract class WebSocketServlet extends HttpServlet policy.setMaxBinaryMessageSize(Integer.parseInt(max)); } - WebSocketServletFactory baseFactory ; + WebSocketServletFactory baseFactory; Iterator factories = ServiceLoader.load(WebSocketServletFactory.class).iterator(); - + if (factories.hasNext()) - baseFactory=factories.next(); + { + baseFactory = factories.next(); + } else { - Class wssf= (Class)getServletContext().getClass().getClassLoader().loadClass("org.eclipse.jetty.websocket.server.WebSocketServerFactory"); - baseFactory=wssf.newInstance(); + Class wssf = (Class)getServletContext().getClass().getClassLoader() + .loadClass("org.eclipse.jetty.websocket.server.WebSocketServerFactory"); + baseFactory = wssf.newInstance(); } factory = baseFactory.createFactory(policy);