Issue #300 - refactor usages of WebSocketComponents
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
e8d21364c3
commit
64eb3217cd
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<Class<? extends Extension>>
|
||||
|
@ -73,7 +71,7 @@ public class WebSocketExtensionRegistry implements Iterable<Class<? extends Exte
|
|||
return availableExtensions.values().iterator();
|
||||
}
|
||||
|
||||
public Extension newInstance(DecoratedObjectFactory objectFactory, ByteBufferPool bufferPool, ExtensionConfig config)
|
||||
public Extension newInstance(ExtensionConfig config, WebSocketComponents components)
|
||||
{
|
||||
if (config == null)
|
||||
{
|
||||
|
@ -94,8 +92,8 @@ public class WebSocketExtensionRegistry implements Iterable<Class<? extends Exte
|
|||
|
||||
try
|
||||
{
|
||||
Extension ext = objectFactory.createInstance(extClass);
|
||||
ext.init(config, bufferPool);
|
||||
Extension ext = components.getObjectFactory().createInstance(extClass);
|
||||
ext.init(config, components);
|
||||
|
||||
return ext;
|
||||
}
|
||||
|
|
|
@ -330,8 +330,8 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon
|
|||
|
||||
// Negotiate the extension stack
|
||||
HttpClient httpClient = wsClient.getHttpClient();
|
||||
ExtensionStack extensionStack = new ExtensionStack(wsClient.getExtensionRegistry(), Behavior.CLIENT);
|
||||
extensionStack.negotiate(wsClient.getObjectFactory(), httpClient.getByteBufferPool(), offeredExtensions, negotiatedExtensions);
|
||||
ExtensionStack extensionStack = new ExtensionStack(wsClient.getWebSocketComponents(), Behavior.CLIENT);
|
||||
extensionStack.negotiate(offeredExtensions, negotiatedExtensions);
|
||||
|
||||
// Get the negotiated subprotocol
|
||||
String negotiatedSubProtocol = null;
|
||||
|
|
|
@ -26,9 +26,7 @@ import java.util.ListIterator;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jetty.http.BadMessageException;
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.DecoratedObjectFactory;
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
|
@ -40,8 +38,8 @@ import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
|||
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.WebSocketExtensionRegistry;
|
||||
|
||||
/**
|
||||
* Represents the stack of Extensions.
|
||||
|
@ -51,16 +49,16 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable
|
|||
{
|
||||
private static final Logger LOG = Log.getLogger(ExtensionStack.class);
|
||||
|
||||
private final WebSocketExtensionRegistry factory;
|
||||
private final WebSocketComponents components;
|
||||
private final Behavior behavior;
|
||||
private List<Extension> 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<ExtensionConfig> offeredConfigs, List<ExtensionConfig> negotiatedConfigs)
|
||||
public void negotiate(List<ExtensionConfig> offeredConfigs, List<ExtensionConfig> 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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<String, String> parameters = config.getParameters();
|
||||
|
||||
|
|
|
@ -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<String, String> 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
|
||||
|
|
|
@ -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<ExtensionConfig> offeredExtensions;
|
||||
private final List<String> 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<String> available = registry.getAvailableExtensionNames();
|
||||
Set<String> 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())
|
||||
|
|
|
@ -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<Negotiation, FrameHandler> negotiate)
|
||||
{
|
||||
return new AbstractNegotiator()
|
||||
|
@ -50,7 +53,7 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer
|
|||
|
||||
static WebSocketNegotiator from(Function<Negotiation, FrameHandler> 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<Negotiation, FrameHandler> 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()
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<Arguments> 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ExtensionConfig> 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<ExtensionConfig> 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<ExtensionConfig> requestedConfigs = ExtensionConfig.parseList(chromeRequest);
|
||||
stack.negotiate(objectFactory, bufferPool, requestedConfigs, requestedConfigs);
|
||||
stack.negotiate(requestedConfigs, requestedConfigs);
|
||||
|
||||
List<ExtensionConfig> negotiated = stack.getNegotiatedExtensions();
|
||||
String response = ExtensionConfig.toHeaderValue(negotiated);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue