diff --git a/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java b/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java index c40004e2ae9..4aeb62293fa 100644 --- a/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java +++ b/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java @@ -46,7 +46,6 @@ import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.ProtocolException; -import org.eclipse.jetty.websocket.core.WebSocketConstants; import org.eclipse.jetty.websocket.core.WebSocketException; import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders; import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryMessageSink; @@ -111,8 +110,6 @@ public class JavaxWebSocketFrameHandler implements FrameHandler private MessageSink textSink; private MessageSink binarySink; private MessageSink activeMessageSink; - private int maxTextMessageBufferSize = WebSocketConstants.DEFAULT_MAX_TEXT_MESSAGE_SIZE; - private int maxBinaryMessageBufferSize = WebSocketConstants.DEFAULT_MAX_BINARY_MESSAGE_SIZE; private JavaxWebSocketSession session; private Map messageHandlerMap; private CoreSession coreSession; @@ -171,26 +168,6 @@ public class JavaxWebSocketFrameHandler implements FrameHandler return session; } - public int getMaxTextMessageBufferSize() - { - return maxTextMessageBufferSize; - } - - public void setMaxTextMessageBufferSize(int maxTextMessageBufferSize) - { - this.maxTextMessageBufferSize = maxTextMessageBufferSize; - } - - public int getMaxBinaryMessageBufferSize() - { - return maxBinaryMessageBufferSize; - } - - public void setMaxBinaryMessageBufferSize(int maxBinaryMessageBufferSize) - { - this.maxBinaryMessageBufferSize = maxBinaryMessageBufferSize; - } - @Override public void onOpen(CoreSession coreSession, Callback callback) { @@ -210,6 +187,9 @@ public class JavaxWebSocketFrameHandler implements FrameHandler if (actualTextMetadata != null) { + if (actualTextMetadata.isMaxMessageSizeSet()) + session.setMaxTextMessageBufferSize(actualTextMetadata.maxMessageSize); + actualTextMetadata.handle = InvokerUtils.bindTo(actualTextMetadata.handle, endpointInstance, endpointConfig, session); actualTextMetadata.handle = JavaxWebSocketFrameHandlerFactory.wrapNonVoidReturnType(actualTextMetadata.handle, session); textSink = JavaxWebSocketFrameHandlerFactory.createMessageSink(session, actualTextMetadata); @@ -219,6 +199,9 @@ public class JavaxWebSocketFrameHandler implements FrameHandler if (actualBinaryMetadata != null) { + if (actualBinaryMetadata.isMaxMessageSizeSet()) + session.setMaxBinaryMessageBufferSize(actualBinaryMetadata.maxMessageSize); + actualBinaryMetadata.handle = InvokerUtils.bindTo(actualBinaryMetadata.handle, endpointInstance, endpointConfig, session); actualBinaryMetadata.handle = JavaxWebSocketFrameHandlerFactory.wrapNonVoidReturnType(actualBinaryMetadata.handle, session); binarySink = JavaxWebSocketFrameHandlerFactory.createMessageSink(session, actualBinaryMetadata); diff --git a/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandlerFactory.java b/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandlerFactory.java index 778b3a3d695..cf37b660e2f 100644 --- a/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandlerFactory.java +++ b/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandlerFactory.java @@ -179,11 +179,6 @@ public abstract class JavaxWebSocketFrameHandlerFactory config, future); - if (metadata.hasTextMetdata() && metadata.getTextMetadata().isMaxMessageSizeSet()) - frameHandler.setMaxTextMessageBufferSize(metadata.getTextMetadata().maxMessageSize); - if (metadata.hasBinaryMetadata() && metadata.getBinaryMetadata().isMaxMessageSizeSet()) - frameHandler.setMaxBinaryMessageBufferSize(metadata.getBinaryMetadata().maxMessageSize); - return frameHandler; } diff --git a/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java b/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java index 357d8538e8d..5de50d041c3 100644 --- a/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java +++ b/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; + import javax.websocket.CloseReason; import javax.websocket.EndpointConfig; import javax.websocket.Extension; @@ -319,7 +320,8 @@ public class JavaxWebSocketSession extends AbstractLifeCycle implements javax.we @Override public int getMaxBinaryMessageBufferSize() { - return frameHandler.getMaxBinaryMessageBufferSize(); + long maxBinaryMsgSize = coreSession.getMaxBinaryMessageSize(); + return (maxBinaryMsgSize > (long)Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)maxBinaryMsgSize; } /** @@ -332,7 +334,7 @@ public class JavaxWebSocketSession extends AbstractLifeCycle implements javax.we @Override public void setMaxBinaryMessageBufferSize(int length) { - frameHandler.setMaxBinaryMessageBufferSize(length); + coreSession.setMaxBinaryMessageSize(length); } /** @@ -368,7 +370,8 @@ public class JavaxWebSocketSession extends AbstractLifeCycle implements javax.we @Override public int getMaxTextMessageBufferSize() { - return frameHandler.getMaxTextMessageBufferSize(); + long maxTextMsgSize = coreSession.getMaxTextMessageSize(); + return (maxTextMsgSize > (long)Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)maxTextMsgSize; } /** @@ -381,7 +384,7 @@ public class JavaxWebSocketSession extends AbstractLifeCycle implements javax.we @Override public void setMaxTextMessageBufferSize(int length) { - frameHandler.setMaxTextMessageBufferSize(length); + coreSession.setMaxTextMessageSize(length); } /** diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java index 73d1ffb23bd..391163824dc 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java @@ -502,6 +502,9 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio @Override public void onFrame(Frame frame, Callback callback) { + if (LOG.isDebugEnabled()) + LOG.debug("onFrame({})", frame); + try { assertValidIncoming(frame); @@ -587,6 +590,9 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio @Override public void abort() { + if (LOG.isDebugEnabled()) + LOG.debug("abort(): {}", this); + connection.cancelDemand(); connection.getEndPoint().close(); } @@ -673,8 +679,7 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio try { if (LOG.isDebugEnabled()) - LOG.debug("receiveFrame({}, {}) - connectionState={}, handler={}", - frame, callback, channelState, handler); + LOG.debug("receiveFrame({}, {}) - connectionState={}, handler={}", frame, callback, channelState, handler); boolean closeConnection = channelState.onIncomingFrame(frame);