From 0d571ef2c24a7388a0031e5c972abd6be5667534 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Mon, 30 Dec 2019 13:25:30 +1100 Subject: [PATCH 01/21] Issue #4450 - websocket Extensions no longer rely upon WSCoreSession Signed-off-by: Lachlan Roberts --- .../jetty/websocket/core/AbstractExtension.java | 12 ++++++------ .../eclipse/jetty/websocket/core/Extension.java | 6 +++--- .../websocket/core/internal/ExtensionStack.java | 2 +- .../internal/PerMessageDeflateExtension.java | 8 ++++---- .../core/internal/ValidationExtension.java | 16 ++++++++++++++-- .../websocket/core/extensions/ExtensionTool.java | 2 +- .../PerMessageDeflateExtensionTest.java | 10 +++++----- 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java index e3c629d5e67..2af69bef8e5 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java @@ -26,7 +26,7 @@ import org.eclipse.jetty.util.compression.DeflaterPool; import org.eclipse.jetty.util.compression.InflaterPool; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession; +import org.eclipse.jetty.websocket.core.FrameHandler.Configuration; @ManagedObject("Abstract Extension") public class AbstractExtension implements Extension @@ -36,7 +36,7 @@ public class AbstractExtension implements Extension private ExtensionConfig config; private OutgoingFrames nextOutgoing; private IncomingFrames nextIncoming; - private WebSocketCoreSession coreSession; + private Configuration configuration; private DeflaterPool deflaterPool; private InflaterPool inflaterPool; @@ -169,14 +169,14 @@ public class AbstractExtension implements Extension } @Override - public void setWebSocketCoreSession(WebSocketCoreSession coreSession) + public void setConfiguration(Configuration configuration) { - this.coreSession = coreSession; + this.configuration = configuration; } - protected WebSocketCoreSession getWebSocketCoreSession() + protected Configuration getConfiguration() { - return coreSession; + return configuration; } @Override diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java index 0fd66060372..0d97a2be44c 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java @@ -18,7 +18,7 @@ package org.eclipse.jetty.websocket.core; -import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession; +import org.eclipse.jetty.websocket.core.FrameHandler.Configuration; /** * Interface for WebSocket Extensions. @@ -88,7 +88,7 @@ public interface Extension extends IncomingFrames, OutgoingFrames void setNextOutgoingFrames(OutgoingFrames nextOutgoing); /** - * Set the {@link WebSocketCoreSession} for this Extension + * Set the {@link Configuration} for this Extension. */ - void setWebSocketCoreSession(WebSocketCoreSession coreSession); + void setConfiguration(Configuration configuration); } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java index 25f9d799b2e..e9784c01a60 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java @@ -254,7 +254,7 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable for (Extension extension : extensions) { - extension.setWebSocketCoreSession(coreSession); + extension.setConfiguration(coreSession); } } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java index 3e79d933285..90e333c9c10 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java @@ -269,7 +269,7 @@ public class PerMessageDeflateExtension extends AbstractExtension private boolean deflate(Callback callback) { // Get a buffer for the inflated payload. - long maxFrameSize = getWebSocketCoreSession().getMaxFrameSize(); + long maxFrameSize = getConfiguration().getMaxFrameSize(); int bufferSize = (maxFrameSize <= 0) ? deflateBufferSize : (int)Math.min(maxFrameSize, deflateBufferSize); final ByteBuffer buffer = getBufferPool().acquire(bufferSize, false); callback = Callback.from(callback, () -> getBufferPool().release(buffer)); @@ -289,7 +289,7 @@ public class PerMessageDeflateExtension extends AbstractExtension if (buffer.limit() == bufferSize) { // We need to fragment. TODO: what if there was only bufferSize of content? - if (!getWebSocketCoreSession().isAutoFragment()) + if (!getConfiguration().isAutoFragment()) throw new MessageTooLargeException("Deflated payload exceeded the compress buffer size"); break; } @@ -402,7 +402,7 @@ public class PerMessageDeflateExtension extends AbstractExtension private boolean inflate(Callback callback) throws DataFormatException { // Get a buffer for the inflated payload. - long maxFrameSize = getWebSocketCoreSession().getMaxFrameSize(); + long maxFrameSize = getConfiguration().getMaxFrameSize(); int bufferSize = (maxFrameSize <= 0) ? inflateBufferSize : (int)Math.min(maxFrameSize, inflateBufferSize); final ByteBuffer payload = getBufferPool().acquire(bufferSize, false); callback = Callback.from(callback, () -> getBufferPool().release(payload)); @@ -421,7 +421,7 @@ public class PerMessageDeflateExtension extends AbstractExtension if (payload.limit() == bufferSize) { // We need to fragment. TODO: what if there was only bufferSize of content? - if (!getWebSocketCoreSession().isAutoFragment()) + if (!getConfiguration().isAutoFragment()) throw new MessageTooLargeException("Inflated payload exceeded the decompress buffer size"); break; } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java index 496ea84eb16..bbce3306a04 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java @@ -26,6 +26,7 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.AbstractExtension; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; +import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.NullAppendable; import org.eclipse.jetty.websocket.core.ProtocolException; import org.eclipse.jetty.websocket.core.WebSocketComponents; @@ -38,6 +39,7 @@ public class ValidationExtension extends AbstractExtension { private static final Logger LOG = Log.getLogger(ValidationExtension.class); + private WebSocketCoreSession coreSession; private FrameSequence incomingSequence = null; private FrameSequence outgoingSequence = null; private boolean incomingFrameValidation = false; @@ -53,6 +55,16 @@ public class ValidationExtension extends AbstractExtension return "@validation"; } + @Override + public void setConfiguration(FrameHandler.Configuration configuration) + { + super.setConfiguration(configuration); + + if (!(configuration instanceof WebSocketCoreSession)) + throw new IllegalArgumentException("ValidationExtension needs a CoreSession Configuration"); + coreSession = (WebSocketCoreSession)configuration; + } + @Override public void onFrame(Frame frame, Callback callback) { @@ -62,7 +74,7 @@ public class ValidationExtension extends AbstractExtension incomingSequence.check(frame.getOpCode(), frame.isFin()); if (incomingFrameValidation) - getWebSocketCoreSession().assertValidIncoming(frame); + coreSession.assertValidIncoming(frame); if (incomingUtf8Validation != null) validateUTF8(frame, incomingUtf8Validation, continuedInOpCode); @@ -85,7 +97,7 @@ public class ValidationExtension extends AbstractExtension outgoingSequence.check(frame.getOpCode(), frame.isFin()); if (outgoingFrameValidation) - getWebSocketCoreSession().assertValidOutgoing(frame); + coreSession.assertValidOutgoing(frame); if (outgoingUtf8Validation != null) validateUTF8(frame, outgoingUtf8Validation, continuedOutOpCode); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java index 890038716e1..b398cb3725b 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java @@ -77,7 +77,7 @@ public class ExtensionTool { this.ext = components.getExtensionRegistry().newInstance(extConfig, components); this.ext.setNextIncomingFrames(capture); - this.ext.setWebSocketCoreSession(newWebSocketCoreSession()); + this.ext.setConfiguration(newWebSocketCoreSession()); } public void parseIncomingHex(String... rawhex) diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java index 4366bff8d3f..01f8ca30b5e 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java @@ -135,7 +135,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest tester.assertNegotiated("permessage-deflate"); - tester.parseIncomingHex( // context takeover (2 messages) + tester.parseIncomingHex(// context takeover (2 messages) // message 1 "0xc1 0x07", // (HEADER added for this test) "0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00", @@ -376,7 +376,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); ExtensionConfig config = ExtensionConfig.parse("permessage-deflate"); ext.init(config, components); - ext.setWebSocketCoreSession(newSession()); + ext.setConfiguration(newSession()); // Setup capture of incoming frames IncomingFramesCapture capture = new IncomingFramesCapture(); @@ -450,7 +450,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest { PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); ext.init(ExtensionConfig.parse("permessage-deflate"), components); - ext.setWebSocketCoreSession(newSession()); + ext.setConfiguration(newSession()); // Setup capture of outgoing frames OutgoingFramesCapture capture = new OutgoingFramesCapture(); @@ -497,7 +497,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); ExtensionConfig config = ExtensionConfig.parse("permessage-deflate"); ext.init(config, components); - ext.setWebSocketCoreSession(newSession()); + ext.setConfiguration(newSession()); // Setup capture of incoming frames OutgoingFramesCapture capture = new OutgoingFramesCapture(); @@ -548,7 +548,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest // Captured from Pywebsocket (r790) - "tora" sent 3 times. - tester.parseIncomingHex( // context takeover (3 messages) + tester.parseIncomingHex(// context takeover (3 messages) "c1 06 2a c9 2f 4a 04 00", // tora 1 "c1 05 2a 01 62 00 00", // tora 2 "c1 04 02 61 00 00" // tora 3 From cf31ab2b9a642a574cf17ecb7b3c49b1d198404d Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Mon, 30 Dec 2019 13:38:05 +1100 Subject: [PATCH 02/21] Issue #4450 - don't expose ExtensionStack through getter on Negotation Signed-off-by: Lachlan Roberts --- .../websocket/core/server/Negotiation.java | 19 ------------------- .../server/internal/AbstractHandshaker.java | 13 ++++++++++--- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java index e7c46ac9d7f..8ded5db6316 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java @@ -31,7 +31,6 @@ import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.QuotedCSV; import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.websocket.core.Behavior; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; @@ -184,24 +183,6 @@ public abstract class Negotiation extensionStack = null; } - public ExtensionStack getExtensionStack() - { - if (extensionStack == null) - { - // Extension stack can decide to drop any of these extensions or their parameters - extensionStack = new ExtensionStack(components, Behavior.SERVER); - extensionStack.negotiate(offeredExtensions, negotiatedExtensions); - negotiatedExtensions = extensionStack.getNegotiatedExtensions(); - - if (extensionStack.hasNegotiatedExtensions()) - baseRequest.getResponse().setHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS, - ExtensionConfig.toHeaderValue(negotiatedExtensions)); - else - baseRequest.getResponse().setHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS, null); - } - return extensionStack; - } - @Override public String toString() { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java index 6647862e817..61c6b2e3c58 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java @@ -62,7 +62,8 @@ public abstract class AbstractHandshaker implements Handshaker if (!validateRequest(request)) return false; - Negotiation negotiation = newNegotiation(request, response, negotiator.getWebSocketComponents()); + WebSocketComponents components = negotiator.getWebSocketComponents(); + Negotiation negotiation = newNegotiation(request, response, components); if (LOG.isDebugEnabled()) LOG.debug("negotiation {}", negotiation); negotiation.negotiate(); @@ -123,8 +124,14 @@ public abstract class AbstractHandshaker implements Handshaker throw new WebSocketException("Upgrade failed: multiple negotiated extensions of the same name"); } - // Create and Negotiate the ExtensionStack - ExtensionStack extensionStack = negotiation.getExtensionStack(); + // Create and Negotiate the ExtensionStack. (ExtensionStack can drop any extensions or their parameters.) + ExtensionStack extensionStack = new ExtensionStack(components, Behavior.SERVER); + extensionStack.negotiate(negotiation.getOfferedExtensions(), negotiation.getNegotiatedExtensions()); + negotiation.setNegotiatedExtensions(extensionStack.getNegotiatedExtensions()); + if (extensionStack.hasNegotiatedExtensions()) + baseRequest.getResponse().setHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS, ExtensionConfig.toHeaderValue(negotiation.getNegotiatedExtensions())); + else + baseRequest.getResponse().setHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS, null); Negotiated negotiated = new Negotiated(baseRequest.getHttpURI().toURI(), protocol, baseRequest.isSecure(), extensionStack, WebSocketConstants.SPEC_VERSION_STRING); From f1838c5f88b0931d090b74bf1da7a3477faa91cb Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Mon, 30 Dec 2019 13:50:00 +1100 Subject: [PATCH 03/21] Issue #4450 - remove methods to create WS CoreSession and Connection Signed-off-by: Lachlan Roberts --- .../core/client/ClientUpgradeRequest.java | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java index aacafa94ddb..566f9961d87 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java @@ -26,7 +26,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -44,14 +43,12 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpVersion; -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.websocket.core.Behavior; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.FrameHandler; @@ -272,16 +269,6 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon { } - protected WebSocketConnection newWebSocketConnection(EndPoint endPoint, Executor executor, Scheduler scheduler, ByteBufferPool byteBufferPool, WebSocketCoreSession coreSession) - { - return new WebSocketConnection(endPoint, executor, scheduler, byteBufferPool, coreSession); - } - - protected WebSocketCoreSession newWebSocketCoreSession(FrameHandler handler, Negotiated negotiated) - { - return new WebSocketCoreSession(handler, Behavior.CLIENT, negotiated); - } - public abstract FrameHandler getFrameHandler(); void requestComplete() @@ -436,11 +423,11 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon extensionStack, WebSocketConstants.SPEC_VERSION_STRING); - WebSocketCoreSession coreSession = newWebSocketCoreSession(frameHandler, negotiated); + WebSocketCoreSession coreSession = new WebSocketCoreSession(frameHandler, Behavior.CLIENT, negotiated); customizer.customize(coreSession); HttpClient httpClient = wsClient.getHttpClient(); - WebSocketConnection wsConnection = newWebSocketConnection(endPoint, httpClient.getExecutor(), httpClient.getScheduler(), httpClient.getByteBufferPool(), coreSession); + WebSocketConnection wsConnection = new WebSocketConnection(endPoint, httpClient.getExecutor(), httpClient.getScheduler(), httpClient.getByteBufferPool(), coreSession); wsClient.getEventListeners().forEach(wsConnection::addEventListener); coreSession.setWebSocketConnection(wsConnection); notifyUpgradeListeners((listener) -> listener.onHandshakeResponse(this, response)); From 356e98f73713fdb49f72d83cf31849b98bb3c957 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Mon, 30 Dec 2019 15:41:02 +1100 Subject: [PATCH 04/21] Clean up websocket-core package structure Signed-off-by: Lachlan Roberts --- .../src/main/java/module-info.java | 1 + .../websocket/core/AbstractExtension.java | 1 - .../jetty/websocket/core/CloseStatus.java | 3 + .../jetty/websocket/core/Configuration.java | 221 +++++++++ .../jetty/websocket/core/CoreSession.java | 266 +++++++++++ .../jetty/websocket/core/Extension.java | 2 - .../jetty/websocket/core/FrameHandler.java | 447 ------------------ .../jetty/websocket/core/MessageHandler.java | 4 +- .../core/client/ClientUpgradeRequest.java | 14 +- .../core/client/WebSocketCoreClient.java | 5 +- .../{ => exception}/BadPayloadException.java | 4 +- .../core/{ => exception}/CloseException.java | 2 +- .../MessageTooLargeException.java | 4 +- .../{ => exception}/ProtocolException.java | 4 +- .../{ => exception}/UpgradeException.java | 2 +- .../{ => exception}/WebSocketException.java | 2 +- .../WebSocketTimeoutException.java | 2 +- .../WebSocketWriteTimeoutException.java | 2 +- .../core/internal/ExtensionStack.java | 2 +- .../core/internal/FragmentExtension.java | 4 +- .../core/internal/FragmentingFlusher.java | 2 +- .../websocket/core/internal/FrameFlusher.java | 4 +- .../core/internal/FrameSequence.java | 2 +- .../core/{ => internal}/NullAppendable.java | 2 +- .../jetty/websocket/core/internal/Parser.java | 10 +- .../internal/PerMessageDeflateExtension.java | 6 +- .../core/internal/ValidationExtension.java | 7 +- .../core/internal/WebSocketConnection.java | 2 +- .../core/internal/WebSocketCoreSession.java | 16 +- .../core/internal/WebSocketSessionState.java | 2 +- .../websocket/core/server/Handshaker.java | 4 +- .../core/server/WebSocketNegotiator.java | 15 +- .../server/internal/AbstractHandshaker.java | 5 +- .../server/internal/HandshakerSelector.java | 4 +- .../websocket/core/AutoFragmentTest.java | 10 +- .../jetty/websocket/core/FrameBufferTest.java | 1 - .../core/GeneratorFrameFlagsTest.java | 1 + .../jetty/websocket/core/GeneratorTest.java | 2 + .../websocket/core/MessageHandlerTest.java | 3 +- .../jetty/websocket/core/OpCodeTest.java | 1 + .../core/ParserBadCloseStatusCodesTest.java | 1 + .../websocket/core/ParserBadOpCodesTest.java | 1 + .../websocket/core/ParserReservedBitTest.java | 1 + .../jetty/websocket/core/ParserTest.java | 2 + .../core/TestWebSocketNegotiator.java | 2 +- .../core/WebSocketNegotiationTest.java | 2 +- .../websocket/core/WebSocketOpenTest.java | 6 +- .../core/autobahn/AutobahnFrameHandler.java | 1 + .../core/autobahn/CoreAutobahnClient.java | 10 +- .../core/chat/ChatWebSocketServer.java | 1 + .../client/WebSocketClientServerTest.java | 2 +- .../PerMessageDeflateExtensionTest.java | 4 +- .../PerMessageDeflaterBufferSizeTest.java | 9 +- .../core/internal/FrameFlusherTest.java | 2 +- .../websocket/core/proxy/WebSocketProxy.java | 1 + .../core/proxy/WebSocketProxyTest.java | 8 +- .../core/server/WebSocketServerTest.java | 1 + .../common/InvalidWebSocketException.java | 2 +- .../common/JavaxWebSocketAsyncRemote.java | 4 +- .../common/JavaxWebSocketBasicRemote.java | 4 +- .../javax/common/JavaxWebSocketContainer.java | 4 +- .../common/JavaxWebSocketFrameHandler.java | 5 +- .../common/JavaxWebSocketRemoteEndpoint.java | 8 +- .../javax/common/JavaxWebSocketSession.java | 8 +- .../common/messages/ByteArrayMessageSink.java | 2 +- .../messages/ByteBufferMessageSink.java | 2 +- .../messages/DecodedBinaryMessageSink.java | 2 +- .../DecodedBinaryStreamMessageSink.java | 2 +- .../messages/DecodedTextMessageSink.java | 2 +- .../DecodedTextStreamMessageSink.java | 2 +- .../common/messages/MessageOutputStream.java | 6 +- .../javax/common/messages/MessageWriter.java | 6 +- .../common/messages/StringMessageSink.java | 2 +- ...bstractJavaxWebSocketFrameHandlerTest.java | 4 +- .../javax/common/AbstractSessionTest.java | 4 +- .../common/messages/MessageWriterTest.java | 6 +- .../JavaxWebSocketServerContainer.java | 2 +- .../websocket/javax/tests/CoreServer.java | 5 +- .../websocket/javax/tests/NetworkFuzzer.java | 3 +- .../javax/tests/framehandlers/FrameEcho.java | 1 + .../framehandlers/FrameHandlerTracker.java | 1 + .../websocket/IdleTimeoutOnOpenSocket.java | 2 +- .../client/AbstractClientSessionTest.java | 4 +- .../tests/client/MessageReceivingTest.java | 3 +- .../javax/tests/client/OnCloseTest.java | 4 +- .../client/SessionAddMessageHandlerTest.java | 4 +- .../javax/tests/client/WriteTimeoutTest.java | 2 +- .../javax/tests/server/ConfiguratorTest.java | 38 +- .../tests/server/EndpointViaConfigTest.java | 6 +- ...FrameHandler_OnMessage_TextStreamTest.java | 4 +- .../tests/server/LargeAnnotatedTest.java | 6 +- .../tests/server/LargeContainerTest.java | 6 +- .../tests/server/OnMessageReturnTest.java | 6 +- .../javax/tests/server/PingPongTest.java | 8 +- .../sockets/IdleTimeoutOnOpenSocket.java | 2 +- .../websocket/client/WebSocketClient.java | 4 +- .../common/FunctionCallException.java | 2 +- .../common/JettyWebSocketFrameHandler.java | 20 +- .../JettyWebSocketFrameHandlerMetadata.java | 4 +- .../common/JettyWebSocketRemoteEndpoint.java | 10 +- .../websocket/common/WebSocketSession.java | 8 +- .../common/message/ByteArrayMessageSink.java | 2 +- .../common/message/ByteBufferMessageSink.java | 2 +- .../common/message/MessageOutputStream.java | 6 +- .../common/message/MessageWriter.java | 6 +- .../common/message/StringMessageSink.java | 2 +- .../JettyWebSocketFrameHandlerTest.java | 4 +- .../common/OutgoingMessageCapture.java | 4 +- .../server/JettyWebSocketServerContainer.java | 6 +- .../tests/client/ClientConnectTest.java | 2 +- .../websocket/servlet/WebSocketMapping.java | 16 +- .../websocket/servlet/WebSocketServlet.java | 4 +- .../servlet/WebSocketServletFactory.java | 4 +- .../servlet/WebSocketUpgradeFilter.java | 4 +- 114 files changed, 758 insertions(+), 679 deletions(-) create mode 100644 jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java create mode 100644 jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java rename jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/{ => exception}/BadPayloadException.java (93%) rename jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/{ => exception}/CloseException.java (96%) rename jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/{ => exception}/MessageTooLargeException.java (93%) rename jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/{ => exception}/ProtocolException.java (92%) rename jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/{ => exception}/UpgradeException.java (97%) rename jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/{ => exception}/WebSocketException.java (96%) rename jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/{ => exception}/WebSocketTimeoutException.java (96%) rename jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/{ => exception}/WebSocketWriteTimeoutException.java (94%) rename jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/{ => internal}/NullAppendable.java (96%) diff --git a/jetty-websocket/websocket-core/src/main/java/module-info.java b/jetty-websocket/websocket-core/src/main/java/module-info.java index e028f524029..038b9931667 100644 --- a/jetty-websocket/websocket-core/src/main/java/module-info.java +++ b/jetty-websocket/websocket-core/src/main/java/module-info.java @@ -27,6 +27,7 @@ module org.eclipse.jetty.websocket.core exports org.eclipse.jetty.websocket.core; exports org.eclipse.jetty.websocket.core.client; exports org.eclipse.jetty.websocket.core.server; + exports org.eclipse.jetty.websocket.core.exception; exports org.eclipse.jetty.websocket.core.internal to org.eclipse.jetty.util; requires jetty.servlet.api; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java index 2af69bef8e5..7a0a18cddfc 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java @@ -26,7 +26,6 @@ import org.eclipse.jetty.util.compression.DeflaterPool; import org.eclipse.jetty.util.compression.InflaterPool; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.core.FrameHandler.Configuration; @ManagedObject("Abstract Extension") public class AbstractExtension implements Extension diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CloseStatus.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CloseStatus.java index e3661992a2a..5ef5617a263 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CloseStatus.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CloseStatus.java @@ -25,6 +25,9 @@ import java.util.Arrays; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Utf8Appendable; import org.eclipse.jetty.util.Utf8StringBuilder; +import org.eclipse.jetty.websocket.core.exception.BadPayloadException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; +import org.eclipse.jetty.websocket.core.internal.NullAppendable; /** * Representation of a WebSocket Close (status code & reason) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java new file mode 100644 index 00000000000..09502df7077 --- /dev/null +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java @@ -0,0 +1,221 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.core; + +import java.time.Duration; + +public interface Configuration +{ + /** + * Get the Idle Timeout + * + * @return the idle timeout + */ + Duration getIdleTimeout(); + + /** + * Get the Write Timeout + * + * @return the write timeout + */ + Duration getWriteTimeout(); + + /** + * Set the Idle Timeout. + * + * @param timeout the timeout duration (timeout <= 0 implies an infinite timeout) + */ + void setIdleTimeout(Duration timeout); + + /** + * Set the Write Timeout. + * + * @param timeout the timeout duration (timeout <= 0 implies an infinite timeout) + */ + void setWriteTimeout(Duration timeout); + + boolean isAutoFragment(); + + void setAutoFragment(boolean autoFragment); + + long getMaxFrameSize(); + + void setMaxFrameSize(long maxFrameSize); + + int getOutputBufferSize(); + + void setOutputBufferSize(int outputBufferSize); + + int getInputBufferSize(); + + void setInputBufferSize(int inputBufferSize); + + long getMaxBinaryMessageSize(); + + void setMaxBinaryMessageSize(long maxSize); + + long getMaxTextMessageSize(); + + void setMaxTextMessageSize(long maxSize); + + interface Customizer + { + void customize(Configuration configurable); + } + + class ConfigurationHolder implements Configuration + { + protected Duration idleTimeout; + protected Duration writeTimeout; + protected Boolean autoFragment; + protected Long maxFrameSize; + protected Integer outputBufferSize; + protected Integer inputBufferSize; + protected Long maxBinaryMessageSize; + protected Long maxTextMessageSize; + + @Override + public Duration getIdleTimeout() + { + return idleTimeout == null ? WebSocketConstants.DEFAULT_IDLE_TIMEOUT : idleTimeout; + } + + @Override + public Duration getWriteTimeout() + { + return writeTimeout == null ? WebSocketConstants.DEFAULT_WRITE_TIMEOUT : writeTimeout; + } + + @Override + public void setIdleTimeout(Duration timeout) + { + this.idleTimeout = timeout; + } + + @Override + public void setWriteTimeout(Duration timeout) + { + this.writeTimeout = timeout; + } + + @Override + public boolean isAutoFragment() + { + return autoFragment == null ? WebSocketConstants.DEFAULT_AUTO_FRAGMENT : autoFragment; + } + + @Override + public void setAutoFragment(boolean autoFragment) + { + this.autoFragment = autoFragment; + } + + @Override + public long getMaxFrameSize() + { + return maxFrameSize == null ? WebSocketConstants.DEFAULT_MAX_FRAME_SIZE : maxFrameSize; + } + + @Override + public void setMaxFrameSize(long maxFrameSize) + { + this.maxFrameSize = maxFrameSize; + } + + @Override + public int getOutputBufferSize() + { + return outputBufferSize == null ? WebSocketConstants.DEFAULT_OUTPUT_BUFFER_SIZE : outputBufferSize; + } + + @Override + public void setOutputBufferSize(int outputBufferSize) + { + this.outputBufferSize = outputBufferSize; + } + + @Override + public int getInputBufferSize() + { + return inputBufferSize == null ? WebSocketConstants.DEFAULT_INPUT_BUFFER_SIZE : inputBufferSize; + } + + @Override + public void setInputBufferSize(int inputBufferSize) + { + this.inputBufferSize = inputBufferSize; + } + + @Override + public long getMaxBinaryMessageSize() + { + return maxBinaryMessageSize == null ? WebSocketConstants.DEFAULT_MAX_BINARY_MESSAGE_SIZE : maxBinaryMessageSize; + } + + @Override + public void setMaxBinaryMessageSize(long maxBinaryMessageSize) + { + this.maxBinaryMessageSize = maxBinaryMessageSize; + } + + @Override + public long getMaxTextMessageSize() + { + return maxTextMessageSize == null ? WebSocketConstants.DEFAULT_MAX_TEXT_MESSAGE_SIZE : maxTextMessageSize; + } + + @Override + public void setMaxTextMessageSize(long maxTextMessageSize) + { + this.maxTextMessageSize = maxTextMessageSize; + } + } + + class ConfigurationCustomizer extends ConfigurationHolder implements Customizer + { + @Override + public void customize(Configuration configurable) + { + if (idleTimeout != null) + configurable.setIdleTimeout(idleTimeout); + if (writeTimeout != null) + configurable.setWriteTimeout(writeTimeout); + if (autoFragment != null) + configurable.setAutoFragment(autoFragment); + if (maxFrameSize != null) + configurable.setMaxFrameSize(maxFrameSize); + if (inputBufferSize != null) + configurable.setInputBufferSize(inputBufferSize); + if (outputBufferSize != null) + configurable.setOutputBufferSize(outputBufferSize); + if (maxBinaryMessageSize != null) + configurable.setMaxBinaryMessageSize(maxBinaryMessageSize); + if (maxTextMessageSize != null) + configurable.setMaxTextMessageSize(maxTextMessageSize); + } + + public static ConfigurationCustomizer from(ConfigurationCustomizer parent, ConfigurationCustomizer child) + { + ConfigurationCustomizer customizer = new ConfigurationCustomizer(); + parent.customize(customizer); + child.customize(customizer); + return customizer; + } + } +} diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java new file mode 100644 index 00000000000..7104323e60a --- /dev/null +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java @@ -0,0 +1,266 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.core; + +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.net.URI; +import java.util.List; +import java.util.Map; + +import org.eclipse.jetty.io.ByteBufferPool; +import org.eclipse.jetty.util.Callback; + +/** + * Represents the outgoing Frames. + */ +public interface CoreSession extends OutgoingFrames, Configuration +{ + /** + * The negotiated WebSocket Sub-Protocol for this session. + * + * @return the negotiated WebSocket Sub-Protocol for this session. + */ + String getNegotiatedSubProtocol(); + + /** + * The negotiated WebSocket Extension Configurations for this session. + * + * @return the list of Negotiated Extension Configurations for this session. + */ + List getNegotiatedExtensions(); + + /** + * The parameter map (from URI Query) for the active session. + * + * @return the immutable map of parameters + */ + Map> getParameterMap(); + + /** + * The active {@code Sec-WebSocket-Version} (protocol version) in use. + * + * @return the protocol version in use. + */ + String getProtocolVersion(); + + /** + * The active connection's Request URI. + * This is the URI of the upgrade request and is typically http: or https: rather than + * the ws: or wss: scheme. + * + * @return the absolute URI (including Query string) + */ + URI getRequestURI(); + + /** + * The active connection's Secure status indicator. + * + * @return true if connection is secure (similar in role to {@code HttpServletRequest.isSecure()}) + */ + boolean isSecure(); + + /** + * @return Client or Server behaviour + */ + Behavior getBehavior(); + + /** + * @return The shared ByteBufferPool + */ + ByteBufferPool getByteBufferPool(); + + /** + * The Local Socket Address for the connection + *

