diff --git a/jetty-util/src/main/java/module-info.java b/jetty-util/src/main/java/module-info.java index 6c0666eaff8..1d5b30905d0 100644 --- a/jetty-util/src/main/java/module-info.java +++ b/jetty-util/src/main/java/module-info.java @@ -31,6 +31,7 @@ module org.eclipse.jetty.util exports org.eclipse.jetty.util.statistic; exports org.eclipse.jetty.util.thread; exports org.eclipse.jetty.util.thread.strategy; + exports org.eclipse.jetty.util.compression; // Only required if using AppContextLeakPreventer/AWTLeakPreventer. requires static java.desktop; diff --git a/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java b/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java index 644482f7891..274fc1d8c26 100644 --- a/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java +++ b/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.function.Function; import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.DefaultHandler; @@ -33,6 +32,7 @@ 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.FrameHandler; +import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; import org.eclipse.jetty.websocket.core.server.Negotiation; import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; @@ -108,15 +108,11 @@ public class CoreServer extends ContainerLifeCycle public abstract static class BaseNegotiator implements WebSocketNegotiator { - protected final WebSocketExtensionRegistry extensionRegistry; - protected final DecoratedObjectFactory objectFactory; - protected final ByteBufferPool bufferPool; + protected final WebSocketComponents components; public BaseNegotiator() { - this.extensionRegistry = new WebSocketExtensionRegistry(); - this.objectFactory = new DecoratedObjectFactory(); - this.bufferPool = new MappedByteBufferPool(); + this.components = new WebSocketComponents(); } @Override @@ -127,19 +123,25 @@ public class CoreServer extends ContainerLifeCycle @Override public WebSocketExtensionRegistry getExtensionRegistry() { - return extensionRegistry; + return components.getExtensionRegistry(); } @Override public DecoratedObjectFactory getObjectFactory() { - return objectFactory; + return components.getObjectFactory(); } @Override public ByteBufferPool getByteBufferPool() { - return bufferPool; + return components.getBufferPool(); + } + + @Override + public WebSocketComponents getWebSocketComponents() + { + return components; } } 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 9e5c0ff9b4d..6f50cc5d4fb 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 @@ -22,6 +22,8 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; +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; @@ -35,6 +37,8 @@ public abstract class AbstractExtension implements Extension private OutgoingFrames nextOutgoing; private IncomingFrames nextIncoming; private WebSocketCoreSession coreSession; + private DeflaterPool deflaterPool; + private InflaterPool inflaterPool; public AbstractExtension() { @@ -42,10 +46,12 @@ public abstract class AbstractExtension implements Extension } @Override - public void init(ExtensionConfig config, ByteBufferPool bufferPool) + public void init(ExtensionConfig config, WebSocketComponents components) { this.config = config; - this.bufferPool = bufferPool; + this.bufferPool = components.getBufferPool(); + this.deflaterPool = components.getDeflaterPool(); + this.inflaterPool = components.getInflaterPool(); } public ByteBufferPool getBufferPool() @@ -59,6 +65,16 @@ public abstract class AbstractExtension implements Extension return config; } + public DeflaterPool getDeflaterPool() + { + return deflaterPool; + } + + public InflaterPool getInflaterPool() + { + return inflaterPool; + } + @Override public String getName() { 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 5a4472cfd6a..0fd66060372 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,6 @@ package org.eclipse.jetty.websocket.core; -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession; /** @@ -29,7 +28,7 @@ import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession; public interface Extension extends IncomingFrames, OutgoingFrames { - void init(ExtensionConfig config, ByteBufferPool bufferPool); + void init(ExtensionConfig config, WebSocketComponents components); /** * The active configuration for this extension. diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketComponents.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketComponents.java index e2c6c63a492..60c451d6554 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketComponents.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketComponents.java @@ -18,11 +18,15 @@ package org.eclipse.jetty.websocket.core; +import java.util.zip.Deflater; import javax.servlet.ServletContext; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.DecoratedObjectFactory; +import org.eclipse.jetty.util.compression.CompressionPool; +import org.eclipse.jetty.util.compression.DeflaterPool; +import org.eclipse.jetty.util.compression.InflaterPool; /** * A collection of components which are the resources needed for websockets such as @@ -50,19 +54,26 @@ public class WebSocketComponents public WebSocketComponents() { - this(new WebSocketExtensionRegistry(), new DecoratedObjectFactory(), new MappedByteBufferPool()); + this(new WebSocketExtensionRegistry(), new DecoratedObjectFactory(), new MappedByteBufferPool(), + new InflaterPool(CompressionPool.INFINITE_CAPACITY, true), + new DeflaterPool(CompressionPool.INFINITE_CAPACITY, Deflater.DEFAULT_COMPRESSION, true)); } - public WebSocketComponents(WebSocketExtensionRegistry extensionRegistry, DecoratedObjectFactory objectFactory, ByteBufferPool bufferPool) + public WebSocketComponents(WebSocketExtensionRegistry extensionRegistry, DecoratedObjectFactory objectFactory, + ByteBufferPool bufferPool, InflaterPool inflaterPool, DeflaterPool deflaterPool) { this.extensionRegistry = extensionRegistry; this.objectFactory = objectFactory; this.bufferPool = bufferPool; + this.deflaterPool = deflaterPool; + this.inflaterPool = inflaterPool; } private DecoratedObjectFactory objectFactory; private WebSocketExtensionRegistry extensionRegistry; private ByteBufferPool bufferPool; + private InflaterPool inflaterPool; + private DeflaterPool deflaterPool; public ByteBufferPool getBufferPool() { @@ -78,4 +89,14 @@ public class WebSocketComponents { return objectFactory; } + + public InflaterPool getInflaterPool() + { + return inflaterPool; + } + + public DeflaterPool getDeflaterPool() + { + return deflaterPool; + } } \ No newline at end of file diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketExtensionRegistry.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketExtensionRegistry.java index 49459e90d8e..0e71b730ed3 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketExtensionRegistry.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketExtensionRegistry.java @@ -25,8 +25,6 @@ import java.util.ServiceLoader; import java.util.Set; import org.eclipse.jetty.http.BadMessageException; -import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.StringUtil; public class WebSocketExtensionRegistry implements Iterable> @@ -73,7 +71,7 @@ public class WebSocketExtensionRegistry implements Iterable extensions; private IncomingFrames incoming; private OutgoingFrames outgoing; private Extension[] rsvClaims = new Extension[3]; - public ExtensionStack(WebSocketExtensionRegistry factory, Behavior behavior) + public ExtensionStack(WebSocketComponents components, Behavior behavior) { - this.factory = factory; + this.components = components; this.behavior = behavior; } @@ -116,7 +114,7 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable * @param offeredConfigs the configurations being requested by the client * @param negotiatedConfigs the configurations accepted by the server */ - public void negotiate(DecoratedObjectFactory objectFactory, ByteBufferPool bufferPool, List offeredConfigs, List negotiatedConfigs) + public void negotiate(List offeredConfigs, List negotiatedConfigs) { if (LOG.isDebugEnabled()) LOG.debug("Extension Configs={}", negotiatedConfigs); @@ -129,7 +127,7 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable try { - ext = factory.newInstance(objectFactory, bufferPool, config); + ext = components.getExtensionRegistry().newInstance(config, components); } catch (Throwable t) { 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 1c9bec9f605..cf2ed8cacbc 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,7 +22,6 @@ import java.nio.ByteBuffer; import java.util.ArrayDeque; import java.util.Queue; -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.IteratingCallback; import org.eclipse.jetty.util.log.Log; @@ -31,6 +30,7 @@ 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.OpCode; +import org.eclipse.jetty.websocket.core.WebSocketComponents; /** * Fragment Extension @@ -74,9 +74,9 @@ public class FragmentExtension extends AbstractExtension } @Override - public void init(ExtensionConfig config, ByteBufferPool bufferPool) + public void init(ExtensionConfig config, WebSocketComponents components) { - super.init(config, bufferPool); + super.init(config, components); maxLength = config.getParameter("maxLength", -1); } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameCaptureExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameCaptureExtension.java index 5a1cbbdafc6..99b51b5b06c 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameCaptureExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameCaptureExtension.java @@ -27,7 +27,6 @@ import java.nio.file.Path; import java.util.Calendar; import java.util.concurrent.atomic.AtomicInteger; -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.IO; @@ -37,6 +36,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.WebSocketComponents; import static java.nio.file.StandardOpenOption.CREATE; import static java.nio.file.StandardOpenOption.WRITE; @@ -140,9 +140,9 @@ public class FrameCaptureExtension extends AbstractExtension } @Override - public void init(ExtensionConfig config, ByteBufferPool bufferPool) + public void init(ExtensionConfig config, WebSocketComponents components) { - super.init(config, bufferPool); + super.init(config, components); String cfgOutputDir = config.getParameter("output-dir", null); if (StringUtil.isNotBlank(cfgOutputDir)) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/IdentityExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/IdentityExtension.java index e7da3a8a781..20ddd17f8af 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/IdentityExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/IdentityExtension.java @@ -18,13 +18,13 @@ package org.eclipse.jetty.websocket.core.internal; -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.annotation.ManagedObject; 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.WebSocketComponents; @ManagedObject("Identity Extension") public class IdentityExtension extends AbstractExtension @@ -57,9 +57,9 @@ public class IdentityExtension extends AbstractExtension } @Override - public void init(ExtensionConfig config, ByteBufferPool bufferPool) + public void init(ExtensionConfig config, WebSocketComponents components) { - super.init(config, bufferPool); + super.init(config, components); StringBuilder s = new StringBuilder(); s.append(config.getName()); 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 425bbcc9d34..496ea84eb16 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 @@ -20,7 +20,6 @@ package org.eclipse.jetty.websocket.core.internal; import java.util.Map; -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -29,6 +28,7 @@ import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.NullAppendable; import org.eclipse.jetty.websocket.core.ProtocolException; +import org.eclipse.jetty.websocket.core.WebSocketComponents; import static org.eclipse.jetty.websocket.core.OpCode.CONTINUATION; import static org.eclipse.jetty.websocket.core.OpCode.TEXT; @@ -100,9 +100,9 @@ public class ValidationExtension extends AbstractExtension } @Override - public void init(ExtensionConfig config, ByteBufferPool bufferPool) + public void init(ExtensionConfig config, WebSocketComponents components) { - super.init(config, bufferPool); + super.init(config, components); Map parameters = config.getParameters(); diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/PerMessageDeflateExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/PerMessageDeflateExtension.java index c09e2777dbd..3a2d81ff4cf 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/PerMessageDeflateExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/PerMessageDeflateExtension.java @@ -23,7 +23,6 @@ import java.util.HashMap; import java.util.Map; import java.util.zip.DataFormatException; -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -32,6 +31,7 @@ import org.eclipse.jetty.websocket.core.ExtensionConfig; 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.WebSocketComponents; /** * Per Message Deflate Compression extension for WebSocket. @@ -144,7 +144,7 @@ public class PerMessageDeflateExtension extends CompressExtension } @Override - public void init(final ExtensionConfig config, ByteBufferPool bufferPool) + public void init(final ExtensionConfig config, WebSocketComponents components) { configRequested = new ExtensionConfig(config); Map paramsNegotiated = new HashMap<>(); @@ -183,7 +183,7 @@ public class PerMessageDeflateExtension extends CompressExtension configNegotiated = new ExtensionConfig(config.getName(), paramsNegotiated); LOG.debug("config: outgoingContextTakover={}, incomingContextTakeover={} : {}", outgoingContextTakeover, incomingContextTakeover, this); - super.init(configNegotiated, bufferPool); + super.init(configNegotiated, components); } @Override 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 2dc0c1f469d..7db266a0d24 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 @@ -30,12 +30,10 @@ import org.eclipse.jetty.http.BadMessageException; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.QuotedCSV; -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.websocket.core.Behavior; import org.eclipse.jetty.websocket.core.ExtensionConfig; -import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; +import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; public class Negotiation @@ -45,9 +43,7 @@ public class Negotiation private final HttpServletResponse response; private final List offeredExtensions; private final List offeredSubprotocols; - private final WebSocketExtensionRegistry registry; - private final DecoratedObjectFactory objectFactory; - private final ByteBufferPool bufferPool; + private final WebSocketComponents components; private final String version; private final Boolean upgrade; private final String key; @@ -63,16 +59,12 @@ public class Negotiation Request baseRequest, HttpServletRequest request, HttpServletResponse response, - WebSocketExtensionRegistry registry, - DecoratedObjectFactory objectFactory, - ByteBufferPool bufferPool) throws BadMessageException + WebSocketComponents components) throws BadMessageException { this.baseRequest = baseRequest; this.request = request; this.response = response; - this.registry = registry; - this.objectFactory = objectFactory; - this.bufferPool = bufferPool; + this.components = components; Boolean upgrade = null; String key = null; @@ -131,7 +123,7 @@ public class Negotiation this.key = key; this.upgrade = upgrade != null && connectionCSVs != null && connectionCSVs.getValues().stream().anyMatch(s -> s.equalsIgnoreCase("Upgrade")); - Set available = registry.getAvailableExtensionNames(); + Set available = components.getExtensionRegistry().getAvailableExtensionNames(); offeredExtensions = extensions == null ? Collections.emptyList() : extensions.getValues().stream() @@ -227,8 +219,8 @@ public class Negotiation if (extensionStack == null) { // Extension stack can decide to drop any of these extensions or their parameters - extensionStack = new ExtensionStack(registry, Behavior.SERVER); - extensionStack.negotiate(objectFactory, bufferPool, offeredExtensions, negotiatedExtensions); + extensionStack = new ExtensionStack(components, Behavior.SERVER); + extensionStack.negotiate(offeredExtensions, negotiatedExtensions); negotiatedExtensions = extensionStack.getNegotiatedExtensions(); if (extensionStack.hasNegotiatedExtensions()) 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 db329df6939..e02a110dc76 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 @@ -24,6 +24,7 @@ import java.util.function.Function; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.DecoratedObjectFactory; 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 @@ -36,6 +37,8 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer ByteBufferPool getByteBufferPool(); + WebSocketComponents getWebSocketComponents(); + static WebSocketNegotiator from(Function negotiate) { return new AbstractNegotiator() @@ -50,7 +53,7 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer static WebSocketNegotiator from(Function negotiate, FrameHandler.Customizer customizer) { - return new AbstractNegotiator(null, null, null, customizer) + return new AbstractNegotiator(null, customizer) { @Override public FrameHandler negotiate(Negotiation negotiation) @@ -62,12 +65,10 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer static WebSocketNegotiator from( Function negotiate, - WebSocketExtensionRegistry extensionRegistry, - DecoratedObjectFactory objectFactory, - ByteBufferPool bufferPool, + WebSocketComponents components, FrameHandler.Customizer customizer) { - return new AbstractNegotiator(extensionRegistry, objectFactory, bufferPool, customizer) + return new AbstractNegotiator(components, customizer) { @Override public FrameHandler negotiate(Negotiation negotiation) @@ -79,25 +80,17 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer abstract class AbstractNegotiator implements WebSocketNegotiator { - final WebSocketExtensionRegistry extensionRegistry; - final DecoratedObjectFactory objectFactory; - final ByteBufferPool bufferPool; + final WebSocketComponents components; final FrameHandler.Customizer customizer; public AbstractNegotiator() { - this(null, null, null, null); + this(null, null); } - public AbstractNegotiator( - WebSocketExtensionRegistry extensionRegistry, - DecoratedObjectFactory objectFactory, - ByteBufferPool bufferPool, - FrameHandler.Customizer customizer) + public AbstractNegotiator(WebSocketComponents components, FrameHandler.Customizer customizer) { - this.extensionRegistry = extensionRegistry == null ? new WebSocketExtensionRegistry() : extensionRegistry; - this.objectFactory = objectFactory == null ? new DecoratedObjectFactory() : objectFactory; - this.bufferPool = bufferPool; + this.components = components == null ? new WebSocketComponents() : components; this.customizer = customizer; } @@ -111,19 +104,25 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer @Override public WebSocketExtensionRegistry getExtensionRegistry() { - return extensionRegistry; + return components.getExtensionRegistry(); } @Override public DecoratedObjectFactory getObjectFactory() { - return objectFactory; + return components.getObjectFactory(); } @Override public ByteBufferPool getByteBufferPool() { - return bufferPool; + return components.getBufferPool(); + } + + @Override + public WebSocketComponents getWebSocketComponents() + { + return components; } public FrameHandler.Customizer getCustomizer() diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java index 62766e01d54..0f038c63324 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java @@ -46,6 +46,7 @@ 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; +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.internal.ExtensionStack; @@ -100,9 +101,7 @@ public final class RFC6455Handshaker implements Handshaker baseRequest, request, response, - negotiator.getExtensionRegistry(), - negotiator.getObjectFactory(), - pool); + new WebSocketComponents()); if (LOG.isDebugEnabled()) LOG.debug("negotiation {}", negotiation); 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 e6c87ee8fd9..93aba40780d 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 @@ -22,9 +22,6 @@ import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.stream.Stream; -import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.io.MappedByteBufferPool; -import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Generator; import org.eclipse.jetty.websocket.core.internal.Negotiated; @@ -40,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; */ public class GeneratorFrameFlagsTest { - private static ByteBufferPool bufferPool = new MappedByteBufferPool(); + private static WebSocketComponents components = new WebSocketComponents(); private WebSocketCoreSession coreSession; public static Stream data() @@ -63,8 +60,8 @@ public class GeneratorFrameFlagsTest public void setup(Frame invalidFrame) { - ExtensionStack exStack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER); - exStack.negotiate(new DecoratedObjectFactory(), bufferPool, new LinkedList<>(), new LinkedList<>()); + ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER); + exStack.negotiate(new LinkedList<>(), new LinkedList<>()); this.coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.CLIENT, Negotiated.from(exStack)); } @@ -75,7 +72,7 @@ public class GeneratorFrameFlagsTest setup(invalidFrame); ByteBuffer buffer = ByteBuffer.allocate(100); - new Generator(bufferPool).generateWholeFrame(invalidFrame, buffer); + new Generator(components.getBufferPool()).generateWholeFrame(invalidFrame, buffer); assertThrows(ProtocolException.class, () -> coreSession.assertValidOutgoing(invalidFrame)); } } 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 30f14d77683..89d289cfd28 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 @@ -24,12 +24,10 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.concurrent.TimeUnit; -import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.toolchain.test.ByteBufferAssert; import org.eclipse.jetty.toolchain.test.Hex; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -53,9 +51,9 @@ public class GeneratorTest private static WebSocketCoreSession newWebSocketCoreSession(Behavior behavior) { - ByteBufferPool bufferPool = new MappedByteBufferPool(); - ExtensionStack exStack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER); - exStack.negotiate(new DecoratedObjectFactory(), bufferPool, new LinkedList<>(), new LinkedList<>()); + WebSocketComponents components = new WebSocketComponents(); + ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER); + exStack.negotiate(new LinkedList<>(), new LinkedList<>()); return new WebSocketCoreSession(new TestMessageHandler(), behavior, Negotiated.from(exStack)); } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserCapture.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserCapture.java index cbf4868853c..a15fe771eed 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserCapture.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserCapture.java @@ -23,9 +23,6 @@ import java.util.LinkedList; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingDeque; -import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.io.MappedByteBufferPool; -import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Negotiated; import org.eclipse.jetty.websocket.core.internal.Parser; @@ -56,11 +53,11 @@ public class ParserCapture { this.copy = copy; - ByteBufferPool bufferPool = new MappedByteBufferPool(); - ExtensionStack exStack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER); - exStack.negotiate(new DecoratedObjectFactory(), bufferPool, new LinkedList<>(), new LinkedList<>()); + WebSocketComponents components = new WebSocketComponents(); + ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER); + exStack.negotiate(new LinkedList<>(), new LinkedList<>()); this.coreSession = new WebSocketCoreSession(new TestMessageHandler(), behavior, Negotiated.from(exStack)); - this.parser = new Parser(bufferPool, coreSession); + this.parser = new Parser(components.getBufferPool(), coreSession); } public void parse(ByteBuffer buffer) 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 1c170fec6f2..53430af39e5 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 @@ -22,32 +22,23 @@ import java.io.IOException; import java.util.List; import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.websocket.core.server.Negotiation; import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; public class TestWebSocketNegotiator implements WebSocketNegotiator { - final DecoratedObjectFactory objectFactory; - final WebSocketExtensionRegistry extensionRegistry; - final ByteBufferPool bufferPool; + final WebSocketComponents components; private final FrameHandler frameHandler; public TestWebSocketNegotiator(FrameHandler frameHandler) { - this.objectFactory = new DecoratedObjectFactory(); - this.extensionRegistry = new WebSocketExtensionRegistry(); - this.bufferPool = new MappedByteBufferPool(); - this.frameHandler = frameHandler; + this (frameHandler, new WebSocketComponents()); } - public TestWebSocketNegotiator(DecoratedObjectFactory objectFactory, WebSocketExtensionRegistry extensionRegistry, ByteBufferPool bufferPool, - FrameHandler frameHandler) + public TestWebSocketNegotiator(FrameHandler frameHandler, WebSocketComponents components) { - this.objectFactory = objectFactory; - this.extensionRegistry = extensionRegistry; - this.bufferPool = bufferPool; + this.components = components; this.frameHandler = frameHandler; } @@ -69,18 +60,24 @@ public class TestWebSocketNegotiator implements WebSocketNegotiator @Override public WebSocketExtensionRegistry getExtensionRegistry() { - return extensionRegistry; + return components.getExtensionRegistry(); } @Override public DecoratedObjectFactory getObjectFactory() { - return objectFactory; + return components.getObjectFactory(); } @Override public ByteBufferPool getByteBufferPool() { - return bufferPool; + return components.getBufferPool(); + } + + @Override + public WebSocketComponents getWebSocketComponents() + { + return components; } } 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 f398f1ff0a7..2e56a37c6ab 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 @@ -31,7 +31,6 @@ import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.BlockingArrayQueue; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -551,8 +550,7 @@ public class WebSocketCloseTest extends WebSocketTester ContextHandler context = new ContextHandler("/"); server.setHandler(context); - WebSocketNegotiator negotiator = new TestWebSocketNegotiator(new DecoratedObjectFactory(), new WebSocketExtensionRegistry(), - connector.getByteBufferPool(), frameHandler); + WebSocketNegotiator negotiator = new TestWebSocketNegotiator(frameHandler); WebSocketUpgradeHandler upgradeHandler = new TestWebSocketUpgradeHandler(negotiator); context.setHandler(upgradeHandler); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/AbstractExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/AbstractExtensionTest.java index fe45a8dd83b..9ae85a0e924 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/AbstractExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/AbstractExtensionTest.java @@ -18,13 +18,12 @@ package org.eclipse.jetty.websocket.core.extensions; -import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.io.MappedByteBufferPool; +import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.junit.jupiter.api.BeforeEach; public abstract class AbstractExtensionTest { - public ByteBufferPool bufferPool = new MappedByteBufferPool(); + public WebSocketComponents components = new WebSocketComponents(); protected ExtensionTool clientExtensions; protected ExtensionTool serverExtensions; @@ -32,7 +31,7 @@ public abstract class AbstractExtensionTest @BeforeEach public void init() { - clientExtensions = new ExtensionTool(bufferPool); - serverExtensions = new ExtensionTool(bufferPool); + clientExtensions = new ExtensionTool(components.getBufferPool()); + serverExtensions = new ExtensionTool(components.getBufferPool()); } } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/DeflateFrameExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/DeflateFrameExtensionTest.java index 04f3f337ae1..8cc06435932 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/DeflateFrameExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/DeflateFrameExtensionTest.java @@ -28,13 +28,10 @@ import java.util.Random; import java.util.zip.Deflater; import java.util.zip.Inflater; -import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.RuntimeIOException; import org.eclipse.jetty.toolchain.test.ByteBufferAssert; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.log.Log; @@ -47,7 +44,6 @@ import org.eclipse.jetty.websocket.core.IncomingFramesCapture; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.OutgoingNetworkBytesCapture; import org.eclipse.jetty.websocket.core.TestMessageHandler; -import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Generator; import org.eclipse.jetty.websocket.core.internal.Negotiated; @@ -78,7 +74,7 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest // Wire up stack ext.setNextIncomingFrames(capture); - Parser parser = new Parser(bufferPool); + Parser parser = new Parser(components.getBufferPool()); ByteBuffer buffer = ByteBuffer.wrap(raw); while (BufferUtil.hasContent(buffer)) { @@ -113,7 +109,7 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest DeflateFrameExtension ext = new DeflateFrameExtension(); init(ext); - Generator generator = new Generator(bufferPool); + Generator generator = new Generator(components.getBufferPool()); OutgoingNetworkBytesCapture capture = new OutgoingNetworkBytesCapture(generator); ext.setNextOutgoingFrames(capture); @@ -238,7 +234,7 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest private void init(DeflateFrameExtension ext) { ext.setWebSocketCoreSession(sessionWithMaxMessageSize(20 * 1024 * 1024)); - ext.init(new ExtensionConfig(ext.getName()), bufferPool); + ext.init(new ExtensionConfig(ext.getName()), components); } @Test @@ -290,7 +286,7 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest DeflateFrameExtension ext = new DeflateFrameExtension(); init(ext); - Generator generator = new Generator(bufferPool); + Generator generator = new Generator(components.getBufferPool()); OutgoingNetworkBytesCapture capture = new OutgoingNetworkBytesCapture(generator); ext.setNextOutgoingFrames(capture); @@ -417,9 +413,8 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest private WebSocketCoreSession sessionWithMaxMessageSize(int maxMessageSize) { - ByteBufferPool bufferPool = new MappedByteBufferPool(); - ExtensionStack exStack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER); - exStack.negotiate(new DecoratedObjectFactory(), bufferPool, new LinkedList<>(), new LinkedList<>()); + ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER); + exStack.negotiate(new LinkedList<>(), new LinkedList<>()); WebSocketCoreSession coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.SERVER, Negotiated.from(exStack)); coreSession.setMaxFrameSize(maxMessageSize); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java index 4fdbadb6ee3..e50008ec0a3 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java @@ -21,9 +21,6 @@ package org.eclipse.jetty.websocket.core.extensions; import java.util.ArrayList; import java.util.List; -import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.io.MappedByteBufferPool; -import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.Behavior; @@ -33,7 +30,7 @@ import org.eclipse.jetty.websocket.core.IncomingFrames; import org.eclipse.jetty.websocket.core.IncomingFramesCapture; import org.eclipse.jetty.websocket.core.OutgoingFrames; import org.eclipse.jetty.websocket.core.OutgoingFramesCapture; -import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; +import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.IdentityExtension; import org.junit.jupiter.api.BeforeAll; @@ -46,17 +43,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class ExtensionStackTest { private static final Logger LOG = Log.getLogger(ExtensionStackTest.class); - - private static DecoratedObjectFactory objectFactory; - private static ByteBufferPool bufferPool; private static ExtensionStack stack; @BeforeAll public static void init() { - objectFactory = new DecoratedObjectFactory(); - bufferPool = new MappedByteBufferPool(); - stack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER); + stack = new ExtensionStack(new WebSocketComponents(), Behavior.SERVER); } @SuppressWarnings("unchecked") @@ -76,7 +68,7 @@ public class ExtensionStackTest // 1 extension List configs = new ArrayList<>(); configs.add(ExtensionConfig.parse("identity")); - stack.negotiate(objectFactory, bufferPool, configs, configs); + stack.negotiate(configs, configs); // Setup Listeners IncomingFrames session = new IncomingFramesCapture(); @@ -99,7 +91,7 @@ public class ExtensionStackTest List configs = new ArrayList<>(); configs.add(ExtensionConfig.parse("identity; id=A")); configs.add(ExtensionConfig.parse("identity; id=B")); - stack.negotiate(objectFactory, bufferPool, configs, configs); + stack.negotiate(configs, configs); // Setup Listeners IncomingFrames session = new IncomingFramesCapture(); @@ -129,7 +121,7 @@ public class ExtensionStackTest { String chromeRequest = "permessage-deflate; client_max_window_bits, x-webkit-deflate-frame"; List requestedConfigs = ExtensionConfig.parseList(chromeRequest); - stack.negotiate(objectFactory, bufferPool, requestedConfigs, requestedConfigs); + stack.negotiate(requestedConfigs, requestedConfigs); List negotiated = stack.getNegotiatedExtensions(); String response = ExtensionConfig.toHeaderValue(negotiated); 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 4d32ce5c214..55008105f04 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 @@ -26,7 +26,6 @@ import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.toolchain.test.ByteBufferAssert; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.websocket.core.Behavior; import org.eclipse.jetty.websocket.core.Extension; @@ -35,7 +34,7 @@ import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.IncomingFramesCapture; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.TestMessageHandler; -import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; +import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; import org.eclipse.jetty.websocket.core.internal.Negotiated; import org.eclipse.jetty.websocket.core.internal.Parser; @@ -61,7 +60,7 @@ public class ExtensionTool { this.requestedExtParams = parameterizedExtension; this.extConfig = ExtensionConfig.parse(parameterizedExtension); - Class extClass = factory.getExtension(extConfig.getName()); + Class extClass = components.getExtensionRegistry().getExtension(extConfig.getName()); assertThat("extClass", extClass, notNullValue()); this.capture = new IncomingFramesCapture(); @@ -75,7 +74,7 @@ public class ExtensionTool public void assertNegotiated(String expectedNegotiation) { - this.ext = factory.newInstance(objectFactory, bufferPool, extConfig); + this.ext = components.getExtensionRegistry().newInstance(extConfig, components); this.ext.setNextIncomingFrames(capture); this.ext.setWebSocketCoreSession(newWebSocketCoreSession()); } @@ -136,15 +135,11 @@ public class ExtensionTool } } - private final DecoratedObjectFactory objectFactory; - private final ByteBufferPool bufferPool; - private final WebSocketExtensionRegistry factory; + private final WebSocketComponents components; public ExtensionTool(ByteBufferPool bufferPool) { - this.objectFactory = new DecoratedObjectFactory(); - this.bufferPool = bufferPool; - this.factory = new WebSocketExtensionRegistry(); + this.components = new WebSocketComponents(); } public Tester newTester(String parameterizedExtension) @@ -154,9 +149,8 @@ public class ExtensionTool private WebSocketCoreSession newWebSocketCoreSession() { - ByteBufferPool bufferPool = new MappedByteBufferPool(); - ExtensionStack exStack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER); - exStack.negotiate(new DecoratedObjectFactory(), bufferPool, new LinkedList<>(), new LinkedList<>()); + ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER); + exStack.negotiate(new LinkedList<>(), new LinkedList<>()); WebSocketCoreSession coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.SERVER, Negotiated.from(exStack)); return coreSession; } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/FragmentExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/FragmentExtensionTest.java index 9d5d79e872f..3f0ed25ba42 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/FragmentExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/FragmentExtensionTest.java @@ -52,7 +52,7 @@ public class FragmentExtensionTest extends AbstractExtensionTest FragmentExtension ext = new FragmentExtension(); ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=4"); - ext.init(config, bufferPool); + ext.init(config, components); ext.setNextIncomingFrames(capture); @@ -101,7 +101,7 @@ public class FragmentExtensionTest extends AbstractExtensionTest FragmentExtension ext = new FragmentExtension(); ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=4"); - ext.init(config, bufferPool); + ext.init(config, components); ext.setNextIncomingFrames(capture); @@ -136,7 +136,7 @@ public class FragmentExtensionTest extends AbstractExtensionTest FragmentExtension ext = new FragmentExtension(); ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=20"); - ext.init(config, bufferPool); + ext.init(config, components); ext.setNextOutgoingFrames(capture); @@ -208,7 +208,7 @@ public class FragmentExtensionTest extends AbstractExtensionTest FragmentExtension ext = new FragmentExtension(); ExtensionConfig config = ExtensionConfig.parse("fragment"); - ext.init(config, bufferPool); + ext.init(config, components); ext.setNextOutgoingFrames(capture); @@ -272,7 +272,7 @@ public class FragmentExtensionTest extends AbstractExtensionTest FragmentExtension ext = new FragmentExtension(); ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=4"); - ext.init(config, bufferPool); + ext.init(config, components); ext.setNextOutgoingFrames(capture); 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 cc6790e31a2..e9e0e499368 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 @@ -53,7 +53,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest { private void init(PerMessageDeflateExtension ext) { - ext.init(new ExtensionConfig(ext.getName()), bufferPool); + ext.init(new ExtensionConfig(ext.getName()), components); } private void assertEndsWithTail(String hexStr, boolean expectedResult) @@ -284,7 +284,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest { PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); ExtensionConfig config = ExtensionConfig.parse("permessage-deflate"); - ext.init(config, bufferPool); + ext.init(config, components); // Setup capture of incoming frames IncomingFramesCapture capture = new IncomingFramesCapture(); @@ -319,7 +319,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest { PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); ExtensionConfig config = ExtensionConfig.parse("permessage-deflate"); - ext.init(config, bufferPool); + ext.init(config, components); // Setup capture of incoming frames IncomingFramesCapture capture = new IncomingFramesCapture(); @@ -354,7 +354,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest { PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); ExtensionConfig config = ExtensionConfig.parse("permessage-deflate"); - ext.init(config, bufferPool); + ext.init(config, components); // Setup capture of incoming frames IncomingFramesCapture capture = new IncomingFramesCapture(); @@ -409,7 +409,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest { PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); ExtensionConfig config = ExtensionConfig.parse("permessage-deflate"); - ext.init(config, bufferPool); + ext.init(config, components); // Setup capture of outgoing frames OutgoingFramesCapture capture = new OutgoingFramesCapture(); @@ -447,7 +447,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest public void testOutgoingFragmentedMessage() throws IOException, InterruptedException { PerMessageDeflateExtension ext = new PerMessageDeflateExtension(); - ext.init(ExtensionConfig.parse("permessage-deflate"), bufferPool); + ext.init(ExtensionConfig.parse("permessage-deflate"), components); // Setup capture of outgoing frames OutgoingFramesCapture capture = new OutgoingFramesCapture(); 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 d6238b47484..b3003314021 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 @@ -246,7 +246,7 @@ public class WebSocketMapping implements Dumpable, LifeCycle.Listener public Negotiator(WebSocketCreator creator, FrameHandlerFactory factory, FrameHandler.Customizer customizer) { - super(components.getExtensionRegistry(), components.getObjectFactory(), components.getBufferPool(), customizer); + super(components, customizer); this.creator = creator; this.factory = factory; }