Move websocket-util classes into websocket-core (#5705)

- Merge websocket-util classes into websocket-core
- rename websocket-util-server to websocket-servlet
- remove websocket-util

* merge websocket-util into websocket-core-common
* move websocket-util-server implementation to websocket-core-server
* rename websocket-util-server to websocket-servlet
* Negotiator should not need the WebSocketComponents, give this to handshaker instead
* fix tests and WebSocketConfigurations
* move exception classes in websocket-core-common
* move MessageSinks and util to internal package
* create internal package for websocket-core-client
* fix JPMS warnings for websocket common modules
* Fixed exports declarations to make MethodHandles.publicLookup() working properly.
* fix broken tests with wrong WebSocketUpgradeFilter package name
* remove -T3 option to not have parallel build
* no need of jacoco here
* do no reuse forks
* remove logback dependency and disable debug log level
* make this test dynamic instead of hardcoded version...
* use -fae
* change websocket-servlet bundle symbolic name
* cleanup changes
* restore bugs....
* Updates after review.

Co-authored-by: Simone Bordet <simone.bordet@gmail.com>
Co-authored-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
Lachlan 2020-12-02 11:10:15 +11:00 committed by GitHub
parent 845c6b457a
commit 121d898517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
178 changed files with 685 additions and 860 deletions

View File

@ -63,7 +63,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util-server</artifactId>
<artifactId>websocket-servlet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>

View File

@ -359,7 +359,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util-server</artifactId>
<artifactId>websocket-servlet</artifactId>
<version>10.0.0-SNAPSHOT</version>
</dependency>
<dependency>

View File

@ -43,7 +43,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util-server</artifactId>
<artifactId>websocket-servlet</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

View File

@ -620,7 +620,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util-server</artifactId>
<artifactId>websocket-servlet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>

View File

@ -316,7 +316,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util-server</artifactId>
<artifactId>websocket-servlet</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>

View File

@ -186,8 +186,7 @@ public class TestOSGiUtil
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-core-server").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-core-client").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-core-common").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-util").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-util-server").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-servlet").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-jetty-api").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-jetty-server").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-jetty-client").versionAsInProject().start());

View File

@ -28,9 +28,8 @@
<module>websocket-javax-client</module>
<module>websocket-javax-server</module>
<module>websocket-javax-tests</module>
<!-- Common WebSocket Implementation -->
<module>websocket-util</module>
<module>websocket-util-server</module>
<!-- Common Servlet WebSocket Implementation -->
<module>websocket-servlet</module>
</modules>
<build>
<plugins>

View File