+ * Do not assume that this will return a {@link InetSocketAddress} in all cases. + * Use of various proxies, and even UnixSockets can result a SocketAddress being returned + * without supporting {@link InetSocketAddress} + *

+ * + * @return the SocketAddress for the local connection, or null if not supported by Session + */ + SocketAddress getLocalAddress(); + + /** + * The Remote Socket Address for the connection + *

+ * Do not assume that this will return a {@link InetSocketAddress} in all cases. + * Use of various proxies, and even UnixSockets can result a SocketAddress being returned + * without supporting {@link InetSocketAddress} + *

+ * + * @return the SocketAddress for the remote connection, or null if not supported by Session + */ + SocketAddress getRemoteAddress(); + + /** + * @return True if the websocket is open outbound + */ + boolean isOutputOpen(); + + /** + * If using BatchMode.ON or BatchMode.AUTO, trigger a flush of enqueued / batched frames. + * + * @param callback the callback to track close frame sent (or failed) + */ + void flush(Callback callback); + + /** + * Initiate close handshake, no payload (no declared status code or reason phrase) + * + * @param callback the callback to track close frame sent (or failed) + */ + void close(Callback callback); + + /** + * Initiate close handshake with provide status code and optional reason phrase. + * + * @param statusCode the status code (should be a valid status code that can be sent) + * @param reason optional reason phrase (will be truncated automatically by implementation to fit within limits of protocol) + * @param callback the callback to track close frame sent (or failed) + */ + void close(int statusCode, String reason, Callback callback); + + /** + * Issue a harsh abort of the underlying connection. + *

+ * This will terminate the connection, without sending a websocket close frame. + * No WebSocket Protocol close handshake will be performed. + *

+ *

+ * Once called, any read/write activity on the websocket from this point will be indeterminate. + * This can result in the {@link FrameHandler#onError(Throwable, Callback)} event being called indicating any issue that arises. + *

+ *

+ * Once the underlying connection has been determined to be closed, the {@link FrameHandler#onClosed(CloseStatus, Callback)} event will be called. + *

+ */ + void abort(); + + /** + * Manage flow control by indicating demand for handling Frames. A call to + * {@link FrameHandler#onFrame(Frame, Callback)} will only be made if a + * corresponding demand has been signaled. It is an error to call this method + * if {@link FrameHandler#isDemanding()} returns false. + * + * @param n The number of frames that can be handled (in sequential calls to + * {@link FrameHandler#onFrame(Frame, Callback)}). May not be negative. + */ + void demand(long n); + + class Empty extends ConfigurationCustomizer implements CoreSession + { + @Override + public String getNegotiatedSubProtocol() + { + return null; + } + + @Override + public List getNegotiatedExtensions() + { + return null; + } + + @Override + public Map> getParameterMap() + { + return null; + } + + @Override + public String getProtocolVersion() + { + return null; + } + + @Override + public URI getRequestURI() + { + return null; + } + + @Override + public boolean isSecure() + { + return false; + } + + @Override + public void abort() + { + } + + @Override + public Behavior getBehavior() + { + return null; + } + + @Override + public ByteBufferPool getByteBufferPool() + { + return null; + } + + @Override + public SocketAddress getLocalAddress() + { + return null; + } + + @Override + public SocketAddress getRemoteAddress() + { + return null; + } + + @Override + public boolean isOutputOpen() + { + return false; + } + + @Override + public void flush(Callback callback) + { + } + + @Override + public void close(Callback callback) + { + } + + @Override + public void close(int statusCode, String reason, Callback callback) + { + } + + @Override + public void demand(long n) + { + } + + @Override + public void sendFrame(Frame frame, Callback callback, boolean batch) + { + } + } +} diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java index 0d97a2be44c..2bbab07de88 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java @@ -18,8 +18,6 @@ package org.eclipse.jetty.websocket.core; -import org.eclipse.jetty.websocket.core.FrameHandler.Configuration; - /** * Interface for WebSocket Extensions. *

diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java index 16fd5bcc3a1..37b3f9181b6 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java @@ -18,14 +18,6 @@ package org.eclipse.jetty.websocket.core; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.net.URI; -import java.time.Duration; -import java.util.List; -import java.util.Map; - -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.core.server.Negotiation; @@ -129,443 +121,4 @@ public interface FrameHandler extends IncomingFrames { return false; } - - interface Configuration - { - - /** - * Get the Idle Timeout - * - * @return the idle timeout - */ - Duration getIdleTimeout(); - - /** - * Get the Write Timeout - * - * @return the write timeout - */ - Duration getWriteTimeout(); - - /** - * Set the Idle Timeout. - * - * @param timeout the timeout duration (timeout <= 0 implies an infinite timeout) - */ - void setIdleTimeout(Duration timeout); - - /** - * Set the Write Timeout. - * - * @param timeout the timeout duration (timeout <= 0 implies an infinite timeout) - */ - void setWriteTimeout(Duration timeout); - - boolean isAutoFragment(); - - void setAutoFragment(boolean autoFragment); - - long getMaxFrameSize(); - - void setMaxFrameSize(long maxFrameSize); - - int getOutputBufferSize(); - - void setOutputBufferSize(int outputBufferSize); - - int getInputBufferSize(); - - void setInputBufferSize(int inputBufferSize); - - long getMaxBinaryMessageSize(); - - void setMaxBinaryMessageSize(long maxSize); - - long getMaxTextMessageSize(); - - void setMaxTextMessageSize(long maxSize); - } - - /** - * Represents the outgoing Frames. - */ - interface CoreSession extends OutgoingFrames, Configuration - { - /** - * The negotiated WebSocket Sub-Protocol for this session. - * - * @return the negotiated WebSocket Sub-Protocol for this session. - */ - String getNegotiatedSubProtocol(); - - /** - * The negotiated WebSocket Extension Configurations for this session. - * - * @return the list of Negotiated Extension Configurations for this session. - */ - List getNegotiatedExtensions(); - - /** - * The parameter map (from URI Query) for the active session. - * - * @return the immutable map of parameters - */ - Map> getParameterMap(); - - /** - * The active {@code Sec-WebSocket-Version} (protocol version) in use. - * - * @return the protocol version in use. - */ - String getProtocolVersion(); - - /** - * The active connection's Request URI. - * This is the URI of the upgrade request and is typically http: or https: rather than - * the ws: or wss: scheme. - * - * @return the absolute URI (including Query string) - */ - URI getRequestURI(); - - /** - * The active connection's Secure status indicator. - * - * @return true if connection is secure (similar in role to {@code HttpServletRequest.isSecure()}) - */ - boolean isSecure(); - - /** - * @return Client or Server behaviour - */ - Behavior getBehavior(); - - /** - * @return The shared ByteBufferPool - */ - ByteBufferPool getByteBufferPool(); - - /** - * The Local Socket Address for the connection - *

- * Do not assume that this will return a {@link InetSocketAddress} in all cases. - * Use of various proxies, and even UnixSockets can result a SocketAddress being returned - * without supporting {@link InetSocketAddress} - *

- * - * @return the SocketAddress for the local connection, or null if not supported by Session - */ - SocketAddress getLocalAddress(); - - /** - * The Remote Socket Address for the connection - *

- * Do not assume that this will return a {@link InetSocketAddress} in all cases. - * Use of various proxies, and even UnixSockets can result a SocketAddress being returned - * without supporting {@link InetSocketAddress} - *

- * - * @return the SocketAddress for the remote connection, or null if not supported by Session - */ - SocketAddress getRemoteAddress(); - - /** - * @return True if the websocket is open outbound - */ - boolean isOutputOpen(); - - /** - * If using BatchMode.ON or BatchMode.AUTO, trigger a flush of enqueued / batched frames. - * - * @param callback the callback to track close frame sent (or failed) - */ - void flush(Callback callback); - - /** - * Initiate close handshake, no payload (no declared status code or reason phrase) - * - * @param callback the callback to track close frame sent (or failed) - */ - void close(Callback callback); - - /** - * Initiate close handshake with provide status code and optional reason phrase. - * - * @param statusCode the status code (should be a valid status code that can be sent) - * @param reason optional reason phrase (will be truncated automatically by implementation to fit within limits of protocol) - * @param callback the callback to track close frame sent (or failed) - */ - void close(int statusCode, String reason, Callback callback); - - /** - * Issue a harsh abort of the underlying connection. - *

- * This will terminate the connection, without sending a websocket close frame. - * No WebSocket Protocol close handshake will be performed. - *

- *

- * Once called, any read/write activity on the websocket from this point will be indeterminate. - * This can result in the {@link #onError(Throwable, Callback)} event being called indicating any issue that arises. - *

- *

- * Once the underlying connection has been determined to be closed, the {@link #onClosed(CloseStatus, Callback)} event will be called. - *

- */ - void abort(); - - /** - * Manage flow control by indicating demand for handling Frames. A call to - * {@link FrameHandler#onFrame(Frame, Callback)} will only be made if a - * corresponding demand has been signaled. It is an error to call this method - * if {@link FrameHandler#isDemanding()} returns false. - * - * @param n The number of frames that can be handled (in sequential calls to - * {@link FrameHandler#onFrame(Frame, Callback)}). May not be negative. - */ - void demand(long n); - - class Empty extends ConfigurationCustomizer implements CoreSession - { - @Override - public String getNegotiatedSubProtocol() - { - return null; - } - - @Override - public List getNegotiatedExtensions() - { - return null; - } - - @Override - public Map> getParameterMap() - { - return null; - } - - @Override - public String getProtocolVersion() - { - return null; - } - - @Override - public URI getRequestURI() - { - return null; - } - - @Override - public boolean isSecure() - { - return false; - } - - @Override - public void abort() - { - } - - @Override - public Behavior getBehavior() - { - return null; - } - - @Override - public ByteBufferPool getByteBufferPool() - { - return null; - } - - @Override - public SocketAddress getLocalAddress() - { - return null; - } - - @Override - public SocketAddress getRemoteAddress() - { - return null; - } - - @Override - public boolean isOutputOpen() - { - return false; - } - - @Override - public void flush(Callback callback) - { - } - - @Override - public void close(Callback callback) - { - } - - @Override - public void close(int statusCode, String reason, Callback callback) - { - } - - @Override - public void demand(long n) - { - } - - @Override - public void sendFrame(Frame frame, Callback callback, boolean batch) - { - } - } - } - - interface Customizer - { - void customize(Configuration configurable); - } - - class ConfigurationHolder implements Configuration - { - protected Duration idleTimeout; - protected Duration writeTimeout; - protected Boolean autoFragment; - protected Long maxFrameSize; - protected Integer outputBufferSize; - protected Integer inputBufferSize; - protected Long maxBinaryMessageSize; - protected Long maxTextMessageSize; - - @Override - public Duration getIdleTimeout() - { - return idleTimeout == null ? WebSocketConstants.DEFAULT_IDLE_TIMEOUT : idleTimeout; - } - - @Override - public Duration getWriteTimeout() - { - return writeTimeout == null ? WebSocketConstants.DEFAULT_WRITE_TIMEOUT : writeTimeout; - } - - @Override - public void setIdleTimeout(Duration timeout) - { - this.idleTimeout = timeout; - } - - @Override - public void setWriteTimeout(Duration timeout) - { - this.writeTimeout = timeout; - } - - @Override - public boolean isAutoFragment() - { - return autoFragment == null ? WebSocketConstants.DEFAULT_AUTO_FRAGMENT : autoFragment; - } - - @Override - public void setAutoFragment(boolean autoFragment) - { - this.autoFragment = autoFragment; - } - - @Override - public long getMaxFrameSize() - { - return maxFrameSize == null ? WebSocketConstants.DEFAULT_MAX_FRAME_SIZE : maxFrameSize; - } - - @Override - public void setMaxFrameSize(long maxFrameSize) - { - this.maxFrameSize = maxFrameSize; - } - - @Override - public int getOutputBufferSize() - { - return outputBufferSize == null ? WebSocketConstants.DEFAULT_OUTPUT_BUFFER_SIZE : outputBufferSize; - } - - @Override - public void setOutputBufferSize(int outputBufferSize) - { - this.outputBufferSize = outputBufferSize; - } - - @Override - public int getInputBufferSize() - { - return inputBufferSize == null ? WebSocketConstants.DEFAULT_INPUT_BUFFER_SIZE : inputBufferSize; - } - - @Override - public void setInputBufferSize(int inputBufferSize) - { - this.inputBufferSize = inputBufferSize; - } - - @Override - public long getMaxBinaryMessageSize() - { - return maxBinaryMessageSize == null ? WebSocketConstants.DEFAULT_MAX_BINARY_MESSAGE_SIZE : maxBinaryMessageSize; - } - - @Override - public void setMaxBinaryMessageSize(long maxBinaryMessageSize) - { - this.maxBinaryMessageSize = maxBinaryMessageSize; - } - - @Override - public long getMaxTextMessageSize() - { - return maxTextMessageSize == null ? WebSocketConstants.DEFAULT_MAX_TEXT_MESSAGE_SIZE : maxTextMessageSize; - } - - @Override - public void setMaxTextMessageSize(long maxTextMessageSize) - { - this.maxTextMessageSize = maxTextMessageSize; - } - } - - class ConfigurationCustomizer extends ConfigurationHolder implements Customizer - { - @Override - public void customize(Configuration configurable) - { - if (idleTimeout != null) - configurable.setIdleTimeout(idleTimeout); - if (writeTimeout != null) - configurable.setWriteTimeout(idleTimeout); - if (autoFragment != null) - configurable.setAutoFragment(autoFragment); - if (maxFrameSize != null) - configurable.setMaxFrameSize(maxFrameSize); - if (inputBufferSize != null) - configurable.setInputBufferSize(inputBufferSize); - if (outputBufferSize != null) - configurable.setOutputBufferSize(outputBufferSize); - if (maxBinaryMessageSize != null) - configurable.setMaxBinaryMessageSize(maxBinaryMessageSize); - if (maxTextMessageSize != null) - configurable.setMaxTextMessageSize(maxTextMessageSize); - } - - public static ConfigurationCustomizer from(ConfigurationCustomizer parent, ConfigurationCustomizer child) - { - ConfigurationCustomizer customizer = new ConfigurationCustomizer(); - parent.customize(customizer); - child.customize(customizer); - return customizer; - } - } } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/MessageHandler.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/MessageHandler.java index 86d962b5f2e..cfd9fe21e64 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/MessageHandler.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/MessageHandler.java @@ -29,13 +29,15 @@ import org.eclipse.jetty.util.Utf8Appendable; import org.eclipse.jetty.util.Utf8StringBuilder; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.exception.BadPayloadException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; /** * A utility implementation of FrameHandler that defragments * text frames into a String message before calling {@link #onText(String, Callback)}. * Flow control is by default automatic, but an implementation * may extend {@link #isDemanding()} to return true and then explicityly control - * demand with calls to {@link org.eclipse.jetty.websocket.core.FrameHandler.CoreSession#demand(long)} + * demand with calls to {@link CoreSession#demand(long)} */ public class MessageHandler implements FrameHandler { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java index 566f9961d87..098fb00060b 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java @@ -50,11 +50,13 @@ import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.Behavior; +import org.eclipse.jetty.websocket.core.Configuration; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.FrameHandler; -import org.eclipse.jetty.websocket.core.UpgradeException; +import org.eclipse.jetty.websocket.core.exception.UpgradeException; import org.eclipse.jetty.websocket.core.WebSocketConstants; -import org.eclipse.jetty.websocket.core.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Negotiated; import org.eclipse.jetty.websocket.core.internal.WebSocketConnection; @@ -75,10 +77,10 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon } private static final Logger LOG = Log.getLogger(ClientUpgradeRequest.class); - protected final CompletableFuture futureCoreSession; + protected final CompletableFuture futureCoreSession; private final WebSocketCoreClient wsClient; private FrameHandler frameHandler; - private FrameHandler.ConfigurationCustomizer customizer = new FrameHandler.ConfigurationCustomizer(); + private Configuration.ConfigurationCustomizer customizer = new Configuration.ConfigurationCustomizer(); private List upgradeListeners = new ArrayList<>(); private List requestedExtensions = new ArrayList<>(); @@ -112,7 +114,7 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon this.futureCoreSession = new CompletableFuture<>(); } - public void setConfiguration(FrameHandler.ConfigurationCustomizer config) + public void setConfiguration(Configuration.ConfigurationCustomizer config) { config.customize(customizer); } @@ -187,7 +189,7 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon super.send(listener); } - public CompletableFuture sendAsync() + public CompletableFuture sendAsync() { send(this); return futureCoreSession; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/WebSocketCoreClient.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/WebSocketCoreClient.java index 1c89cdcc871..b64223a5e6f 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/WebSocketCoreClient.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/WebSocketCoreClient.java @@ -28,6 +28,7 @@ import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.WebSocketComponents; @@ -68,13 +69,13 @@ public class WebSocketCoreClient extends ContainerLifeCycle addBean(httpClient); } - public CompletableFuture connect(FrameHandler frameHandler, URI wsUri) throws IOException + public CompletableFuture connect(FrameHandler frameHandler, URI wsUri) throws IOException { ClientUpgradeRequest request = ClientUpgradeRequest.from(this, wsUri, frameHandler); return connect(request); } - public CompletableFuture connect(ClientUpgradeRequest request) throws IOException + public CompletableFuture connect(ClientUpgradeRequest request) throws IOException { if (!isStarted()) throw new IllegalStateException(WebSocketCoreClient.class.getSimpleName() + "@" + this.hashCode() + " is not started"); diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/BadPayloadException.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/BadPayloadException.java similarity index 93% rename from jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/BadPayloadException.java rename to jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/BadPayloadException.java index d0cfdae380b..1d184674615 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/BadPayloadException.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/BadPayloadException.java @@ -16,7 +16,9 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.core; +package org.eclipse.jetty.websocket.core.exception; + +import org.eclipse.jetty.websocket.core.CloseStatus; /** * Exception to terminate the connection because it has received data within a frame payload that was not consistent with the requirements of that frame diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CloseException.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/CloseException.java similarity index 96% rename from jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CloseException.java rename to jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/CloseException.java index a28f7a5fb08..e7a85c8ff0f 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CloseException.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/CloseException.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.core; +package org.eclipse.jetty.websocket.core.exception; @SuppressWarnings("serial") public class CloseException extends WebSocketException diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/MessageTooLargeException.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/MessageTooLargeException.java similarity index 93% rename from jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/MessageTooLargeException.java rename to jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/MessageTooLargeException.java index b6e8ff47f48..51bdf3c35b0 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/MessageTooLargeException.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/MessageTooLargeException.java @@ -16,7 +16,9 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.core; +package org.eclipse.jetty.websocket.core.exception; + +import org.eclipse.jetty.websocket.core.CloseStatus; /** * Exception when a message is too large for the internal buffers occurs and should trigger a connection close. diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/ProtocolException.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/ProtocolException.java similarity index 92% rename from jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/ProtocolException.java rename to jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/ProtocolException.java index 9aa97fa98d0..d5d9e1fab59 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/ProtocolException.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/ProtocolException.java @@ -16,7 +16,9 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.core; +package org.eclipse.jetty.websocket.core.exception; + +import org.eclipse.jetty.websocket.core.CloseStatus; /** * Per spec, a protocol error should result in a Close frame of status code 1002 (PROTOCOL_ERROR) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/UpgradeException.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/UpgradeException.java similarity index 97% rename from jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/UpgradeException.java rename to jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/UpgradeException.java index 6ad3b78c200..da4428ebca9 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/UpgradeException.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/UpgradeException.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.core; +package org.eclipse.jetty.websocket.core.exception; import java.net.URI; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketException.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/WebSocketException.java similarity index 96% rename from jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketException.java rename to jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/WebSocketException.java index 2da71d2f94d..1239f1d7e3c 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketException.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/WebSocketException.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.core; +package org.eclipse.jetty.websocket.core.exception; /** * A recoverable exception within the websocket framework. diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketTimeoutException.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/WebSocketTimeoutException.java similarity index 96% rename from jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketTimeoutException.java rename to jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/WebSocketTimeoutException.java index 8dcfab5b104..4f96a86f9b0 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketTimeoutException.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/WebSocketTimeoutException.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.core; +package org.eclipse.jetty.websocket.core.exception; /** * Exception thrown to indicate a connection I/O timeout. diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketWriteTimeoutException.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/WebSocketWriteTimeoutException.java similarity index 94% rename from jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketWriteTimeoutException.java rename to jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/WebSocketWriteTimeoutException.java index 2dabed13133..c4b885e7dd5 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketWriteTimeoutException.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/exception/WebSocketWriteTimeoutException.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.core; +package org.eclipse.jetty.websocket.core.exception; public class WebSocketWriteTimeoutException extends WebSocketTimeoutException { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java index e9784c01a60..2632fb6d264 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java @@ -39,7 +39,7 @@ import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.IncomingFrames; import org.eclipse.jetty.websocket.core.OutgoingFrames; import org.eclipse.jetty.websocket.core.WebSocketComponents; -import org.eclipse.jetty.websocket.core.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; /** * Represents the stack of Extensions. diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java index 5f481d800d4..22231c1a9a5 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java @@ -22,9 +22,9 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.AbstractExtension; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.WebSocketComponents; /** @@ -35,7 +35,7 @@ public class FragmentExtension extends AbstractExtension private static final Logger LOG = Log.getLogger(FragmentExtension.class); private final FragmentingFlusher flusher; - private final FrameHandler.Configuration configuration = new FrameHandler.ConfigurationHolder(); + private final Configuration configuration = new Configuration.ConfigurationHolder(); public FragmentExtension() { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentingFlusher.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentingFlusher.java index 520b4c508fb..464acff2c69 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentingFlusher.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentingFlusher.java @@ -24,7 +24,7 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler.Configuration; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.OpCode; /** diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameFlusher.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameFlusher.java index d9538973363..ac0169b89cc 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameFlusher.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameFlusher.java @@ -41,8 +41,8 @@ import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; -import org.eclipse.jetty.websocket.core.WebSocketException; -import org.eclipse.jetty.websocket.core.WebSocketWriteTimeoutException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketWriteTimeoutException; public class FrameFlusher extends IteratingCallback { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameSequence.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameSequence.java index 7e2ed5f805a..812a992abe5 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameSequence.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameSequence.java @@ -19,7 +19,7 @@ package org.eclipse.jetty.websocket.core.internal; import org.eclipse.jetty.websocket.core.OpCode; -import org.eclipse.jetty.websocket.core.ProtocolException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; public class FrameSequence { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/NullAppendable.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/NullAppendable.java similarity index 96% rename from jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/NullAppendable.java rename to jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/NullAppendable.java index 6dde40e4d7a..769fed304b2 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/NullAppendable.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/NullAppendable.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.core; +package org.eclipse.jetty.websocket.core.internal; import org.eclipse.jetty.util.Utf8Appendable; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java index 486aaaffbbc..e63e17a8f6a 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java @@ -28,12 +28,12 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler.Configuration; -import org.eclipse.jetty.websocket.core.FrameHandler.ConfigurationHolder; -import org.eclipse.jetty.websocket.core.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.Configuration; +import org.eclipse.jetty.websocket.core.Configuration.ConfigurationHolder; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.core.OpCode; -import org.eclipse.jetty.websocket.core.ProtocolException; -import org.eclipse.jetty.websocket.core.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; /** * Parsing of a frames in WebSocket land. diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java index 90e333c9c10..c9fea2a1ea7 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java @@ -30,12 +30,12 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.AbstractExtension; -import org.eclipse.jetty.websocket.core.BadPayloadException; +import org.eclipse.jetty.websocket.core.exception.BadPayloadException; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.core.OpCode; -import org.eclipse.jetty.websocket.core.ProtocolException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.WebSocketComponents; /** diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java index bbce3306a04..c2d2689fcaf 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java @@ -24,11 +24,10 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.AbstractExtension; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler; -import org.eclipse.jetty.websocket.core.NullAppendable; -import org.eclipse.jetty.websocket.core.ProtocolException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.WebSocketComponents; import static org.eclipse.jetty.websocket.core.OpCode.CONTINUATION; @@ -56,7 +55,7 @@ public class ValidationExtension extends AbstractExtension } @Override - public void setConfiguration(FrameHandler.Configuration configuration) + public void setConfiguration(Configuration configuration) { super.setConfiguration(configuration); diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketConnection.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketConnection.java index 9b7d6766788..0438cc0199a 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketConnection.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketConnection.java @@ -39,7 +39,7 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.websocket.core.Behavior; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.WebSocketTimeoutException; +import org.eclipse.jetty.websocket.core.exception.WebSocketTimeoutException; /** * Provides the implementation of {@link org.eclipse.jetty.io.Connection} that is suitable for WebSocket diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java index 1ed5fc8590f..ad76f095f31 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java @@ -36,19 +36,21 @@ import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.Behavior; -import org.eclipse.jetty.websocket.core.CloseException; +import org.eclipse.jetty.websocket.core.Configuration; +import org.eclipse.jetty.websocket.core.CoreSession; +import org.eclipse.jetty.websocket.core.exception.CloseException; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.IncomingFrames; -import org.eclipse.jetty.websocket.core.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.OutgoingFrames; -import org.eclipse.jetty.websocket.core.ProtocolException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.WebSocketConstants; -import org.eclipse.jetty.websocket.core.WebSocketTimeoutException; -import org.eclipse.jetty.websocket.core.WebSocketWriteTimeoutException; +import org.eclipse.jetty.websocket.core.exception.WebSocketTimeoutException; +import org.eclipse.jetty.websocket.core.exception.WebSocketWriteTimeoutException; import org.eclipse.jetty.websocket.core.internal.Parser.ParsedFrame; import static org.eclipse.jetty.util.Callback.NOOP; @@ -56,7 +58,7 @@ import static org.eclipse.jetty.util.Callback.NOOP; /** * The Core WebSocket Session. */ -public class WebSocketCoreSession implements IncomingFrames, FrameHandler.CoreSession, Dumpable +public class WebSocketCoreSession implements IncomingFrames, CoreSession, Dumpable { private static final Logger LOG = Log.getLogger(WebSocketCoreSession.class); private static final CloseStatus NO_CODE = new CloseStatus(CloseStatus.NO_CODE); @@ -809,7 +811,7 @@ public class WebSocketCoreSession implements IncomingFrames, FrameHandler.CoreSe private class Flusher extends FragmentingFlusher { - public Flusher(FrameHandler.Configuration configuration) + public Flusher(Configuration configuration) { super(configuration); } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketSessionState.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketSessionState.java index acb18f801ab..4da7a78cce4 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketSessionState.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketSessionState.java @@ -23,7 +23,7 @@ import java.nio.channels.ClosedChannelException; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; -import org.eclipse.jetty.websocket.core.ProtocolException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; /** * Atomic Connection State diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Handshaker.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Handshaker.java index 88a2fff7368..c6644587257 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Handshaker.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Handshaker.java @@ -22,7 +22,7 @@ import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.server.internal.HandshakerSelector; public interface Handshaker @@ -32,5 +32,5 @@ public interface Handshaker return new HandshakerSelector(); } - boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, FrameHandler.Customizer defaultCustomizer) throws IOException; + boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, Configuration.Customizer defaultCustomizer) throws IOException; } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketNegotiator.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketNegotiator.java index e02a110dc76..962f28be9de 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketNegotiator.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketNegotiator.java @@ -23,11 +23,12 @@ import java.util.function.Function; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.DecoratedObjectFactory; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; -public interface WebSocketNegotiator extends FrameHandler.Customizer +public interface WebSocketNegotiator extends Configuration.Customizer { FrameHandler negotiate(Negotiation negotiation) throws IOException; @@ -51,7 +52,7 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer }; } - static WebSocketNegotiator from(Function negotiate, FrameHandler.Customizer customizer) + static WebSocketNegotiator from(Function negotiate, Configuration.Customizer customizer) { return new AbstractNegotiator(null, customizer) { @@ -66,7 +67,7 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer static WebSocketNegotiator from( Function negotiate, WebSocketComponents components, - FrameHandler.Customizer customizer) + Configuration.Customizer customizer) { return new AbstractNegotiator(components, customizer) { @@ -81,21 +82,21 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer abstract class AbstractNegotiator implements WebSocketNegotiator { final WebSocketComponents components; - final FrameHandler.Customizer customizer; + final Configuration.Customizer customizer; public AbstractNegotiator() { this(null, null); } - public AbstractNegotiator(WebSocketComponents components, FrameHandler.Customizer customizer) + public AbstractNegotiator(WebSocketComponents components, Configuration.Customizer customizer) { this.components = components == null ? new WebSocketComponents() : components; this.customizer = customizer; } @Override - public void customize(FrameHandler.Configuration configurable) + public void customize(Configuration configurable) { if (customizer != null) customizer.customize(configurable); @@ -125,7 +126,7 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer return components; } - public FrameHandler.Customizer getCustomizer() + public Configuration.Customizer getCustomizer() { return customizer; } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java index 61c6b2e3c58..8693dbe3585 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java @@ -38,11 +38,12 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.websocket.core.Behavior; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.WebSocketConstants; -import org.eclipse.jetty.websocket.core.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Negotiated; import org.eclipse.jetty.websocket.core.internal.WebSocketConnection; @@ -57,7 +58,7 @@ public abstract class AbstractHandshaker implements Handshaker private static final HttpField SERVER_VERSION = new PreEncodedHttpField(HttpHeader.SERVER, HttpConfiguration.SERVER_VERSION); @Override - public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, FrameHandler.Customizer defaultCustomizer) throws IOException + public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, Configuration.Customizer defaultCustomizer) throws IOException { if (!validateRequest(request)) return false; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/HandshakerSelector.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/HandshakerSelector.java index 9fc54235365..1310298f9b8 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/HandshakerSelector.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/HandshakerSelector.java @@ -22,7 +22,7 @@ import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.server.Handshaker; import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; @@ -37,7 +37,7 @@ public class HandshakerSelector implements Handshaker private final RFC8441Handshaker rfc8441 = new RFC8441Handshaker(); @Override - public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, FrameHandler.Customizer defaultCustomizer) throws IOException + public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, Configuration.Customizer defaultCustomizer) throws IOException { // Try HTTP/1.1 WS upgrade, if this fails try an HTTP/2 WS upgrade if no response was committed. return rfc6455.upgradeRequest(negotiator, request, response, defaultCustomizer) || diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/AutoFragmentTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/AutoFragmentTest.java index db05b7180b5..1cde7b9a5dd 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/AutoFragmentTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/AutoFragmentTest.java @@ -74,7 +74,7 @@ public class AutoFragmentTest public void testOutgoingAutoFragmentToMaxFrameSize() throws Exception { TestFrameHandler clientHandler = new TestFrameHandler(); - CompletableFuture connect = client.connect(clientHandler, serverUri); + CompletableFuture connect = client.connect(clientHandler, serverUri); connect.get(5, TimeUnit.SECONDS); // Turn off fragmentation on the server. @@ -122,7 +122,7 @@ public class AutoFragmentTest public void testIncomingAutoFragmentToMaxFrameSize() throws Exception { TestFrameHandler clientHandler = new TestFrameHandler(); - CompletableFuture connect = client.connect(clientHandler, serverUri); + CompletableFuture connect = client.connect(clientHandler, serverUri); connect.get(5, TimeUnit.SECONDS); // Turn off fragmentation on the client. @@ -167,7 +167,7 @@ public class AutoFragmentTest TestFrameHandler clientHandler = new TestFrameHandler(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, serverUri, clientHandler); upgradeRequest.addExtensions("permessage-deflate"); - CompletableFuture connect = client.connect(upgradeRequest); + CompletableFuture connect = client.connect(upgradeRequest); connect.get(5, TimeUnit.SECONDS); // Turn off fragmentation on the client. @@ -218,7 +218,7 @@ public class AutoFragmentTest TestFrameHandler clientHandler = new TestFrameHandler(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, serverUri, clientHandler); upgradeRequest.addExtensions("permessage-deflate"); - CompletableFuture connect = client.connect(upgradeRequest); + CompletableFuture connect = client.connect(upgradeRequest); connect.get(5, TimeUnit.SECONDS); // Turn off fragmentation on the client. @@ -282,7 +282,7 @@ public class AutoFragmentTest TestFrameHandler clientHandler = new TestFrameHandler(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, serverUri, clientHandler); upgradeRequest.addExtensions("permessage-deflate"); - CompletableFuture connect = client.connect(upgradeRequest); + CompletableFuture connect = client.connect(upgradeRequest); connect.get(5, TimeUnit.SECONDS); // Turn off fragmentation on the client. diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FrameBufferTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FrameBufferTest.java index 19e440f8dd0..da8ee33408b 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FrameBufferTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FrameBufferTest.java @@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.websocket.core.FrameHandler.CoreSession; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; import org.junit.jupiter.api.AfterEach; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorFrameFlagsTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorFrameFlagsTest.java index e21ce49fefe..941101cf3d9 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorFrameFlagsTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorFrameFlagsTest.java @@ -23,6 +23,7 @@ import java.util.LinkedList; import java.util.stream.Stream; import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Generator; import org.eclipse.jetty.websocket.core.internal.Negotiated; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorTest.java index 28d8c8364dd..292f58f041c 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorTest.java @@ -30,6 +30,8 @@ import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Generator; import org.eclipse.jetty.websocket.core.internal.Negotiated; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/MessageHandlerTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/MessageHandlerTest.java index e4e67f8e3ff..37f811939c6 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/MessageHandlerTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/MessageHandlerTest.java @@ -29,7 +29,8 @@ import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.FutureCallback; -import org.eclipse.jetty.websocket.core.FrameHandler.CoreSession; +import org.eclipse.jetty.websocket.core.exception.BadPayloadException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/OpCodeTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/OpCodeTest.java index c68a4d1eaa2..c7680ffce37 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/OpCodeTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/OpCodeTest.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.websocket.core; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.internal.FrameSequence; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadCloseStatusCodesTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadCloseStatusCodesTest.java index 3dc9212ffa6..e09c49d95d1 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadCloseStatusCodesTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadCloseStatusCodesTest.java @@ -25,6 +25,7 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.log.StacklessLogging; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.internal.Parser; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadOpCodesTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadOpCodesTest.java index 48286570d8e..900b51b33da 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadOpCodesTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadOpCodesTest.java @@ -25,6 +25,7 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.log.StacklessLogging; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.internal.Parser; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserReservedBitTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserReservedBitTest.java index 6cd16a093a6..6613d18d316 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserReservedBitTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserReservedBitTest.java @@ -25,6 +25,7 @@ import java.util.List; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.log.StacklessLogging; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.internal.Generator; import org.eclipse.jetty.websocket.core.internal.Parser; import org.junit.jupiter.api.Test; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserTest.java index f7dee5b749b..4486e6901ad 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserTest.java @@ -29,6 +29,8 @@ import org.eclipse.jetty.toolchain.test.Hex; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.TypeUtil; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.internal.Generator; import org.eclipse.jetty.websocket.core.internal.Parser; import org.hamcrest.Matchers; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/TestWebSocketNegotiator.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/TestWebSocketNegotiator.java index 53430af39e5..6aa60d090b7 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/TestWebSocketNegotiator.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/TestWebSocketNegotiator.java @@ -53,7 +53,7 @@ public class TestWebSocketNegotiator implements WebSocketNegotiator } @Override - public void customize(FrameHandler.Configuration configurable) + public void customize(Configuration configurable) { } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java index 63dc1b99b79..67d41aedd2c 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java @@ -37,10 +37,10 @@ import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.StacklessLogging; -import org.eclipse.jetty.websocket.core.FrameHandler.CoreSession; import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.core.client.UpgradeListener; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; +import org.eclipse.jetty.websocket.core.exception.UpgradeException; import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession; import org.eclipse.jetty.websocket.core.server.Negotiation; import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java index a55d389c2c9..d70097df1a1 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java @@ -59,7 +59,7 @@ public class WebSocketOpenTest extends WebSocketTester server.stop(); } - public void setup(BiFunction onOpen) throws Exception + public void setup(BiFunction onOpen) throws Exception { serverHandler = new DemandingAsyncFrameHandler(onOpen); server = new WebSocketServer(serverHandler); @@ -136,7 +136,7 @@ public class WebSocketOpenTest extends WebSocketTester @Test public void testAsyncOnOpen() throws Exception { - Exchanger sx = new Exchanger<>(); + Exchanger sx = new Exchanger<>(); Exchanger cx = new Exchanger<>(); setup((s, c) -> { @@ -153,7 +153,7 @@ public class WebSocketOpenTest extends WebSocketTester return null; }); - FrameHandler.CoreSession coreSession = sx.exchange(null); + CoreSession coreSession = sx.exchange(null); Callback onOpenCallback = cx.exchange(null); Thread.sleep(100); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnFrameHandler.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnFrameHandler.java index 3de7b168cd2..e79b726af5a 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnFrameHandler.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnFrameHandler.java @@ -22,6 +22,7 @@ import java.nio.ByteBuffer; import java.time.Duration; import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.TestMessageHandler; public class AutobahnFrameHandler extends TestMessageHandler diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/autobahn/CoreAutobahnClient.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/autobahn/CoreAutobahnClient.java index 6503abf72ea..8c793b59e23 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/autobahn/CoreAutobahnClient.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/autobahn/CoreAutobahnClient.java @@ -29,7 +29,7 @@ import org.eclipse.jetty.util.Jetty; import org.eclipse.jetty.util.UrlEncoded; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.TestMessageHandler; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; @@ -154,7 +154,7 @@ public class CoreAutobahnClient { URI wsUri = baseWebsocketUri.resolve("/getCaseCount"); TestMessageHandler onCaseCount = new TestMessageHandler(); - Future response = client.connect(onCaseCount, wsUri); + Future response = client.connect(onCaseCount, wsUri); if (waitForUpgrade(wsUri, response)) { @@ -173,7 +173,7 @@ public class CoreAutobahnClient LOG.info("test uri: {}", wsUri); AutobahnFrameHandler echoHandler = new AutobahnFrameHandler(); - Future response = client.connect(echoHandler, wsUri); + Future response = client.connect(echoHandler, wsUri); if (waitForUpgrade(wsUri, response)) { // Wait up to 5 min as some of the tests can take a while @@ -201,14 +201,14 @@ public class CoreAutobahnClient { URI wsUri = baseWebsocketUri.resolve("/updateReports?agent=" + UrlEncoded.encodeString(userAgent)); TestMessageHandler onUpdateReports = new TestMessageHandler(); - Future response = client.connect(onUpdateReports, wsUri); + Future response = client.connect(onUpdateReports, wsUri); response.get(5, TimeUnit.SECONDS); assertTrue(onUpdateReports.closeLatch.await(15, TimeUnit.SECONDS)); LOG.info("Reports updated."); LOG.info("Test suite finished!"); } - private boolean waitForUpgrade(URI wsUri, Future response) throws InterruptedException + private boolean waitForUpgrade(URI wsUri, Future response) throws InterruptedException { try { diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/chat/ChatWebSocketServer.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/chat/ChatWebSocketServer.java index c12c300b788..f2b861dbe9b 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/chat/ChatWebSocketServer.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/chat/ChatWebSocketServer.java @@ -34,6 +34,7 @@ import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.MessageHandler; import org.eclipse.jetty.websocket.core.server.Negotiation; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java index 36d460f3d06..b8d35bd8fe4 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java @@ -27,7 +27,7 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler.CoreSession; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.TestFrameHandler; import org.eclipse.jetty.websocket.core.WebSocketServer; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java index 01f8ca30b5e..a1097aefc46 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java @@ -33,11 +33,11 @@ import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.websocket.core.Behavior; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler.ConfigurationCustomizer; +import org.eclipse.jetty.websocket.core.Configuration.ConfigurationCustomizer; import org.eclipse.jetty.websocket.core.IncomingFramesCapture; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.OutgoingFramesCapture; -import org.eclipse.jetty.websocket.core.ProtocolException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.TestMessageHandler; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Negotiated; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflaterBufferSizeTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflaterBufferSizeTest.java index 498ed794f13..f4dac1f1d97 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflaterBufferSizeTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflaterBufferSizeTest.java @@ -28,6 +28,7 @@ import org.eclipse.jetty.client.HttpRequest; import org.eclipse.jetty.client.HttpResponse; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; @@ -115,7 +116,7 @@ public class PerMessageDeflaterBufferSizeTest }); // Connect to the server. - CompletableFuture connect = client.connect(upgradeRequest); + CompletableFuture connect = client.connect(upgradeRequest); connect.get(5, TimeUnit.SECONDS); // Make sure the internal parameter was not sent to the server. @@ -168,7 +169,7 @@ public class PerMessageDeflaterBufferSizeTest }); // Connect to the server. - CompletableFuture connect = client.connect(upgradeRequest); + CompletableFuture connect = client.connect(upgradeRequest); connect.get(5, TimeUnit.SECONDS); // Make sure the internal parameter was not sent to the server. @@ -222,7 +223,7 @@ public class PerMessageDeflaterBufferSizeTest }); // Connect to the server. - CompletableFuture connect = client.connect(upgradeRequest); + CompletableFuture connect = client.connect(upgradeRequest); connect.get(5, TimeUnit.SECONDS); // Make sure the internal parameter was not sent from the server. @@ -276,7 +277,7 @@ public class PerMessageDeflaterBufferSizeTest }); // Connect to the server. - CompletableFuture connect = client.connect(upgradeRequest); + CompletableFuture connect = client.connect(upgradeRequest); connect.get(5, TimeUnit.SECONDS); // Make sure the internal parameter was not sent from the server. diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/internal/FrameFlusherTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/internal/FrameFlusherTest.java index 25fb27171b1..6fa6295e7b9 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/internal/FrameFlusherTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/internal/FrameFlusherTest.java @@ -43,7 +43,7 @@ import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.WebSocketConstants; -import org.eclipse.jetty.websocket.core.WebSocketWriteTimeoutException; +import org.eclipse.jetty.websocket.core.exception.WebSocketWriteTimeoutException; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxy.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxy.java index 24dd71c2f30..5f5151e4bd6 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxy.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxy.java @@ -29,6 +29,7 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.OpCode; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java index b7e3d984dc7..cad6048e962 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java @@ -39,10 +39,10 @@ import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.EchoFrameHandler; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler; -import org.eclipse.jetty.websocket.core.FrameHandler.CoreSession; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.TestAsyncFrameHandler; import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest; @@ -72,7 +72,7 @@ public class WebSocketProxyTest private WebSocketProxy proxy; private EchoFrameHandler serverFrameHandler; private TestHandler testHandler; - FrameHandler.ConfigurationCustomizer defaultCustomizer; + Configuration.ConfigurationCustomizer defaultCustomizer; private class TestHandler extends AbstractHandler { @@ -109,7 +109,7 @@ public class WebSocketProxyTest testHandler = new TestHandler(); handlers.addHandler(testHandler); - defaultCustomizer = new FrameHandler.ConfigurationCustomizer(); + defaultCustomizer = new Configuration.ConfigurationCustomizer(); defaultCustomizer.setIdleTimeout(Duration.ofSeconds(3)); ContextHandler serverContext = new ContextHandler("/server"); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/server/WebSocketServerTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/server/WebSocketServerTest.java index 60ddf4b3a7d..c1aeb0d8c0f 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/server/WebSocketServerTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/server/WebSocketServerTest.java @@ -30,6 +30,7 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.RawFrameBuilder; diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/InvalidWebSocketException.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/InvalidWebSocketException.java index 04f9457da4e..7abbc21fdbb 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/InvalidWebSocketException.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/InvalidWebSocketException.java @@ -18,7 +18,7 @@ package org.eclipse.jetty.websocket.javax.common; -import org.eclipse.jetty.websocket.core.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; /** * Indicating that the provided Class is not a valid WebSocket per the chosen API. diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketAsyncRemote.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketAsyncRemote.java index 5a969df1b52..c8a9fdd8dd0 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketAsyncRemote.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketAsyncRemote.java @@ -30,8 +30,8 @@ import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.CoreSession; 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.javax.common.messages.MessageOutputStream; import org.eclipse.jetty.websocket.javax.common.messages.MessageWriter; @@ -41,7 +41,7 @@ public class JavaxWebSocketAsyncRemote extends JavaxWebSocketRemoteEndpoint impl { static final Logger LOG = Log.getLogger(JavaxWebSocketAsyncRemote.class); - protected JavaxWebSocketAsyncRemote(JavaxWebSocketSession session, FrameHandler.CoreSession coreSession) + protected JavaxWebSocketAsyncRemote(JavaxWebSocketSession session, CoreSession coreSession) { super(session, coreSession); } diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketBasicRemote.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketBasicRemote.java index facff847978..80a0c86fac7 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketBasicRemote.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketBasicRemote.java @@ -29,8 +29,8 @@ import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.SharedBlockingCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.CoreSession; 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.javax.common.util.TextUtil; @@ -40,7 +40,7 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl { private static final Logger LOG = Log.getLogger(JavaxWebSocketBasicRemote.class); - protected JavaxWebSocketBasicRemote(JavaxWebSocketSession session, FrameHandler.CoreSession coreSession) + protected JavaxWebSocketBasicRemote(JavaxWebSocketSession session, CoreSession coreSession) { super(session, coreSession); } diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketContainer.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketContainer.java index 6822525f0b5..5ce80190aba 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketContainer.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketContainer.java @@ -33,7 +33,7 @@ import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; @@ -42,7 +42,7 @@ public abstract class JavaxWebSocketContainer extends ContainerLifeCycle impleme private static final Logger LOG = Log.getLogger(JavaxWebSocketContainer.class); private final SessionTracker sessionTracker = new SessionTracker(); private List sessionListeners = new ArrayList<>(); - protected FrameHandler.ConfigurationCustomizer defaultCustomizer = new FrameHandler.ConfigurationCustomizer(); + protected Configuration.ConfigurationCustomizer defaultCustomizer = new Configuration.ConfigurationCustomizer(); protected WebSocketComponents components; public JavaxWebSocketContainer(WebSocketComponents components) diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java index 378ef535da6..7bd8b007082 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java @@ -41,11 +41,12 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.core.CoreSession; 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.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders; import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryMessageSink; import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryStreamMessageSink; diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketRemoteEndpoint.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketRemoteEndpoint.java index d02b27459fa..df80fbdf880 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketRemoteEndpoint.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketRemoteEndpoint.java @@ -30,11 +30,11 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.SharedBlockingCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.CoreSession; 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.OutgoingFrames; -import org.eclipse.jetty.websocket.core.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.javax.common.messages.MessageOutputStream; import org.eclipse.jetty.websocket.javax.common.messages.MessageWriter; @@ -43,11 +43,11 @@ public class JavaxWebSocketRemoteEndpoint implements javax.websocket.RemoteEndpo private static final Logger LOG = Log.getLogger(JavaxWebSocketRemoteEndpoint.class); protected final JavaxWebSocketSession session; - private final FrameHandler.CoreSession coreSession; + private final CoreSession coreSession; protected boolean batch = false; protected byte messageType = -1; - protected JavaxWebSocketRemoteEndpoint(JavaxWebSocketSession session, FrameHandler.CoreSession coreSession) + protected JavaxWebSocketRemoteEndpoint(JavaxWebSocketSession session, CoreSession coreSession) { this.session = session; this.coreSession = coreSession; diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java index 0ba2dee7304..938aece5753 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java @@ -41,8 +41,8 @@ import javax.websocket.WebSocketContainer; import org.eclipse.jetty.util.SharedBlockingCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.ExtensionConfig; -import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders; import org.eclipse.jetty.websocket.javax.common.encoders.AvailableEncoders; import org.eclipse.jetty.websocket.javax.common.util.ReflectUtils; @@ -56,7 +56,7 @@ public class JavaxWebSocketSession implements javax.websocket.Session protected final SharedBlockingCallback blocking = new SharedBlockingCallback(); private final JavaxWebSocketContainer container; - private final FrameHandler.CoreSession coreSession; + private final CoreSession coreSession; private final JavaxWebSocketFrameHandler frameHandler; private final EndpointConfig config; private final AvailableDecoders availableDecoders; @@ -69,7 +69,7 @@ public class JavaxWebSocketSession implements javax.websocket.Session private JavaxWebSocketBasicRemote basicRemote; public JavaxWebSocketSession(JavaxWebSocketContainer container, - FrameHandler.CoreSession coreSession, + CoreSession coreSession, JavaxWebSocketFrameHandler frameHandler, EndpointConfig endpointConfig) { @@ -94,7 +94,7 @@ public class JavaxWebSocketSession implements javax.websocket.Session this.userProperties = this.config.getUserProperties(); } - public FrameHandler.CoreSession getCoreSession() + public CoreSession getCoreSession() { return coreSession; } diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/ByteArrayMessageSink.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/ByteArrayMessageSink.java index 2d9100ab3af..0e9f6792499 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/ByteArrayMessageSink.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/ByteArrayMessageSink.java @@ -27,7 +27,7 @@ import java.util.Objects; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSession; import org.eclipse.jetty.websocket.javax.common.util.InvalidSignatureException; diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/ByteBufferMessageSink.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/ByteBufferMessageSink.java index ed939a05540..532ad76b2f7 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/ByteBufferMessageSink.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/ByteBufferMessageSink.java @@ -25,7 +25,7 @@ import java.nio.ByteBuffer; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSession; public class ByteBufferMessageSink extends AbstractMessageSink diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedBinaryMessageSink.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedBinaryMessageSink.java index de56031549a..be4744adfe3 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedBinaryMessageSink.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedBinaryMessageSink.java @@ -26,7 +26,7 @@ import javax.websocket.CloseReason; import javax.websocket.DecodeException; import javax.websocket.Decoder; -import org.eclipse.jetty.websocket.core.CloseException; +import org.eclipse.jetty.websocket.core.exception.CloseException; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSession; import org.eclipse.jetty.websocket.javax.common.MessageSink; diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedBinaryStreamMessageSink.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedBinaryStreamMessageSink.java index 4b8d8382639..916b67711de 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedBinaryStreamMessageSink.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedBinaryStreamMessageSink.java @@ -26,7 +26,7 @@ import javax.websocket.CloseReason; import javax.websocket.DecodeException; import javax.websocket.Decoder; -import org.eclipse.jetty.websocket.core.CloseException; +import org.eclipse.jetty.websocket.core.exception.CloseException; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSession; import org.eclipse.jetty.websocket.javax.common.MessageSink; diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedTextMessageSink.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedTextMessageSink.java index 07c6c6f99a3..d5db51ec574 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedTextMessageSink.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedTextMessageSink.java @@ -25,7 +25,7 @@ import javax.websocket.CloseReason; import javax.websocket.DecodeException; import javax.websocket.Decoder; -import org.eclipse.jetty.websocket.core.CloseException; +import org.eclipse.jetty.websocket.core.exception.CloseException; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSession; import org.eclipse.jetty.websocket.javax.common.MessageSink; diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedTextStreamMessageSink.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedTextStreamMessageSink.java index 7051f38a7d2..439efd0207b 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedTextStreamMessageSink.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/DecodedTextStreamMessageSink.java @@ -26,7 +26,7 @@ import javax.websocket.CloseReason; import javax.websocket.DecodeException; import javax.websocket.Decoder; -import org.eclipse.jetty.websocket.core.CloseException; +import org.eclipse.jetty.websocket.core.exception.CloseException; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSession; import org.eclipse.jetty.websocket.javax.common.MessageSink; diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/MessageOutputStream.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/MessageOutputStream.java index 0e868f158ed..8bf5030bbc6 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/MessageOutputStream.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/MessageOutputStream.java @@ -28,8 +28,8 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.SharedBlockingCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.OpCode; /** @@ -39,7 +39,7 @@ public class MessageOutputStream extends OutputStream { private static final Logger LOG = Log.getLogger(MessageOutputStream.class); - private final FrameHandler.CoreSession coreSession; + private final CoreSession coreSession; private final ByteBufferPool bufferPool; private final SharedBlockingCallback blocker; private long frameCount; @@ -49,7 +49,7 @@ public class MessageOutputStream extends OutputStream private Callback callback; private boolean closed; - public MessageOutputStream(FrameHandler.CoreSession coreSession, int bufferSize, ByteBufferPool bufferPool) + public MessageOutputStream(CoreSession coreSession, int bufferSize, ByteBufferPool bufferPool) { this.coreSession = coreSession; this.bufferPool = bufferPool; diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/MessageWriter.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/MessageWriter.java index 33916a756c7..a9ba0f6f061 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/MessageWriter.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/MessageWriter.java @@ -30,8 +30,8 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.SharedBlockingCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.OpCode; import static java.nio.charset.StandardCharsets.UTF_8; @@ -49,7 +49,7 @@ public class MessageWriter extends Writer .onUnmappableCharacter(CodingErrorAction.REPORT) .onMalformedInput(CodingErrorAction.REPORT); - private final FrameHandler.CoreSession coreSession; + private final CoreSession coreSession; private final SharedBlockingCallback blocker; private long frameCount; private Frame frame; @@ -57,7 +57,7 @@ public class MessageWriter extends Writer private Callback callback; private boolean closed; - public MessageWriter(FrameHandler.CoreSession coreSession, int bufferSize) + public MessageWriter(CoreSession coreSession, int bufferSize) { this.coreSession = coreSession; this.blocker = new SharedBlockingCallback(); diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/StringMessageSink.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/StringMessageSink.java index 291c6a5c67d..7bbf4ad0d91 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/StringMessageSink.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/messages/StringMessageSink.java @@ -27,7 +27,7 @@ import org.eclipse.jetty.util.Utf8StringBuilder; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSession; public class StringMessageSink extends AbstractMessageSink diff --git a/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/AbstractJavaxWebSocketFrameHandlerTest.java b/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/AbstractJavaxWebSocketFrameHandlerTest.java index 412919c77d7..65395d89792 100644 --- a/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/AbstractJavaxWebSocketFrameHandlerTest.java +++ b/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/AbstractJavaxWebSocketFrameHandlerTest.java @@ -23,7 +23,7 @@ import java.util.Map; import javax.websocket.ClientEndpointConfig; import javax.websocket.EndpointConfig; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders; import org.eclipse.jetty.websocket.javax.common.encoders.AvailableEncoders; import org.junit.jupiter.api.AfterAll; @@ -50,7 +50,7 @@ public abstract class AbstractJavaxWebSocketFrameHandlerTest protected AvailableDecoders decoders; protected Map uriParams; protected EndpointConfig endpointConfig; - protected FrameHandler.CoreSession coreSession = new FrameHandler.CoreSession.Empty(); + protected CoreSession coreSession = new CoreSession.Empty(); public AbstractJavaxWebSocketFrameHandlerTest() { diff --git a/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/AbstractSessionTest.java b/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/AbstractSessionTest.java index 9411bb26ab2..fc103c40646 100644 --- a/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/AbstractSessionTest.java +++ b/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/AbstractSessionTest.java @@ -22,7 +22,7 @@ import javax.websocket.Endpoint; import javax.websocket.EndpointConfig; import javax.websocket.Session; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.CoreSession; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -39,7 +39,7 @@ public abstract class AbstractSessionTest Object websocketPojo = new DummyEndpoint(); UpgradeRequest upgradeRequest = new UpgradeRequestAdapter(); JavaxWebSocketFrameHandler frameHandler = container.newFrameHandler(websocketPojo, upgradeRequest); - FrameHandler.CoreSession coreSession = new FrameHandler.CoreSession.Empty(); + CoreSession coreSession = new CoreSession.Empty(); session = new JavaxWebSocketSession(container, coreSession, frameHandler, container.getFrameHandlerFactory() .newDefaultEndpointConfig(websocketPojo.getClass(), null)); } diff --git a/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/messages/MessageWriterTest.java b/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/messages/MessageWriterTest.java index 24efba23ce2..fa4660c2084 100644 --- a/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/messages/MessageWriterTest.java +++ b/jetty-websocket/websocket-javax-common/src/test/java/org/eclipse/jetty/websocket/javax/common/messages/MessageWriterTest.java @@ -26,8 +26,8 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Utf8StringBuilder; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.OpCode; import org.junit.jupiter.api.Test; @@ -139,7 +139,7 @@ public class MessageWriterTest assertThat("Message[0].length", message.length(), is(testSize)); } - public static class FrameCapture extends FrameHandler.CoreSession.Empty + public static class FrameCapture extends CoreSession.Empty { public BlockingQueue frames = new LinkedBlockingQueue<>(); @@ -151,7 +151,7 @@ public class MessageWriterTest } } - public static class WholeMessageCapture extends FrameHandler.CoreSession.Empty + public static class WholeMessageCapture extends CoreSession.Empty { public BlockingQueue messages = new LinkedBlockingQueue<>(); diff --git a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java index a20eadd32a3..bfad5ae60aa 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java @@ -37,7 +37,7 @@ import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.WebSocketComponents; -import org.eclipse.jetty.websocket.core.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer; import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; diff --git a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java index 274fc1d8c26..dea69e7c877 100644 --- a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java +++ b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java @@ -31,6 +31,7 @@ import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.thread.QueuedThreadPool; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; @@ -116,7 +117,7 @@ public class CoreServer extends ContainerLifeCycle } @Override - public void customize(FrameHandler.Configuration configurable) + public void customize(Configuration configurable) { } @@ -178,7 +179,7 @@ public class CoreServer extends ContainerLifeCycle } @Override - public void customize(FrameHandler.Configuration configurable) + public void customize(Configuration configurable) { } } diff --git a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/NetworkFuzzer.java b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/NetworkFuzzer.java index 4a9b7a14db1..ac46308ed2d 100644 --- a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/NetworkFuzzer.java +++ b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/NetworkFuzzer.java @@ -36,6 +36,7 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.SharedBlockingCallback; import org.eclipse.jetty.websocket.core.Behavior; import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest; @@ -81,7 +82,7 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab this.client.start(); this.generator = new UnitGenerator(Behavior.CLIENT); - CompletableFuture futureHandler = this.client.connect(upgradeRequest); + CompletableFuture futureHandler = this.client.connect(upgradeRequest); CompletableFuture futureCapture = futureHandler.thenCombine(upgradeRequest.getFuture(), (session, capture) -> capture); this.frameCapture = futureCapture.get(10, TimeUnit.SECONDS); } diff --git a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/framehandlers/FrameEcho.java b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/framehandlers/FrameEcho.java index 6d7cbe87a3d..5a2fd118f8f 100644 --- a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/framehandlers/FrameEcho.java +++ b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/framehandlers/FrameEcho.java @@ -22,6 +22,7 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; diff --git a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/framehandlers/FrameHandlerTracker.java b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/framehandlers/FrameHandlerTracker.java index b4ff93b0a6b..2a296734d50 100644 --- a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/framehandlers/FrameHandlerTracker.java +++ b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/framehandlers/FrameHandlerTracker.java @@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.MessageHandler; public class FrameHandlerTracker extends MessageHandler diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenSocket.java b/jetty-websocket/websocket-javax-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenSocket.java index 3278e6594db..56ff4fc200f 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenSocket.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenSocket.java @@ -24,7 +24,7 @@ import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; -import org.eclipse.jetty.websocket.core.WebSocketTimeoutException; +import org.eclipse.jetty.websocket.core.exception.WebSocketTimeoutException; @ServerEndpoint(value = "/idle-onopen-socket") public class IdleTimeoutOnOpenSocket diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/AbstractClientSessionTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/AbstractClientSessionTest.java index bb59615edc5..76499f264de 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/AbstractClientSessionTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/AbstractClientSessionTest.java @@ -18,7 +18,7 @@ package org.eclipse.jetty.websocket.javax.tests.client; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.javax.client.BasicClientEndpointConfig; import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer; @@ -43,7 +43,7 @@ public abstract class AbstractClientSessionTest Object websocketPojo = new DummyEndpoint(); UpgradeRequest upgradeRequest = new UpgradeRequestAdapter(); JavaxWebSocketFrameHandler frameHandler = container.newFrameHandler(websocketPojo, upgradeRequest); - FrameHandler.CoreSession coreSession = new FrameHandler.CoreSession.Empty(); + CoreSession coreSession = new CoreSession.Empty(); session = new JavaxWebSocketSession(container, coreSession, frameHandler, new BasicClientEndpointConfig()); } diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/MessageReceivingTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/MessageReceivingTest.java index 8dd935eaba9..b5331a36ebc 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/MessageReceivingTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/MessageReceivingTest.java @@ -41,6 +41,7 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.MessageHandler; @@ -379,7 +380,7 @@ public class MessageReceivingTest } @Override - public void customize(FrameHandler.Configuration configurable) + public void customize(Configuration configurable) { configurable.setMaxBinaryMessageSize(MAX_MESSAGE_SIZE); configurable.setMaxTextMessageSize(MAX_MESSAGE_SIZE); diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/OnCloseTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/OnCloseTest.java index 2b6649f413f..ec2669828c4 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/OnCloseTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/OnCloseTest.java @@ -26,7 +26,7 @@ import javax.websocket.ClientEndpointConfig; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.websocket.core.CloseStatus; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.javax.client.BasicClientEndpointConfig; import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandler; @@ -104,7 +104,7 @@ public class OnCloseTest UpgradeRequest request = new UpgradeRequestAdapter(); JavaxWebSocketFrameHandler frameHandler = container.newFrameHandler(endpoint, request); - frameHandler.onOpen(new FrameHandler.CoreSession.Empty(), Callback.NOOP); + frameHandler.onOpen(new CoreSession.Empty(), Callback.NOOP); // Execute onClose call frameHandler.onFrame(CloseStatus.toFrame(CloseStatus.NORMAL), Callback.NOOP); diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/SessionAddMessageHandlerTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/SessionAddMessageHandlerTest.java index 94c6eeb68f9..d074a7dd965 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/SessionAddMessageHandlerTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/SessionAddMessageHandlerTest.java @@ -27,8 +27,8 @@ import javax.websocket.MessageHandler; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.websocket.core.CoreSession; 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.javax.client.BasicClientEndpointConfig; import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer; @@ -78,7 +78,7 @@ public class SessionAddMessageHandlerTest JavaxWebSocketFrameHandlerFactory frameHandlerFactory = new JavaxWebSocketClientFrameHandlerFactory(container); frameHandler = frameHandlerFactory.newJavaxWebSocketFrameHandler(ei, handshakeRequest); - frameHandler.onOpen(new FrameHandler.CoreSession.Empty(), Callback.NOOP); + frameHandler.onOpen(new CoreSession.Empty(), Callback.NOOP); // Session session = frameHandler.getSession(); diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/WriteTimeoutTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/WriteTimeoutTest.java index 160791b315c..8c22d63b328 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/WriteTimeoutTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/WriteTimeoutTest.java @@ -30,7 +30,7 @@ import javax.websocket.server.ServerEndpoint; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.core.WebSocketWriteTimeoutException; +import org.eclipse.jetty.websocket.core.exception.WebSocketWriteTimeoutException; import org.eclipse.jetty.websocket.javax.tests.LocalServer; import org.eclipse.jetty.websocket.javax.tests.WSEndpointTracker; import org.hamcrest.Matchers; diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/ConfiguratorTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/ConfiguratorTest.java index ac72ce9732e..095eaabdac7 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/ConfiguratorTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/ConfiguratorTest.java @@ -53,8 +53,8 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.CoreSession; 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.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; @@ -432,9 +432,9 @@ public class ConfiguratorTest FrameHandlerTracker clientSocket = new FrameHandlerTracker(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); upgradeRequest.addExtensions("identity"); - Future clientConnectFuture = client.connect(upgradeRequest); + Future clientConnectFuture = client.connect(upgradeRequest); - FrameHandler.CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); + CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); try { coreSession.sendFrame(new Frame(OpCode.TEXT).setPayload(HttpHeader.SEC_WEBSOCKET_EXTENSIONS.asString()), Callback.NOOP, false); @@ -456,9 +456,9 @@ public class ConfiguratorTest FrameHandlerTracker clientSocket = new FrameHandlerTracker(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); upgradeRequest.addExtensions("identity"); - Future clientConnectFuture = client.connect(upgradeRequest); + Future clientConnectFuture = client.connect(upgradeRequest); - FrameHandler.CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); + CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); try { coreSession.sendFrame(new Frame(OpCode.TEXT).setPayload("NegoExts"), Callback.NOOP, false); @@ -480,9 +480,9 @@ public class ConfiguratorTest FrameHandlerTracker clientSocket = new FrameHandlerTracker(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); upgradeRequest.header("X-Dummy", "Bogus"); - Future clientConnectFuture = client.connect(upgradeRequest); + Future clientConnectFuture = client.connect(upgradeRequest); - FrameHandler.CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); + CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); try { coreSession.sendFrame(new Frame(OpCode.TEXT).setPayload("X-Dummy"), Callback.NOOP, false); @@ -504,9 +504,9 @@ public class ConfiguratorTest // First Request FrameHandlerTracker clientSocket = new FrameHandlerTracker(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); - Future clientConnectFuture = client.connect(upgradeRequest); + Future clientConnectFuture = client.connect(upgradeRequest); - FrameHandler.CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); + CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); try { // first request has this UserProperty @@ -551,9 +551,9 @@ public class ConfiguratorTest FrameHandlerTracker clientSocket = new FrameHandlerTracker(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); - Future clientConnectFuture = client.connect(upgradeRequest); + Future clientConnectFuture = client.connect(upgradeRequest); - FrameHandler.CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); + CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); try { SocketAddress expectedLocal = coreSession.getLocalAddress(); @@ -593,7 +593,7 @@ public class ConfiguratorTest FrameHandlerTracker clientSocket = new FrameHandlerTracker(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); upgradeRequest.setSubProtocols("status"); - Future clientConnectFuture = client.connect(upgradeRequest); + Future clientConnectFuture = client.connect(upgradeRequest); assertProtocols(clientSocket, clientConnectFuture, is("Requested Protocols: [status]")); } @@ -612,7 +612,7 @@ public class ConfiguratorTest FrameHandlerTracker clientSocket = new FrameHandlerTracker(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); upgradeRequest.setSubProtocols("echo", "chat", "status"); - Future clientConnectFuture = client.connect(upgradeRequest); + Future clientConnectFuture = client.connect(upgradeRequest); assertProtocols(clientSocket, clientConnectFuture, is("Requested Protocols: [echo,chat,status]")); } @@ -631,7 +631,7 @@ public class ConfiguratorTest FrameHandlerTracker clientSocket = new FrameHandlerTracker(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); upgradeRequest.setSubProtocols("echo", "chat", "status"); - Future clientConnectFuture = client.connect(upgradeRequest); + Future clientConnectFuture = client.connect(upgradeRequest); assertProtocols(clientSocket, clientConnectFuture, is("Requested Protocols: [echo,chat,status]")); } @@ -650,15 +650,15 @@ public class ConfiguratorTest FrameHandlerTracker clientSocket = new FrameHandlerTracker(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); upgradeRequest.setSubProtocols("echo", "chat", "status"); - Future clientConnectFuture = client.connect(upgradeRequest); + Future clientConnectFuture = client.connect(upgradeRequest); assertProtocols(clientSocket, clientConnectFuture, is("Requested Protocols: [echo,chat,status]")); } - protected void assertProtocols(FrameHandlerTracker clientSocket, Future clientConnectFuture, Matcher responseMatcher) + protected void assertProtocols(FrameHandlerTracker clientSocket, Future clientConnectFuture, Matcher responseMatcher) throws InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException { - FrameHandler.CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); + CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); try { coreSession.sendFrame(new Frame(OpCode.TEXT).setPayload("getProtocols"), Callback.NOOP, false); @@ -683,9 +683,9 @@ public class ConfiguratorTest FrameHandlerTracker clientSocket = new FrameHandlerTracker(); ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); upgradeRequest.setSubProtocols("gmt"); - Future clientConnectFuture = client.connect(upgradeRequest); + Future clientConnectFuture = client.connect(upgradeRequest); - FrameHandler.CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); + CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); try { coreSession.sendFrame(new Frame(OpCode.TEXT).setPayload("2016-06-20T14:27:44"), Callback.NOOP, false); diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/EndpointViaConfigTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/EndpointViaConfigTest.java index 43f0e5dbe8c..0e1bdffba2c 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/EndpointViaConfigTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/EndpointViaConfigTest.java @@ -30,8 +30,8 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.WebAppContext; +import org.eclipse.jetty.websocket.core.CoreSession; 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.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.javax.tests.WSServer; @@ -76,9 +76,9 @@ public class EndpointViaConfigTest { client.start(); FrameHandlerTracker clientSocket = new FrameHandlerTracker(); - Future clientConnectFuture = client.connect(clientSocket, uri.resolve("/app/echo")); + Future clientConnectFuture = client.connect(clientSocket, uri.resolve("/app/echo")); // wait for connect - FrameHandler.CoreSession coreSession = clientConnectFuture.get(5, TimeUnit.SECONDS); + CoreSession coreSession = clientConnectFuture.get(5, TimeUnit.SECONDS); try { coreSession.sendFrame(new Frame(OpCode.TEXT).setPayload("Hello World"), Callback.NOOP, false); diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JavaxWebSocketFrameHandler_OnMessage_TextStreamTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JavaxWebSocketFrameHandler_OnMessage_TextStreamTest.java index 0891c15d484..8d9c739eb7f 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JavaxWebSocketFrameHandler_OnMessage_TextStreamTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JavaxWebSocketFrameHandler_OnMessage_TextStreamTest.java @@ -29,8 +29,8 @@ import javax.websocket.server.ServerEndpoint; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.websocket.core.CoreSession; 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.javax.common.JavaxWebSocketFrameHandler; import org.eclipse.jetty.websocket.javax.common.UpgradeRequest; @@ -50,7 +50,7 @@ public class JavaxWebSocketFrameHandler_OnMessage_TextStreamTest extends Abstrac // Establish endpoint function JavaxWebSocketFrameHandler frameHandler = container.newFrameHandler(socket, request); - frameHandler.onOpen(new FrameHandler.CoreSession.Empty(), Callback.NOOP); + frameHandler.onOpen(new CoreSession.Empty(), Callback.NOOP); func.accept(frameHandler); return socket; } diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeAnnotatedTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeAnnotatedTest.java index 91a702836d1..e60bcae64fa 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeAnnotatedTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeAnnotatedTest.java @@ -30,8 +30,8 @@ import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.webapp.WebAppContext; +import org.eclipse.jetty.websocket.core.CoreSession; 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.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.javax.tests.WSServer; @@ -82,9 +82,9 @@ public class LargeAnnotatedTest FrameHandlerTracker clientSocket = new FrameHandlerTracker(); - Future clientConnectFuture = client.connect(clientSocket, uri.resolve("/app/echo/large")); + Future clientConnectFuture = client.connect(clientSocket, uri.resolve("/app/echo/large")); // wait for connect - FrameHandler.CoreSession coreSession = clientConnectFuture.get(1, TimeUnit.SECONDS); + CoreSession coreSession = clientConnectFuture.get(1, TimeUnit.SECONDS); coreSession.setMaxTextMessageSize(128 * 1024); try { diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeContainerTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeContainerTest.java index fbdf26ce9db..052e451e913 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeContainerTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeContainerTest.java @@ -29,8 +29,8 @@ import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.webapp.WebAppContext; +import org.eclipse.jetty.websocket.core.CoreSession; 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.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.javax.tests.WSServer; @@ -71,10 +71,10 @@ public class LargeContainerTest client.start(); FrameHandlerTracker clientSocket = new FrameHandlerTracker(); - Future clientConnectFuture = client.connect(clientSocket, uri.resolve("/app/echo/large")); + Future clientConnectFuture = client.connect(clientSocket, uri.resolve("/app/echo/large")); // wait for connect - FrameHandler.CoreSession coreSession = clientConnectFuture.get(5, TimeUnit.SECONDS); + CoreSession coreSession = clientConnectFuture.get(5, TimeUnit.SECONDS); coreSession.setMaxTextMessageSize(128 * 1024); try { diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/OnMessageReturnTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/OnMessageReturnTest.java index 1204b55304c..569bf6838af 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/OnMessageReturnTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/OnMessageReturnTest.java @@ -32,8 +32,8 @@ import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.webapp.WebAppContext; +import org.eclipse.jetty.websocket.core.CoreSession; 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.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.javax.tests.WSServer; @@ -105,10 +105,10 @@ public class OnMessageReturnTest client.start(); FrameHandlerTracker clientSocket = new FrameHandlerTracker(); - Future clientConnectFuture = client.connect(clientSocket, uri.resolve("/app/echoreturn")); + Future clientConnectFuture = client.connect(clientSocket, uri.resolve("/app/echoreturn")); // wait for connect - FrameHandler.CoreSession coreSession = clientConnectFuture.get(5, TimeUnit.SECONDS); + CoreSession coreSession = clientConnectFuture.get(5, TimeUnit.SECONDS); try { // Send message diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/PingPongTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/PingPongTest.java index e323ff87ea5..b7edff1a468 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/PingPongTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/PingPongTest.java @@ -31,8 +31,8 @@ import com.acme.websocket.PongSocket; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.webapp.WebAppContext; +import org.eclipse.jetty.websocket.core.CoreSession; 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.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.javax.tests.Timeouts; @@ -81,14 +81,14 @@ public class PingPongTest server.stop(); } - private void assertEcho(String endpointPath, Consumer sendAction, String... expectedMsgs) throws Exception + private void assertEcho(String endpointPath, Consumer sendAction, String... expectedMsgs) throws Exception { FrameHandlerTracker clientSocket = new FrameHandlerTracker(); URI toUri = server.getWsUri().resolve(endpointPath); // Connect - Future futureSession = client.connect(clientSocket, toUri); - FrameHandler.CoreSession coreSession = futureSession.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); + Future futureSession = client.connect(clientSocket, toUri); + CoreSession coreSession = futureSession.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); try { // Apply send action diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/sockets/IdleTimeoutOnOpenSocket.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/sockets/IdleTimeoutOnOpenSocket.java index 5b9085c3a83..b0802a1e870 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/sockets/IdleTimeoutOnOpenSocket.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/sockets/IdleTimeoutOnOpenSocket.java @@ -24,7 +24,7 @@ import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; -import org.eclipse.jetty.websocket.core.WebSocketTimeoutException; +import org.eclipse.jetty.websocket.core.exception.WebSocketTimeoutException; @ServerEndpoint(value = "/idle-onopen-socket") public class IdleTimeoutOnOpenSocket diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index c37ff27ecb9..bc7f5ffb859 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -52,7 +52,7 @@ import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler; import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory; import org.eclipse.jetty.websocket.common.SessionTracker; import org.eclipse.jetty.websocket.common.WebSocketContainer; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.client.UpgradeListener; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; @@ -65,7 +65,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli private final JettyWebSocketFrameHandlerFactory frameHandlerFactory; private final List sessionListeners = new CopyOnWriteArrayList<>(); private final SessionTracker sessionTracker = new SessionTracker(); - private final FrameHandler.ConfigurationCustomizer configurationCustomizer = new FrameHandler.ConfigurationCustomizer(); + private final Configuration.ConfigurationCustomizer configurationCustomizer = new Configuration.ConfigurationCustomizer(); private final WebSocketComponents components = new WebSocketComponents(); private boolean stopAtShutdown = false; diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/FunctionCallException.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/FunctionCallException.java index 41397859ed9..855dee065b3 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/FunctionCallException.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/FunctionCallException.java @@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.common; import java.lang.reflect.InvocationTargetException; -import org.eclipse.jetty.websocket.core.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; public class FunctionCallException extends WebSocketException { diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java index 9a2ccaa23e7..5242d3a8152 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java @@ -31,17 +31,19 @@ import org.eclipse.jetty.websocket.api.UpgradeRequest; import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.api.WriteCallback; import org.eclipse.jetty.websocket.common.invoke.InvalidSignatureException; -import org.eclipse.jetty.websocket.core.BadPayloadException; -import org.eclipse.jetty.websocket.core.CloseException; +import org.eclipse.jetty.websocket.core.Configuration; +import org.eclipse.jetty.websocket.core.CoreSession; +import org.eclipse.jetty.websocket.core.exception.BadPayloadException; +import org.eclipse.jetty.websocket.core.exception.CloseException; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; -import org.eclipse.jetty.websocket.core.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.core.OpCode; -import org.eclipse.jetty.websocket.core.ProtocolException; -import org.eclipse.jetty.websocket.core.UpgradeException; -import org.eclipse.jetty.websocket.core.WebSocketException; -import org.eclipse.jetty.websocket.core.WebSocketTimeoutException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; +import org.eclipse.jetty.websocket.core.exception.UpgradeException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketTimeoutException; public class JettyWebSocketFrameHandler implements FrameHandler { @@ -70,7 +72,7 @@ public class JettyWebSocketFrameHandler implements FrameHandler private UpgradeRequest upgradeRequest; private UpgradeResponse upgradeResponse; - private final Customizer customizer; + private final Configuration.Customizer customizer; private MessageSink textSink; private MessageSink binarySink; private MessageSink activeMessageSink; @@ -87,7 +89,7 @@ public class JettyWebSocketFrameHandler implements FrameHandler MethodHandle frameHandle, MethodHandle pingHandle, MethodHandle pongHandle, BatchMode batchMode, - Customizer customizer) + Configuration.Customizer customizer) { this.log = Log.getLogger(endpointInstance.getClass()); diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerMetadata.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerMetadata.java index a99c2877d7a..1c4d3f41870 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerMetadata.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerMetadata.java @@ -22,9 +22,9 @@ import java.lang.invoke.MethodHandle; import org.eclipse.jetty.websocket.api.BatchMode; import org.eclipse.jetty.websocket.api.InvalidWebSocketException; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.Configuration; -public class JettyWebSocketFrameHandlerMetadata extends FrameHandler.ConfigurationCustomizer +public class JettyWebSocketFrameHandlerMetadata extends Configuration.ConfigurationCustomizer { private MethodHandle openHandle; private MethodHandle closeHandle; diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java index ca8c3b37fd9..76e1f69fccd 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java @@ -28,21 +28,21 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.SharedBlockingCallback; import org.eclipse.jetty.websocket.api.BatchMode; import org.eclipse.jetty.websocket.api.WriteCallback; +import org.eclipse.jetty.websocket.core.CoreSession; 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.exception.ProtocolException; import static java.nio.charset.StandardCharsets.UTF_8; public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket.api.RemoteEndpoint { - private final FrameHandler.CoreSession coreSession; + private final CoreSession coreSession; private byte messageType = -1; private final SharedBlockingCallback blocker = new SharedBlockingCallback(); private BatchMode batchMode; - public JettyWebSocketRemoteEndpoint(FrameHandler.CoreSession coreSession, BatchMode batchMode) + public JettyWebSocketRemoteEndpoint(CoreSession coreSession, BatchMode batchMode) { this.coreSession = Objects.requireNonNull(coreSession); this.batchMode = batchMode; @@ -234,7 +234,7 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket } } - protected FrameHandler.CoreSession getCoreSession() + protected CoreSession getCoreSession() { return coreSession; } diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java index cdbeacf38ea..eaf3af890a2 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java @@ -32,18 +32,18 @@ import org.eclipse.jetty.websocket.api.SuspendToken; import org.eclipse.jetty.websocket.api.UpgradeRequest; import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.api.WebSocketBehavior; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.CoreSession; public class WebSocketSession implements Session, SuspendToken, Dumpable { private static final Logger LOG = Log.getLogger(WebSocketSession.class); - private final FrameHandler.CoreSession coreSession; + private final CoreSession coreSession; private final JettyWebSocketFrameHandler frameHandler; private final JettyWebSocketRemoteEndpoint remoteEndpoint; private final UpgradeRequest upgradeRequest; private final UpgradeResponse upgradeResponse; - public WebSocketSession(FrameHandler.CoreSession coreSession, JettyWebSocketFrameHandler frameHandler) + public WebSocketSession(CoreSession coreSession, JettyWebSocketFrameHandler frameHandler) { this.frameHandler = Objects.requireNonNull(frameHandler); this.coreSession = Objects.requireNonNull(coreSession); @@ -235,7 +235,7 @@ public class WebSocketSession implements Session, SuspendToken, Dumpable frameHandler.resume(); } - public FrameHandler.CoreSession getCoreSession() + public CoreSession getCoreSession() { return coreSession; } diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/ByteArrayMessageSink.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/ByteArrayMessageSink.java index dc5b48a50f7..9cf8d8c91fd 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/ByteArrayMessageSink.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/ByteArrayMessageSink.java @@ -31,7 +31,7 @@ import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.common.AbstractMessageSink; import org.eclipse.jetty.websocket.common.invoke.InvalidSignatureException; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; public class ByteArrayMessageSink extends AbstractMessageSink { diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/ByteBufferMessageSink.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/ByteBufferMessageSink.java index d40d7ea1e0a..5e128c8540d 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/ByteBufferMessageSink.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/ByteBufferMessageSink.java @@ -31,7 +31,7 @@ import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.common.AbstractMessageSink; import org.eclipse.jetty.websocket.common.invoke.InvalidSignatureException; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; public class ByteBufferMessageSink extends AbstractMessageSink { diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java index 0275496e9db..517c8702dbc 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java @@ -28,8 +28,8 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.SharedBlockingCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.OpCode; /** @@ -39,7 +39,7 @@ public class MessageOutputStream extends OutputStream { private static final Logger LOG = Log.getLogger(MessageOutputStream.class); - private final FrameHandler.CoreSession coreSession; + private final CoreSession coreSession; private final ByteBufferPool bufferPool; private final SharedBlockingCallback blocker; private long frameCount; @@ -49,7 +49,7 @@ public class MessageOutputStream extends OutputStream private Callback callback; private boolean closed; - public MessageOutputStream(FrameHandler.CoreSession coreSession, int bufferSize, ByteBufferPool bufferPool) + public MessageOutputStream(CoreSession coreSession, int bufferSize, ByteBufferPool bufferPool) { this.coreSession = coreSession; this.bufferPool = bufferPool; diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageWriter.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageWriter.java index 534a7194039..fe2d3f5cbf4 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageWriter.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageWriter.java @@ -30,8 +30,8 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.SharedBlockingCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.OpCode; import static java.nio.charset.StandardCharsets.UTF_8; @@ -49,7 +49,7 @@ public class MessageWriter extends Writer .onUnmappableCharacter(CodingErrorAction.REPORT) .onMalformedInput(CodingErrorAction.REPORT); - private final FrameHandler.CoreSession coreSession; + private final CoreSession coreSession; private final SharedBlockingCallback blocker; private long frameCount; private Frame frame; @@ -57,7 +57,7 @@ public class MessageWriter extends Writer private Callback callback; private boolean closed; - public MessageWriter(FrameHandler.CoreSession coreSession, int bufferSize) + public MessageWriter(CoreSession coreSession, int bufferSize) { this.coreSession = coreSession; this.blocker = new SharedBlockingCallback(); diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/StringMessageSink.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/StringMessageSink.java index 8d2780bd5d2..68a246c7e08 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/StringMessageSink.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/message/StringMessageSink.java @@ -33,7 +33,7 @@ import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.common.AbstractMessageSink; import org.eclipse.jetty.websocket.common.invoke.InvalidSignatureException; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; public class StringMessageSink extends AbstractMessageSink { diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java index 6ac2ec2d348..e39dbc4f135 100644 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java +++ b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java @@ -38,8 +38,8 @@ import org.eclipse.jetty.websocket.common.endpoints.listeners.ListenerPartialSoc import org.eclipse.jetty.websocket.common.endpoints.listeners.ListenerPingPongSocket; import org.eclipse.jetty.websocket.core.Behavior; import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.OpCode; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -67,7 +67,7 @@ public class JettyWebSocketFrameHandlerTest } private JettyWebSocketFrameHandlerFactory endpointFactory = new JettyWebSocketFrameHandlerFactory(container); - private FrameHandler.CoreSession coreSession = new FrameHandler.CoreSession.Empty() + private CoreSession coreSession = new CoreSession.Empty() { @Override public Behavior getBehavior() diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/OutgoingMessageCapture.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/OutgoingMessageCapture.java index 76164af7236..c1aee371c84 100644 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/OutgoingMessageCapture.java +++ b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/OutgoingMessageCapture.java @@ -40,11 +40,11 @@ import org.eclipse.jetty.websocket.api.WebSocketBehavior; import org.eclipse.jetty.websocket.common.message.ByteBufferMessageSink; import org.eclipse.jetty.websocket.common.message.StringMessageSink; import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.OpCode; -public class OutgoingMessageCapture extends FrameHandler.CoreSession.Empty implements FrameHandler.CoreSession +public class OutgoingMessageCapture extends CoreSession.Empty implements CoreSession { private static final Logger LOG = Log.getLogger(OutgoingMessageCapture.class); diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServerContainer.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServerContainer.java index f9fa837f8d5..6ce4abe031e 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServerContainer.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServerContainer.java @@ -38,9 +38,9 @@ import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.api.WebSocketSessionListener; import org.eclipse.jetty.websocket.common.SessionTracker; import org.eclipse.jetty.websocket.common.WebSocketContainer; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.WebSocketComponents; -import org.eclipse.jetty.websocket.core.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer; import org.eclipse.jetty.websocket.server.internal.JettyServerFrameHandlerFactory; import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory; @@ -88,7 +88,7 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements private final WebSocketComponents webSocketComponents; private final FrameHandlerFactory frameHandlerFactory; private final Executor executor; - private final FrameHandler.ConfigurationCustomizer customizer = new FrameHandler.ConfigurationCustomizer(); + private final Configuration.ConfigurationCustomizer customizer = new Configuration.ConfigurationCustomizer(); private final List sessionListeners = new ArrayList<>(); private final SessionTracker sessionTracker = new SessionTracker(); diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConnectTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConnectTest.java index 2f9988dcaae..7fefb422b1a 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConnectTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConnectTest.java @@ -427,7 +427,7 @@ public class ClientConnectTest assertThat(jettyUpgradeException, instanceOf(UpgradeException.class)); Throwable coreUpgradeException = jettyUpgradeException.getCause(); - assertThat(coreUpgradeException, instanceOf(org.eclipse.jetty.websocket.core.UpgradeException.class)); + assertThat(coreUpgradeException, instanceOf(org.eclipse.jetty.websocket.core.exception.UpgradeException.class)); Throwable timeoutException = coreUpgradeException.getCause(); assertThat(timeoutException, instanceOf(TimeoutException.class)); diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java index d9233a3b9ce..e0a54fd153d 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java @@ -36,9 +36,11 @@ import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.core.Configuration; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.WebSocketComponents; -import org.eclipse.jetty.websocket.core.WebSocketException; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.core.server.Handshaker; import org.eclipse.jetty.websocket.core.server.Negotiation; import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; @@ -47,13 +49,13 @@ import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE; /** * Mapping of pathSpec to a tupple of {@link WebSocketCreator}, {@link FrameHandlerFactory} and - * {@link org.eclipse.jetty.websocket.core.FrameHandler.Customizer}. + * {@link Configuration.Customizer}. *

- * When the {@link #upgrade(HttpServletRequest, HttpServletResponse, FrameHandler.Customizer)} + * When the {@link #upgrade(HttpServletRequest, HttpServletResponse, Configuration.Customizer)} * method is called, a match for the pathSpec is looked for. If one is found then the * creator is used to create a POJO for the WebSocket endpoint, the factory is used to * wrap that POJO with a {@link FrameHandler} and the customizer is used to configure the resulting - * {@link FrameHandler.CoreSession}.

+ * {@link CoreSession}.

*/ public class WebSocketMapping implements Dumpable, LifeCycle.Listener { @@ -187,7 +189,7 @@ public class WebSocketMapping implements Dumpable, LifeCycle.Listener * @param factory the factory to use to create a FrameHandler for the websocket * @param customizer the customizer to use to customize the WebSocket session. */ - public void addMapping(PathSpec pathSpec, WebSocketCreator creator, FrameHandlerFactory factory, FrameHandler.Customizer customizer) throws WebSocketException + public void addMapping(PathSpec pathSpec, WebSocketCreator creator, FrameHandlerFactory factory, Configuration.Customizer customizer) throws WebSocketException { mappings.put(pathSpec, new Negotiator(creator, factory, customizer)); } @@ -214,7 +216,7 @@ public class WebSocketMapping implements Dumpable, LifeCycle.Listener return mapping.getResource(); } - public boolean upgrade(HttpServletRequest request, HttpServletResponse response, FrameHandler.Customizer defaultCustomizer) throws IOException + public boolean upgrade(HttpServletRequest request, HttpServletResponse response, Configuration.Customizer defaultCustomizer) throws IOException { // Since this may be a filter, we need to be smart about determining the target path. // We should rely on the Container for stripping path parameters and its ilk before @@ -245,7 +247,7 @@ public class WebSocketMapping implements Dumpable, LifeCycle.Listener private final WebSocketCreator creator; private final FrameHandlerFactory factory; - public Negotiator(WebSocketCreator creator, FrameHandlerFactory factory, FrameHandler.Customizer customizer) + public Negotiator(WebSocketCreator creator, FrameHandlerFactory factory, Configuration.Customizer customizer) { super(components, customizer); this.creator = creator; 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 c818781d191..6351e5537be 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 @@ -31,7 +31,7 @@ import org.eclipse.jetty.http.pathmap.PathSpec; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; @@ -181,7 +181,7 @@ public abstract class WebSocketServlet extends HttpServlet super.service(req, resp); } - private class CustomizedWebSocketServletFactory extends FrameHandler.ConfigurationCustomizer implements WebSocketServletFactory + private class CustomizedWebSocketServletFactory extends Configuration.ConfigurationCustomizer implements WebSocketServletFactory { @Override public WebSocketExtensionRegistry getExtensionRegistry() diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServletFactory.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServletFactory.java index d659b9a95a3..e379d2d61c4 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServletFactory.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServletFactory.java @@ -21,10 +21,10 @@ package org.eclipse.jetty.websocket.servlet; import java.time.Duration; import org.eclipse.jetty.http.pathmap.PathSpec; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; -public interface WebSocketServletFactory extends FrameHandler.Configuration +public interface WebSocketServletFactory extends Configuration { WebSocketExtensionRegistry getExtensionRegistry(); diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketUpgradeFilter.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketUpgradeFilter.java index af5c385e75f..9b107a5ca95 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketUpgradeFilter.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketUpgradeFilter.java @@ -40,7 +40,7 @@ import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.WebSocketComponents; /** @@ -125,7 +125,7 @@ public class WebSocketUpgradeFilter implements Filter, Dumpable public static final String MAPPING_ATTRIBUTE_INIT_PARAM = "org.eclipse.jetty.websocket.servlet.WebSocketMapping.key"; - private final FrameHandler.ConfigurationCustomizer defaultCustomizer = new FrameHandler.ConfigurationCustomizer(); + private final Configuration.ConfigurationCustomizer defaultCustomizer = new Configuration.ConfigurationCustomizer(); private WebSocketMapping mapping; @Override From eef87a3fe1b9ef1884652447ceac435c324fc98b Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 31 Dec 2019 12:53:05 +1100 Subject: [PATCH 05/21] fix broken test Signed-off-by: Lachlan Roberts --- .../jetty/websocket/core/proxy/WebSocketProxyTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java index cad6048e962..6f0ad7d209a 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java @@ -40,9 +40,9 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Configuration; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.EchoFrameHandler; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.TestAsyncFrameHandler; import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest; @@ -221,7 +221,7 @@ public class WebSocketProxyTest CloseStatus closeStatus = CloseStatus.getCloseStatus(clientFrameHandler.receivedFrames.poll()); assertThat(closeStatus.getCode(), is(CloseStatus.SERVER_ERROR)); - assertThat(closeStatus.getReason(), containsString("Failed to upgrade to websocket: Unexpected HTTP Response Status Code:")); + assertThat(closeStatus.getReason(), containsString("Failed to upgrade to websocket: Unexpected HTTP Response")); } @Test From b14c9b6fae7abd35dbff6c8dce949bd2a6e078dd Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 7 Jan 2020 17:40:11 +0100 Subject: [PATCH 06/21] Updated copyright in new classes. Signed-off-by: Simone Bordet --- .../java/org/eclipse/jetty/websocket/core/Configuration.java | 2 +- .../main/java/org/eclipse/jetty/websocket/core/CoreSession.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java index 09502df7077..0dca1751b1f 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java @@ -1,6 +1,6 @@ // // ======================================================================== -// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java index 7104323e60a..6bfe4b01575 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java @@ -1,6 +1,6 @@ // // ======================================================================== -// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 From acabec2e91d5a1004b14c308758629970d34700e Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 22 Jan 2020 16:08:08 +1100 Subject: [PATCH 07/21] fix licence headers and checkstyle Signed-off-by: Lachlan Roberts --- .../jetty/websocket/core/Configuration.java | 24 +++++++++---------- .../jetty/websocket/core/CoreSession.java | 24 +++++++++---------- .../core/client/ClientUpgradeRequest.java | 2 +- .../core/internal/FragmentingFlusher.java | 2 +- .../jetty/websocket/core/internal/Parser.java | 4 ++-- .../internal/PerMessageDeflateExtension.java | 6 ++--- .../core/internal/ValidationExtension.java | 2 +- .../core/internal/WebSocketCoreSession.java | 8 +++---- 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java index 0dca1751b1f..8ca544c1521 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java @@ -1,19 +1,19 @@ // -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. // -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 // -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 // -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== // package org.eclipse.jetty.websocket.core; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java index 6bfe4b01575..ec946d38dc5 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java @@ -1,19 +1,19 @@ // -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. // -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 // -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 // -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== // package org.eclipse.jetty.websocket.core; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java index 8c57b5c078a..2ca5886da7f 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java @@ -54,8 +54,8 @@ import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.FrameHandler; -import org.eclipse.jetty.websocket.core.exception.UpgradeException; import org.eclipse.jetty.websocket.core.WebSocketConstants; +import org.eclipse.jetty.websocket.core.exception.UpgradeException; import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Negotiated; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentingFlusher.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentingFlusher.java index e623389944d..aa818c95073 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentingFlusher.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentingFlusher.java @@ -23,8 +23,8 @@ import java.nio.ByteBuffer; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.Configuration; +import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; /** diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java index 2b7b4e61621..7748273d0c2 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java @@ -27,11 +27,11 @@ import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.CloseStatus; -import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.Configuration.ConfigurationHolder; -import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.exception.WebSocketException; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java index c0643f4131c..64f96125549 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java @@ -30,13 +30,13 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.AbstractExtension; -import org.eclipse.jetty.websocket.core.exception.BadPayloadException; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.core.OpCode; -import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.WebSocketComponents; +import org.eclipse.jetty.websocket.core.exception.BadPayloadException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; /** * Per Message Deflate Compression extension for WebSocket. diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java index c7ca6628ec7..2ece2f145e4 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java @@ -27,8 +27,8 @@ import org.eclipse.jetty.websocket.core.AbstractExtension; import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.WebSocketComponents; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import static org.eclipse.jetty.websocket.core.OpCode.CONTINUATION; import static org.eclipse.jetty.websocket.core.OpCode.TEXT; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java index 099dd92a253..3cf6ceeb0ba 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java @@ -36,19 +36,19 @@ import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.Behavior; +import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.CoreSession; -import org.eclipse.jetty.websocket.core.exception.CloseException; -import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.IncomingFrames; -import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.OutgoingFrames; -import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.WebSocketConstants; +import org.eclipse.jetty.websocket.core.exception.CloseException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.exception.WebSocketTimeoutException; import org.eclipse.jetty.websocket.core.exception.WebSocketWriteTimeoutException; import org.eclipse.jetty.websocket.core.internal.Parser.ParsedFrame; From f35a01c73cd2f369e29733fd277e1524bdabec16 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 22 Jan 2020 17:26:07 +1100 Subject: [PATCH 08/21] further checkstyle fixes Signed-off-by: Lachlan Roberts --- .../websocket/core/client/WebSocketClientServerTest.java | 2 +- .../core/extensions/PerMessageDeflateExtensionTest.java | 4 ++-- .../server/internal/JavaxWebSocketServerContainer.java | 2 +- .../websocket/common/JettyWebSocketFrameHandler.java | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java index 2aad46fe91e..59754fbc0d9 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java @@ -26,8 +26,8 @@ import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.CoreSession; +import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.TestFrameHandler; import org.eclipse.jetty.websocket.core.WebSocketServer; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java index dd2bbbbd555..aa12bca3d93 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java @@ -31,14 +31,14 @@ import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.websocket.core.Behavior; +import org.eclipse.jetty.websocket.core.Configuration.ConfigurationCustomizer; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.core.Configuration.ConfigurationCustomizer; import org.eclipse.jetty.websocket.core.IncomingFramesCapture; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.OutgoingFramesCapture; -import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.TestMessageHandler; +import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Negotiated; import org.eclipse.jetty.websocket.core.internal.PerMessageDeflateExtension; diff --git a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java index eeae199b61a..0c84a4ab83d 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java @@ -37,8 +37,8 @@ import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.WebSocketComponents; -import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; +import org.eclipse.jetty.websocket.core.exception.WebSocketException; import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer; import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; import org.eclipse.jetty.websocket.servlet.WebSocketMapping; diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java index 8a1dc7b850a..9679928c97d 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java @@ -31,15 +31,15 @@ import org.eclipse.jetty.websocket.api.UpgradeRequest; import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.api.WriteCallback; import org.eclipse.jetty.websocket.common.invoke.InvalidSignatureException; +import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.CoreSession; -import org.eclipse.jetty.websocket.core.exception.BadPayloadException; -import org.eclipse.jetty.websocket.core.exception.CloseException; -import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; -import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.core.OpCode; +import org.eclipse.jetty.websocket.core.exception.BadPayloadException; +import org.eclipse.jetty.websocket.core.exception.CloseException; +import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.exception.UpgradeException; import org.eclipse.jetty.websocket.core.exception.WebSocketException; From bc88224f1990ce2e106a82ecc40a03e509400b47 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 22 Jan 2020 18:15:59 +1100 Subject: [PATCH 09/21] combine ConfigurationHolder and ConfigurationCustomizer Signed-off-by: Lachlan Roberts --- .../jetty/websocket/core/Configuration.java | 21 ++++++++----------- .../core/internal/FragmentExtension.java | 2 +- .../jetty/websocket/core/internal/Parser.java | 3 +-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java index 8ca544c1521..208923551f0 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java @@ -79,16 +79,16 @@ public interface Configuration void customize(Configuration configurable); } - class ConfigurationHolder implements Configuration + class ConfigurationCustomizer implements Configuration, Customizer { - protected Duration idleTimeout; - protected Duration writeTimeout; - protected Boolean autoFragment; - protected Long maxFrameSize; - protected Integer outputBufferSize; - protected Integer inputBufferSize; - protected Long maxBinaryMessageSize; - protected Long maxTextMessageSize; + private Duration idleTimeout; + private Duration writeTimeout; + private Boolean autoFragment; + private Long maxFrameSize; + private Integer outputBufferSize; + private Integer inputBufferSize; + private Long maxBinaryMessageSize; + private Long maxTextMessageSize; @Override public Duration getIdleTimeout() @@ -185,10 +185,7 @@ public interface Configuration { this.maxTextMessageSize = maxTextMessageSize; } - } - class ConfigurationCustomizer extends ConfigurationHolder implements Customizer - { @Override public void customize(Configuration configurable) { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java index 6cb3a969e21..6d1cecab62a 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java @@ -35,7 +35,7 @@ public class FragmentExtension extends AbstractExtension private static final Logger LOG = Log.getLogger(FragmentExtension.class); private final FragmentingFlusher flusher; - private final Configuration configuration = new Configuration.ConfigurationHolder(); + private final Configuration configuration = new Configuration.ConfigurationCustomizer(); public FragmentExtension() { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java index 7748273d0c2..9ba506a8218 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/Parser.java @@ -28,7 +28,6 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Configuration; -import org.eclipse.jetty.websocket.core.Configuration.ConfigurationHolder; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException; @@ -65,7 +64,7 @@ public class Parser public Parser(ByteBufferPool bufferPool) { - this(bufferPool, new ConfigurationHolder()); + this(bufferPool, new Configuration.ConfigurationCustomizer()); } public Parser(ByteBufferPool bufferPool, Configuration configuration) From 64d72abde60a910e9e9cc56daaa30a069bd9cb61 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 23 Jan 2020 10:20:40 +1100 Subject: [PATCH 10/21] Extension interface now uses CoreSession and not Configuration Signed-off-by: Lachlan Roberts --- .../jetty/websocket/core/AbstractExtension.java | 4 ++-- .../org/eclipse/jetty/websocket/core/Extension.java | 5 +++-- .../jetty/websocket/core/internal/ExtensionStack.java | 2 +- .../websocket/core/internal/ValidationExtension.java | 11 ++++++----- .../websocket/core/extensions/ExtensionTool.java | 2 +- .../extensions/PerMessageDeflateExtensionTest.java | 6 +++--- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java index ca8500453d8..bb9a9d2e849 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java @@ -168,9 +168,9 @@ public class AbstractExtension implements Extension } @Override - public void setConfiguration(Configuration configuration) + public void setCoreSession(CoreSession coreSession) { - this.configuration = configuration; + this.configuration = coreSession; } protected Configuration getConfiguration() diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java index 2fdd345f543..9e67ffa51c5 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java @@ -86,7 +86,8 @@ public interface Extension extends IncomingFrames, OutgoingFrames void setNextOutgoingFrames(OutgoingFrames nextOutgoing); /** - * Set the {@link Configuration} for this Extension. + * Set the {@link CoreSession} for this Extension. + * @param coreSession */ - void setConfiguration(Configuration configuration); + void setCoreSession(CoreSession coreSession); } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java index 8f661710a2f..c1e0cc448e9 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java @@ -254,7 +254,7 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable for (Extension extension : extensions) { - extension.setConfiguration(coreSession); + extension.setCoreSession(coreSession); } } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java index 2ece2f145e4..3cc5f0166ee 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java @@ -24,7 +24,7 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.AbstractExtension; -import org.eclipse.jetty.websocket.core.Configuration; +import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.WebSocketComponents; @@ -55,13 +55,14 @@ public class ValidationExtension extends AbstractExtension } @Override - public void setConfiguration(Configuration configuration) + public void setCoreSession(CoreSession coreSession) { - super.setConfiguration(configuration); + super.setCoreSession(coreSession); - if (!(configuration instanceof WebSocketCoreSession)) + // TODO: change validation to use static methods instead of down casting CoreSession. + if (!(coreSession instanceof WebSocketCoreSession)) throw new IllegalArgumentException("ValidationExtension needs a CoreSession Configuration"); - coreSession = (WebSocketCoreSession)configuration; + this.coreSession = (WebSocketCoreSession)coreSession; } @Override diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java index 6b70e2b725c..c6ee2bf1083 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java @@ -77,7 +77,7 @@ public class ExtensionTool { this.ext = components.getExtensionRegistry().newInstance(extConfig, components); this.ext.setNextIncomingFrames(capture); - this.ext.setConfiguration(newWebSocketCoreSession()); + this.ext.setCoreSession(newWebSocketCoreSession()); } public void parseIncomingHex(String... rawhex) diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java index aa12bca3d93..22d881d9996 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java @@ -376,7 +376,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); ExtensionConfig config = ExtensionConfig.parse("permessage-deflate"); ext.init(config, components); - ext.setConfiguration(newSession()); + ext.setCoreSession(newSession()); // Setup capture of incoming frames IncomingFramesCapture capture = new IncomingFramesCapture(); @@ -450,7 +450,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest { PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); ext.init(ExtensionConfig.parse("permessage-deflate"), components); - ext.setConfiguration(newSession()); + ext.setCoreSession(newSession()); // Setup capture of outgoing frames OutgoingFramesCapture capture = new OutgoingFramesCapture(); @@ -497,7 +497,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); ExtensionConfig config = ExtensionConfig.parse("permessage-deflate"); ext.init(config, components); - ext.setConfiguration(newSession()); + ext.setCoreSession(newSession()); // Setup capture of incoming frames OutgoingFramesCapture capture = new OutgoingFramesCapture(); From 6c2c4d8ad78d6aa78b05135410212f825aeac185 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Fri, 24 Jan 2020 11:05:14 +1100 Subject: [PATCH 11/21] Issue 4450 - remove ConfigurationCustomizer static method Signed-off-by: Lachlan Roberts --- .../org/eclipse/jetty/websocket/core/Configuration.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java index 208923551f0..ffc2d8d9225 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Configuration.java @@ -206,13 +206,5 @@ public interface Configuration if (maxTextMessageSize != null) configurable.setMaxTextMessageSize(maxTextMessageSize); } - - public static ConfigurationCustomizer from(ConfigurationCustomizer parent, ConfigurationCustomizer child) - { - ConfigurationCustomizer customizer = new ConfigurationCustomizer(); - parent.customize(customizer); - child.customize(customizer); - return customizer; - } } } From d74676e46c28e15434eb9ecd105817053f56bf29 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 28 Jan 2020 20:33:16 +1000 Subject: [PATCH 12/21] tck tests are done after ServletContext has already been initialized so we need to test this first to get some tck test passing... (#4514) Signed-off-by: olivier lamy --- .../org/eclipse/jetty/servlet/ServletContextHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java index e93bfa96fbf..7ce95f9709f 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java @@ -1299,15 +1299,15 @@ public class ServletContextHandler extends ContextHandler @Override public boolean setInitParameter(String name, String value) { + //since servlet spec 4.0 + Objects.requireNonNull(name); + if (!isStarting()) throw new IllegalStateException(); if (!_enabled) throw new UnsupportedOperationException(); - //since servlet spec 4.0 - Objects.requireNonNull(name); - return super.setInitParameter(name, value); } From ae6610f4ba49ddb1f253f8ad574d518d7548501a Mon Sep 17 00:00:00 2001 From: Chris Walker Date: Tue, 28 Jan 2020 12:35:50 -0600 Subject: [PATCH 13/21] Updated wireframe of Jetty 9.4 to 10.0 upgrade guide --- .../upgrading/chapter.adoc | 0 .../upgrading/sample.adoc | 0 .../upgrading/upgrading-9.3-to-9.4.adoc | 0 .../upgrading/upgrading-9.4-to.10.0.adoc} | 35 +++++++++++++++---- 4 files changed, 28 insertions(+), 7 deletions(-) rename jetty-documentation/src/main/asciidoc/{embedded-guide/server => quickstart-guide}/upgrading/chapter.adoc (100%) rename jetty-documentation/src/main/asciidoc/{embedded-guide/server => quickstart-guide}/upgrading/sample.adoc (100%) rename jetty-documentation/src/main/asciidoc/{embedded-guide/server => quickstart-guide}/upgrading/upgrading-9.3-to-9.4.adoc (100%) rename jetty-documentation/src/main/asciidoc/{embedded-guide/server/upgrading/upgrading-from-jetty-9.adoc => quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc} (67%) diff --git a/jetty-documentation/src/main/asciidoc/embedded-guide/server/upgrading/chapter.adoc b/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/chapter.adoc similarity index 100% rename from jetty-documentation/src/main/asciidoc/embedded-guide/server/upgrading/chapter.adoc rename to jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/chapter.adoc diff --git a/jetty-documentation/src/main/asciidoc/embedded-guide/server/upgrading/sample.adoc b/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/sample.adoc similarity index 100% rename from jetty-documentation/src/main/asciidoc/embedded-guide/server/upgrading/sample.adoc rename to jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/sample.adoc diff --git a/jetty-documentation/src/main/asciidoc/embedded-guide/server/upgrading/upgrading-9.3-to-9.4.adoc b/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.3-to-9.4.adoc similarity index 100% rename from jetty-documentation/src/main/asciidoc/embedded-guide/server/upgrading/upgrading-9.3-to-9.4.adoc rename to jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.3-to-9.4.adoc diff --git a/jetty-documentation/src/main/asciidoc/embedded-guide/server/upgrading/upgrading-from-jetty-9.adoc b/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc similarity index 67% rename from jetty-documentation/src/main/asciidoc/embedded-guide/server/upgrading/upgrading-from-jetty-9.adoc rename to jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc index bb9bd752bf5..0b3653c10c9 100644 --- a/jetty-documentation/src/main/asciidoc/embedded-guide/server/upgrading/upgrading-from-jetty-9.adoc +++ b/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc @@ -16,22 +16,43 @@ // ======================================================================== // -=== Upgrading from Jetty 9.x to Jetty 10.0.x +=== Upgrading from Jetty 9.4.x to Jetty 10.0.x -The purpose of this guide is to assist users migrating from Jetty 9 to 10. +The purpose of this guide is to assist users migrating from Jetty 9.4 to 10. It is not comprehensive, but covers many of the major changes included in the release that may prove as problem areas for users. -//TODO - Make note of any specific required Java versions. +==== Required Java Version + +Jetty 10 requires, at a minimum, Java 9 to function. +Items such as the Java Platform Module System (JPMS), which Jetty 10 supports, are not available in earlier versions of Java. + +==== Removed Classes + +//TODO - Insert major removed/refactored classes from Jetty-9.x.x to Jetty-10.0.x ==== Changes to Websocket +//TODO - List of changes to Websocket -- Joakim/Lachlan + ==== `javax.mail` and `javax.transaction` Both `javax.mail` and `javax.transaction` have been removed from the Jetty Distribution in Jetty 10. If you require these jars, you will need to enable the `ext` link:#startup-modules[module] and copy the files to your `$JETTY_BASE/lib/ext` directory. -==== Removed Classes - -//TODO - Insert major removed/refactored classes from Jetty-9.x.x to Jetty-10.0.x - ==== Module Changes in Jetty 10.0 + +===== New Modules in Jetty 10.0 + +//TODO - Insert new modules introduced in Jetty 10 + +===== Changes to Existing Modules in Jetty 10.0 + +//TODO - Insert module changes introduced in Jetty 10 + +==== Changes to Sessions + +//TODO - List of changes to Sessions -- Jan + +==== Removal of System Properties(?) + +//TODO - List of removed System bits --- Greg From f6fd3c41a5991f7062c379a90b7182af97484b39 Mon Sep 17 00:00:00 2001 From: Lachlan Date: Wed, 29 Jan 2020 09:15:40 +1100 Subject: [PATCH 14/21] Issue #4462 - Prevent jetty 10 WebSocket close deadlocks (#4472) - Replicate problems from WS close deadlock with test cases - use FutureCallback instead of SharedBlockingCallback for WS blocking methods - add timeout to the blocking callbacks for WS for (idleTimeout + 1000ms) - Core throws ClosedChannelException instead of ISE if send after closed --- .../eclipse/jetty/util/FutureCallback.java | 37 +++++ .../jetty/websocket/core/FrameHandler.java | 4 + .../core/internal/WebSocketSessionState.java | 4 +- .../jetty/websocket/core/FlushTest.java | 135 ++++++++++++++++++ .../websocket/core/WebSocketCloseTest.java | 97 +++++++++++++ .../jetty/websocket/core/WebSocketTester.java | 28 ++-- .../common/JavaxWebSocketBasicRemote.java | 113 ++++++++------- .../common/JavaxWebSocketRemoteEndpoint.java | 34 +++-- .../javax/common/JavaxWebSocketSession.java | 27 ++-- .../javax/common/SessionTracker.java | 16 ++- .../tests/server/SessionTrackingTest.java | 86 ++++++----- .../common/JettyWebSocketRemoteEndpoint.java | 67 ++++----- .../websocket/common/WebSocketSession.java | 2 +- .../websocket/tests/WebSocketStopTest.java | 4 +- .../tests/client/ClientCloseTest.java | 24 ++++ .../tests/server/AbstractCloseEndpoint.java | 10 ++ .../tests/server/CloseInOnCloseEndpoint.java | 31 ++++ .../CloseInOnCloseEndpointNewThread.java | 47 ++++++ .../tests/server/ServerCloseCreator.java | 10 ++ .../tests/server/ServerCloseTest.java | 49 +++++++ 20 files changed, 639 insertions(+), 186 deletions(-) create mode 100644 jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FlushTest.java create mode 100644 jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/CloseInOnCloseEndpoint.java create mode 100644 jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/CloseInOnCloseEndpointNewThread.java diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/FutureCallback.java b/jetty-util/src/main/java/org/eclipse/jetty/util/FutureCallback.java index c7affdf6b1a..f932fc29980 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/FutureCallback.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/FutureCallback.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.util; import java.io.IOException; +import java.io.InterruptedIOException; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -138,6 +139,42 @@ public class FutureCallback implements Future, Callback throw new ExecutionException(_cause); } + public void block() throws IOException + { + block(-1, TimeUnit.SECONDS); + } + + public void block(long timeout, TimeUnit unit) throws IOException + { + try + { + if (timeout > 0) + get(timeout, unit); + else + get(); + } + catch (InterruptedException e) + { + InterruptedIOException exception = new InterruptedIOException(); + exception.initCause(e); + throw exception; + } + catch (ExecutionException e) + { + Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) + throw (RuntimeException)cause; + else if (cause instanceof IOException) + throw (IOException)cause; + else + throw new IOException(cause); + } + catch (TimeoutException e) + { + throw new IOException(e); + } + } + public static void rethrow(ExecutionException e) throws IOException { Throwable cause = e.getCause(); diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java index f62aef00b47..68f853ffd5d 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java @@ -400,16 +400,19 @@ public interface FrameHandler extends IncomingFrames @Override public void flush(Callback callback) { + callback.succeeded(); } @Override public void close(Callback callback) { + callback.succeeded(); } @Override public void close(int statusCode, String reason, Callback callback) { + callback.succeeded(); } @Override @@ -420,6 +423,7 @@ public interface FrameHandler extends IncomingFrames @Override public void sendFrame(Frame frame, Callback callback, boolean batch) { + callback.succeeded(); } } } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketSessionState.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketSessionState.java index dbfefa2ff58..c9597f0fa2d 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketSessionState.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketSessionState.java @@ -142,7 +142,7 @@ public class WebSocketSessionState } } - public boolean onOutgoingFrame(Frame frame) throws ProtocolException + public boolean onOutgoingFrame(Frame frame) throws Exception { byte opcode = frame.getOpCode(); boolean fin = frame.isFin(); @@ -150,7 +150,7 @@ public class WebSocketSessionState synchronized (this) { if (!isOutputOpen()) - throw new IllegalStateException(_sessionState.toString()); + throw new ClosedChannelException(); if (opcode == OpCode.CLOSE) { diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FlushTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FlushTest.java new file mode 100644 index 00000000000..597ef213d82 --- /dev/null +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FlushTest.java @@ -0,0 +1,135 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.core; + +import java.nio.channels.ClosedChannelException; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; +import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class FlushTest +{ + private WebSocketServer server; + private TestFrameHandler serverHandler = new TestFrameHandler(); + private WebSocketCoreClient client; + private WebSocketComponents components = new WebSocketComponents(); + + @BeforeEach + public void startup() throws Exception + { + WebSocketNegotiator negotiator = WebSocketNegotiator.from((negotiation) -> serverHandler); + server = new WebSocketServer(negotiator); + client = new WebSocketCoreClient(null, components); + + server.start(); + client.start(); + } + + @AfterEach + public void shutdown() throws Exception + { + server.stop(); + client.stop(); + } + + @Test + public void testStandardFlush() throws Exception + { + TestFrameHandler clientHandler = new TestFrameHandler(); + CompletableFuture connect = client.connect(clientHandler, server.getUri()); + connect.get(5, TimeUnit.SECONDS); + + // Send a batched frame. + clientHandler.sendFrame(new Frame(OpCode.TEXT, "text payload"), Callback.NOOP, true); + + // We have batched the frame and not sent it. + assertNull(serverHandler.receivedFrames.poll(1, TimeUnit.SECONDS)); + + // Once we flush the frame is received. + clientHandler.getCoreSession().flush(Callback.NOOP); + Frame frame = Objects.requireNonNull(serverHandler.receivedFrames.poll(5, TimeUnit.SECONDS)); + assertThat(frame.getOpCode(), is(OpCode.TEXT)); + assertThat(frame.getPayloadAsUTF8(), is("text payload")); + + clientHandler.sendClose(); + frame = Objects.requireNonNull(serverHandler.receivedFrames.poll(5, TimeUnit.SECONDS)); + assertThat(CloseStatus.getCloseStatus(frame).getCode(), is(CloseStatus.NO_CODE)); + assertTrue(clientHandler.closed.await(5, TimeUnit.SECONDS)); + assertNull(clientHandler.getError()); + assertThat(clientHandler.closeStatus.getCode(), is(CloseStatus.NO_CODE)); + } + + @Test + public void testFlushOnCloseFrame() throws Exception + { + TestFrameHandler clientHandler = new TestFrameHandler(); + CompletableFuture connect = client.connect(clientHandler, server.getUri()); + connect.get(5, TimeUnit.SECONDS); + + // Send a batched frame. + clientHandler.sendFrame(new Frame(OpCode.TEXT, "text payload"), Callback.NOOP, true); + + // We have batched the frame and not sent it. + assertNull(serverHandler.receivedFrames.poll(1, TimeUnit.SECONDS)); + + // Sending the close initiates the flush and the frame is received. + clientHandler.sendClose(); + Frame frame = Objects.requireNonNull(serverHandler.receivedFrames.poll(5, TimeUnit.SECONDS)); + assertThat(frame.getOpCode(), is(OpCode.TEXT)); + assertThat(frame.getPayloadAsUTF8(), is("text payload")); + + frame = Objects.requireNonNull(serverHandler.receivedFrames.poll(5, TimeUnit.SECONDS)); + assertThat(CloseStatus.getCloseStatus(frame).getCode(), is(CloseStatus.NO_CODE)); + assertTrue(clientHandler.closed.await(5, TimeUnit.SECONDS)); + assertNull(clientHandler.getError()); + assertThat(clientHandler.closeStatus.getCode(), is(CloseStatus.NO_CODE)); + } + + @Test + public void testFlushAfterClose() throws Exception + { + TestFrameHandler clientHandler = new TestFrameHandler(); + CompletableFuture connect = client.connect(clientHandler, server.getUri()); + connect.get(5, TimeUnit.SECONDS); + + clientHandler.sendClose(); + assertTrue(clientHandler.closed.await(5, TimeUnit.SECONDS)); + assertNull(clientHandler.getError()); + + Callback.Completable flushCallback = new Callback.Completable(); + clientHandler.getCoreSession().flush(flushCallback); + ExecutionException e = assertThrows(ExecutionException.class, () -> flushCallback.get(5, TimeUnit.SECONDS)); + assertThat(e.getCause(), instanceOf(ClosedChannelException.class)); + } +} diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java index 408e87828eb..8d67222c0e4 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java @@ -19,9 +19,12 @@ package org.eclipse.jetty.websocket.core; import java.net.Socket; +import java.nio.channels.ClosedChannelException; import java.time.Duration; +import java.util.Objects; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.server.NetworkConnector; @@ -48,10 +51,13 @@ import org.junit.jupiter.params.provider.ValueSource; import static org.eclipse.jetty.util.Callback.NOOP; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -425,6 +431,97 @@ public class WebSocketCloseTest extends WebSocketTester assertThat(CloseStatus.getCloseStatus(frame).getCode(), is(CloseStatus.SERVER_ERROR)); } + @ParameterizedTest + @ValueSource(strings = {WS_SCHEME, WSS_SCHEME}) + public void doubleNormalClose(String scheme) throws Exception + { + setup(State.OPEN, scheme); + + Callback.Completable callback1 = new Callback.Completable(); + server.handler.getCoreSession().close(CloseStatus.NORMAL, "normal 1", callback1); + Callback.Completable callback2 = new Callback.Completable(); + server.handler.getCoreSession().close(CloseStatus.NORMAL, "normal 2", callback2); + + // First Callback Succeeded + assertDoesNotThrow(() -> callback1.get(5, TimeUnit.SECONDS)); + + // Second Callback Failed with ClosedChannelException + ExecutionException error = assertThrows(ExecutionException.class, () -> callback2.get(5, TimeUnit.SECONDS)); + assertThat(error.getCause(), instanceOf(ClosedChannelException.class)); + + // Normal close frame received on client. + Frame closeFrame = receiveFrame(client.getInputStream()); + assertThat(closeFrame.getOpCode(), is(OpCode.CLOSE)); + CloseStatus closeStatus = CloseStatus.getCloseStatus(closeFrame); + assertThat(closeStatus.getCode(), is(CloseStatus.NORMAL)); + assertThat(closeStatus.getReason(), is("normal 1")); + + // Send close response from client. + client.getOutputStream().write(RawFrameBuilder.buildClose( + new CloseStatus(CloseStatus.NORMAL, "normal response 1"), true)); + + server.handler.getCoreSession().demand(1); + assertNotNull(server.handler.receivedFrames.poll(10, TimeUnit.SECONDS)); + Callback closeFrameCallback = Objects.requireNonNull(server.handler.receivedCallback.poll()); + closeFrameCallback.succeeded(); + + assertTrue(server.handler.closed.await(5, TimeUnit.SECONDS)); + assertThat(server.handler.closeStatus.getCode(), is(CloseStatus.NORMAL)); + assertThat(server.handler.closeStatus.getReason(), is("normal response 1")); + } + + @ParameterizedTest + @ValueSource(strings = {WS_SCHEME, WSS_SCHEME}) + public void doubleAbnormalClose(String scheme) throws Exception + { + setup(State.OPEN, scheme); + + Callback.Completable callback1 = new Callback.Completable(); + server.handler.getCoreSession().close(CloseStatus.SERVER_ERROR, "server error should succeed", callback1); + Callback.Completable callback2 = new Callback.Completable(); + server.handler.getCoreSession().close(CloseStatus.PROTOCOL, "protocol error should fail", callback2); + + // First Callback Succeeded + assertDoesNotThrow(() -> callback1.get(5, TimeUnit.SECONDS)); + + // Second Callback Failed with ClosedChannelException + ExecutionException error = assertThrows(ExecutionException.class, () -> callback2.get(5, TimeUnit.SECONDS)); + assertThat(error.getCause(), instanceOf(ClosedChannelException.class)); + + assertTrue(server.handler.closed.await(5, TimeUnit.SECONDS)); + assertThat(server.handler.closeStatus.getCode(), is(CloseStatus.SERVER_ERROR)); + assertThat(server.handler.closeStatus.getReason(), containsString("server error should succeed")); + + Frame frame = receiveFrame(client.getInputStream()); + assertThat(CloseStatus.getCloseStatus(frame).getCode(), is(CloseStatus.SERVER_ERROR)); + } + + @ParameterizedTest + @ValueSource(strings = {WS_SCHEME, WSS_SCHEME}) + public void doubleCloseAbnormalOvertakesNormalClose(String scheme) throws Exception + { + setup(State.OPEN, scheme); + + Callback.Completable callback1 = new Callback.Completable(); + server.handler.getCoreSession().close(CloseStatus.NORMAL, "normal close (client does not complete close handshake)", callback1); + Callback.Completable callback2 = new Callback.Completable(); + server.handler.getCoreSession().close(CloseStatus.SERVER_ERROR, "error close should overtake normal close", callback2); + + // First Callback Succeeded + assertDoesNotThrow(() -> callback1.get(5, TimeUnit.SECONDS)); + + // Second Callback Failed with ClosedChannelException + ExecutionException error = assertThrows(ExecutionException.class, () -> callback2.get(5, TimeUnit.SECONDS)); + assertThat(error.getCause(), instanceOf(ClosedChannelException.class)); + + assertTrue(server.handler.closed.await(5, TimeUnit.SECONDS)); + assertThat(server.handler.closeStatus.getCode(), is(CloseStatus.SERVER_ERROR)); + assertThat(server.handler.closeStatus.getReason(), containsString("error close should overtake normal close")); + + Frame frame = receiveFrame(client.getInputStream()); + assertThat(CloseStatus.getCloseStatus(frame).getCode(), is(CloseStatus.NORMAL)); + } + static class DemandingTestFrameHandler implements SynchronousFrameHandler { private CoreSession coreSession; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketTester.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketTester.java index b724ac93db9..d54fa0938e5 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketTester.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketTester.java @@ -47,6 +47,7 @@ public class WebSocketTester private static String NON_RANDOM_KEY = Base64.getEncoder().encodeToString("0123456701234567".getBytes()); private static SslContextFactory.Client sslContextFactory; protected ByteBufferPool bufferPool; + protected ByteBuffer buffer; protected Parser parser; @BeforeAll @@ -159,33 +160,34 @@ public class WebSocketTester protected Parser.ParsedFrame receiveFrame(InputStream in) throws IOException { - ByteBuffer buffer = bufferPool.acquire(4096, false); + if (buffer == null) + buffer = bufferPool.acquire(4096, false); + while (true) { + Parser.ParsedFrame frame = parser.parse(buffer); + if (!buffer.hasRemaining()) + BufferUtil.clear(buffer); + if (frame != null) + return frame; + int p = BufferUtil.flipToFill(buffer); int len = in.read(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); if (len < 0) return null; buffer.position(buffer.position() + len); BufferUtil.flipToFlush(buffer, p); - - Parser.ParsedFrame frame = parser.parse(buffer); - if (frame != null) - return frame; } } protected void receiveEof(InputStream in) throws IOException { ByteBuffer buffer = bufferPool.acquire(4096, false); - while (true) - { - BufferUtil.flipToFill(buffer); - int len = in.read(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); - if (len < 0) - return; + BufferUtil.clearToFill(buffer); + int len = in.read(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); + if (len < 0) + return; - throw new IllegalStateException("unexpected content"); - } + throw new IllegalStateException("unexpected content"); } } diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketBasicRemote.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketBasicRemote.java index 990d6628ce8..ce1570881d6 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketBasicRemote.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketBasicRemote.java @@ -22,11 +22,12 @@ import java.io.IOException; import java.io.OutputStream; import java.io.Writer; import java.nio.ByteBuffer; +import java.util.concurrent.TimeUnit; import javax.websocket.EncodeException; import javax.websocket.RemoteEndpoint; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.SharedBlockingCallback; +import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.Frame; @@ -65,10 +66,10 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl { LOG.debug("sendBinary({})", BufferUtil.toDetailString(data)); } - try (SharedBlockingCallback.Blocker b = session.getBlocking().acquire()) - { - sendFrame(new Frame(OpCode.BINARY).setPayload(data), b, false); - } + + FutureCallback b = new FutureCallback(); + sendFrame(new Frame(OpCode.BINARY).setPayload(data), b, false); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } @Override @@ -79,37 +80,36 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl { LOG.debug("sendBinary({},{})", BufferUtil.toDetailString(partialByte), isLast); } - try (SharedBlockingCallback.Blocker b = session.getBlocking().acquire()) - { - Frame frame; - switch (messageType) - { - case -1: - // New message! - frame = new Frame(OpCode.BINARY); - break; - case OpCode.TEXT: - throw new IllegalStateException("Cannot send a partial BINARY message: TEXT message in progress"); - case OpCode.BINARY: - frame = new Frame(OpCode.CONTINUATION); - break; - default: - throw new IllegalStateException("Cannot send a partial BINARY message: unrecognized active message type " + OpCode.name(messageType)); - } - frame.setPayload(partialByte); - frame.setFin(isLast); - sendFrame(frame, b, false); + Frame frame; + switch (messageType) + { + case -1: + // New message! + frame = new Frame(OpCode.BINARY); + break; + case OpCode.TEXT: + throw new IllegalStateException("Cannot send a partial BINARY message: TEXT message in progress"); + case OpCode.BINARY: + frame = new Frame(OpCode.CONTINUATION); + break; + default: + throw new IllegalStateException("Cannot send a partial BINARY message: unrecognized active message type " + OpCode.name(messageType)); } + + frame.setPayload(partialByte); + frame.setFin(isLast); + FutureCallback b = new FutureCallback(); + sendFrame(frame, b, false); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } @Override public void sendObject(Object data) throws IOException, EncodeException { - try (SharedBlockingCallback.Blocker b = session.getBlocking().acquire()) - { - super.sendObject(data, b); - } + FutureCallback b = new FutureCallback(); + super.sendObject(data, b); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } @Override @@ -120,10 +120,11 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl { LOG.debug("sendText({})", TextUtil.hint(text)); } - try (SharedBlockingCallback.Blocker b = session.getBlocking().acquire()) - { - sendFrame(new Frame(OpCode.TEXT).setPayload(text), b, false); - } + + + FutureCallback b = new FutureCallback(); + sendFrame(new Frame(OpCode.TEXT).setPayload(text), b, false); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } @Override @@ -134,27 +135,33 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl { LOG.debug("sendText({},{})", TextUtil.hint(partialMessage), isLast); } - try (SharedBlockingCallback.Blocker b = session.getBlocking().acquire()) - { - Frame frame; - switch (messageType) - { - case -1: - // New message! - frame = new Frame(OpCode.TEXT); - break; - case OpCode.TEXT: - frame = new Frame(OpCode.CONTINUATION); - break; - case OpCode.BINARY: - throw new IllegalStateException("Cannot send a partial TEXT message: BINARY message in progress"); - default: - throw new IllegalStateException("Cannot send a partial TEXT message: unrecognized active message type " + OpCode.name(messageType)); - } - frame.setPayload(BufferUtil.toBuffer(partialMessage, UTF_8)); - frame.setFin(isLast); - sendFrame(frame, b, false); + Frame frame; + switch (messageType) + { + case -1: + // New message! + frame = new Frame(OpCode.TEXT); + break; + case OpCode.TEXT: + frame = new Frame(OpCode.CONTINUATION); + break; + case OpCode.BINARY: + throw new IllegalStateException("Cannot send a partial TEXT message: BINARY message in progress"); + default: + throw new IllegalStateException("Cannot send a partial TEXT message: unrecognized active message type " + OpCode.name(messageType)); } + + frame.setPayload(BufferUtil.toBuffer(partialMessage, UTF_8)); + frame.setFin(isLast); + FutureCallback b = new FutureCallback(); + sendFrame(frame, b, false); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); + } + + private long getBlockingTimeout() + { + long idleTimeout = getIdleTimeout(); + return (idleTimeout > 0) ? idleTimeout + 1000 : idleTimeout; } } diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketRemoteEndpoint.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketRemoteEndpoint.java index b58dab7cbb9..b9788c3a129 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketRemoteEndpoint.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketRemoteEndpoint.java @@ -21,13 +21,14 @@ package org.eclipse.jetty.websocket.javax.common; import java.io.IOException; import java.nio.ByteBuffer; import java.time.Duration; +import java.util.concurrent.TimeUnit; import javax.websocket.EncodeException; import javax.websocket.Encoder; import javax.websocket.SendHandler; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.SharedBlockingCallback; +import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.Frame; @@ -66,10 +67,9 @@ public class JavaxWebSocketRemoteEndpoint implements javax.websocket.RemoteEndpo @Override public void flushBatch() throws IOException { - try (SharedBlockingCallback.Blocker blocker = session.getBlocking().acquire()) - { - coreSession.flush(blocker); - } + FutureCallback b = new FutureCallback(); + coreSession.flush(b); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } @Override @@ -227,24 +227,22 @@ public class JavaxWebSocketRemoteEndpoint implements javax.websocket.RemoteEndpo public void sendPing(ByteBuffer data) throws IOException, IllegalArgumentException { if (LOG.isDebugEnabled()) - { LOG.debug("sendPing({})", BufferUtil.toDetailString(data)); - } - // TODO: is this supposed to be a blocking call? - // TODO: what to do on excessively large payloads (error and close connection per RFC6455, or truncate?) - sendFrame(new Frame(OpCode.PING).setPayload(data), Callback.NOOP, batch); + + FutureCallback b = new FutureCallback(); + sendFrame(new Frame(OpCode.PING).setPayload(data), b, batch); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } @Override public void sendPong(ByteBuffer data) throws IOException, IllegalArgumentException { if (LOG.isDebugEnabled()) - { LOG.debug("sendPong({})", BufferUtil.toDetailString(data)); - } - // TODO: is this supposed to be a blocking call? - // TODO: what to do on excessively large payloads (error and close connection per RFC6455, or truncate?) - sendFrame(new Frame(OpCode.PONG).setPayload(data), Callback.NOOP, batch); + + FutureCallback b = new FutureCallback(); + sendFrame(new Frame(OpCode.PONG).setPayload(data), b, batch); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } protected void assertMessageNotNull(Object data) @@ -262,4 +260,10 @@ public class JavaxWebSocketRemoteEndpoint implements javax.websocket.RemoteEndpo throw new IllegalArgumentException("SendHandler cannot be null"); } } + + private long getBlockingTimeout() + { + long idleTimeout = getIdleTimeout(); + return (idleTimeout > 0) ? idleTimeout + 1000 : idleTimeout; + } } diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java index 1dcfa2215a4..3ea4335fd2f 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketSession.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.websocket.CloseReason; import javax.websocket.EndpointConfig; @@ -38,7 +39,7 @@ import javax.websocket.RemoteEndpoint.Basic; import javax.websocket.Session; import javax.websocket.WebSocketContainer; -import org.eclipse.jetty.util.SharedBlockingCallback; +import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.ExtensionConfig; @@ -54,7 +55,6 @@ public class JavaxWebSocketSession implements javax.websocket.Session { private static final Logger LOG = Log.getLogger(JavaxWebSocketSession.class); - protected final SharedBlockingCallback blocking = new SharedBlockingCallback(); private final JavaxWebSocketContainer container; private final FrameHandler.CoreSession coreSession; private final JavaxWebSocketFrameHandler frameHandler; @@ -179,10 +179,7 @@ public class JavaxWebSocketSession implements javax.websocket.Session @Override public void close() throws IOException { - try (SharedBlockingCallback.Blocker blocker = blocking.acquire()) - { - coreSession.close(blocker); - } + close(new CloseReason(CloseReason.CloseCodes.NO_STATUS_CODE, null)); } /** @@ -194,10 +191,15 @@ public class JavaxWebSocketSession implements javax.websocket.Session @Override public void close(CloseReason closeReason) throws IOException { - try (SharedBlockingCallback.Blocker blocker = blocking.acquire()) - { - coreSession.close(closeReason.getCloseCode().getCode(), closeReason.getReasonPhrase(), blocker); - } + FutureCallback b = new FutureCallback(); + coreSession.close(closeReason.getCloseCode().getCode(), closeReason.getReasonPhrase(), b); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); + } + + private long getBlockingTimeout() + { + long idleTimeout = getMaxIdleTimeout(); + return (idleTimeout > 0) ? idleTimeout + 1000 : idleTimeout; } /** @@ -565,9 +567,4 @@ public class JavaxWebSocketSession implements javax.websocket.Session return String.format("%s@%x[%s,%s]", this.getClass().getSimpleName(), this.hashCode(), coreSession.getBehavior(), frameHandler); } - - protected SharedBlockingCallback getBlocking() - { - return blocking; - } } diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/SessionTracker.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/SessionTracker.java index 31e3b3a8c65..afb500d7fa8 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/SessionTracker.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/SessionTracker.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.websocket.javax.common; +import java.io.IOException; import java.util.Collections; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; @@ -25,9 +26,13 @@ import javax.websocket.CloseReason; import javax.websocket.Session; import org.eclipse.jetty.util.component.AbstractLifeCycle; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; public class SessionTracker extends AbstractLifeCycle implements JavaxWebSocketSessionListener { + private static final Logger LOG = Log.getLogger(SessionTracker.class); + private CopyOnWriteArraySet sessions = new CopyOnWriteArraySet<>(); public Set getSessions() @@ -52,8 +57,15 @@ public class SessionTracker extends AbstractLifeCycle implements JavaxWebSocketS { for (Session session : sessions) { - // GOING_AWAY is abnormal close status so it will hard close connection after sent. - session.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, "Container being shut down")); + try + { + // GOING_AWAY is abnormal close status so it will hard close connection after sent. + session.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, "Container being shut down")); + } + catch (IOException e) + { + LOG.ignore(e); + } } super.doStop(); diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/SessionTrackingTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/SessionTrackingTest.java index ad811ab992c..167ed437a13 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/SessionTrackingTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/SessionTrackingTest.java @@ -42,7 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class SessionTrackingTest { - static BlockingArrayQueue serverSessions = new BlockingArrayQueue<>(); + private static BlockingArrayQueue serverSessions = new BlockingArrayQueue<>(); @ServerEndpoint("/session-info/{sessionId}") public static class SessionTrackingSocket @@ -104,59 +104,53 @@ public class SessionTrackingTest EventSocket clientSocket2 = new EventSocket(); EventSocket clientSocket3 = new EventSocket(); - try (Session session1 = client.connectToServer(clientSocket1, server.getWsUri().resolve("/session-info/1"))) - { - Session serverSession1 = serverSessions.poll(5, TimeUnit.SECONDS); - assertNotNull(serverSession1); - sendTextFrameToAll("openSessions|in-1", session1); - assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-1).size=1")); + Session session1 = client.connectToServer(clientSocket1, server.getWsUri().resolve("/session-info/1")); + Session serverSession1 = serverSessions.poll(5, TimeUnit.SECONDS); + assertNotNull(serverSession1); + sendTextFrameToAll("openSessions|in-1", session1); + assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-1).size=1")); - try (Session session2 = client.connectToServer(clientSocket2, server.getWsUri().resolve("/session-info/2"))) - { - Session serverSession2 = serverSessions.poll(5, TimeUnit.SECONDS); - assertNotNull(serverSession2); - sendTextFrameToAll("openSessions|in-2", session1, session2); - assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-2).size=2")); - assertThat(clientSocket2.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-2).size=2")); + Session session2 = client.connectToServer(clientSocket2, server.getWsUri().resolve("/session-info/2")); + Session serverSession2 = serverSessions.poll(5, TimeUnit.SECONDS); + assertNotNull(serverSession2); + sendTextFrameToAll("openSessions|in-2", session1, session2); + assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-2).size=2")); + assertThat(clientSocket2.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-2).size=2")); - try (Session session3 = client.connectToServer(clientSocket3, server.getWsUri().resolve("/session-info/3"))) - { - Session serverSession3 = serverSessions.poll(5, TimeUnit.SECONDS); - assertNotNull(serverSession3); - sendTextFrameToAll("openSessions|in-3", session1, session2, session3); - assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-3).size=3")); - assertThat(clientSocket2.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-3).size=3")); - assertThat(clientSocket3.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-3).size=3")); + Session session3 = client.connectToServer(clientSocket3, server.getWsUri().resolve("/session-info/3")); + Session serverSession3 = serverSessions.poll(5, TimeUnit.SECONDS); + assertNotNull(serverSession3); + sendTextFrameToAll("openSessions|in-3", session1, session2, session3); + assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-3).size=3")); + assertThat(clientSocket2.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-3).size=3")); + assertThat(clientSocket3.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@in-3).size=3")); - sendTextFrameToAll("openSessions|lvl-3", session1, session2, session3); - assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-3).size=3")); - assertThat(clientSocket2.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-3).size=3")); - assertThat(clientSocket3.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-3).size=3")); + sendTextFrameToAll("openSessions|lvl-3", session1, session2, session3); + assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-3).size=3")); + assertThat(clientSocket2.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-3).size=3")); + assertThat(clientSocket3.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-3).size=3")); - // assert session is closed, and we have received the notification from the SessionListener - session3.close(); - assertThat(server.getTrackingListener().getClosedSessions().poll(5, TimeUnit.SECONDS), sameInstance(serverSession3)); - assertTrue(clientSocket3.closeLatch.await(5, TimeUnit.SECONDS)); - } + // assert session is closed, and we have received the notification from the SessionListener + session3.close(); + assertThat(server.getTrackingListener().getClosedSessions().poll(5, TimeUnit.SECONDS), sameInstance(serverSession3)); + assertTrue(clientSocket3.closeLatch.await(5, TimeUnit.SECONDS)); - sendTextFrameToAll("openSessions|lvl-2", session1, session2); - assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-2).size=2")); - assertThat(clientSocket2.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-2).size=2")); + sendTextFrameToAll("openSessions|lvl-2", session1, session2); + assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-2).size=2")); + assertThat(clientSocket2.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-2).size=2")); - // assert session is closed, and we have received the notification from the SessionListener - session2.close(); - assertThat(server.getTrackingListener().getClosedSessions().poll(5, TimeUnit.SECONDS), sameInstance(serverSession2)); - assertTrue(clientSocket2.closeLatch.await(5, TimeUnit.SECONDS)); - } + // assert session is closed, and we have received the notification from the SessionListener + session2.close(); + assertThat(server.getTrackingListener().getClosedSessions().poll(5, TimeUnit.SECONDS), sameInstance(serverSession2)); + assertTrue(clientSocket2.closeLatch.await(5, TimeUnit.SECONDS)); - sendTextFrameToAll("openSessions|lvl-1", session1); - assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-1).size=1")); + sendTextFrameToAll("openSessions|lvl-1", session1); + assertThat(clientSocket1.messageQueue.poll(5, TimeUnit.SECONDS), is("openSessions(@lvl-1).size=1")); - // assert session is closed, and we have received the notification from the SessionListener - session1.close(); - assertThat(server.getTrackingListener().getClosedSessions().poll(5, TimeUnit.SECONDS), sameInstance(serverSession1)); - assertTrue(clientSocket1.closeLatch.await(5, TimeUnit.SECONDS)); - } + // assert session is closed, and we have received the notification from the SessionListener + session1.close(); + assertThat(server.getTrackingListener().getClosedSessions().poll(5, TimeUnit.SECONDS), sameInstance(serverSession1)); + assertTrue(clientSocket1.closeLatch.await(5, TimeUnit.SECONDS)); } private static void sendTextFrameToAll(String msg, Session... sessions) throws IOException diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java index 75ba4aed8dd..7d66e544808 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java @@ -22,11 +22,15 @@ import java.io.IOException; import java.net.SocketAddress; import java.nio.ByteBuffer; import java.util.Objects; +import java.util.concurrent.TimeUnit; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.SharedBlockingCallback; +import org.eclipse.jetty.util.FutureCallback; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.api.BatchMode; +import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.WriteCallback; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; @@ -37,9 +41,10 @@ import static java.nio.charset.StandardCharsets.UTF_8; public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket.api.RemoteEndpoint { + private static final Logger LOG = Log.getLogger(JettyWebSocketRemoteEndpoint.class); + private final FrameHandler.CoreSession coreSession; private byte messageType = -1; - private final SharedBlockingCallback blocker = new SharedBlockingCallback(); private BatchMode batchMode; public JettyWebSocketRemoteEndpoint(FrameHandler.CoreSession coreSession, BatchMode batchMode) @@ -55,14 +60,7 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket */ public void close() { - try (SharedBlockingCallback.Blocker b = blocker.acquire()) - { - coreSession.close(b); - } - catch (IOException e) - { - coreSession.close(Callback.NOOP); - } + close(StatusCode.NO_CODE, null); } /** @@ -74,13 +72,15 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket */ public void close(int statusCode, String reason) { - try (SharedBlockingCallback.Blocker b = blocker.acquire()) + try { + FutureCallback b = new FutureCallback(); coreSession.close(statusCode, reason, b); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } catch (IOException e) { - coreSession.close(Callback.NOOP); + LOG.ignore(e); } } @@ -114,11 +114,9 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket @Override public void sendPartialBytes(ByteBuffer fragment, boolean isLast) throws IOException { - try (SharedBlockingCallback.Blocker b = blocker.acquire()) - { - sendPartialBytes(fragment, isLast, b); - b.block(); - } + FutureCallback b = new FutureCallback(); + sendPartialBytes(fragment, isLast, b); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } @Override @@ -158,11 +156,9 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket @Override public void sendPartialString(String fragment, boolean isLast) throws IOException { - try (SharedBlockingCallback.Blocker b = blocker.acquire()) - { - sendPartialText(fragment, isLast, b); - b.block(); - } + FutureCallback b = new FutureCallback(); + sendPartialText(fragment, isLast, b); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } @Override @@ -227,16 +223,9 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket private void sendBlocking(Frame frame) throws IOException { - try (SharedBlockingCallback.Blocker b = blocker.acquire()) - { - coreSession.sendFrame(frame, b, false); - b.block(); - } - } - - protected FrameHandler.CoreSession getCoreSession() - { - return coreSession; + FutureCallback b = new FutureCallback(); + coreSession.sendFrame(frame, b, false); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); } @Override @@ -265,10 +254,14 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket @Override public void flush() throws IOException { - try (SharedBlockingCallback.Blocker b = blocker.acquire()) - { - coreSession.flush(b); - b.block(); - } + FutureCallback b = new FutureCallback(); + coreSession.flush(b); + b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); + } + + private long getBlockingTimeout() + { + long idleTimeout = coreSession.getIdleTimeout().toMillis(); + return (idleTimeout > 0) ? idleTimeout + 1000 : idleTimeout; } } diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java index 7dbe4c02ea5..e7d7b8da258 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java @@ -183,7 +183,7 @@ public class WebSocketSession implements Session, SuspendToken, Dumpable @Override public boolean isOpen() { - return remoteEndpoint.getCoreSession().isOutputOpen(); + return coreSession.isOutputOpen(); } @Override diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java index 41a00d51f89..cefe7e6854f 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.websocket.tests; import java.net.URI; +import java.nio.channels.ClosedChannelException; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.server.Server; @@ -125,8 +126,7 @@ public class WebSocketStopTest assertThat(clientSocket.statusCode, is(StatusCode.NORMAL)); assertThat(serverSocket.statusCode, is(StatusCode.NORMAL)); - IllegalStateException failure = assertThrows(IllegalStateException.class, + assertThrows(ClosedChannelException.class, () -> session.getRemote().sendString("this should fail before ExtensionStack")); - assertThat(failure.getMessage(), is("CLOSED")); } } diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java index 2e068164158..f6396f5a6f3 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java @@ -65,6 +65,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -285,6 +286,29 @@ public class ClientCloseTest clientSessionTracker.assertClosedProperly(client); } + @Test + public void testDoubleClose() throws Exception + { + ClientOpenSessionTracker clientSessionTracker = new ClientOpenSessionTracker(1); + clientSessionTracker.addTo(client); + + // Client connects + URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/ws")); + CloseTrackingEndpoint clientSocket = new CloseTrackingEndpoint(); + Future clientConnectFuture = client.connect(clientSocket, wsUri); + + // Client confirms connection via echo. + confirmConnection(clientSocket, clientConnectFuture); + + // Close twice, first close should succeed and second close is a NOOP + clientSocket.getSession().close(StatusCode.NORMAL, "close1"); + clientSocket.getSession().close(StatusCode.NO_CODE, "close2"); + + // Second close is ignored, we are notified of the first close. + clientSocket.assertReceivedCloseEvent(5000, is(StatusCode.NORMAL), containsString("close1")); + assertNull(clientSocket.error.get()); + } + @Test public void testStopLifecycle() throws Exception { diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractCloseEndpoint.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractCloseEndpoint.java index b5f97941718..65986dc4c31 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractCloseEndpoint.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractCloseEndpoint.java @@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.WebSocketAdapter; import org.hamcrest.Matcher; @@ -34,6 +35,7 @@ import static org.hamcrest.Matchers.nullValue; public abstract class AbstractCloseEndpoint extends WebSocketAdapter { public final Logger log; + public CountDownLatch openLatch = new CountDownLatch(1); public CountDownLatch closeLatch = new CountDownLatch(1); public String closeReason = null; public int closeStatusCode = -1; @@ -44,6 +46,14 @@ public abstract class AbstractCloseEndpoint extends WebSocketAdapter this.log = Log.getLogger(this.getClass().getName()); } + @Override + public void onWebSocketConnect(Session sess) + { + super.onWebSocketConnect(sess); + log.debug("onWebSocketConnect({})", sess); + openLatch.countDown(); + } + @Override public void onWebSocketClose(int statusCode, String reason) { diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/CloseInOnCloseEndpoint.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/CloseInOnCloseEndpoint.java new file mode 100644 index 00000000000..37de5a3928c --- /dev/null +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/CloseInOnCloseEndpoint.java @@ -0,0 +1,31 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests.server; + +import org.eclipse.jetty.websocket.api.StatusCode; + +public class CloseInOnCloseEndpoint extends AbstractCloseEndpoint +{ + @Override + public void onWebSocketClose(int statusCode, String reason) + { + getSession().close(StatusCode.SERVER_ERROR, "this should be a noop"); + super.onWebSocketClose(statusCode, reason); + } +} diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/CloseInOnCloseEndpointNewThread.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/CloseInOnCloseEndpointNewThread.java new file mode 100644 index 00000000000..8286ad10dfa --- /dev/null +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/CloseInOnCloseEndpointNewThread.java @@ -0,0 +1,47 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests.server; + +import java.util.concurrent.CountDownLatch; + +import org.eclipse.jetty.websocket.api.StatusCode; + +public class CloseInOnCloseEndpointNewThread extends AbstractCloseEndpoint +{ + @Override + public void onWebSocketClose(int statusCode, String reason) + { + try + { + CountDownLatch complete = new CountDownLatch(1); + new Thread(() -> + { + getSession().close(StatusCode.SERVER_ERROR, "this should be a noop"); + complete.countDown(); + }).start(); + complete.await(); + } + catch (InterruptedException e) + { + throw new RuntimeException(e); + } + + super.onWebSocketClose(statusCode, reason); + } +} diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseCreator.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseCreator.java index 178e8f7e02a..2b2e90f3f0b 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseCreator.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseCreator.java @@ -63,6 +63,16 @@ public class ServerCloseCreator implements JettyWebSocketCreator closeSocket = new ContainerEndpoint(container); resp.setAcceptedSubProtocol("container"); } + else if (req.hasSubProtocol("closeInOnClose")) + { + closeSocket = new CloseInOnCloseEndpoint(); + resp.setAcceptedSubProtocol("closeInOnClose"); + } + else if (req.hasSubProtocol("closeInOnCloseNewThread")) + { + closeSocket = new CloseInOnCloseEndpointNewThread(); + resp.setAcceptedSubProtocol("closeInOnCloseNewThread"); + } if (closeSocket != null) { diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java index 1c5f489c39f..8870a9868d2 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java @@ -51,6 +51,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests various close scenarios @@ -275,4 +276,52 @@ public class ServerCloseTest close(session); } } + + @Test + public void testSecondCloseFromOnClosed() throws Exception + { + // Testing WebSocketSession.close() in onClosed() does not cause deadlock. + ClientUpgradeRequest request = new ClientUpgradeRequest(); + request.setSubProtocols("closeInOnClose"); + CloseTrackingEndpoint clientEndpoint = new CloseTrackingEndpoint(); + + URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/ws")); + client.connect(clientEndpoint, wsUri, request).get(5, SECONDS); + + // Hard close from the server. Server onClosed() will try to close again which should be a NOOP. + AbstractCloseEndpoint serverEndpoint = serverEndpointCreator.pollLastCreated(); + assertTrue(serverEndpoint.openLatch.await(5, SECONDS)); + serverEndpoint.getSession().close(StatusCode.SHUTDOWN, "SHUTDOWN hard close"); + + // Verify that client got close + clientEndpoint.assertReceivedCloseEvent(5000, is(StatusCode.SHUTDOWN), containsString("SHUTDOWN hard close")); + + // Verify that server socket got close event + assertTrue(serverEndpoint.closeLatch.await(5, SECONDS)); + assertThat(serverEndpoint.closeStatusCode, is(StatusCode.SHUTDOWN)); + } + + @Test + public void testSecondCloseFromOnClosedInNewThread() throws Exception + { + // Testing WebSocketSession.close() in onClosed() does not cause deadlock. + ClientUpgradeRequest request = new ClientUpgradeRequest(); + request.setSubProtocols("closeInOnCloseNewThread"); + CloseTrackingEndpoint clientEndpoint = new CloseTrackingEndpoint(); + + URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/ws")); + client.connect(clientEndpoint, wsUri, request).get(5, SECONDS); + + // Hard close from the server. Server onClosed() will try to close again which should be a NOOP. + AbstractCloseEndpoint serverEndpoint = serverEndpointCreator.pollLastCreated(); + assertTrue(serverEndpoint.openLatch.await(5, SECONDS)); + serverEndpoint.getSession().close(StatusCode.SHUTDOWN, "SHUTDOWN hard close"); + + // Verify that client got close + clientEndpoint.assertReceivedCloseEvent(5000, is(StatusCode.SHUTDOWN), containsString("SHUTDOWN hard close")); + + // Verify that server socket got close event + assertTrue(serverEndpoint.closeLatch.await(5, SECONDS)); + assertThat(serverEndpoint.closeStatusCode, is(StatusCode.SHUTDOWN)); + } } From 4ef208e9f62282ff8a9315ef80d47b43ce9a70f8 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 29 Jan 2020 15:19:48 +1100 Subject: [PATCH 15/21] Issue #4502 - onClose can now be triggered on receiving a close frame Signed-off-by: Lachlan Roberts --- .../common/JavaxWebSocketFrameHandler.java | 30 ++++++++++++++----- .../common/JettyWebSocketFrameHandler.java | 28 ++++++++++++----- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java index 0f794aac574..04f2f745ee0 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java @@ -22,10 +22,12 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import javax.websocket.ClientEndpointConfig; import javax.websocket.CloseReason; @@ -60,6 +62,8 @@ public class JavaxWebSocketFrameHandler implements FrameHandler private final Logger logger; private final JavaxWebSocketContainer container; private final Object endpointInstance; + private final AtomicBoolean closeNotified = new AtomicBoolean(); + /** * List of configured named variables in the uri-template. *

@@ -278,9 +282,27 @@ public class JavaxWebSocketFrameHandler implements FrameHandler dataType = OpCode.UNDEFINED; } + public void onClose(Frame frame, Callback callback) + { + notifyOnClose(CloseStatus.getCloseStatus(frame), callback); + } + @Override public void onClosed(CloseStatus closeStatus, Callback callback) { + notifyOnClose(closeStatus, callback); + container.notifySessionListeners((listener) -> listener.onJavaxWebSocketSessionClosed(session)); + } + + private void notifyOnClose(CloseStatus closeStatus, Callback callback) + { + // Make sure onClose is only notified once. + if (!closeNotified.compareAndSet(false, true)) + { + callback.failed(new ClosedChannelException()); + return; + } + try { if (closeHandle != null) @@ -288,14 +310,13 @@ public class JavaxWebSocketFrameHandler implements FrameHandler CloseReason closeReason = new CloseReason(CloseReason.CloseCodes.getCloseCode(closeStatus.getCode()), closeStatus.getReason()); closeHandle.invoke(closeReason); } + callback.succeeded(); } catch (Throwable cause) { callback.failed(new WebSocketException(endpointInstance.getClass().getSimpleName() + " CLOSE method error: " + cause.getMessage(), cause)); } - - container.notifySessionListeners((listener) -> listener.onJavaxWebSocketSessionClosed(session)); } @Override @@ -572,11 +593,6 @@ public class JavaxWebSocketFrameHandler implements FrameHandler activeMessageSink = null; } - public void onClose(Frame frame, Callback callback) - { - callback.succeeded(); - } - public void onPing(Frame frame, Callback callback) { ByteBuffer payload = BufferUtil.copy(frame.getPayload()); diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java index e2688befbbd..556eabd835e 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandler.java @@ -20,7 +20,9 @@ package org.eclipse.jetty.websocket.common; import java.lang.invoke.MethodHandle; import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; import java.util.concurrent.Executor; +import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; @@ -57,6 +59,7 @@ public class JettyWebSocketFrameHandler implements FrameHandler private final WebSocketContainer container; private final Object endpointInstance; private final BatchMode batchMode; + private final AtomicBoolean closeNotified = new AtomicBoolean(); private MethodHandle openHandle; private MethodHandle closeHandle; private MethodHandle errorHandle; @@ -278,6 +281,11 @@ public class JettyWebSocketFrameHandler implements FrameHandler } } + private void onCloseFrame(Frame frame, Callback callback) + { + notifyOnClose(CloseStatus.getCloseStatus(frame), callback); + } + @Override public void onClosed(CloseStatus closeStatus, Callback callback) { @@ -287,6 +295,19 @@ public class JettyWebSocketFrameHandler implements FrameHandler state = SuspendState.CLOSED; } + notifyOnClose(closeStatus, callback); + container.notifySessionListeners((listener) -> listener.onWebSocketSessionClosed(session)); + } + + private void notifyOnClose(CloseStatus closeStatus, Callback callback) + { + // Make sure onClose is only notified once. + if (!closeNotified.compareAndSet(false, true)) + { + callback.failed(new ClosedChannelException()); + return; + } + try { if (closeHandle != null) @@ -298,8 +319,6 @@ public class JettyWebSocketFrameHandler implements FrameHandler { callback.failed(new WebSocketException(endpointInstance.getClass().getSimpleName() + " CLOSE method error: " + cause.getMessage(), cause)); } - - container.notifySessionListeners((listener) -> listener.onWebSocketSessionClosed(session)); } public String toString() @@ -330,11 +349,6 @@ public class JettyWebSocketFrameHandler implements FrameHandler acceptMessage(frame, callback); } - private void onCloseFrame(Frame frame, Callback callback) - { - callback.succeeded(); - } - private void onContinuationFrame(Frame frame, Callback callback) { acceptMessage(frame, callback); From fdd27a9f28a66754675cd2db0f11a8b3e3593503 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 29 Jan 2020 15:20:36 +1100 Subject: [PATCH 16/21] Issue #4502 - add onClose tests for Jetty and Javax WS APIs Signed-off-by: Lachlan Roberts --- .../eclipse/jetty/util/FutureCallback.java | 4 +- .../websocket/javax/tests/EventSocket.java | 2 + .../javax/tests/JavaxOnCloseTest.java | 226 ++++++++++++++++++ .../websocket/tests/JettyOnCloseTest.java | 195 +++++++++++++++ .../test/resources/jetty-logging.properties | 1 + 5 files changed, 425 insertions(+), 3 deletions(-) create mode 100644 jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/JavaxOnCloseTest.java create mode 100644 jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyOnCloseTest.java diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/FutureCallback.java b/jetty-util/src/main/java/org/eclipse/jetty/util/FutureCallback.java index f932fc29980..fb419f1a229 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/FutureCallback.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/FutureCallback.java @@ -163,9 +163,7 @@ public class FutureCallback implements Future, Callback { Throwable cause = e.getCause(); if (cause instanceof RuntimeException) - throw (RuntimeException)cause; - else if (cause instanceof IOException) - throw (IOException)cause; + throw new RuntimeException(cause); else throw new IOException(cause); } diff --git a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/EventSocket.java b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/EventSocket.java index 154175233b1..714c6bad803 100644 --- a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/EventSocket.java +++ b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/EventSocket.java @@ -50,6 +50,7 @@ public class EventSocket public CountDownLatch openLatch = new CountDownLatch(1); public CountDownLatch closeLatch = new CountDownLatch(1); + public CountDownLatch errorLatch = new CountDownLatch(1); @OnOpen public void onOpen(Session session, EndpointConfig endpointConfig) @@ -85,5 +86,6 @@ public class EventSocket if (LOG.isDebugEnabled()) LOG.debug("{} onError(): {}", toString(), cause); error = cause; + errorLatch.countDown(); } } diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/JavaxOnCloseTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/JavaxOnCloseTest.java new file mode 100644 index 00000000000..6ab8fcfd55a --- /dev/null +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/JavaxOnCloseTest.java @@ -0,0 +1,226 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.javax.tests; + +import java.io.IOException; +import java.net.URI; +import java.nio.channels.ClosedChannelException; +import java.util.Objects; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; +import javax.websocket.ClientEndpoint; +import javax.websocket.CloseReason; +import javax.websocket.CloseReason.CloseCodes; +import javax.websocket.EndpointConfig; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.util.BlockingArrayQueue; +import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class JavaxOnCloseTest +{ + private static BlockingArrayQueue serverEndpoints = new BlockingArrayQueue<>(); + + private Server server; + private ServerConnector connector; + private JavaxWebSocketClientContainer client = new JavaxWebSocketClientContainer(); + + @ServerEndpoint("/") + public static class OnCloseEndpoint extends EventSocket + { + private Consumer onClose; + + public void setOnClose(Consumer onClose) + { + this.onClose = onClose; + } + + @Override + public void onOpen(Session session, EndpointConfig endpointConfig) + { + super.onOpen(session, endpointConfig); + serverEndpoints.add(this); + } + + @Override + public void onClose(CloseReason reason) + { + super.onClose(reason); + onClose.accept(session); + } + } + + @ClientEndpoint + public static class BlockingClientEndpoint extends EventSocket + { + private CountDownLatch blockInClose = new CountDownLatch(1); + + public void unBlockClose() + { + blockInClose.countDown(); + } + + @Override + public void onClose(CloseReason reason) + { + try + { + blockInClose.await(); + super.onClose(reason); + } + catch (InterruptedException e) + { + throw new RuntimeException(e); + } + } + } + + @BeforeEach + public void start() throws Exception + { + server = new Server(); + connector = new ServerConnector(server); + connector.setPort(0); + server.addConnector(connector); + + ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); + contextHandler.setContextPath("/"); + server.setHandler(contextHandler); + + JavaxWebSocketServletContainerInitializer.configure(contextHandler, ((servletContext, container) -> + container.addEndpoint(OnCloseEndpoint.class))); + + client.start(); + server.start(); + } + + @AfterEach + public void stop() throws Exception + { + client.stop(); + server.stop(); + } + + @Test + public void changeStatusCodeInOnClose() throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + URI uri = new URI("ws://localhost:" + connector.getLocalPort() + "/"); + client.connectToServer(clientEndpoint, uri); + + OnCloseEndpoint serverEndpoint = Objects.requireNonNull(serverEndpoints.poll(5, TimeUnit.SECONDS)); + serverEndpoint.setOnClose((session) -> assertDoesNotThrow(() -> + session.close(new CloseReason(CloseCodes.SERVICE_RESTART, "custom close reason")))); + assertTrue(serverEndpoint.openLatch.await(5, TimeUnit.SECONDS)); + + clientEndpoint.session.close(); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.closeReason.getCloseCode(), is(CloseCodes.SERVICE_RESTART)); + assertThat(clientEndpoint.closeReason.getReasonPhrase(), is("custom close reason")); + } + + @Test + public void secondCloseFromOnCloseFails() throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + URI uri = new URI("ws://localhost:" + connector.getLocalPort() + "/"); + client.connectToServer(clientEndpoint, uri); + + OnCloseEndpoint serverEndpoint = Objects.requireNonNull(serverEndpoints.poll(5, TimeUnit.SECONDS)); + assertTrue(serverEndpoint.openLatch.await(5, TimeUnit.SECONDS)); + serverEndpoint.setOnClose((session) -> assertThrows(ClosedChannelException.class, session::close)); + + serverEndpoint.session.close(new CloseReason(CloseCodes.NORMAL_CLOSURE, "first close")); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.closeReason.getCloseCode(), is(CloseCodes.NORMAL_CLOSURE)); + assertThat(clientEndpoint.closeReason.getReasonPhrase(), is("first close")); + } + + @Test + public void abnormalStatusDoesNotChange() throws Exception + { + BlockingClientEndpoint clientEndpoint = new BlockingClientEndpoint(); + URI uri = new URI("ws://localhost:" + connector.getLocalPort() + "/"); + client.connectToServer(clientEndpoint, uri); + + OnCloseEndpoint serverEndpoint = Objects.requireNonNull(serverEndpoints.poll(5, TimeUnit.SECONDS)); + assertTrue(serverEndpoint.openLatch.await(5, TimeUnit.SECONDS)); + serverEndpoint.setOnClose((session) -> + { + assertThrows(ClosedChannelException.class, + () -> session.close(new CloseReason(CloseCodes.UNEXPECTED_CONDITION, "abnormal close 2"))); + clientEndpoint.unBlockClose(); + }); + + serverEndpoint.session.close(new CloseReason(CloseCodes.PROTOCOL_ERROR, "abnormal close 1")); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.closeReason.getCloseCode(), is(CloseCodes.PROTOCOL_ERROR)); + assertThat(clientEndpoint.closeReason.getReasonPhrase(), is("abnormal close 1")); + } + + @Test + public void onErrorOccurringAfterOnClose() throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + URI uri = new URI("ws://localhost:" + connector.getLocalPort() + "/"); + client.connectToServer(clientEndpoint, uri); + + OnCloseEndpoint serverEndpoint = Objects.requireNonNull(serverEndpoints.poll(5, TimeUnit.SECONDS)); + assertTrue(serverEndpoint.openLatch.await(5, TimeUnit.SECONDS)); + serverEndpoint.setOnClose((session) -> + { + throw new RuntimeException("trigger onError from onClose"); + }); + + try + { + clientEndpoint.session.close(); + } + catch (IOException e) + { + // Ignore. This only occurs in the rare case where the + // close response is received while we are still sending the message. + } + + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.closeReason.getCloseCode(), is(CloseCodes.UNEXPECTED_CONDITION)); + assertThat(clientEndpoint.closeReason.getReasonPhrase(), containsString("trigger onError from onClose")); + + assertTrue(serverEndpoint.errorLatch.await(5, TimeUnit.SECONDS)); + assertThat(serverEndpoint.error, instanceOf(RuntimeException.class)); + assertThat(serverEndpoint.error.getMessage(), containsString("trigger onError from onClose")); + } +} diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyOnCloseTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyOnCloseTest.java new file mode 100644 index 00000000000..77b15837219 --- /dev/null +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyOnCloseTest.java @@ -0,0 +1,195 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests; + +import java.net.URI; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.StatusCode; +import org.eclipse.jetty.websocket.api.annotations.WebSocket; +import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class JettyOnCloseTest +{ + private Server server; + private ServerConnector connector; + private WebSocketClient client; + private OnCloseEndpoint serverEndpoint = new OnCloseEndpoint(); + + @WebSocket + public static class OnCloseEndpoint extends EventSocket + { + private Consumer onClose; + + public void setOnClose(Consumer onClose) + { + this.onClose = onClose; + } + + @Override + public void onClose(int statusCode, String reason) + { + onClose.accept(session); + super.onClose(statusCode, reason); + } + } + + @WebSocket + public static class BlockingClientEndpoint extends EventSocket + { + private CountDownLatch blockInClose = new CountDownLatch(1); + + public void unBlockClose() + { + blockInClose.countDown(); + } + + @Override + public void onClose(int statusCode, String reason) + { + try + { + blockInClose.await(); + super.onClose(statusCode, reason); + } + catch (InterruptedException e) + { + throw new RuntimeException(e); + } + } + } + + @BeforeEach + public void start() throws Exception + { + server = new Server(); + connector = new ServerConnector(server); + connector.setPort(0); + server.addConnector(connector); + + ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); + contextHandler.setContextPath("/"); + server.setHandler(contextHandler); + + JettyWebSocketServletContainerInitializer.configure(contextHandler, ((servletContext, container) -> + container.addMapping("/", (req, resp) -> serverEndpoint))); + + client = new WebSocketClient(); + server.start(); + client.start(); + } + + @AfterEach + public void stop() throws Exception + { + client.stop(); + server.stop(); + } + + @Test + public void changeStatusCodeInOnClose() throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + URI uri = new URI("ws://localhost:" + connector.getLocalPort() + "/"); + client.connect(clientEndpoint, uri).get(5, TimeUnit.SECONDS); + + assertTrue(serverEndpoint.openLatch.await(5, TimeUnit.SECONDS)); + serverEndpoint.setOnClose((session) -> session.close(StatusCode.SERVICE_RESTART, "custom close reason")); + + clientEndpoint.session.close(); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.statusCode, is(StatusCode.SERVICE_RESTART)); + assertThat(clientEndpoint.reason, is("custom close reason")); + } + + @Test + public void secondCloseFromOnCloseFails() throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + URI uri = new URI("ws://localhost:" + connector.getLocalPort() + "/"); + client.connect(clientEndpoint, uri).get(5, TimeUnit.SECONDS); + + assertTrue(serverEndpoint.openLatch.await(5, TimeUnit.SECONDS)); + serverEndpoint.setOnClose(Session::close); + + serverEndpoint.session.close(StatusCode.NORMAL, "first close"); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.statusCode, is(StatusCode.NORMAL)); + assertThat(clientEndpoint.reason, is("first close")); + } + + @Test + public void abnormalStatusDoesNotChange() throws Exception + { + BlockingClientEndpoint clientEndpoint = new BlockingClientEndpoint(); + URI uri = new URI("ws://localhost:" + connector.getLocalPort() + "/"); + client.connect(clientEndpoint, uri).get(5, TimeUnit.SECONDS); + + assertTrue(serverEndpoint.openLatch.await(5, TimeUnit.SECONDS)); + serverEndpoint.setOnClose((session) -> + { + session.close(StatusCode.SERVER_ERROR, "abnormal close 2"); + clientEndpoint.unBlockClose(); + }); + + serverEndpoint.session.close(StatusCode.PROTOCOL, "abnormal close 1"); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.statusCode, is(StatusCode.PROTOCOL)); + assertThat(clientEndpoint.reason, is("abnormal close 1")); + } + + @Test + public void onErrorOccurringAfterOnClose() throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + URI uri = new URI("ws://localhost:" + connector.getLocalPort() + "/"); + client.connect(clientEndpoint, uri).get(5, TimeUnit.SECONDS); + + assertTrue(serverEndpoint.openLatch.await(5, TimeUnit.SECONDS)); + serverEndpoint.setOnClose((session) -> + { + throw new RuntimeException("trigger onError from onClose"); + }); + + clientEndpoint.session.close(); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.statusCode, is(StatusCode.SERVER_ERROR)); + assertThat(clientEndpoint.reason, containsString("trigger onError from onClose")); + + assertTrue(serverEndpoint.errorLatch.await(5, TimeUnit.SECONDS)); + assertThat(serverEndpoint.error, instanceOf(RuntimeException.class)); + assertThat(serverEndpoint.error.getMessage(), containsString("trigger onError from onClose")); + } +} diff --git a/jetty-websocket/websocket-jetty-tests/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-jetty-tests/src/test/resources/jetty-logging.properties index dfc2622c371..41e1bef3cd0 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-jetty-tests/src/test/resources/jetty-logging.properties @@ -2,6 +2,7 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog # org.eclipse.jetty.LEVEL=DEBUG # org.eclipse.jetty.websocket.LEVEL=DEBUG # org.eclipse.jetty.websocket.test.LEVEL=DEBUG +# org.eclipse.jetty.websocket.tests.EventSocket.LEVEL=DEBUG # org.eclipse.jetty.server.AbstractConnector.LEVEL=DEBUG # org.eclipse.jetty.io.WriteFlusher.LEVEL=DEBUG # org.eclipse.jetty.io.FillInterest.LEVEL=DEBUG From 8638fb2cc3ed80c7410249a31ad253d67479a458 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 29 Jan 2020 19:13:03 +1100 Subject: [PATCH 17/21] Fix broken test cases Signed-off-by: Lachlan Roberts --- .../jetty/websocket/javax/tests/JavaxOnCloseTest.java | 3 ++- .../org/eclipse/jetty/websocket/tests/WebSocketStopTest.java | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/JavaxOnCloseTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/JavaxOnCloseTest.java index 6ab8fcfd55a..7a0ee518d70 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/JavaxOnCloseTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/JavaxOnCloseTest.java @@ -180,8 +180,9 @@ public class JavaxOnCloseTest assertTrue(serverEndpoint.openLatch.await(5, TimeUnit.SECONDS)); serverEndpoint.setOnClose((session) -> { - assertThrows(ClosedChannelException.class, + IOException error = assertThrows(IOException.class, () -> session.close(new CloseReason(CloseCodes.UNEXPECTED_CONDITION, "abnormal close 2"))); + assertThat(error.getCause(), instanceOf(ClosedChannelException.class)); clientEndpoint.unBlockClose(); }); diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java index cefe7e6854f..43ffc5e687f 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.websocket.tests; +import java.io.IOException; import java.net.URI; import java.nio.channels.ClosedChannelException; import java.util.concurrent.TimeUnit; @@ -38,6 +39,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -126,7 +128,8 @@ public class WebSocketStopTest assertThat(clientSocket.statusCode, is(StatusCode.NORMAL)); assertThat(serverSocket.statusCode, is(StatusCode.NORMAL)); - assertThrows(ClosedChannelException.class, + IOException error = assertThrows(IOException.class, () -> session.getRemote().sendString("this should fail before ExtensionStack")); + assertThat(error.getCause(), instanceOf(ClosedChannelException.class)); } } From 96741ebb287bb7572b5a586ca271633797e55539 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 29 Jan 2020 10:11:21 +0100 Subject: [PATCH 18/21] Fixed compilation issues after merge. Signed-off-by: Simone Bordet --- .../jetty/websocket/core/FlushTest.java | 6 +- .../common/JettyWebSocketRemoteEndpoint.java | 8 +-- .../servlet/WebSocketServletFactory.java | 57 +------------------ 3 files changed, 10 insertions(+), 61 deletions(-) diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FlushTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FlushTest.java index 597ef213d82..f787ae8fd89 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FlushTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/FlushTest.java @@ -67,7 +67,7 @@ public class FlushTest public void testStandardFlush() throws Exception { TestFrameHandler clientHandler = new TestFrameHandler(); - CompletableFuture connect = client.connect(clientHandler, server.getUri()); + CompletableFuture connect = client.connect(clientHandler, server.getUri()); connect.get(5, TimeUnit.SECONDS); // Send a batched frame. @@ -94,7 +94,7 @@ public class FlushTest public void testFlushOnCloseFrame() throws Exception { TestFrameHandler clientHandler = new TestFrameHandler(); - CompletableFuture connect = client.connect(clientHandler, server.getUri()); + CompletableFuture connect = client.connect(clientHandler, server.getUri()); connect.get(5, TimeUnit.SECONDS); // Send a batched frame. @@ -120,7 +120,7 @@ public class FlushTest public void testFlushAfterClose() throws Exception { TestFrameHandler clientHandler = new TestFrameHandler(); - CompletableFuture connect = client.connect(clientHandler, server.getUri()); + CompletableFuture connect = client.connect(clientHandler, server.getUri()); connect.get(5, TimeUnit.SECONDS); clientHandler.sendClose(); diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java index 7d66e544808..4307c3600de 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java @@ -32,10 +32,10 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.api.BatchMode; import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.WriteCallback; +import org.eclipse.jetty.websocket.core.CoreSession; 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.exception.ProtocolException; import static java.nio.charset.StandardCharsets.UTF_8; @@ -43,11 +43,11 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket { private static final Logger LOG = Log.getLogger(JettyWebSocketRemoteEndpoint.class); - private final FrameHandler.CoreSession coreSession; + private final CoreSession coreSession; private byte messageType = -1; private BatchMode batchMode; - public JettyWebSocketRemoteEndpoint(FrameHandler.CoreSession coreSession, BatchMode batchMode) + public JettyWebSocketRemoteEndpoint(CoreSession coreSession, BatchMode batchMode) { this.coreSession = Objects.requireNonNull(coreSession); this.batchMode = batchMode; diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServletFactory.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServletFactory.java index d22a80fa620..f62a25056e5 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServletFactory.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServletFactory.java @@ -18,65 +18,14 @@ package org.eclipse.jetty.websocket.servlet; -import java.time.Duration; - import org.eclipse.jetty.http.pathmap.PathSpec; import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; public interface WebSocketServletFactory extends Configuration { - WebSocketExtensionRegistry getExtensionRegistry(); - @Override - Duration getIdleTimeout(); - - @Override - void setIdleTimeout(Duration duration); - - @Override - Duration getWriteTimeout(); - - @Override - void setWriteTimeout(Duration duration); - - @Override - int getInputBufferSize(); - - @Override - void setInputBufferSize(int bufferSize); - - @Override - long getMaxFrameSize(); - - @Override - void setMaxFrameSize(long maxFrameSize); - - @Override - long getMaxBinaryMessageSize(); - - @Override - void setMaxBinaryMessageSize(long bufferSize); - - @Override - long getMaxTextMessageSize(); - - @Override - void setMaxTextMessageSize(long bufferSize); - - @Override - int getOutputBufferSize(); - - @Override - void setOutputBufferSize(int bufferSize); - - @Override - boolean isAutoFragment(); - - @Override - void setAutoFragment(boolean autoFragment); - void addMapping(String pathSpec, WebSocketCreator creator); /** @@ -129,11 +78,11 @@ public interface WebSocketServletFactory extends Configuration * Recognized Path Spec syntaxes: *

*
- *
/path/to or / or *.ext or servlet|{spec}
+ *
{@code /path/to} or {@code /} or {@code *.ext} or {@code servlet|{spec}}
*
Servlet Syntax
- *
^{spec} or regex|{spec}
+ *
{@code ^{spec}} or {@code regex|{spec}}
*
Regex Syntax
- *
uri-template|{spec}
+ *
{@code uri-template|{spec}}
*
URI Template (see JSR356 and RFC6570 level 1)
*
* From 842fa6aa5309ae8343b3efd01597b6e30a9b942f Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 24 Jan 2020 11:20:52 +0100 Subject: [PATCH 19/21] Issue #4504 Forwarded Host and Server (#4511) X-Forwarded-Host has precedence of X-Forwarded-Server and outcome is not order dependent. Signed-off-by: Greg Wilkins --- .../server/ForwardedRequestCustomizer.java | 15 ++++++++-- .../ForwardedRequestCustomizerTest.java | 28 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java index 5ada04a38f2..7f010442f55 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java @@ -397,11 +397,21 @@ public class ForwardedRequestCustomizer implements Customizer request.setSecure(true); } - if (forwarded._host != null) + if (forwarded._server != null && forwarded._host instanceof PortSetHostPort) + { + httpFields.put(new HostPortHttpField(forwarded._server, forwarded._host.getPort())); + request.setAuthority(forwarded._server, forwarded._host.getPort()); + } + else if (forwarded._host != null) { httpFields.put(new HostPortHttpField(forwarded._host)); request.setAuthority(forwarded._host.getHost(), forwarded._host.getPort()); } + else if (forwarded._server != null) + { + httpFields.put(new HostPortHttpField(forwarded._server)); + request.setAuthority(forwarded._server, 0); + } if (forwarded._for != null) { @@ -544,6 +554,7 @@ public class ForwardedRequestCustomizer implements Customizer String _proto; HostPort _for; HostPort _host; + String _server; public Forwarded(Request request, HttpConfiguration config) { @@ -596,7 +607,7 @@ public class ForwardedRequestCustomizer implements Customizer { if (getProxyAsAuthority()) return; - handleHost(field); + _server = getLeftMost(field.getValue()); } @SuppressWarnings("unused") diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java index 18a399c55d3..33f6bde4c6f 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java @@ -412,6 +412,34 @@ public class ForwardedRequestCustomizerTest .requestURL("https://www.example.com:4333/") .remoteAddr("8.5.4.3").remotePort(2222) ), + Arguments.of(new Request("X-Forwarded-* (Server before Host)") + .headers( + "GET / HTTP/1.1", + "Host: myhost", + "X-Forwarded-Proto: https", + "X-Forwarded-Server: fw.example.com", + "X-Forwarded-Host: www.example.com", + "X-Forwarded-Port: 4333", + "X-Forwarded-For: 8.5.4.3:2222" + ), + new Expectations() + .scheme("https").serverName("www.example.com").serverPort(4333) + .requestURL("https://www.example.com:4333/") + .remoteAddr("8.5.4.3").remotePort(2222) + ), + Arguments.of(new Request("X-Forwarded-* (Server and Port)") + .headers( + "GET / HTTP/1.1", + "Host: myhost", + "X-Forwarded-Server: fw.example.com", + "X-Forwarded-Port: 4333", + "X-Forwarded-For: 8.5.4.3:2222" + ), + new Expectations() + .scheme("http").serverName("fw.example.com").serverPort(4333) + .requestURL("http://fw.example.com:4333/") + .remoteAddr("8.5.4.3").remotePort(2222) + ), // ================================================================= // Mixed Behavior From 79a337567fca330ecbed547737ab7c78d6e53513 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 29 Jan 2020 11:05:35 +0100 Subject: [PATCH 20/21] Issue #4247 use context default for samesite cookie attribute (#4512) * Issue #4247 use context default for samesite cookie attribute Signed-off-by: Jan Bartel --- .../org/eclipse/jetty/http/HttpCookie.java | 50 ++- .../eclipse/jetty/http/HttpCookieTest.java | 355 ++++++++++++++++++ .../org/eclipse/jetty/server/Response.java | 35 +- .../eclipse/jetty/server/ResponseTest.java | 92 +++++ 4 files changed, 528 insertions(+), 4 deletions(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java index 8752754f5f9..013d1174029 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java @@ -19,14 +19,21 @@ package org.eclipse.jetty.http; import java.util.List; +import java.util.Locale; import java.util.concurrent.TimeUnit; +import javax.servlet.ServletContext; + import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; // TODO consider replacing this with java.net.HttpCookie (once it supports RFC6265) public class HttpCookie { + private static final Logger LOG = Log.getLogger(HttpCookie.class); + private static final String __COOKIE_DELIM = "\",;\\ \t"; private static final String __01Jan1970_COOKIE = DateGenerator.formatCookieDate(0).trim(); @@ -41,6 +48,11 @@ public class HttpCookie public static final String SAME_SITE_NONE_COMMENT = SAME_SITE_COMMENT + "NONE__"; public static final String SAME_SITE_LAX_COMMENT = SAME_SITE_COMMENT + "LAX__"; public static final String SAME_SITE_STRICT_COMMENT = SAME_SITE_COMMENT + "STRICT__"; + + /** + * Name of context attribute with default SameSite cookie value + */ + public static final String SAME_SITE_DEFAULT_ATTRIBUTE = "org.eclipse.jetty.cookie.sameSiteDefault"; public enum SameSite { @@ -70,7 +82,7 @@ public class HttpCookie private final boolean _httpOnly; private final long _expiration; private final SameSite _sameSite; - + public HttpCookie(String name, String value) { this(name, value, -1); @@ -445,6 +457,42 @@ public class HttpCookie return null; } + /** + * Get the default value for SameSite cookie attribute, if one + * has been set for the given context. + * + * @param context the context to check for default SameSite value + * @return the default SameSite value or null if one does not exist + * @throws IllegalStateException if the default value is not a permitted value + */ + public static SameSite getSameSiteDefault(ServletContext context) + { + if (context == null) + return null; + Object o = context.getAttribute(SAME_SITE_DEFAULT_ATTRIBUTE); + if (o == null) + { + if (LOG.isDebugEnabled()) + LOG.debug("No default value for SameSite"); + return null; + } + + if (o instanceof SameSite) + return (SameSite)o; + + try + { + SameSite samesite = Enum.valueOf(SameSite.class, o.toString().trim().toUpperCase(Locale.ENGLISH)); + context.setAttribute(SAME_SITE_DEFAULT_ATTRIBUTE, samesite); + return samesite; + } + catch (Exception e) + { + LOG.warn("Bad default value {} for SameSite", o); + throw new IllegalStateException(e); + } + } + public static String getCommentWithoutAttributes(String comment) { if (comment == null) diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java index f357ea7b848..c2fd7210c44 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java @@ -18,8 +18,30 @@ package org.eclipse.jetty.http; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.EventListener; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; import java.util.stream.Stream; +import javax.servlet.Filter; +import javax.servlet.FilterRegistration; +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; +import javax.servlet.ServletRegistration.Dynamic; +import javax.servlet.SessionCookieConfig; +import javax.servlet.SessionTrackingMode; +import javax.servlet.descriptor.JspConfigDescriptor; + +import org.eclipse.jetty.http.HttpCookie.SameSite; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -40,7 +62,340 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpCookieTest { + public static class TestServletContext implements ServletContext + { + private Map _attributes = new HashMap<>(); + + @Override + public String getContextPath() + { + return null; + } + @Override + public ServletContext getContext(String uripath) + { + return null; + } + + @Override + public int getMajorVersion() + { + return 0; + } + + @Override + public int getMinorVersion() + { + return 0; + } + + @Override + public int getEffectiveMajorVersion() + { + return 0; + } + + @Override + public int getEffectiveMinorVersion() + { + return 0; + } + + @Override + public String getMimeType(String file) + { + return null; + } + + @Override + public Set getResourcePaths(String path) + { + return null; + } + + @Override + public URL getResource(String path) throws MalformedURLException + { + return null; + } + + @Override + public InputStream getResourceAsStream(String path) + { + return null; + } + + @Override + public RequestDispatcher getRequestDispatcher(String path) + { + return null; + } + + @Override + public RequestDispatcher getNamedDispatcher(String name) + { + return null; + } + + @Override + public Servlet getServlet(String name) throws ServletException + { + return null; + } + + @Override + public Enumeration getServlets() + { + return null; + } + + @Override + public Enumeration getServletNames() + { + return null; + } + + @Override + public void log(String msg) + { + } + + @Override + public void log(Exception exception, String msg) + { + } + + @Override + public void log(String message, Throwable throwable) + { + } + + @Override + public String getRealPath(String path) + { + return null; + } + + @Override + public String getServerInfo() + { + return null; + } + + @Override + public String getInitParameter(String name) + { + return null; + } + + @Override + public Enumeration getInitParameterNames() + { + return null; + } + + @Override + public boolean setInitParameter(String name, String value) + { + return false; + } + + @Override + public Object getAttribute(String name) + { + return _attributes.get(name); + } + + @Override + public Enumeration getAttributeNames() + { + return Collections.enumeration(_attributes.keySet()); + } + + @Override + public void setAttribute(String name, Object object) + { + _attributes.put(name,object); + } + + @Override + public void removeAttribute(String name) + { + _attributes.remove(name); + } + + @Override + public String getServletContextName() + { + return null; + } + + @Override + public Dynamic addServlet(String servletName, String className) + { + return null; + } + + @Override + public Dynamic addServlet(String servletName, Servlet servlet) + { + return null; + } + + @Override + public Dynamic addServlet(String servletName, Class servletClass) + { + return null; + } + + @Override + public T createServlet(Class clazz) throws ServletException + { + return null; + } + + @Override + public ServletRegistration getServletRegistration(String servletName) + { + return null; + } + + @Override + public Map getServletRegistrations() + { + return null; + } + + @Override + public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className) + { + return null; + } + + @Override + public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Filter filter) + { + return null; + } + + @Override + public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class filterClass) + { + return null; + } + + @Override + public T createFilter(Class clazz) throws ServletException + { + return null; + } + + @Override + public FilterRegistration getFilterRegistration(String filterName) + { + return null; + } + + @Override + public Map getFilterRegistrations() + { + return null; + } + + @Override + public SessionCookieConfig getSessionCookieConfig() + { + return null; + } + + @Override + public void setSessionTrackingModes(Set sessionTrackingModes) + { + } + + @Override + public Set getDefaultSessionTrackingModes() + { + return null; + } + + @Override + public Set getEffectiveSessionTrackingModes() + { + return null; + } + + @Override + public void addListener(String className) + { + } + + @Override + public void addListener(T t) + { + } + + @Override + public void addListener(Class listenerClass) + { + } + + @Override + public T createListener(Class clazz) throws ServletException + { + return null; + } + + @Override + public JspConfigDescriptor getJspConfigDescriptor() + { + return null; + } + + @Override + public ClassLoader getClassLoader() + { + return null; + } + + @Override + public void declareRoles(String... roleNames) + { + } + + @Override + public String getVirtualServerName() + { + return null; + } + } + + @Test + public void testDefaultSameSite() + { + TestServletContext context = new TestServletContext(); + //test null value for default + assertNull(HttpCookie.getSameSiteDefault(context)); + + //test good value for default as SameSite enum + context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, SameSite.LAX); + assertEquals(SameSite.LAX, HttpCookie.getSameSiteDefault(context)); + + //test good value for default as String + context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "NONE"); + assertEquals(SameSite.NONE, HttpCookie.getSameSiteDefault(context)); + + //test case for default as String + context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "sTrIcT"); + assertEquals(SameSite.STRICT, HttpCookie.getSameSiteDefault(context)); + + //test bad value for default as String + context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "fooBAR"); + assertThrows(IllegalStateException.class, + () -> HttpCookie.getSameSiteDefault(context)); + } + @Test public void testConstructFromSetCookie() { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java index 0bdb6944ffe..883c7ed3a77 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java @@ -190,13 +190,42 @@ public class Response implements HttpServletResponse { if (StringUtil.isBlank(cookie.getName())) throw new IllegalArgumentException("Cookie.name cannot be blank/null"); - + // add the set cookie - _fields.add(new SetCookieHttpField(cookie, getHttpChannel().getHttpConfiguration().getResponseCookieCompliance())); + _fields.add(new SetCookieHttpField(checkSameSite(cookie), getHttpChannel().getHttpConfiguration().getResponseCookieCompliance())); // Expire responses with set-cookie headers so they do not get cached. _fields.put(__EXPIRES_01JAN1970); } + + /** + * Check that samesite is set on the cookie. If not, use a + * context default value, if one has been set. + * + * @param cookie the cookie to check + * @return either the original cookie, or a new one that has the samesit default set + */ + private HttpCookie checkSameSite(HttpCookie cookie) + { + if (cookie == null || cookie.getSameSite() != null) + return cookie; + + //sameSite is not set, use the default configured for the context, if one exists + SameSite contextDefault = HttpCookie.getSameSiteDefault(_channel.getRequest().getServletContext()); + if (contextDefault == null) + return cookie; //no default set + + return new HttpCookie(cookie.getName(), + cookie.getValue(), + cookie.getDomain(), + cookie.getPath(), + cookie.getMaxAge(), + cookie.isHttpOnly(), + cookie.isSecure(), + cookie.getComment(), + cookie.getVersion(), + contextDefault); + } @Override public void addCookie(Cookie cookie) @@ -264,7 +293,7 @@ public class Response implements HttpServletResponse else if (!cookie.getPath().equals(oldCookie.getPath())) continue; - i.set(new SetCookieHttpField(cookie, compliance)); + i.set(new SetCookieHttpField(checkSameSite(cookie), compliance)); return; } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index 653700e9b7f..7821cd8a02f 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -32,10 +32,13 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.stream.Stream; + import javax.servlet.RequestDispatcher; import javax.servlet.ServletOutputStream; import javax.servlet.http.Cookie; @@ -1015,6 +1018,32 @@ public class ResponseTest assertEquals("name=value; Path=/path; Domain=domain; Secure; HttpOnly", set); } + + @Test + public void testAddCookieSameSiteDefault() throws Exception + { + Response response = getResponse(); + TestServletContextHandler context = new TestServletContextHandler(); + _channel.getRequest().setContext(context.getServletContext()); + context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, HttpCookie.SameSite.STRICT); + Cookie cookie = new Cookie("name", "value"); + cookie.setDomain("domain"); + cookie.setPath("/path"); + cookie.setSecure(true); + cookie.setComment("comment__HTTP_ONLY__"); + + response.addCookie(cookie); + String set = response.getHttpFields().get("Set-Cookie"); + assertEquals("name=value; Path=/path; Domain=domain; Secure; HttpOnly; SameSite=Strict", set); + + response.getHttpFields().remove("Set-Cookie"); + + //test bad default samesite value + context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "FooBar"); + + assertThrows(IllegalStateException.class, + () -> response.addCookie(cookie)); + } @Test public void testAddCookieComplianceRFC2965() @@ -1154,6 +1183,23 @@ public class ResponseTest List actual = Collections.list(response.getHttpFields().getValues("Set-Cookie")); assertThat("HttpCookie order", actual, hasItems(expected)); } + + @Test + public void testReplaceHttpCookieSameSite() + { + Response response = getResponse(); + TestServletContextHandler context = new TestServletContextHandler(); + context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "LAX"); + _channel.getRequest().setContext(context.getServletContext()); + //replace with no prior does an add + response.replaceCookie(new HttpCookie("Foo", "123456")); + String set = response.getHttpFields().get("Set-Cookie"); + assertEquals("Foo=123456; SameSite=Lax", set); + //check replacement + response.replaceCookie(new HttpCookie("Foo", "other")); + set = response.getHttpFields().get("Set-Cookie"); + assertEquals("Foo=other; SameSite=Lax", set); + } @Test public void testReplaceParsedHttpCookie() @@ -1179,6 +1225,20 @@ public class ResponseTest actual = Collections.list(response.getHttpFields().getValues("Set-Cookie")); assertThat(actual, hasItems(new String[]{"Foo=replaced; Path=/path; Domain=Bah"})); } + + @Test + public void testReplaceParsedHttpCookieSiteDefault() + { + Response response = getResponse(); + TestServletContextHandler context = new TestServletContextHandler(); + context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "LAX"); + _channel.getRequest().setContext(context.getServletContext()); + + response.addHeader(HttpHeader.SET_COOKIE.asString(), "Foo=123456"); + response.replaceCookie(new HttpCookie("Foo", "value")); + String set = response.getHttpFields().get("Set-Cookie"); + assertEquals("Foo=value; SameSite=Lax", set); + } @Test public void testFlushAfterFullContent() throws Exception @@ -1208,4 +1268,36 @@ public class ResponseTest super(handler, new SessionData(id, "", "0.0.0.0", 0, 0, 0, 300)); } } + + private static class TestServletContextHandler extends ContextHandler + { + private class Context extends ContextHandler.Context + { + private Map _attributes = new HashMap<>(); + + @Override + public Object getAttribute(String name) + { + return _attributes.get(name); + } + + @Override + public Enumeration getAttributeNames() + { + return Collections.enumeration(_attributes.keySet()); + } + + @Override + public void setAttribute(String name, Object object) + { + _attributes.put(name,object); + } + + @Override + public void removeAttribute(String name) + { + _attributes.remove(name); + } + } + } } From 45771dbd26c33dda8dbb3c96efd7cf1885b5665e Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 29 Jan 2020 12:08:13 +0100 Subject: [PATCH 21/21] Fix bad merge --- .../org/eclipse/jetty/http/HttpCookie.java | 13 +- .../eclipse/jetty/http/HttpCookieTest.java | 324 +----------------- .../org/eclipse/jetty/server/Response.java | 2 +- 3 files changed, 10 insertions(+), 329 deletions(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java index 013d1174029..50acc57d57b 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java @@ -22,8 +22,7 @@ import java.util.List; import java.util.Locale; import java.util.concurrent.TimeUnit; -import javax.servlet.ServletContext; - +import org.eclipse.jetty.util.Attributes; import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; @@ -461,15 +460,15 @@ public class HttpCookie * Get the default value for SameSite cookie attribute, if one * has been set for the given context. * - * @param context the context to check for default SameSite value + * @param contextAttributes the context to check for default SameSite value * @return the default SameSite value or null if one does not exist * @throws IllegalStateException if the default value is not a permitted value */ - public static SameSite getSameSiteDefault(ServletContext context) + public static SameSite getSameSiteDefault(Attributes contextAttributes) { - if (context == null) + if (contextAttributes == null) return null; - Object o = context.getAttribute(SAME_SITE_DEFAULT_ATTRIBUTE); + Object o = contextAttributes.getAttribute(SAME_SITE_DEFAULT_ATTRIBUTE); if (o == null) { if (LOG.isDebugEnabled()) @@ -483,7 +482,7 @@ public class HttpCookie try { SameSite samesite = Enum.valueOf(SameSite.class, o.toString().trim().toUpperCase(Locale.ENGLISH)); - context.setAttribute(SAME_SITE_DEFAULT_ATTRIBUTE, samesite); + contextAttributes.setAttribute(SAME_SITE_DEFAULT_ATTRIBUTE, samesite); return samesite; } catch (Exception e) diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java index c2fd7210c44..f3e9a1e1952 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java @@ -29,19 +29,8 @@ import java.util.Map; import java.util.Set; import java.util.stream.Stream; -import javax.servlet.Filter; -import javax.servlet.FilterRegistration; -import javax.servlet.RequestDispatcher; -import javax.servlet.Servlet; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; -import javax.servlet.ServletRegistration.Dynamic; -import javax.servlet.SessionCookieConfig; -import javax.servlet.SessionTrackingMode; -import javax.servlet.descriptor.JspConfigDescriptor; - import org.eclipse.jetty.http.HttpCookie.SameSite; +import org.eclipse.jetty.util.AttributesMap; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -62,319 +51,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpCookieTest { - public static class TestServletContext implements ServletContext - { - private Map _attributes = new HashMap<>(); - - @Override - public String getContextPath() - { - return null; - } - - @Override - public ServletContext getContext(String uripath) - { - return null; - } - - @Override - public int getMajorVersion() - { - return 0; - } - - @Override - public int getMinorVersion() - { - return 0; - } - - @Override - public int getEffectiveMajorVersion() - { - return 0; - } - - @Override - public int getEffectiveMinorVersion() - { - return 0; - } - - @Override - public String getMimeType(String file) - { - return null; - } - - @Override - public Set getResourcePaths(String path) - { - return null; - } - - @Override - public URL getResource(String path) throws MalformedURLException - { - return null; - } - - @Override - public InputStream getResourceAsStream(String path) - { - return null; - } - - @Override - public RequestDispatcher getRequestDispatcher(String path) - { - return null; - } - - @Override - public RequestDispatcher getNamedDispatcher(String name) - { - return null; - } - - @Override - public Servlet getServlet(String name) throws ServletException - { - return null; - } - - @Override - public Enumeration getServlets() - { - return null; - } - - @Override - public Enumeration getServletNames() - { - return null; - } - - @Override - public void log(String msg) - { - } - - @Override - public void log(Exception exception, String msg) - { - } - - @Override - public void log(String message, Throwable throwable) - { - } - - @Override - public String getRealPath(String path) - { - return null; - } - - @Override - public String getServerInfo() - { - return null; - } - - @Override - public String getInitParameter(String name) - { - return null; - } - - @Override - public Enumeration getInitParameterNames() - { - return null; - } - - @Override - public boolean setInitParameter(String name, String value) - { - return false; - } - - @Override - public Object getAttribute(String name) - { - return _attributes.get(name); - } - - @Override - public Enumeration getAttributeNames() - { - return Collections.enumeration(_attributes.keySet()); - } - - @Override - public void setAttribute(String name, Object object) - { - _attributes.put(name,object); - } - - @Override - public void removeAttribute(String name) - { - _attributes.remove(name); - } - - @Override - public String getServletContextName() - { - return null; - } - - @Override - public Dynamic addServlet(String servletName, String className) - { - return null; - } - - @Override - public Dynamic addServlet(String servletName, Servlet servlet) - { - return null; - } - - @Override - public Dynamic addServlet(String servletName, Class servletClass) - { - return null; - } - - @Override - public T createServlet(Class clazz) throws ServletException - { - return null; - } - - @Override - public ServletRegistration getServletRegistration(String servletName) - { - return null; - } - - @Override - public Map getServletRegistrations() - { - return null; - } - - @Override - public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className) - { - return null; - } - - @Override - public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Filter filter) - { - return null; - } - - @Override - public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class filterClass) - { - return null; - } - - @Override - public T createFilter(Class clazz) throws ServletException - { - return null; - } - - @Override - public FilterRegistration getFilterRegistration(String filterName) - { - return null; - } - - @Override - public Map getFilterRegistrations() - { - return null; - } - - @Override - public SessionCookieConfig getSessionCookieConfig() - { - return null; - } - - @Override - public void setSessionTrackingModes(Set sessionTrackingModes) - { - } - - @Override - public Set getDefaultSessionTrackingModes() - { - return null; - } - - @Override - public Set getEffectiveSessionTrackingModes() - { - return null; - } - - @Override - public void addListener(String className) - { - } - - @Override - public void addListener(T t) - { - } - - @Override - public void addListener(Class listenerClass) - { - } - - @Override - public T createListener(Class clazz) throws ServletException - { - return null; - } - - @Override - public JspConfigDescriptor getJspConfigDescriptor() - { - return null; - } - - @Override - public ClassLoader getClassLoader() - { - return null; - } - - @Override - public void declareRoles(String... roleNames) - { - } - - @Override - public String getVirtualServerName() - { - return null; - } - } @Test public void testDefaultSameSite() { - TestServletContext context = new TestServletContext(); + AttributesMap context = new AttributesMap(); + //test null value for default assertNull(HttpCookie.getSameSiteDefault(context)); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java index 883c7ed3a77..9ba6a7140bf 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java @@ -211,7 +211,7 @@ public class Response implements HttpServletResponse return cookie; //sameSite is not set, use the default configured for the context, if one exists - SameSite contextDefault = HttpCookie.getSameSiteDefault(_channel.getRequest().getServletContext()); + SameSite contextDefault = HttpCookie.getSameSiteDefault(_channel.getRequest().getContext()); if (contextDefault == null) return cookie; //no default set