Issue #4722 - create new module websocket-util-server

- This module contains the WebSocketUpgradeFilter.
- Also has an internal package with the components used
  to implement websocket upgrades common to both the
  jetty and javax websocket implementations.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-04-22 17:26:46 +10:00
parent e189691917
commit b58697817f
43 changed files with 195 additions and 78 deletions

View File

@ -379,6 +379,16 @@
<artifactId>websocket-core</artifactId>
<version>10.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util</artifactId>
<version>10.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util-server</artifactId>
<version>10.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>

View File

@ -149,6 +149,7 @@ public class TestOSGiUtil
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-annotations").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-core").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-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

@ -16,6 +16,7 @@
<modules>
<module>websocket-core</module>
<module>websocket-util</module>
<module>websocket-util-server</module>
<!-- Jetty WebSocket Implementation -->
<module>websocket-jetty-api</module>
<module>websocket-jetty-common</module>

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.TextUtil;
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.slf4j.Logger;
@ -184,7 +184,7 @@ public class JavaxWebSocketAsyncRemote extends JavaxWebSocketRemoteEndpoint impl
assertMessageNotNull(text);
if (LOG.isDebugEnabled())
{
LOG.debug("sendText({})", TextUtil.hint(text));
LOG.debug("sendText({})", TextUtils.hint(text));
}
FutureCallback future = new FutureCallback();
sendFrame(new Frame(OpCode.TEXT).setPayload(text), future, batch);
@ -198,7 +198,7 @@ public class JavaxWebSocketAsyncRemote extends JavaxWebSocketRemoteEndpoint impl
assertSendHandlerNotNull(handler);
if (LOG.isDebugEnabled())
{
LOG.debug("sendText({},{})", TextUtil.hint(text), handler);
LOG.debug("sendText({},{})", TextUtils.hint(text), handler);
}
sendFrame(new Frame(OpCode.TEXT).setPayload(text), new SendHandlerCallback(handler), batch);
}

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.TextUtil;
import org.eclipse.jetty.websocket.util.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -118,7 +118,7 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl
assertMessageNotNull(text);
if (LOG.isDebugEnabled())
{
LOG.debug("sendText({})", TextUtil.hint(text));
LOG.debug("sendText({})", TextUtils.hint(text));
}
FutureCallback b = new FutureCallback();
@ -132,7 +132,7 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl
assertMessageNotNull(partialMessage);
if (LOG.isDebugEnabled())
{
LOG.debug("sendText({},{})", TextUtil.hint(partialMessage), isLast);
LOG.debug("sendText({},{})", TextUtils.hint(partialMessage), isLast);
}
Frame frame;

View File

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

View File

@ -13,6 +13,7 @@ annotations
[lib]
lib/websocket/websocket-core-${jetty.version}.jar
lib/websocket/websocket-util-${jetty.version}.jar
lib/websocket/websocket-util-server${jetty.version}.jar
lib/websocket/jetty-javax-websocket-api-1.1.2.jar
lib/websocket/websocket-javax-client-${jetty.version}.jar
lib/websocket/websocket-javax-common-${jetty.version}.jar

View File

@ -31,6 +31,7 @@ module org.eclipse.jetty.websocket.javax.server
requires transitive org.eclipse.jetty.webapp;
requires transitive org.eclipse.jetty.websocket.javax.client;
requires org.eclipse.jetty.websocket.javax.common;
requires org.eclipse.jetty.websocket.util.server;
requires org.slf4j;
provides ServletContainerInitializer with JavaxWebSocketServletContainerInitializer;

View File