@ -77,6 +77,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>generate-manifest</id>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Export-Package>*,org.eclipse.jetty.websocket.core.client.internal.*</Export-Package>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -52,6 +52,8 @@ import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
import org.eclipse.jetty.websocket.core.client.internal.HttpUpgraderOverHTTP;
import org.eclipse.jetty.websocket.core.client.internal.HttpUpgraderOverHTTP2;
import org.eclipse.jetty.websocket.core.exception.UpgradeException;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
@ -281,7 +283,7 @@ public abstract class CoreClientUpgradeRequest extends HttpRequest implements Re
public abstract FrameHandler getFrameHandler();
void requestComplete()
public void requestComplete()
{
// Add extensions header filtering out internal extensions and internal parameters.
String extensionString = requestedExtensions.stream()

View File

@ -32,6 +32,7 @@ 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.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.client.internal.HttpClientProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.core.client;
package org.eclipse.jetty.websocket.core.client.internal;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.thread.QueuedThreadPool;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.core.client;
package org.eclipse.jetty.websocket.core.client.internal;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
@ -34,6 +34,7 @@ import org.eclipse.jetty.http.PreEncodedHttpField;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.internal.WebSocketCore;
public class HttpUpgraderOverHTTP implements HttpUpgrader

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.core.client;
package org.eclipse.jetty.websocket.core.client.internal;
import org.eclipse.jetty.client.HttpRequest;
import org.eclipse.jetty.client.HttpResponse;
@ -27,6 +27,7 @@ import org.eclipse.jetty.http.PreEncodedHttpField;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
public class HttpUpgraderOverHTTP2 implements HttpUpgrader
{

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.core.client;
package org.eclipse.jetty.websocket.core.client.internal;
import java.net.URL;
@ -26,7 +26,7 @@ import org.eclipse.jetty.xml.XmlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class XmlHttpClientProvider implements HttpClientProvider
public class XmlHttpClientProvider implements HttpClientProvider
{
private static final Logger LOG = LoggerFactory.getLogger(XmlHttpClientProvider.class);

View File

@ -26,7 +26,27 @@ module org.eclipse.jetty.websocket.core.common
{
exports org.eclipse.jetty.websocket.core;
exports org.eclipse.jetty.websocket.core.exception;
exports org.eclipse.jetty.websocket.core.internal to org.eclipse.jetty.websocket.core.client, org.eclipse.jetty.websocket.core.server, org.eclipse.jetty.util;
exports org.eclipse.jetty.websocket.core.internal to
org.eclipse.jetty.websocket.core.client,
org.eclipse.jetty.websocket.core.server;
// The Jetty & Javax API Layers need to access both access some internal utilities which we don't want to expose.
exports org.eclipse.jetty.websocket.core.internal.util to
org.eclipse.jetty.websocket.jetty.common,
org.eclipse.jetty.websocket.jetty.client,
org.eclipse.jetty.websocket.jetty.server,
org.eclipse.jetty.websocket.javax.common,
org.eclipse.jetty.websocket.javax.client,
org.eclipse.jetty.websocket.javax.server;
exports org.eclipse.jetty.websocket.core.internal.messages to
org.eclipse.jetty.websocket.jetty.common,
org.eclipse.jetty.websocket.jetty.client,
org.eclipse.jetty.websocket.jetty.server,
org.eclipse.jetty.websocket.javax.common,
org.eclipse.jetty.websocket.javax.client,
org.eclipse.jetty.websocket.javax.server;
requires org.eclipse.jetty.http;
requires transitive org.eclipse.jetty.io;

View File

@ -16,11 +16,13 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util;
package org.eclipse.jetty.websocket.core.exception;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import org.eclipse.jetty.websocket.core.internal.util.ReflectUtils;
@SuppressWarnings("serial")
public class DuplicateAnnotationException extends InvalidWebSocketException
{

View File

@ -16,12 +16,14 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util;
package org.eclipse.jetty.websocket.core.exception;
import java.lang.annotation.Annotation;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import org.eclipse.jetty.websocket.core.internal.util.ReflectUtils;
@SuppressWarnings("serial")
public class InvalidSignatureException extends InvalidWebSocketException
{

View File

@ -16,9 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
package org.eclipse.jetty.websocket.core.exception;
/**
* Indicating that the provided Class is not a valid WebSocket per the chosen API.

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.core;
package org.eclipse.jetty.websocket.core.internal;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
@ -27,6 +27,11 @@ import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IteratingNestedCallback;
import org.eclipse.jetty.util.Utf8Appendable;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.websocket.core.CloseStatus;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.exception.BadPayloadException;
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
import org.slf4j.Logger;
@ -87,7 +92,7 @@ public class MessageHandler implements FrameHandler
};
}
protected static final Logger LOG = LoggerFactory.getLogger(MessageHandler.class);
private static final Logger LOG = LoggerFactory.getLogger(MessageHandler.class);
private CoreSession coreSession;
private Utf8StringBuilder textMessageBuffer;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.lang.invoke.MethodHandle;
import java.util.Objects;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -28,8 +28,8 @@ import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
import org.eclipse.jetty.websocket.util.InvalidSignatureException;
public class ByteArrayMessageSink extends AbstractMessageSink
{

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -29,8 +29,8 @@ import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
import org.eclipse.jetty.websocket.util.InvalidSignatureException;
public class ByteBufferMessageSink extends AbstractMessageSink
{

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.io.Closeable;
import java.lang.invoke.MethodHandle;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.lang.invoke.MethodHandle;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.io.IOException;
import java.io.InputStream;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.io.IOException;
import java.io.OutputStream;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.io.IOException;
import java.io.Reader;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.Frame;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.io.IOException;
import java.io.Writer;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.lang.invoke.MethodHandle;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.lang.invoke.MethodHandle;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.lang.invoke.MethodHandle;
import java.util.Objects;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.lang.invoke.MethodHandle;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.messages;
package org.eclipse.jetty.websocket.core.internal.messages;
import java.lang.invoke.MethodHandle;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util;
package org.eclipse.jetty.websocket.core.internal.util;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util;
package org.eclipse.jetty.websocket.core.internal.util;
import java.lang.annotation.Annotation;
import java.lang.invoke.MethodType;
@ -31,6 +31,9 @@ import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.eclipse.jetty.websocket.core.exception.DuplicateAnnotationException;
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
public class ReflectUtils
{

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util;
package org.eclipse.jetty.websocket.core.internal.util;
/**
* Collection of utility methods for Text content

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.server.internal;
package org.eclipse.jetty.websocket.core.server;
import org.eclipse.jetty.websocket.core.FrameHandler;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.server.internal;
package org.eclipse.jetty.websocket.core.server;
import java.net.HttpCookie;
import java.net.InetSocketAddress;
@ -41,22 +41,19 @@ import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.internal.UpgradeHttpServletRequest;
/**
* Holder of request data for a WebSocket upgrade request.
*/
public class ServerUpgradeRequest
{
private final URI requestURI;
private final String queryString;
private final UpgradeHttpServletRequest request;
private final boolean secure;
private final Negotiation negotiation;
private final WebSocketNegotiation negotiation;
private List<HttpCookie> cookies;
private Map<String, List<String>> parameterMap;
public ServerUpgradeRequest(Negotiation negotiation) throws BadMessageException
public ServerUpgradeRequest(WebSocketNegotiation negotiation) throws BadMessageException
{
this.negotiation = negotiation;
HttpServletRequest httpRequest = negotiation.getRequest();
@ -114,7 +111,7 @@ public class ServerUpgradeRequest
/**
* @return The extensions offered
* @see Negotiation#getOfferedExtensions()
* @see WebSocketNegotiation#getOfferedExtensions()
*/
public List<ExtensionConfig> getExtensions()
{

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.server.internal;
package org.eclipse.jetty.websocket.core.server;
import java.io.IOException;
import java.util.ArrayList;
@ -31,17 +31,13 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.server.Negotiation;
/**
* Servlet Specific UpgradeResponse implementation.
*/
public class ServerUpgradeResponse
{
private final HttpServletResponse response;
private final Negotiation negotiation;
private final WebSocketNegotiation negotiation;
public ServerUpgradeResponse(Negotiation negotiation)
public ServerUpgradeResponse(WebSocketNegotiation negotiation)
{
this.negotiation = negotiation;
this.response = negotiation.getResponse();

View File

@ -16,13 +16,13 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.server.internal;
package org.eclipse.jetty.websocket.core.server;
/**
* Abstract WebSocket creator interface.
* <p>
* Should you desire filtering of the WebSocket object creation due to criteria such as origin or sub-protocol, then you will be required to implement a custom
* WebSocketCreator implementation.
* Should you desire filtering of the WebSocket object creation due to criteria such as origin or sub-protocol,
* then you will be required to implement a custom WebSocketCreator implementation.
* </p>
*/
public interface WebSocketCreator

View File

@ -16,10 +16,9 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.server.internal;
package org.eclipse.jetty.websocket.core.server;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@ -39,10 +38,9 @@ import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.core.server.Handshaker;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
import org.eclipse.jetty.websocket.core.server.WebSocketServerComponents;
import org.eclipse.jetty.websocket.core.server.internal.CreatorNegotiator;
import org.eclipse.jetty.websocket.core.server.internal.Handshaker;
import org.eclipse.jetty.websocket.core.server.internal.HandshakerSelector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -61,20 +59,14 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
private static final Logger LOG = LoggerFactory.getLogger(WebSocketMappings.class);
public static final String WEBSOCKET_MAPPING_ATTRIBUTE = WebSocketMappings.class.getName();
public static WebSocketMappings getMapping(ServletContext servletContext)
public static WebSocketMappings getWebSocketNegotiator(ServletContext servletContext)
{
return (WebSocketMappings)servletContext.getAttribute(WEBSOCKET_MAPPING_ATTRIBUTE);
}
public WebSocketCreator getMapping(PathSpec pathSpec)
public static WebSocketMappings ensureMappings(ServletContext servletContext)
{
Negotiator cn = mappings.get(pathSpec);
return cn == null ? null : cn.getWebSocketCreator();
}
public static WebSocketMappings ensureMapping(ServletContext servletContext)
{
WebSocketMappings mapping = getMapping(servletContext);
WebSocketMappings mapping = getWebSocketNegotiator(servletContext);
if (mapping == null)
{
mapping = new WebSocketMappings(WebSocketServerComponents.getWebSocketComponents(servletContext));
@ -123,9 +115,9 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
throw new IllegalArgumentException("Unrecognized path spec syntax [" + rawSpec + "]");
}
private final PathMappings<Negotiator> mappings = new PathMappings<>();
private final PathMappings<WebSocketNegotiator> mappings = new PathMappings<>();
private final WebSocketComponents components;
private final Handshaker handshaker = Handshaker.newInstance();
private final Handshaker handshaker = new HandshakerSelector();
public WebSocketMappings()
{
@ -161,6 +153,19 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
Dumpable.dumpObjects(out, indent, this, mappings);
}
public WebSocketNegotiator getWebSocketNegotiator(PathSpec pathSpec)
{
return mappings.get(pathSpec);
}
public WebSocketCreator getWebSocketCreator(PathSpec pathSpec)
{
WebSocketNegotiator negotiator = getWebSocketNegotiator(pathSpec);
if (negotiator instanceof CreatorNegotiator)
return ((CreatorNegotiator)negotiator).getWebSocketCreator();
return null;
}
/**
* Manually add a WebSocket mapping.
* <p>
@ -171,12 +176,28 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
*
* @param pathSpec the pathspec to respond on
* @param creator the websocket creator to activate on the provided mapping.
* @param factory the factory to use to create a FrameHandler for the websocket
* @param factory the factory to use to create a FrameHandler for the websocket.
* @param customizer the customizer to use to customize the WebSocket session.
*/
public void addMapping(PathSpec pathSpec, WebSocketCreator creator, FrameHandlerFactory factory, Configuration.Customizer customizer) throws WebSocketException
{
mappings.put(pathSpec, new Negotiator(creator, factory, customizer));
mappings.put(pathSpec, new CreatorNegotiator(creator, factory, customizer));
}
/**
* Manually add a WebSocket mapping.
* <p>
* If mapping is added before this configuration is started, then it is persisted through
* stop/start of this configuration's lifecycle. Otherwise it will be removed when
* this configuration is stopped.
* </p>
*
* @param pathSpec the pathspec to respond on
* @param negotiator the WebSocketNegotiator to use to create a FrameHandler for the websocket.
*/
public void addMapping(PathSpec pathSpec, WebSocketNegotiator negotiator) throws WebSocketException
{
mappings.put(pathSpec, negotiator);
}
public boolean removeMapping(PathSpec pathSpec)
@ -193,7 +214,7 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
*/
public WebSocketNegotiator getMatchedNegotiator(String target, Consumer<PathSpec> pathSpecConsumer)
{
MappedResource<Negotiator> mapping = this.mappings.getMatch(target);
MappedResource<WebSocketNegotiator> mapping = this.mappings.getMatch(target);
if (mapping == null)
return null;
@ -224,59 +245,6 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
LOG.debug("WebSocket Negotiated detected on {} for endpoint {}", target, negotiator);
// We have an upgrade request
return handshaker.upgradeRequest(negotiator, request, response, defaultCustomizer);
}
private class Negotiator extends WebSocketNegotiator.AbstractNegotiator
{
private final WebSocketCreator creator;
private final FrameHandlerFactory factory;
public Negotiator(WebSocketCreator creator, FrameHandlerFactory factory, Configuration.Customizer customizer)
{
super(components, customizer);
this.creator = creator;
this.factory = factory;
}
public WebSocketCreator getWebSocketCreator()
{
return creator;
}
@Override
public FrameHandler negotiate(Negotiation negotiation) throws IOException
{
ServletContext servletContext = negotiation.getRequest().getServletContext();
if (servletContext == null)
throw new IllegalStateException("null servletContext from request");
ServerUpgradeRequest upgradeRequest = new ServerUpgradeRequest(negotiation);
ServerUpgradeResponse upgradeResponse = new ServerUpgradeResponse(negotiation);
AtomicReference<Object> result = new AtomicReference<>();
((ContextHandler.Context)servletContext).getContextHandler().handle(() ->
result.set(creator.createWebSocket(upgradeRequest, upgradeResponse)));
Object websocketPojo = result.get();
// Handling for response forbidden (and similar paths)
if (upgradeResponse.isCommitted())
return null;
if (websocketPojo == null)
{
// no creation, sorry
upgradeResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "WebSocket Endpoint Creation Refused");
return null;
}
return factory.newFrameHandler(websocketPojo, upgradeRequest, upgradeResponse);
}
@Override
public String toString()
{
return String.format("%s@%x{%s,%s,%s}", getClass().getSimpleName(), hashCode(), creator, factory, getCustomizer());
}
return handshaker.upgradeRequest(negotiator, request, response, components, defaultCustomizer);
}
}

View File

@ -33,9 +33,8 @@ import org.eclipse.jetty.http.QuotedCSV;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
public abstract class Negotiation
public abstract class WebSocketNegotiation
{
private final Request baseRequest;
private final HttpServletRequest request;
@ -45,10 +44,9 @@ public abstract class Negotiation
private List<ExtensionConfig> offeredExtensions;
private List<ExtensionConfig> negotiatedExtensions;
private List<String> offeredProtocols;
private ExtensionStack extensionStack;
private String protocol;
public Negotiation(Request baseRequest, HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
public WebSocketNegotiation(Request baseRequest, HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
{
this.baseRequest = baseRequest;
this.request = request;
@ -180,7 +178,6 @@ public abstract class Negotiation
if (extensions == offeredExtensions)
return;
negotiatedExtensions = extensions;
extensionStack = null;
}
@Override

View File

@ -21,77 +21,41 @@ package org.eclipse.jetty.websocket.core.server;
import java.io.IOException;
import java.util.function.Function;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.websocket.core.Configuration;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
public interface WebSocketNegotiator extends Configuration.Customizer
{
FrameHandler negotiate(Negotiation negotiation) throws IOException;
FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException;
WebSocketExtensionRegistry getExtensionRegistry();
DecoratedObjectFactory getObjectFactory();
ByteBufferPool getByteBufferPool();
WebSocketComponents getWebSocketComponents();
static WebSocketNegotiator from(Function<Negotiation, FrameHandler> negotiate)
static WebSocketNegotiator from(Function<WebSocketNegotiation, FrameHandler> negotiate)
{
return new AbstractNegotiator()
return from(negotiate, null);
}
static WebSocketNegotiator from(Function<WebSocketNegotiation, FrameHandler> negotiate, Configuration.Customizer customizer)
{
return new AbstractNegotiator(customizer)
{
@Override
public FrameHandler negotiate(Negotiation negotiation)
public FrameHandler negotiate(WebSocketNegotiation negotiation)
{
return negotiate.apply(negotiation);
}
};
}
static WebSocketNegotiator from(Function<Negotiation, FrameHandler> negotiate, Configuration.Customizer customizer)
abstract class AbstractNegotiator extends Configuration.ConfigurationCustomizer implements WebSocketNegotiator
{
return new AbstractNegotiator(null, customizer)
{
@Override
public FrameHandler negotiate(Negotiation negotiation)
{
return negotiate.apply(negotiation);
}
};
}
static WebSocketNegotiator from(
Function<Negotiation, FrameHandler> negotiate,
WebSocketComponents components,
Configuration.Customizer customizer)
{
return new AbstractNegotiator(components, customizer)
{
@Override
public FrameHandler negotiate(Negotiation negotiation)
{
return negotiate.apply(negotiation);
}
};
}
abstract class AbstractNegotiator implements WebSocketNegotiator
{
final WebSocketComponents components;
final Configuration.Customizer customizer;
public AbstractNegotiator()
{
this(null, null);
this(null);
}
public AbstractNegotiator(WebSocketComponents components, Configuration.Customizer customizer)
public AbstractNegotiator(Configuration.Customizer customizer)
{
this.components = components == null ? new WebSocketComponents() : components;
this.customizer = customizer;
}
@ -100,35 +64,7 @@ public interface WebSocketNegotiator extends Configuration.Customizer
{
if (customizer != null)
customizer.customize(configurable);
}
@Override
public WebSocketExtensionRegistry getExtensionRegistry()
{
return components.getExtensionRegistry();
}
@Override
public DecoratedObjectFactory getObjectFactory()
{
return components.getObjectFactory();
}
@Override
public ByteBufferPool getByteBufferPool()
{
return components.getBufferPool();
}
@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}
public Configuration.Customizer getCustomizer()
{
return customizer;
super.customize(configurable);
}
}
}

View File

@ -19,65 +19,46 @@
package org.eclipse.jetty.websocket.core.server;
import java.io.IOException;
import java.util.Objects;
import java.util.function.Function;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.pathmap.PathSpecSet;
import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.jetty.websocket.core.Configuration;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
public class WebSocketUpgradeHandler extends HandlerWrapper
{
private static final Logger LOG = LoggerFactory.getLogger(WebSocketUpgradeHandler.class);
final Handshaker handshaker = Handshaker.newInstance();
final PathSpecSet paths = new PathSpecSet();
final WebSocketNegotiator negotiator;
private final WebSocketMappings mappings;
private final Configuration.ConfigurationCustomizer customizer = new Configuration.ConfigurationCustomizer();
public WebSocketUpgradeHandler(
Function<Negotiation, FrameHandler> negotiate,
String... pathSpecs)
public WebSocketUpgradeHandler()
{
this(WebSocketNegotiator.from(negotiate), pathSpecs);
this(new WebSocketComponents());
}
public WebSocketUpgradeHandler(WebSocketNegotiator negotiator, String... pathSpecs)
public WebSocketUpgradeHandler(WebSocketComponents components)
{
this.negotiator = Objects.requireNonNull(negotiator);
addPathSpec(pathSpecs);
this.mappings = new WebSocketMappings(components);
}
public WebSocketNegotiator getWebSocketNegotiator()
public void addMapping(String pathSpec, WebSocketNegotiator negotiator)
{
return negotiator;
mappings.addMapping(new ServletPathSpec(pathSpec), negotiator);
}
public void addPathSpec(String... pathSpecs)
public void addMapping(PathSpec pathSpec, WebSocketNegotiator negotiator)
{
if (pathSpecs != null)
{
for (String spec : pathSpecs)
{
this.paths.add(spec);
}
}
mappings.addMapping(pathSpec, negotiator);
}
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (!paths.isEmpty() && !paths.test(target))
{
super.handle(target, baseRequest, request, response);
return;
}
if (handshaker.upgradeRequest(negotiator, request, response, null))
if (mappings.upgrade(request, response, customizer))
return;
if (!baseRequest.isHandled())

View File

@ -47,8 +47,7 @@ import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
import org.eclipse.jetty.websocket.core.internal.Negotiated;
import org.eclipse.jetty.websocket.core.internal.WebSocketConnection;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
import org.eclipse.jetty.websocket.core.server.Handshaker;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -59,13 +58,12 @@ public abstract class AbstractHandshaker implements Handshaker
private static final HttpField SERVER_VERSION = new PreEncodedHttpField(HttpHeader.SERVER, HttpConfiguration.SERVER_VERSION);
@Override
public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, Configuration.Customizer defaultCustomizer) throws IOException
public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, WebSocketComponents components, Configuration.Customizer defaultCustomizer) throws IOException
{
if (!validateRequest(request))
return false;
WebSocketComponents components = negotiator.getWebSocketComponents();
Negotiation negotiation = newNegotiation(request, response, components);
WebSocketNegotiation negotiation = newNegotiation(request, response, components);
if (LOG.isDebugEnabled())
LOG.debug("negotiation {}", negotiation);
negotiation.negotiate();
@ -173,11 +171,11 @@ public abstract class AbstractHandshaker implements Handshaker
protected abstract boolean validateRequest(HttpServletRequest request);
protected abstract Negotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents);
protected abstract WebSocketNegotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents);
protected abstract boolean validateFrameHandler(FrameHandler frameHandler, HttpServletResponse response);
protected boolean validateNegotiation(Negotiation negotiation)
protected boolean validateNegotiation(WebSocketNegotiation negotiation)
{
if (!negotiation.validateHeaders())
{
@ -219,5 +217,5 @@ public abstract class AbstractHandshaker implements Handshaker
return new WebSocketConnection(endPoint, executor, scheduler, byteBufferPool, coreSession);
}
protected abstract void prepareResponse(Response response, Negotiation negotiation);
protected abstract void prepareResponse(Response response, WebSocketNegotiation negotiation);
}

View File

@ -0,0 +1,86 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.websocket.core.server.internal;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.server.FrameHandlerFactory;
import org.eclipse.jetty.websocket.core.server.ServerUpgradeRequest;
import org.eclipse.jetty.websocket.core.server.ServerUpgradeResponse;
import org.eclipse.jetty.websocket.core.server.WebSocketCreator;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
public class CreatorNegotiator extends WebSocketNegotiator.AbstractNegotiator
{
private final WebSocketCreator creator;
private final FrameHandlerFactory factory;
public CreatorNegotiator(WebSocketCreator creator, FrameHandlerFactory factory, Customizer customizer)
{
super(customizer);
this.creator = creator;
this.factory = factory;
}
public WebSocketCreator getWebSocketCreator()
{
return creator;
}
@Override
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
{
ServletContext servletContext = negotiation.getRequest().getServletContext();
if (servletContext == null)
throw new IllegalStateException("null servletContext from request");
ServerUpgradeRequest upgradeRequest = new ServerUpgradeRequest(negotiation);
ServerUpgradeResponse upgradeResponse = new ServerUpgradeResponse(negotiation);
AtomicReference<Object> result = new AtomicReference<>();
((ContextHandler.Context)servletContext).getContextHandler().handle(() ->
result.set(creator.createWebSocket(upgradeRequest, upgradeResponse)));
Object websocketPojo = result.get();
// Handling for response forbidden (and similar paths)
if (upgradeResponse.isCommitted())
return null;
if (websocketPojo == null)
{
// no creation, sorry
upgradeResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "WebSocket Endpoint Creation Refused");
return null;
}
return factory.newFrameHandler(websocketPojo, upgradeRequest, upgradeResponse);
}
@Override
public String toString()
{
return String.format("%s@%x{%s,%s}", getClass().getSimpleName(), hashCode(), creator, factory);
}
}

View File

@ -16,21 +16,17 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.core.server;
package org.eclipse.jetty.websocket.core.server.internal;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.websocket.core.Configuration;
import org.eclipse.jetty.websocket.core.server.internal.HandshakerSelector;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
public interface Handshaker
{
static Handshaker newInstance()
{
return new HandshakerSelector();
}
boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, Configuration.Customizer defaultCustomizer) throws IOException;
boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, WebSocketComponents components, Configuration.Customizer defaultCustomizer) throws IOException;
}

View File

@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.websocket.core.Configuration;
import org.eclipse.jetty.websocket.core.server.Handshaker;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
/**
@ -37,10 +37,10 @@ public class HandshakerSelector implements Handshaker
private final RFC8441Handshaker rfc8441 = new RFC8441Handshaker();
@Override
public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, Configuration.Customizer defaultCustomizer) throws IOException
public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, WebSocketComponents components, Configuration.Customizer defaultCustomizer) throws IOException
{
// Try HTTP/1.1 WS upgrade, if this fails try an HTTP/2 WS upgrade if no response was committed.
return rfc6455.upgradeRequest(negotiator, request, response, defaultCustomizer) ||
!response.isCommitted() && rfc8441.upgradeRequest(negotiator, request, response, defaultCustomizer);
return rfc6455.upgradeRequest(negotiator, request, response, components, defaultCustomizer) ||
!response.isCommitted() && rfc8441.upgradeRequest(negotiator, request, response, components, defaultCustomizer);
}
}

View File

@ -37,7 +37,7 @@ import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.internal.WebSocketConnection;
import org.eclipse.jetty.websocket.core.internal.WebSocketCore;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
public final class RFC6455Handshaker extends AbstractHandshaker
{
@ -65,13 +65,13 @@ public final class RFC6455Handshaker extends AbstractHandshaker
}
@Override
protected Negotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
protected WebSocketNegotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
{
return new RFC6455Negotiation(Request.getBaseRequest(request), request, response, webSocketComponents);
}
@Override
protected boolean validateNegotiation(Negotiation negotiation)
protected boolean validateNegotiation(WebSocketNegotiation negotiation)
{
boolean result = super.validateNegotiation(negotiation);
if (!result)
@ -103,7 +103,7 @@ public final class RFC6455Handshaker extends AbstractHandshaker
}
@Override
protected void prepareResponse(Response response, Negotiation negotiation)
protected void prepareResponse(Response response, WebSocketNegotiation negotiation)
{
response.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
HttpFields.Mutable responseFields = response.getHttpFields();

View File

@ -27,9 +27,9 @@ import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.QuotedCSV;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
public class RFC6455Negotiation extends Negotiation
public class RFC6455Negotiation extends WebSocketNegotiation
{
private boolean successful;
private String key;

View File

@ -33,7 +33,7 @@ import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.internal.WebSocketConnection;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
public class RFC8441Handshaker extends AbstractHandshaker
{
@ -58,7 +58,7 @@ public class RFC8441Handshaker extends AbstractHandshaker
}
@Override
protected Negotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
protected WebSocketNegotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
{
return new RFC8441Negotiation(Request.getBaseRequest(request), request, response, webSocketComponents);
}
@ -87,7 +87,7 @@ public class RFC8441Handshaker extends AbstractHandshaker
}
@Override
protected void prepareResponse(Response response, Negotiation negotiation)
protected void prepareResponse(Response response, WebSocketNegotiation negotiation)
{
response.setStatus(HttpStatus.OK_200);
}

View File

@ -25,9 +25,9 @@ import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
public class RFC8441Negotiation extends Negotiation
public class RFC8441Negotiation extends WebSocketNegotiation
{
public RFC8441Negotiation(Request baseRequest, HttpServletRequest request, HttpServletResponse response, WebSocketComponents components) throws BadMessageException
{

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.server.internal;
package org.eclipse.jetty.websocket.core.server.internal;
import java.io.BufferedReader;
import java.net.InetSocketAddress;

View File

@ -29,6 +29,11 @@ public class EchoFrameHandler extends TestAsyncFrameHandler
throwOnFrame = true;
}
public EchoFrameHandler()
{
super(EchoFrameHandler.class.getName());
}
public EchoFrameHandler(String name)
{
super(name);
@ -48,7 +53,7 @@ public class EchoFrameHandler extends TestAsyncFrameHandler
{
if (LOG.isDebugEnabled())
LOG.debug("[{}] echoDataFrame {}", name, frame);
Frame echo = Frame.copy(frame).setMask(null);
Frame echo = new Frame(frame.getOpCode(), frame.isFin(), frame.getPayload());
coreSession.sendFrame(echo, callback, false);
}
else

View File

@ -48,7 +48,7 @@ public class FlushTest
@BeforeEach
public void startup() throws Exception
{
WebSocketNegotiator negotiator = WebSocketNegotiator.from((negotiation) -> serverHandler);
WebSocketNegotiator negotiator = new TestWebSocketNegotiator(serverHandler);
server = new WebSocketServer(negotiator);
client = new WebSocketCoreClient(null, components);

View File

@ -47,7 +47,7 @@ public class FrameBufferTest extends WebSocketTester
@BeforeEach
public void startup() throws Exception
{
WebSocketNegotiator negotiator = WebSocketNegotiator.from((negotiation) -> serverHandler);
WebSocketNegotiator negotiator = new TestWebSocketNegotiator(serverHandler);
server = new WebSocketServer(negotiator);
client = new WebSocketCoreClient(null, components);

View File

@ -31,6 +31,7 @@ import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.core.exception.BadPayloadException;
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

View File

@ -24,6 +24,7 @@ import java.util.concurrent.CountDownLatch;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,49 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.websocket.core;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
public class TestUpgradeHandler extends WebSocketUpgradeHandler
{
public TestUpgradeHandler(WebSocketNegotiator negotiator)
{
super(negotiator);
setHandler(new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setStatus(200);
response.setContentType("text/plain");
response.getOutputStream().println("Test WS Upgrade Handler!");
baseRequest.setHandled(true);
}
});
}
}

View File

@ -21,29 +21,26 @@ package org.eclipse.jetty.websocket.core;
import java.io.IOException;
import java.util.List;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
public class TestWebSocketNegotiator implements WebSocketNegotiator
public class TestWebSocketNegotiator extends WebSocketNegotiator.AbstractNegotiator
{
final WebSocketComponents components;
private final FrameHandler frameHandler;
public TestWebSocketNegotiator(FrameHandler frameHandler)
{
this (frameHandler, new WebSocketComponents());
this(frameHandler, null);
}
public TestWebSocketNegotiator(FrameHandler frameHandler, WebSocketComponents components)
public TestWebSocketNegotiator(FrameHandler frameHandler, Configuration.Customizer customizer)
{
this.components = components;
super(customizer);
this.frameHandler = frameHandler;
}
@Override
public FrameHandler negotiate(Negotiation negotiation) throws IOException
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
{
List<String> offeredSubprotocols = negotiation.getOfferedSubprotocols();
if (!offeredSubprotocols.isEmpty())
@ -51,33 +48,4 @@ public class TestWebSocketNegotiator implements WebSocketNegotiator
return frameHandler;
}
@Override
public void customize(Configuration configurable)
{
}
@Override
public WebSocketExtensionRegistry getExtensionRegistry()
{
return components.getExtensionRegistry();
}
@Override
public DecoratedObjectFactory getObjectFactory()
{
return components.getObjectFactory();
}
@Override
public ByteBufferPool getByteBufferPool()
{
return components.getBufferPool();
}
@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}
}

View File

@ -1,50 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.websocket.core;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
public class TestWebSocketUpgradeHandler extends WebSocketUpgradeHandler
{
public TestWebSocketUpgradeHandler(WebSocketNegotiator negotiator)
{
super(negotiator);
setHandler(new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setStatus(200);
response.setContentType("text/plain");
response.getOutputStream().println("Hello World!");
baseRequest.setHandled(true);
}
});
}
}

View File

@ -42,7 +42,7 @@ import org.eclipse.jetty.websocket.core.client.UpgradeListener;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.exception.UpgradeException;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@ -81,10 +81,10 @@ public class WebSocketNegotiationTest extends WebSocketTester
@BeforeEach
public void startup() throws Exception
{
WebSocketNegotiator negotiator = new WebSocketNegotiator.AbstractNegotiator(components, null)
WebSocketNegotiator negotiator = new WebSocketNegotiator.AbstractNegotiator()
{
@Override
public FrameHandler negotiate(Negotiation negotiation) throws IOException
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
{
if (negotiation.getOfferedSubprotocols().isEmpty())
{
@ -127,7 +127,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
}
};
server = new WebSocketServer(negotiator);
server = new WebSocketServer(components, negotiator, false);
client = new WebSocketCoreClient(null, components);
server.start();

View File

@ -27,7 +27,7 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
@ -73,6 +73,11 @@ public class WebSocketServer
}
public WebSocketServer(WebSocketNegotiator negotiator, boolean tls)
{
this(new WebSocketComponents(), negotiator, tls);
}
public WebSocketServer(WebSocketComponents components, WebSocketNegotiator negotiator, boolean tls)
{
ServerConnector connector;
if (tls)
@ -84,7 +89,8 @@ public class WebSocketServer
ContextHandler context = new ContextHandler("/");
server.setHandler(context);
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler(negotiator);
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler(components);
upgradeHandler.addMapping("/*", negotiator);
context.setHandler(upgradeHandler);
}
@ -111,7 +117,7 @@ public class WebSocketServer
}
@Override
public FrameHandler negotiate(Negotiation negotiation) throws IOException
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
{
List<String> offeredSubprotocols = negotiation.getOfferedSubprotocols();
if (!offeredSubprotocols.isEmpty())

View File

@ -0,0 +1,76 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.websocket.core;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class WebSocketUpgradeHandlerTest
{
private Server server;
private WebSocketCoreClient client;
private URI serverUri;
@BeforeEach
public void before() throws Exception
{
server = new Server();
ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler();
upgradeHandler.addMapping("/path/echo", new TestWebSocketNegotiator(new EchoFrameHandler()));
server.setHandler(upgradeHandler);
server.start();
client = new WebSocketCoreClient();
client.start();
serverUri = URI.create("ws://localhost:" + connector.getLocalPort());
}
@AfterEach
public void after() throws Exception
{
server.stop();
client.stop();
}
@Test
public void testUpgradeByWebSocketUpgradeHandler() throws Exception
{
TestMessageHandler clientEndpoint = new TestMessageHandler();
CoreSession coreSession = client.connect(clientEndpoint, serverUri.resolve("/path/echo")).get(5, TimeUnit.SECONDS);
assertNotNull(coreSession);
coreSession.close(Callback.NOOP);
assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS));
}
}

View File

@ -52,14 +52,12 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.DockerStatus;
import org.testcontainers.utility.MountableFile;
import org.testcontainers.utility.TestcontainersConfiguration;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Testcontainers
public class AutobahnTests
{
private static final Logger LOG = LoggerFactory.getLogger(AutobahnTests.class);
private static final Path USER_DIR = Paths.get(System.getProperty("user.dir"));

View File

@ -28,10 +28,10 @@ import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.UrlEncoded;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.MessageHandler;
import org.eclipse.jetty.websocket.core.TestMessageHandler;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -21,6 +21,8 @@ package org.eclipse.jetty.websocket.core.autobahn;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.websocket.core.TestWebSocketNegotiator;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
/**
@ -78,9 +80,11 @@ public class CoreAutobahnServer
ContextHandler context = new ContextHandler("/");
server.setHandler(context);
WebSocketUpgradeHandler handler = new WebSocketUpgradeHandler((neg) -> new AutobahnFrameHandler());
context.setHandler(handler);
WebSocketComponents components = new WebSocketComponents();
WebSocketUpgradeHandler handler = new WebSocketUpgradeHandler(components);
handler.addMapping("/*", new TestWebSocketNegotiator(new AutobahnFrameHandler()));
context.setHandler(handler);
server.start();
return server;
}

View File

@ -28,9 +28,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.MessageHandler;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -26,6 +26,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
@ -36,18 +37,23 @@ import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.CloseStatus;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.MessageHandler;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.eclipse.jetty.util.Callback.NOOP;
public class ChatWebSocketServer
{
protected static final Logger LOG = LoggerFactory.getLogger(ChatWebSocketServer.class);
private final Set<MessageHandler> members = new HashSet<>();
private FrameHandler negotiate(Negotiation negotiation)
private FrameHandler negotiate(WebSocketNegotiation negotiation)
{
// Finalize negotiations in API layer involves:
// + MAY mutate the policy
@ -113,7 +119,9 @@ public class ChatWebSocketServer
server.setHandler(context);
ChatWebSocketServer chat = new ChatWebSocketServer();
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler(WebSocketNegotiator.from(chat::negotiate));
WebSocketComponents components = new WebSocketComponents();
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler(components);
upgradeHandler.addMapping(new ServletPathSpec("/*"), WebSocketNegotiator.from(chat::negotiate));
context.setHandler(upgradeHandler);
upgradeHandler.setHandler(new AbstractHandler()

View File

@ -41,7 +41,7 @@ import org.eclipse.jetty.websocket.core.WebSocketServer;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.UpgradeListener;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
@ -69,7 +69,7 @@ public class PerMessageDeflaterBufferSizeTest
int inflateBufferSize = -1;
@Override
public FrameHandler negotiate(Negotiation negotiation) throws IOException
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
{
for (ExtensionConfig extensionConfig : negotiation.getOfferedExtensions())
{

View File

@ -35,7 +35,7 @@ import org.eclipse.jetty.websocket.core.TestFrameHandler;
import org.eclipse.jetty.websocket.core.TestWebSocketNegotiator;
import org.eclipse.jetty.websocket.core.WebSocketServer;
import org.eclipse.jetty.websocket.core.WebSocketTester;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@ -58,7 +58,7 @@ public class ValidationExtensionTest extends WebSocketTester
WebSocketNegotiator negotiator = new TestWebSocketNegotiator(serverHandler)
{
@Override
public FrameHandler negotiate(Negotiation negotiation) throws IOException
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
{
List<ExtensionConfig> negotiatedExtensions = new ArrayList<>();
negotiatedExtensions.add(ExtensionConfig.parse(

View File

@ -45,6 +45,7 @@ import org.eclipse.jetty.websocket.core.EchoFrameHandler;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.TestAsyncFrameHandler;
import org.eclipse.jetty.websocket.core.TestWebSocketNegotiator;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
@ -112,14 +113,16 @@ public class WebSocketProxyTest
ContextHandler serverContext = new ContextHandler("/server");
serverFrameHandler = new EchoFrameHandler("SERVER");
WebSocketNegotiator negotiator = WebSocketNegotiator.from((negotiation) -> serverFrameHandler, defaultCustomizer);
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler(negotiator);
WebSocketNegotiator negotiator = new TestWebSocketNegotiator(serverFrameHandler, defaultCustomizer);
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler();
upgradeHandler.addMapping("/*", negotiator);
serverContext.setHandler(upgradeHandler);
handlers.addHandler(serverContext);
ContextHandler proxyContext = new ContextHandler("/proxy");
negotiator = WebSocketNegotiator.from((negotiation) -> proxy.client2Proxy, defaultCustomizer);
upgradeHandler = new WebSocketUpgradeHandler(negotiator);
negotiator = WebSocketNegotiator.from(negotiation -> proxy.client2Proxy, defaultCustomizer);
upgradeHandler = new WebSocketUpgradeHandler();
upgradeHandler.addMapping("/*", negotiator);
proxyContext.setHandler(upgradeHandler);
handlers.addHandler(proxyContext);

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util;
package org.eclipse.jetty.websocket.core.util;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -31,7 +31,7 @@ import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.util.messages.MessageReader;
import org.eclipse.jetty.websocket.core.internal.messages.MessageReader;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util;
package org.eclipse.jetty.websocket.core.util;
import java.io.IOException;
import java.nio.charset.MalformedInputException;
@ -32,7 +32,7 @@ import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.util.messages.MessageWriter;
import org.eclipse.jetty.websocket.core.internal.messages.MessageWriter;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util;
package org.eclipse.jetty.websocket.core.util;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
@ -34,7 +34,7 @@ import org.eclipse.jetty.util.Utf8Appendable;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.util.messages.PartialStringMessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.PartialStringMessageSink;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util;
package org.eclipse.jetty.websocket.core.util;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
@ -32,7 +32,7 @@ import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
import org.eclipse.jetty.websocket.util.messages.StringMessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.StringMessageSink;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;

View File

@ -24,11 +24,6 @@
<artifactId>websocket-javax-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-core-client</artifactId>

View File

@ -23,8 +23,8 @@ import java.util.List;
import javax.websocket.ClientEndpoint;
import javax.websocket.ClientEndpointConfig;
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
import org.eclipse.jetty.websocket.javax.common.ClientEndpointConfigWrapper;
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;
public class AnnotatedClientEndpointConfig extends ClientEndpointConfigWrapper
{

View File

@ -40,6 +40,7 @@ import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
import org.eclipse.jetty.websocket.core.exception.UpgradeException;
import org.eclipse.jetty.websocket.core.exception.WebSocketTimeoutException;
import org.eclipse.jetty.websocket.javax.common.ConfiguredEndpoint;
@ -47,7 +48,6 @@ import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketExtensionConfig;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandler;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory;
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;
/**
* Container for Client use of the javax.websocket API.

View File

@ -21,10 +21,10 @@ package org.eclipse.jetty.websocket.javax.client.internal;
import javax.websocket.ClientEndpoint;
import javax.websocket.EndpointConfig;
import org.eclipse.jetty.websocket.core.internal.util.InvokerUtils;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerMetadata;
import org.eclipse.jetty.websocket.util.InvokerUtils;
public class JavaxWebSocketClientFrameHandlerFactory extends JavaxWebSocketFrameHandlerFactory
{

View File

@ -70,11 +70,6 @@
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-javax-websocket-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-core-client</artifactId>

View File

@ -26,5 +26,4 @@ module org.eclipse.jetty.websocket.javax.common
requires org.slf4j;
requires transitive jetty.websocket.api;
requires transitive org.eclipse.jetty.websocket.core.client;
requires transitive org.eclipse.jetty.websocket.util;
}

View File

@ -31,9 +31,9 @@ import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.util.TextUtils;
import org.eclipse.jetty.websocket.util.messages.MessageOutputStream;
import org.eclipse.jetty.websocket.util.messages.MessageWriter;
import org.eclipse.jetty.websocket.core.internal.messages.MessageOutputStream;
import org.eclipse.jetty.websocket.core.internal.messages.MessageWriter;
import org.eclipse.jetty.websocket.core.internal.util.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -31,7 +31,7 @@ import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.util.TextUtils;
import org.eclipse.jetty.websocket.core.internal.util.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -45,17 +45,17 @@ import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.exception.ProtocolException;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.core.internal.messages.MessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.PartialByteArrayMessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.PartialByteBufferMessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.PartialStringMessageSink;
import org.eclipse.jetty.websocket.core.internal.util.InvokerUtils;
import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders;
import org.eclipse.jetty.websocket.javax.common.decoders.RegisteredDecoder;
import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryMessageSink;
import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryStreamMessageSink;
import org.eclipse.jetty.websocket.javax.common.messages.DecodedTextMessageSink;
import org.eclipse.jetty.websocket.javax.common.messages.DecodedTextStreamMessageSink;
import org.eclipse.jetty.websocket.util.InvokerUtils;
import org.eclipse.jetty.websocket.util.messages.MessageSink;
import org.eclipse.jetty.websocket.util.messages.PartialByteArrayMessageSink;
import org.eclipse.jetty.websocket.util.messages.PartialByteBufferMessageSink;
import org.eclipse.jetty.websocket.util.messages.PartialStringMessageSink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -43,20 +43,20 @@ import javax.websocket.Session;
import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
import org.eclipse.jetty.websocket.core.internal.messages.MessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.PartialByteArrayMessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.PartialByteBufferMessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.PartialStringMessageSink;
import org.eclipse.jetty.websocket.core.internal.util.InvokerUtils;
import org.eclipse.jetty.websocket.core.internal.util.ReflectUtils;
import org.eclipse.jetty.websocket.javax.common.decoders.RegisteredDecoder;
import org.eclipse.jetty.websocket.javax.common.messages.AbstractDecodedMessageSink;
import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryMessageSink;
import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryStreamMessageSink;
import org.eclipse.jetty.websocket.javax.common.messages.DecodedTextMessageSink;
import org.eclipse.jetty.websocket.javax.common.messages.DecodedTextStreamMessageSink;
import org.eclipse.jetty.websocket.util.InvalidSignatureException;
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;
import org.eclipse.jetty.websocket.util.InvokerUtils;
import org.eclipse.jetty.websocket.util.ReflectUtils;
import org.eclipse.jetty.websocket.util.messages.MessageSink;
import org.eclipse.jetty.websocket.util.messages.PartialByteArrayMessageSink;
import org.eclipse.jetty.websocket.util.messages.PartialByteBufferMessageSink;
import org.eclipse.jetty.websocket.util.messages.PartialStringMessageSink;
import static java.nio.charset.StandardCharsets.UTF_8;

View File

@ -23,9 +23,9 @@ import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec;
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders;
import org.eclipse.jetty.websocket.javax.common.encoders.AvailableEncoders;
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;
public class JavaxWebSocketFrameHandlerMetadata
{

View File

@ -21,8 +21,8 @@ package org.eclipse.jetty.websocket.javax.common;
import java.lang.invoke.MethodHandle;
import java.util.List;
import org.eclipse.jetty.websocket.core.internal.messages.MessageSink;
import org.eclipse.jetty.websocket.javax.common.decoders.RegisteredDecoder;
import org.eclipse.jetty.websocket.util.messages.MessageSink;
public class JavaxWebSocketMessageMetadata
{

View File

@ -34,8 +34,8 @@ import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.OutgoingFrames;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.util.messages.MessageOutputStream;
import org.eclipse.jetty.websocket.util.messages.MessageWriter;
import org.eclipse.jetty.websocket.core.internal.messages.MessageOutputStream;
import org.eclipse.jetty.websocket.core.internal.messages.MessageWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -43,9 +43,9 @@ import javax.websocket.WebSocketContainer;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.internal.util.ReflectUtils;
import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders;
import org.eclipse.jetty.websocket.javax.common.encoders.AvailableEncoders;
import org.eclipse.jetty.websocket.util.ReflectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -30,9 +30,9 @@ import java.util.stream.Stream;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;
import org.eclipse.jetty.websocket.util.InvalidSignatureException;
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;
import org.eclipse.jetty.websocket.util.ReflectUtils;
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
import org.eclipse.jetty.websocket.core.internal.util.ReflectUtils;
public class AvailableDecoders implements Iterable<RegisteredDecoder>
{

View File

@ -29,10 +29,10 @@ import java.util.stream.Collectors;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
import org.eclipse.jetty.websocket.core.internal.util.ReflectUtils;
import org.eclipse.jetty.websocket.javax.common.InitException;
import org.eclipse.jetty.websocket.util.InvalidSignatureException;
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;
import org.eclipse.jetty.websocket.util.ReflectUtils;
public class AvailableEncoders implements Predicate<Class<?>>
{

View File

@ -28,8 +28,8 @@ import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.exception.CloseException;
import org.eclipse.jetty.websocket.core.internal.messages.MessageSink;
import org.eclipse.jetty.websocket.javax.common.decoders.RegisteredDecoder;
import org.eclipse.jetty.websocket.util.messages.MessageSink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -28,10 +28,10 @@ import javax.websocket.Decoder;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.exception.CloseException;
import org.eclipse.jetty.websocket.core.internal.messages.ByteBufferMessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.MessageSink;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory;
import org.eclipse.jetty.websocket.javax.common.decoders.RegisteredDecoder;
import org.eclipse.jetty.websocket.util.messages.ByteBufferMessageSink;
import org.eclipse.jetty.websocket.util.messages.MessageSink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -29,10 +29,10 @@ import javax.websocket.Decoder;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.exception.CloseException;
import org.eclipse.jetty.websocket.core.internal.messages.InputStreamMessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.MessageSink;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory;
import org.eclipse.jetty.websocket.javax.common.decoders.RegisteredDecoder;
import org.eclipse.jetty.websocket.util.messages.InputStreamMessageSink;
import org.eclipse.jetty.websocket.util.messages.MessageSink;
public class DecodedBinaryStreamMessageSink<T> extends AbstractDecodedMessageSink.Stream<Decoder.BinaryStream<T>>
{

View File

@ -27,10 +27,10 @@ import javax.websocket.Decoder;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.exception.CloseException;
import org.eclipse.jetty.websocket.core.internal.messages.MessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.StringMessageSink;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory;
import org.eclipse.jetty.websocket.javax.common.decoders.RegisteredDecoder;
import org.eclipse.jetty.websocket.util.messages.MessageSink;
import org.eclipse.jetty.websocket.util.messages.StringMessageSink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -29,10 +29,10 @@ import javax.websocket.Decoder;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.exception.CloseException;
import org.eclipse.jetty.websocket.core.internal.messages.MessageSink;
import org.eclipse.jetty.websocket.core.internal.messages.ReaderMessageSink;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory;
import org.eclipse.jetty.websocket.javax.common.decoders.RegisteredDecoder;
import org.eclipse.jetty.websocket.util.messages.MessageSink;
import org.eclipse.jetty.websocket.util.messages.ReaderMessageSink;
public class DecodedTextStreamMessageSink<T> extends AbstractDecodedMessageSink.Stream<Decoder.TextStream<T>>
{

View File

@ -22,7 +22,7 @@ import javax.websocket.ClientEndpoint;
import javax.websocket.ClientEndpointConfig;
import javax.websocket.EndpointConfig;
import org.eclipse.jetty.websocket.util.InvokerUtils;
import org.eclipse.jetty.websocket.core.internal.util.InvokerUtils;
public class DummyFrameHandlerFactory extends JavaxWebSocketFrameHandlerFactory
{

View File

@ -25,7 +25,7 @@ import javax.websocket.OnError;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import org.eclipse.jetty.websocket.util.InvalidSignatureException;
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;

Some files were not shown because too many files have changed in this diff Show More