@ -38,8 +38,8 @@ import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.thread.ThreadClassLoaderScope;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer;
import org.eclipse.jetty.websocket.util.server.WebSocketMapping;
import org.eclipse.jetty.websocket.util.server.WebSocketUpgradeFilter;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -22,7 +22,7 @@ import java.net.URI;
import java.security.Principal;
import org.eclipse.jetty.websocket.javax.common.UpgradeRequest;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest;
public class JavaxServerUpgradeRequest implements UpgradeRequest
{

View File

@ -37,9 +37,9 @@ import org.eclipse.jetty.websocket.javax.common.ConfiguredEndpoint;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketExtension;
import org.eclipse.jetty.websocket.javax.common.ServerEndpointConfigWrapper;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.WebSocketCreator;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketCreator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -39,7 +39,7 @@ import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.javax.client.internal.JavaxWebSocketClientContainer;
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
import org.eclipse.jetty.websocket.util.server.WebSocketMapping;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -27,9 +27,9 @@ import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.javax.client.internal.JavaxWebSocketClientFrameHandlerFactory;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerMetadata;
import org.eclipse.jetty.websocket.util.server.FrameHandlerFactory;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.FrameHandlerFactory;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeResponse;
public class JavaxWebSocketServerFrameHandlerFactory extends JavaxWebSocketClientFrameHandlerFactory implements FrameHandlerFactory
{

View File

@ -25,7 +25,7 @@ import java.util.Map;
import javax.websocket.server.HandshakeRequest;
import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest;
public class JsrHandshakeRequest implements HandshakeRequest
{

View File

@ -23,7 +23,7 @@ import java.util.List;
import java.util.Map;
import javax.websocket.HandshakeResponse;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeResponse;
public class JsrHandshakeResponse implements HandshakeResponse
{

View File

@ -47,7 +47,7 @@ import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.javax.tests.CoreServer;
import org.eclipse.jetty.websocket.javax.tests.DataUtils;
import org.eclipse.jetty.websocket.util.TextUtil;
import org.eclipse.jetty.websocket.util.TextUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@ -328,7 +328,7 @@ public class MessageReceivingTest
{
if (LOG.isDebugEnabled())
{
LOG.debug("{}.onWholeText({})", EchoWholeMessageFrameHandler.class.getSimpleName(), TextUtil.hint(wholeMessage));
LOG.debug("{}.onWholeText({})", EchoWholeMessageFrameHandler.class.getSimpleName(), TextUtils.hint(wholeMessage));
}
sendText(wholeMessage, callback, false);

View File

@ -38,7 +38,7 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.CloseStatus;
import org.eclipse.jetty.websocket.util.TextUtil;
import org.eclipse.jetty.websocket.util.TextUtils;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
@ -62,7 +62,7 @@ public class EndPoints
@Override
public void onWebSocketClose(int statusCode, String reason)
{
events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason));
events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtils.quote(reason));
}
@Override
@ -74,13 +74,13 @@ public class EndPoints
@Override
public void onWebSocketError(Throwable cause)
{
events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage()));
events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtils.quote(cause.getMessage()));
}
@Override
public void onWebSocketText(String message)
{
events.add("onWebSocketText(%s)", TextUtil.quote(message));
events.add("onWebSocketText(%s)", TextUtils.quote(message));
}
}
@ -91,7 +91,7 @@ public class EndPoints
@Override
public void onWebSocketClose(int statusCode, String reason)
{
events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason));
events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtils.quote(reason));
}
@Override
@ -103,7 +103,7 @@ public class EndPoints
@Override
public void onWebSocketError(Throwable cause)
{
events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage()));
events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtils.quote(cause.getMessage()));
}
@Override
@ -120,7 +120,7 @@ public class EndPoints
@Override
public void onWebSocketClose(int statusCode, String reason)
{
events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason));
events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtils.quote(reason));
}
@Override
@ -132,13 +132,13 @@ public class EndPoints
@Override
public void onWebSocketError(Throwable cause)
{
events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage()));
events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtils.quote(cause.getMessage()));
}
@Override
public void onWebSocketPartialText(String payload, boolean fin)
{
events.add("onWebSocketPartialText(%s, %b)", TextUtil.quote(payload), fin);
events.add("onWebSocketPartialText(%s, %b)", TextUtils.quote(payload), fin);
}
@Override
@ -155,7 +155,7 @@ public class EndPoints
@Override
public void onWebSocketClose(int statusCode, String reason)
{
events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason));
events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtils.quote(reason));
}
@Override
@ -167,7 +167,7 @@ public class EndPoints
@Override
public void onWebSocketError(Throwable cause)
{
events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage()));
events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtils.quote(cause.getMessage()));
}
@Override
@ -228,7 +228,7 @@ public class EndPoints
@OnWebSocketClose
public void onClose(int statusCode, String reason)
{
events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason));
events.add("onClose(%d, %s)", statusCode, TextUtils.quote(reason));
}
@OnWebSocketConnect
@ -253,7 +253,7 @@ public class EndPoints
@OnWebSocketClose
public void onClose(int statusCode, String reason)
{
events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason));
events.add("onClose(%d, %s)", statusCode, TextUtils.quote(reason));
}
@OnWebSocketConnect
@ -271,7 +271,7 @@ public class EndPoints
@OnWebSocketClose
public void onClose(int statusCode, String reason)
{
events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason));
events.add("onClose(%d, %s)", statusCode, TextUtils.quote(reason));
}
@OnWebSocketConnect
@ -289,7 +289,7 @@ public class EndPoints
@OnWebSocketMessage
public void onText(String message)
{
events.add("onText(%s)", TextUtil.quote(message));
events.add("onText(%s)", TextUtils.quote(message));
}
}
@ -301,7 +301,7 @@ public class EndPoints
@OnWebSocketClose
public void onClose(int statusCode, String reason)
{
events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason));
events.add("onClose(%d, %s)", statusCode, TextUtils.quote(reason));
}
@OnWebSocketConnect

View File

@ -46,6 +46,11 @@
<artifactId>websocket-jetty-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-servlet-api</artifactId>

View File

@ -13,6 +13,7 @@ annotations
[lib]
lib/websocket/websocket-core-${jetty.version}.jar
lib/websocket/websocket-util-${jetty.version}.jar
lib/websocket/websocket-util-server${jetty.version}.jar
lib/websocket/websocket-jetty-api-${jetty.version}.jar
lib/websocket/websocket-jetty-common-${jetty.version}.jar
lib/websocket/websocket-jetty-server-${jetty.version}.jar

View File

@ -29,9 +29,10 @@ module org.eclipse.jetty.websocket.jetty.server
requires jetty.servlet.api;
requires org.eclipse.jetty.websocket.jetty.common;
requires org.eclipse.jetty.websocket.util.server;
requires org.slf4j;
requires transitive org.eclipse.jetty.webapp;
requires transitive org.eclipse.jetty.websocket.jetty.api;
requires org.slf4j;
// Only required if using JMX.
requires static org.eclipse.jetty.jmx;

View File

@ -36,7 +36,7 @@ import javax.servlet.http.HttpSession;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.common.JettyExtensionConfig;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest;
public class JettyServerUpgradeRequest
{

View File

@ -26,7 +26,7 @@ import java.util.stream.Collectors;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.common.JettyExtensionConfig;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeResponse;
public class JettyServerUpgradeResponse
{

View File

@ -41,8 +41,8 @@ import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.eclipse.jetty.websocket.server.internal.JettyServerFrameHandlerFactory;
import org.eclipse.jetty.websocket.util.server.FrameHandlerFactory;
import org.eclipse.jetty.websocket.util.server.WebSocketMapping;
import org.eclipse.jetty.websocket.util.server.internal.FrameHandlerFactory;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -32,12 +32,12 @@ import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.websocket.core.Configuration;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.server.internal.JettyServerFrameHandlerFactory;
import org.eclipse.jetty.websocket.util.server.FrameHandlerFactory;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.WebSocketCreator;
import org.eclipse.jetty.websocket.util.server.WebSocketMapping;
import org.eclipse.jetty.websocket.util.server.WebSocketUpgradeFilter;
import org.eclipse.jetty.websocket.util.server.internal.FrameHandlerFactory;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketCreator;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -27,8 +27,8 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.listener.ContainerInitializer;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer;
import org.eclipse.jetty.websocket.util.server.WebSocketMapping;
import org.eclipse.jetty.websocket.util.server.WebSocketUpgradeFilter;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -27,9 +27,9 @@ import org.eclipse.jetty.websocket.api.WebSocketContainer;
import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler;
import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.util.server.FrameHandlerFactory;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.FrameHandlerFactory;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeResponse;
public class JettyServerFrameHandlerFactory
extends JettyWebSocketFrameHandlerFactory

View File

@ -28,7 +28,7 @@ import java.util.stream.Collectors;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.common.JettyExtensionConfig;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest;
public class UpgradeRequestAdapter implements UpgradeRequest
{

View File

@ -27,7 +27,7 @@ import java.util.stream.Collectors;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.common.JettyExtensionConfig;
import org.eclipse.jetty.websocket.util.server.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeResponse;
public class UpgradeResponseAdapter implements UpgradeResponse
{

View File

@ -47,7 +47,7 @@ import org.eclipse.jetty.websocket.server.JettyWebSocketServlet;
import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint;
import org.eclipse.jetty.websocket.util.TextUtil;
import org.eclipse.jetty.websocket.util.TextUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -297,7 +297,7 @@ public class PartialListenerTest
@Override
public void onWebSocketPartialText(String payload, boolean fin)
{
partialEvents.offer(String.format("TEXT[payload=%s, fin=%b]", TextUtil.maxStringLength(30, payload), fin));
partialEvents.offer(String.format("TEXT[payload=%s, fin=%b]", TextUtils.maxStringLength(30, payload), fin));
}
}
}

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-parent</artifactId>
<version>10.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>websocket-util-server</artifactId>
<name>Jetty :: Websocket :: org.eclipse.jetty.websocket :: Util-Server</name>
<properties>
<bundle-symbolic-name>${project.groupId}.util.server</bundle-symbolic-name>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>ban-java-servlet-api</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<includes>
<include>javax.servlet</include>
<include>servletapi</include>
<include>org.eclipse.jetty.orbit:javax.servlet</include>
<include>org.mortbay.jetty:servlet-api</include>
<include>jetty:servlet-api</include>
<include>jetty-servlet-api</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,27 @@
//
// ========================================================================
// 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
// ========================================================================
//
module org.eclipse.jetty.websocket.util.server
{
exports org.eclipse.jetty.websocket.util.server;
exports org.eclipse.jetty.websocket.util.server.internal to org.eclipse.jetty.websocket.jetty.server, org.eclipse.jetty.websocket.javax.server;
requires org.slf4j;
requires transitive org.eclipse.jetty.servlet;
requires transitive org.eclipse.jetty.websocket.core;
}

View File

@ -35,11 +35,11 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.websocket.core.Configuration;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -123,7 +123,7 @@ public class WebSocketUpgradeFilter implements Filter, Dumpable
return holder;
}
public static final String MAPPING_ATTRIBUTE_INIT_PARAM = "org.eclipse.jetty.websocket.util.server.WebSocketMapping.key";
public static final String MAPPING_ATTRIBUTE_INIT_PARAM = "org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping.key";
private final Configuration.ConfigurationCustomizer defaultCustomizer = new Configuration.ConfigurationCustomizer();
private WebSocketMapping mapping;
@ -159,12 +159,6 @@ public class WebSocketUpgradeFilter implements Filter, Dumpable
Dumpable.dumpObjects(out, indent, this, mapping);
}
@ManagedAttribute(value = "factory", readonly = true)
public WebSocketMapping getMapping()
{
return mapping;
}
@Override
public void init(FilterConfig config) throws ServletException
{

View File

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

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.server;
package org.eclipse.jetty.websocket.util.server.internal;
import java.net.HttpCookie;
import java.net.InetSocketAddress;
@ -41,7 +41,6 @@ import org.eclipse.jetty.http.HttpHeader;
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.util.server.internal.UpgradeHttpServletRequest;
/**
* Holder of request data for a WebSocket upgrade request.

View File

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

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.server;
package org.eclipse.jetty.websocket.util.server.internal;
/**
* Abstract WebSocket creator interface.

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.util.server;
package org.eclipse.jetty.websocket.util.server.internal;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;
@ -45,8 +45,6 @@ import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
/**
* Mapping of pathSpec to a tupple of {@link WebSocketCreator}, {@link FrameHandlerFactory} and
* {@link Configuration.Customizer}.
@ -136,7 +134,7 @@ public class WebSocketMapping implements Dumpable, LifeCycle.Listener
throw new IllegalArgumentException("Unrecognized path spec syntax [" + rawSpec + "]");
}
public static final String DEFAULT_KEY = "org.eclipse.jetty.websocket.util.server.WebSocketMapping";
public static final String DEFAULT_KEY = "org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping";
private final PathMappings<Negotiator> mappings = new PathMappings<>();
private final WebSocketComponents components;
@ -281,7 +279,7 @@ public class WebSocketMapping implements Dumpable, LifeCycle.Listener
if (websocketPojo == null)
{
// no creation, sorry
upgradeResponse.sendError(SC_SERVICE_UNAVAILABLE, "WebSocket Endpoint Creation Refused");
upgradeResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "WebSocket Endpoint Creation Refused");
return null;
}

View File

@ -55,7 +55,6 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>

View File

@ -20,7 +20,6 @@ module org.eclipse.jetty.websocket.util
{
exports org.eclipse.jetty.websocket.util;
exports org.eclipse.jetty.websocket.util.messages;
exports org.eclipse.jetty.websocket.util.server;
requires org.slf4j;
requires org.eclipse.jetty.servlet;

View File

@ -21,7 +21,7 @@ package org.eclipse.jetty.websocket.util;
/**
* Collection of utility methods for Text content
*/
public final class TextUtil
public final class TextUtils
{
/**
* Create a hint of what the text is like.

View File

@ -67,7 +67,7 @@ public class PartialStringMessageSinkTest
List<String> message = Objects.requireNonNull(endpoint.messages.poll(5, TimeUnit.SECONDS));
assertThat(message.size(), is(1));
assertThat(message.get(0), is("\uD800\uDF48"));
assertThat(message.get(0), is("\uD800\uDF48")); // UTF-8 encoded payload.
}
@Test
@ -87,7 +87,7 @@ public class PartialStringMessageSinkTest
List<String> message = Objects.requireNonNull(endpoint.messages.poll(5, TimeUnit.SECONDS));
assertThat(message.size(), is(2));
assertThat(message.get(0), is(""));
assertThat(message.get(1), is("\uD800\uDF48"));
assertThat(message.get(1), is("\uD800\uDF48")); // UTF-8 encoded payload.
}
@Test

View File

@ -72,7 +72,7 @@ public class StringMessageSinkTest
messageSink.accept(new Frame(OpCode.TEXT, utf8Payload).setFin(true), callback);
callback.block(5, TimeUnit.SECONDS);
assertThat(endpoint.messages.poll(5, TimeUnit.SECONDS), is("\uD800\uDF48"));
assertThat(endpoint.messages.poll(5, TimeUnit.SECONDS), is("\uD800\uDF48")); // UTF-8 encoded payload.
}
@Test
@ -90,7 +90,7 @@ public class StringMessageSinkTest
messageSink.accept(new Frame(OpCode.TEXT, continuationUtf8Payload).setFin(true), callback);
callback.block(5, TimeUnit.SECONDS);
assertThat(endpoint.messages.poll(5, TimeUnit.SECONDS), is("\uD800\uDF48"));
assertThat(endpoint.messages.poll(5, TimeUnit.SECONDS), is('\uD800' + '\uDF48')); // UTF-8 encoded payload.
}
@Test