Merge pull request #5101 from eclipse/jetty-10.0.x-5044-WebSocketUpgradeRequestResponse

Issue #5044 - Refactor of Jetty WebSocket Upgrade Request/Response
This commit is contained in:
Lachlan 2020-08-06 09:11:12 +10:00 committed by GitHub
commit 1e7ce3ac1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 640 additions and 1090 deletions

View File

@ -61,11 +61,11 @@ import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class ClientUpgradeRequest extends HttpRequest implements Response.CompleteListener, HttpUpgrader.Factory
public abstract class CoreClientUpgradeRequest extends HttpRequest implements Response.CompleteListener, HttpUpgrader.Factory
{
public static ClientUpgradeRequest from(WebSocketCoreClient webSocketClient, URI requestURI, FrameHandler frameHandler)
public static CoreClientUpgradeRequest from(WebSocketCoreClient webSocketClient, URI requestURI, FrameHandler frameHandler)
{
return new ClientUpgradeRequest(webSocketClient, requestURI)
return new CoreClientUpgradeRequest(webSocketClient, requestURI)
{
@Override
public FrameHandler getFrameHandler()
@ -75,7 +75,7 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon
};
}
private static final Logger LOG = LoggerFactory.getLogger(ClientUpgradeRequest.class);
private static final Logger LOG = LoggerFactory.getLogger(CoreClientUpgradeRequest.class);
protected final CompletableFuture<CoreSession> futureCoreSession;
private final WebSocketCoreClient wsClient;
private FrameHandler frameHandler;
@ -83,7 +83,7 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon
private final List<UpgradeListener> upgradeListeners = new ArrayList<>();
private List<ExtensionConfig> requestedExtensions = new ArrayList<>();
public ClientUpgradeRequest(WebSocketCoreClient webSocketClient, URI requestURI)
public CoreClientUpgradeRequest(WebSocketCoreClient webSocketClient, URI requestURI)
{
super(webSocketClient.getHttpClient(), new HttpConversation(), requestURI);

View File

@ -43,9 +43,9 @@ public class HttpUpgraderOverHTTP implements HttpUpgrader
private static final PreEncodedHttpField WS_CONNECTION_FIELD = new PreEncodedHttpField(HttpHeader.CONNECTION, "Upgrade");
private static final PreEncodedHttpField PRAGMA_NO_CACHE_FIELD = new PreEncodedHttpField(HttpHeader.PRAGMA, "no-cache");
private static final PreEncodedHttpField CACHE_CONTROL_NO_CACHE_FIELD = new PreEncodedHttpField(HttpHeader.CACHE_CONTROL, "no-cache");
private final ClientUpgradeRequest clientUpgradeRequest;
private final CoreClientUpgradeRequest clientUpgradeRequest;
public HttpUpgraderOverHTTP(ClientUpgradeRequest clientUpgradeRequest)
public HttpUpgraderOverHTTP(CoreClientUpgradeRequest clientUpgradeRequest)
{
this.clientUpgradeRequest = clientUpgradeRequest;
}

View File

@ -31,9 +31,9 @@ import org.eclipse.jetty.websocket.core.WebSocketConstants;
public class HttpUpgraderOverHTTP2 implements HttpUpgrader
{
private static final PreEncodedHttpField WS_VERSION_FIELD = new PreEncodedHttpField(HttpHeader.SEC_WEBSOCKET_VERSION, WebSocketConstants.SPEC_VERSION_STRING);
private final ClientUpgradeRequest clientUpgradeRequest;
private final CoreClientUpgradeRequest clientUpgradeRequest;
public HttpUpgraderOverHTTP2(ClientUpgradeRequest clientUpgradeRequest)
public HttpUpgraderOverHTTP2(CoreClientUpgradeRequest clientUpgradeRequest)
{
this.clientUpgradeRequest = clientUpgradeRequest;
}

View File

@ -71,11 +71,11 @@ public class WebSocketCoreClient extends ContainerLifeCycle
public CompletableFuture<CoreSession> connect(FrameHandler frameHandler, URI wsUri) throws IOException
{
ClientUpgradeRequest request = ClientUpgradeRequest.from(this, wsUri, frameHandler);
CoreClientUpgradeRequest request = CoreClientUpgradeRequest.from(this, wsUri, frameHandler);
return connect(request);
}
public CompletableFuture<CoreSession> connect(ClientUpgradeRequest request) throws IOException
public CompletableFuture<CoreSession> connect(CoreClientUpgradeRequest request) throws IOException
{
if (!isStarted())
throw new IllegalStateException(WebSocketCoreClient.class.getSimpleName() + "@" + this.hashCode() + " is not started");

View File

@ -29,7 +29,7 @@ import java.util.zip.Deflater;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@ -165,7 +165,7 @@ public class AutoFragmentTest
public void testIncomingAutoFragmentWithPermessageDeflate() throws Exception
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, serverUri, clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, serverUri, clientHandler);
upgradeRequest.addExtensions("permessage-deflate");
CompletableFuture<CoreSession> connect = client.connect(upgradeRequest);
connect.get(5, TimeUnit.SECONDS);
@ -218,7 +218,7 @@ public class AutoFragmentTest
public void testGzipBomb() throws Exception
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, serverUri, clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, serverUri, clientHandler);
upgradeRequest.addExtensions("permessage-deflate");
CompletableFuture<CoreSession> connect = client.connect(upgradeRequest);
connect.get(5, TimeUnit.SECONDS);
@ -281,7 +281,7 @@ public class AutoFragmentTest
// Connect to server with permessage-deflate enabled.
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, serverUri, clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, serverUri, clientHandler);
upgradeRequest.addExtensions("permessage-deflate");
CompletableFuture<CoreSession> connect = client.connect(upgradeRequest);
connect.get(5, TimeUnit.SECONDS);

View File

@ -37,7 +37,7 @@ import org.eclipse.jetty.logging.StacklessLogging;
import org.eclipse.jetty.server.HttpChannel;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
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.exception.UpgradeException;
@ -146,7 +146,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, server.getUri(), clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, server.getUri(), clientHandler);
upgradeRequest.setSubProtocols("testExtensionSelection");
upgradeRequest.addExtensions("permessage-deflate;server_no_context_takeover", "permessage-deflate;client_no_context_takeover");
@ -177,7 +177,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, server.getUri(), clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, server.getUri(), clientHandler);
upgradeRequest.setSubProtocols("testNotOfferedParameter");
upgradeRequest.addExtensions("permessage-deflate;client_no_context_takeover");
@ -207,7 +207,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, server.getUri(), clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, server.getUri(), clientHandler);
upgradeRequest.setSubProtocols("testInvalidExtensionParameter");
upgradeRequest.addExtensions("permessage-deflate;invalid_parameter");
@ -223,7 +223,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, server.getUri(), clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, server.getUri(), clientHandler);
upgradeRequest.setSubProtocols("testNotAcceptingExtensions");
upgradeRequest.addExtensions("permessage-deflate;server_no_context_takeover", "permessage-deflate;client_no_context_takeover");
@ -271,7 +271,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, server.getUri(), clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, server.getUri(), clientHandler);
upgradeRequest.setSubProtocols("testAcceptTwoExtensionsOfSameName");
upgradeRequest.addExtensions("permessage-deflate;server_no_context_takeover", "permessage-deflate;client_no_context_takeover");
@ -302,7 +302,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, server.getUri(), clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, server.getUri(), clientHandler);
try (StacklessLogging stacklessLogging = new StacklessLogging(HttpChannel.class))
{
@ -317,7 +317,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
public void testNoSubProtocolSelected() throws Exception
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, server.getUri(), clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, server.getUri(), clientHandler);
upgradeRequest.setSubProtocols("testNoSubProtocolSelected");
CompletableFuture<HttpFields> headers = new CompletableFuture<>();
upgradeRequest.addListener(new UpgradeListener()
@ -378,7 +378,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, server.getUri(), clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, server.getUri(), clientHandler);
upgradeRequest.setSubProtocols("test");
CompletableFuture<String> extensionHeader = new CompletableFuture<>();
@ -409,7 +409,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
public void testListenerExtensionSelectionError() throws Exception
{
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, server.getUri(), clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, server.getUri(), clientHandler);
upgradeRequest.setSubProtocols("test");
upgradeRequest.addExtensions("permessage-deflate;server_no_context_takeover");
@ -467,7 +467,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
TestFrameHandler clientHandler = new TestFrameHandler();
CompletableFuture<String> extensionHeader = new CompletableFuture<>();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, server.getUri(), clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, server.getUri(), clientHandler);
upgradeRequest.setSubProtocols("test");
if (!StringUtil.isEmpty(reqExts))
upgradeRequest.addExtensions(reqExts.split(","));

View File

@ -29,7 +29,7 @@ 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.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -51,7 +51,7 @@ public class ChatWebSocketClient
URI wsUri = baseWebsocketUri.resolve("/chat");
handler = MessageHandler.from(this::onText, null);
ClientUpgradeRequest request = ClientUpgradeRequest.from(client, wsUri, handler);
CoreClientUpgradeRequest request = CoreClientUpgradeRequest.from(client, wsUri, handler);
request.setSubProtocols("chat");
client.connect(request).get(5, TimeUnit.SECONDS);
handler.sendText("[" + name + ": has joined the room]", Callback.NOOP, false);

View File

@ -34,7 +34,7 @@ import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.TestFrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketServer;
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
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;
@ -103,7 +103,7 @@ public class PerMessageDeflaterBufferSizeTest
{
int deflateBufferSize = 6;
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, serverUri, clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, serverUri, clientHandler);
upgradeRequest.addExtensions("permessage-deflate; @deflate_buffer_size=" + deflateBufferSize);
CompletableFuture<HttpFields> futureRequestHeaders = new CompletableFuture<>();
@ -157,7 +157,7 @@ public class PerMessageDeflaterBufferSizeTest
{
int inflateBufferSize = 6;
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, serverUri, clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, serverUri, clientHandler);
upgradeRequest.addExtensions("permessage-deflate; @inflate_buffer_size=" + inflateBufferSize);
CompletableFuture<HttpFields> futureRequestHeaders = new CompletableFuture<>();
@ -212,7 +212,7 @@ public class PerMessageDeflaterBufferSizeTest
{
testNegotiator.deflateBufferSize = 6;
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, serverUri, clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, serverUri, clientHandler);
upgradeRequest.addExtensions("permessage-deflate");
CompletableFuture<HttpFields> futureResponseHeaders = new CompletableFuture<>();
@ -267,7 +267,7 @@ public class PerMessageDeflaterBufferSizeTest
{
testNegotiator.inflateBufferSize = 6;
TestFrameHandler clientHandler = new TestFrameHandler();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, serverUri, clientHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, serverUri, clientHandler);
upgradeRequest.addExtensions("permessage-deflate");
CompletableFuture<HttpFields> futureResponseHeaders = new CompletableFuture<>();

View File

@ -45,7 +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.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
@ -161,7 +161,7 @@ public class WebSocketProxyTest
WebSocketProxy.Client2Proxy proxyClientSide = proxy.client2Proxy;
WebSocketProxy.Server2Proxy proxyServerSide = proxy.server2Proxy;
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
upgradeRequest.setConfiguration(defaultCustomizer);
CompletableFuture<CoreSession> response = _client.connect(upgradeRequest);
@ -201,7 +201,7 @@ public class WebSocketProxyTest
TestAsyncFrameHandler clientFrameHandler = new TestAsyncFrameHandler("CLIENT");
try (StacklessLogging stacklessLogging = new StacklessLogging(WebSocketCoreSession.class))
{
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
upgradeRequest.setConfiguration(defaultCustomizer);
CompletableFuture<CoreSession> response = _client.connect(upgradeRequest);
response.get(5, TimeUnit.SECONDS);
@ -240,7 +240,7 @@ public class WebSocketProxyTest
try (StacklessLogging stacklessLogging = new StacklessLogging(WebSocketCoreSession.class))
{
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
upgradeRequest.setConfiguration(defaultCustomizer);
CompletableFuture<CoreSession> response = _client.connect(upgradeRequest);
Exception e = assertThrows(ExecutionException.class, () -> response.get(5, TimeUnit.SECONDS));
@ -271,7 +271,7 @@ public class WebSocketProxyTest
WebSocketProxy.Server2Proxy proxyServerSide = proxy.server2Proxy;
TestAsyncFrameHandler clientFrameHandler = new TestAsyncFrameHandler("CLIENT");
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
upgradeRequest.setConfiguration(defaultCustomizer);
CompletableFuture<CoreSession> response = _client.connect(upgradeRequest);
@ -335,7 +335,7 @@ public class WebSocketProxyTest
}
};
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
upgradeRequest.setConfiguration(defaultCustomizer);
CompletableFuture<CoreSession> response = _client.connect(upgradeRequest);
response.get(5, TimeUnit.SECONDS);

View File

@ -24,12 +24,12 @@ import java.security.Principal;
import org.eclipse.jetty.client.HttpResponse;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandler;
import org.eclipse.jetty.websocket.javax.common.UpgradeRequest;
public class JavaxClientUpgradeRequest extends ClientUpgradeRequest implements UpgradeRequest
public class JavaxClientUpgradeRequest extends CoreClientUpgradeRequest implements UpgradeRequest
{
private final JavaxWebSocketFrameHandler frameHandler;

View File

@ -67,33 +67,6 @@ public class JavaxWebSocketFrameHandler implements FrameHandler
private final Object endpointInstance;
private final AtomicBoolean closeNotified = new AtomicBoolean();
/**
* List of configured named variables in the uri-template.
* <p>
* Used to bind uri-template variables, with their values from the upgrade, to the methods
* that have declared their interest in these values via {@code @PathParam} annotations.
* </p>
* <p>
* Can be null if client side, or no named variables were configured on the server side.
* </p>
*/
/**
* The Map of path parameter values that arrived during the server side upgrade process.
* <p>
* Used to bind uri-template variables, with their values from the upgrade, to the methods
* that have declared their interest in these values via {@code @PathParam} annotations.
* </p>
* <p>
* The values are represented as {@link String} and are essentially static for this
* instance of the the JavaxWebSocketFrameHandler. They will be converted to the
* type declared by the {@code @PathParam} annotations following the JSR356 advice
* to only support String, Java Primitives (or their Boxed version).
* </p>
* <p>
* Can be null if client side, or no named variables were configured on the server side,
* or the server side component didn't use the {@link org.eclipse.jetty.http.pathmap.UriTemplatePathSpec} for its mapping.
* </p>
*/
private MethodHandle openHandle;
private MethodHandle closeHandle;
private MethodHandle errorHandle;

View File

@ -22,13 +22,13 @@ import java.net.URI;
import java.security.Principal;
import org.eclipse.jetty.websocket.javax.common.UpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeRequest;
public class JavaxServerUpgradeRequest implements UpgradeRequest
{
private final ServletUpgradeRequest servletRequest;
private final ServerUpgradeRequest servletRequest;
public JavaxServerUpgradeRequest(ServletUpgradeRequest servletRequest)
public JavaxServerUpgradeRequest(ServerUpgradeRequest servletRequest)
{
this.servletRequest = servletRequest;
}

View File

@ -38,8 +38,8 @@ 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.internal.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketCreator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -62,7 +62,7 @@ public class JavaxWebSocketCreator implements WebSocketCreator
}
@Override
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
public Object createWebSocket(ServerUpgradeRequest req, ServerUpgradeResponse resp)
{
final JsrHandshakeRequest jsrHandshakeRequest = new JsrHandshakeRequest(req);
final JsrHandshakeResponse jsrHandshakeResponse = new JsrHandshakeResponse(resp);

View File

@ -27,8 +27,8 @@ import org.eclipse.jetty.websocket.javax.client.internal.JavaxWebSocketClientFra
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerMetadata;
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.ServerUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeResponse;
public class JavaxWebSocketServerFrameHandlerFactory extends JavaxWebSocketClientFrameHandlerFactory implements FrameHandlerFactory
{
@ -54,7 +54,7 @@ public class JavaxWebSocketServerFrameHandlerFactory extends JavaxWebSocketClien
}
@Override
public FrameHandler newFrameHandler(Object websocketPojo, ServletUpgradeRequest upgradeRequest, ServletUpgradeResponse upgradeResponse)
public FrameHandler newFrameHandler(Object websocketPojo, ServerUpgradeRequest upgradeRequest, ServerUpgradeResponse upgradeResponse)
{
return newJavaxWebSocketFrameHandler(websocketPojo, new JavaxServerUpgradeRequest(upgradeRequest));
}

View File

@ -25,13 +25,13 @@ import java.util.Map;
import javax.websocket.server.HandshakeRequest;
import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeRequest;
public class JsrHandshakeRequest implements HandshakeRequest
{
private final ServletUpgradeRequest delegate;
private final ServerUpgradeRequest delegate;
public JsrHandshakeRequest(ServletUpgradeRequest req)
public JsrHandshakeRequest(ServerUpgradeRequest req)
{
this.delegate = req;
}

View File

@ -23,14 +23,14 @@ import java.util.List;
import java.util.Map;
import javax.websocket.HandshakeResponse;
import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeResponse;
public class JsrHandshakeResponse implements HandshakeResponse
{
private final ServletUpgradeResponse delegate;
private final ServerUpgradeResponse delegate;
private Map<String, List<String>> headerMap;
public JsrHandshakeResponse(ServletUpgradeResponse resp)
public JsrHandshakeResponse(ServerUpgradeResponse resp)
{
this.delegate = resp;
this.headerMap = new HashMap<>();

View File

@ -39,7 +39,7 @@ import org.eclipse.jetty.websocket.core.CloseStatus;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.internal.Generator;
@ -179,7 +179,7 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
}
}
public static class RawUpgradeRequest extends ClientUpgradeRequest
public static class RawUpgradeRequest extends CoreClientUpgradeRequest
{
private final FrameCapture frameCapture = new FrameCapture();
private final CompletableFuture<FrameCapture> futureCapture;

View File

@ -54,7 +54,7 @@ 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.OpCode;
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketCreator;
import org.eclipse.jetty.websocket.javax.tests.LocalServer;
@ -430,7 +430,7 @@ public class ConfiguratorTest
URI wsUri = server.getWsUri().resolve("/capture-request-headers");
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
upgradeRequest.addExtensions("identity");
Future<CoreSession> clientConnectFuture = client.connect(upgradeRequest);
@ -454,7 +454,7 @@ public class ConfiguratorTest
URI wsUri = server.getWsUri().resolve("/no-extensions");
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
upgradeRequest.addExtensions("identity");
Future<CoreSession> clientConnectFuture = client.connect(upgradeRequest);
@ -478,7 +478,7 @@ public class ConfiguratorTest
URI wsUri = server.getWsUri().resolve("/capture-request-headers");
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
upgradeRequest.headers(headers -> headers.put("X-Dummy", "Bogus"));
Future<CoreSession> clientConnectFuture = client.connect(upgradeRequest);
@ -503,7 +503,7 @@ public class ConfiguratorTest
// First Request
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
Future<CoreSession> clientConnectFuture = client.connect(upgradeRequest);
CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS);
@ -522,7 +522,7 @@ public class ConfiguratorTest
// Second request
clientSocket = new FrameHandlerTracker();
upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
clientConnectFuture = client.connect(upgradeRequest);
coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS);
@ -550,7 +550,7 @@ public class ConfiguratorTest
URI wsUri = server.getWsUri().resolve("/addr");
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
Future<CoreSession> clientConnectFuture = client.connect(upgradeRequest);
CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS);
@ -591,7 +591,7 @@ public class ConfiguratorTest
ProtocolsConfigurator.seenProtocols.set(null);
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
upgradeRequest.setSubProtocols("status");
Future<CoreSession> clientConnectFuture = client.connect(upgradeRequest);
@ -610,7 +610,7 @@ public class ConfiguratorTest
ProtocolsConfigurator.seenProtocols.set(null);
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
upgradeRequest.setSubProtocols("echo", "chat", "status");
Future<CoreSession> clientConnectFuture = client.connect(upgradeRequest);
@ -629,7 +629,7 @@ public class ConfiguratorTest
ProtocolsConfigurator.seenProtocols.set(null);
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
upgradeRequest.setSubProtocols("echo", "chat", "status");
Future<CoreSession> clientConnectFuture = client.connect(upgradeRequest);
@ -648,7 +648,7 @@ public class ConfiguratorTest
ProtocolsConfigurator.seenProtocols.set(null);
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
upgradeRequest.setSubProtocols("echo", "chat", "status");
Future<CoreSession> clientConnectFuture = client.connect(upgradeRequest);
@ -681,7 +681,7 @@ public class ConfiguratorTest
URI wsUri = server.getWsUri().resolve("/timedecoder");
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket);
upgradeRequest.setSubProtocols("gmt");
Future<CoreSession> clientConnectFuture = client.connect(upgradeRequest);

View File

@ -31,26 +31,6 @@ import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
*/
public interface UpgradeRequest
{
/**
* Add WebSocket Extension Configuration(s) to Upgrade Request.
* <p>
* This is merely the list of requested Extensions to use, see {@link UpgradeResponse#getExtensions()} for what was
* negotiated
*
* @param configs the configuration(s) to add
*/
void addExtensions(ExtensionConfig... configs);
/**
* Add WebSocket Extension Configuration(s) to request
* <p>
* This is merely the list of requested Extensions to use, see {@link UpgradeResponse#getExtensions()} for what was
* negotiated
*
* @param configs the configuration(s) to add
*/
void addExtensions(String... configs);
/**
* Get the list of Cookies on the Upgrade request
*
@ -168,15 +148,6 @@ public interface UpgradeRequest
*/
URI getRequestURI();
/**
* Access the Servlet HTTP Session (if present)
* <p>
* Note: Never present on a Client UpgradeRequest.
*
* @return the Servlet HTTPSession on server side UpgradeRequests
*/
Object getSession();
/**
* Get the list of offered WebSocket sub-protocols.
*
@ -207,74 +178,4 @@ public interface UpgradeRequest
* @return true if connection is secure.
*/
boolean isSecure();
/**
* Set the list of Cookies on the request
*
* @param cookies the cookies to use
*/
void setCookies(List<HttpCookie> cookies);
/**
* Set the list of WebSocket Extension configurations on the request.
*
* @param configs the list of extension configurations
*/
void setExtensions(List<ExtensionConfig> configs);
/**
* Set a specific header with multi-value field
* <p>
* Overrides any previous value for this named header
*
* @param name the name of the header
* @param values the multi-value field
*/
void setHeader(String name, List<String> values);
/**
* Set a specific header value
* <p>
* Overrides any previous value for this named header
*
* @param name the header to set
* @param value the value to set it to
*/
void setHeader(String name, String value);
/**
* Sets multiple headers on the request.
* <p>
* Only sets those headers provided, does not remove
* headers that exist on request and are not provided in the
* parameter for this method.
* <p>
* Convenience method vs calling {@link #setHeader(String, List)} multiple times.
*
* @param headers the headers to set
*/
void setHeaders(Map<String, List<String>> headers);
/**
* Set the Session associated with this request.
* <p>
* Typically used to associate the Servlet HttpSession object.
*
* @param session the session object to associate with this request
*/
void setSession(Object session);
/**
* Set the offered WebSocket Sub-Protocol list.
*
* @param protocols the offered sub-protocol list
*/
void setSubProtocols(List<String> protocols);
/**
* Set the offered WebSocket Sub-Protocol list.
*
* @param protocols the offered sub-protocol list
*/
void setSubProtocols(String... protocols);
}

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.websocket.api;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -30,14 +29,6 @@ import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
*/
public interface UpgradeResponse
{
/**
* Add a header value to the response.
*
* @param name the header name
* @param value the header value
*/
void addHeader(String name, String value);
/**
* Get the accepted WebSocket protocol.
*
@ -88,57 +79,4 @@ public interface UpgradeResponse
* @return the status code
*/
int getStatusCode();
/**
* Issue a forbidden upgrade response.
* <p>
* This means that the websocket endpoint was valid, but the conditions to use a WebSocket resulted in a forbidden
* access.
* <p>
* Use this when the origin or authentication is invalid.
*
* @param message the short 1 line detail message about the forbidden response
* @throws IOException if unable to send the forbidden
*/
void sendForbidden(String message) throws IOException;
/**
* Set the accepted WebSocket Protocol.
*
* @param protocol the protocol to list as accepted
*/
void setAcceptedSubProtocol(String protocol);
/**
* Set the list of extensions that are approved for use with this websocket.
* <p>
* Notes:
* <ul>
* <li>Per the spec you cannot add extensions that have not been seen in the {@link UpgradeRequest}, just remove
* entries you don't want to use</li>
* <li>If this is unused, or a null is passed, then the list negotiation will follow default behavior and use the
* complete list of extensions that are
* available in this WebSocket server implementation.</li>
* </ul>
*
* @param extensions the list of extensions to use.
*/
void setExtensions(List<ExtensionConfig> extensions);
/**
* Set a header
* <p>
* Overrides previous value of header (if set)
*
* @param name the header name
* @param value the header value
*/
void setHeader(String name, String value);
/**
* Set the HTTP Response status code
*
* @param statusCode the status code
*/
void setStatusCode(int statusCode);
}

View File

@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
/**
@ -63,53 +64,18 @@ public final class ClientUpgradeRequest implements UpgradeRequest
this.host = this.requestURI.getHost();
}
@Override
public void addExtensions(ExtensionConfig... configs)
{
Collections.addAll(extensions, configs);
}
@Override
public void addExtensions(String... configs)
{
for (String config : configs)
{
extensions.add(ExtensionConfig.parse(config));
}
}
@Override
public List<HttpCookie> getCookies()
{
return cookies;
}
@Override
public void setCookies(List<HttpCookie> cookies)
{
this.cookies.clear();
if (cookies != null && !cookies.isEmpty())
{
this.cookies.addAll(cookies);
}
}
@Override
public List<ExtensionConfig> getExtensions()
{
return extensions;
}
@Override
public void setExtensions(List<ExtensionConfig> configs)
{
this.extensions.clear();
if (configs != null)
{
this.extensions.addAll(configs);
}
}
@Override
public String getHeader(String name)
{
@ -201,12 +167,6 @@ public final class ClientUpgradeRequest implements UpgradeRequest
return requestURI;
}
@Override
public Object getSession()
{
throw new UnsupportedOperationException("HttpSession not available on Client request");
}
@Override
public List<String> getSubProtocols()
{
@ -219,28 +179,6 @@ public final class ClientUpgradeRequest implements UpgradeRequest
throw new UnsupportedOperationException("User Principal not available on Client request");
}
/**
* Set Sub Protocol request list.
*
* @param protocols the sub protocols desired
*/
@Override
public void setSubProtocols(String... protocols)
{
subProtocols.clear();
Collections.addAll(subProtocols, protocols);
}
@Override
public void setSubProtocols(List<String> subProtocols)
{
this.subProtocols.clear();
if (subProtocols != null)
{
this.subProtocols.addAll(subProtocols);
}
}
@Override
public boolean hasSubProtocol(String test)
{
@ -260,13 +198,84 @@ public final class ClientUpgradeRequest implements UpgradeRequest
throw new UnsupportedOperationException("Request.isSecure not available on Client request");
}
@Override
/**
* Add WebSocket Extension Configuration(s) to Upgrade Request.
* <p>
* This is merely the list of requested Extensions to use, see {@link UpgradeResponse#getExtensions()} for what was
* negotiated
*
* @param configs the configuration(s) to add
*/
public void addExtensions(ExtensionConfig... configs)
{
Collections.addAll(extensions, configs);
}
/**
* Add WebSocket Extension Configuration(s) to request
* <p>
* This is merely the list of requested Extensions to use, see {@link UpgradeResponse#getExtensions()} for what was
* negotiated
*
* @param configs the configuration(s) to add
*/
public void addExtensions(String... configs)
{
for (String config : configs)
{
extensions.add(ExtensionConfig.parse(config));
}
}
/**
* Set the list of Cookies on the request
*
* @param cookies the cookies to use
*/
public void setCookies(List<HttpCookie> cookies)
{
this.cookies.clear();
if (cookies != null && !cookies.isEmpty())
{
this.cookies.addAll(cookies);
}
}
/**
* Set the list of WebSocket Extension configurations on the request.
*
* @param configs the list of extension configurations
*/
public void setExtensions(List<ExtensionConfig> configs)
{
this.extensions.clear();
if (configs != null)
{
this.extensions.addAll(configs);
}
}
/**
* Set a specific header with multi-value field
* <p>
* Overrides any previous value for this named header
*
* @param name the name of the header
* @param values the multi-value field
*/
public void setHeader(String name, List<String> values)
{
headers.put(name, values);
}
@Override
/**
* Set a specific header value
* <p>
* Overrides any previous value for this named header
*
* @param name the header to set
* @param value the value to set it to
*/
public void setHeader(String name, String value)
{
List<String> values = new ArrayList<>();
@ -274,7 +283,17 @@ public final class ClientUpgradeRequest implements UpgradeRequest
setHeader(name, values);
}
@Override
/**
* Sets multiple headers on the request.
* <p>
* Only sets those headers provided, does not remove
* headers that exist on request and are not provided in the
* parameter for this method.
* <p>
* Convenience method vs calling {@link #setHeader(String, List)} multiple times.
*
* @param headers the headers to set
*/
public void setHeaders(Map<String, List<String>> headers)
{
this.headers.clear();
@ -286,10 +305,29 @@ public final class ClientUpgradeRequest implements UpgradeRequest
}
}
@Override
public void setSession(Object session)
/**
* Set the offered WebSocket Sub-Protocol list.
*
* @param protocols the offered sub-protocol list
*/
public void setSubProtocols(List<String> protocols)
{
throw new UnsupportedOperationException("HttpSession not available on Client request");
this.subProtocols.clear();
if (protocols != null)
{
this.subProtocols.addAll(protocols);
}
}
/**
* Set the offered WebSocket Sub-Protocol list.
*
* @param protocols the offered sub-protocol list
*/
public void setSubProtocols(String... protocols)
{
subProtocols.clear();
Collections.addAll(subProtocols, protocols);
}
/**

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.websocket.client.impl;
import java.net.HttpCookie;
import java.net.SocketAddress;
import java.net.URI;
import java.security.Principal;
import java.util.Collections;
@ -27,6 +26,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.io.EndPoint;
@ -34,7 +34,7 @@ import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.UrlEncoded;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import static java.nio.charset.StandardCharsets.UTF_8;
@ -44,11 +44,9 @@ import static java.nio.charset.StandardCharsets.UTF_8;
*/
public class DelegatedJettyClientUpgradeRequest implements UpgradeRequest
{
private final ClientUpgradeRequest delegate;
private SocketAddress localSocketAddress;
private SocketAddress remoteSocketAddress;
private final CoreClientUpgradeRequest delegate;
public DelegatedJettyClientUpgradeRequest(ClientUpgradeRequest delegate)
public DelegatedJettyClientUpgradeRequest(CoreClientUpgradeRequest delegate)
{
this.delegate = delegate;
}
@ -100,8 +98,6 @@ public class DelegatedJettyClientUpgradeRequest implements UpgradeRequest
public void configure(EndPoint endpoint)
{
this.localSocketAddress = endpoint.getLocalAddress();
this.remoteSocketAddress = endpoint.getRemoteAddress();
}
@Override
@ -163,26 +159,7 @@ public class DelegatedJettyClientUpgradeRequest implements UpgradeRequest
@Override
public boolean isSecure()
{
// TODO: figure out how to obtain from HttpClient's HttpRequest
return false;
}
@Override
public void addExtensions(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig... configs)
{
// TODO
}
@Override
public void addExtensions(String... configs)
{
// TODO
}
@Override
public Object getSession()
{
return null;
return HttpClient.isSchemeSecure(delegate.getScheme());
}
@Override
@ -191,12 +168,6 @@ public class DelegatedJettyClientUpgradeRequest implements UpgradeRequest
return null;
}
@Override
public void setCookies(List<HttpCookie> cookies)
{
// TODO
}
@Override
public List<ExtensionConfig> getExtensions()
{
@ -204,48 +175,6 @@ public class DelegatedJettyClientUpgradeRequest implements UpgradeRequest
if (rawExtensions == null || rawExtensions.isEmpty())
return Collections.emptyList();
return rawExtensions.stream().map((parameterizedName) -> ExtensionConfig.parse(parameterizedName)).collect(Collectors.toList());
}
@Override
public void setExtensions(List<org.eclipse.jetty.websocket.api.extensions.ExtensionConfig> configs)
{
// TODO
}
@Override
public void setHeader(String name, List<String> values)
{
// TODO
}
@Override
public void setHeader(String name, String value)
{
// TODO
}
@Override
public void setHeaders(Map<String, List<String>> headers)
{
// TODO
}
@Override
public void setSession(Object session)
{
// TODO
}
@Override
public void setSubProtocols(List<String> protocols)
{
// TODO
}
@Override
public void setSubProtocols(String... protocols)
{
// TODO
return rawExtensions.stream().map(ExtensionConfig::parse).collect(Collectors.toList());
}
}

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.websocket.client.impl;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -36,7 +35,7 @@ import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
*/
public class DelegatedJettyClientUpgradeResponse implements UpgradeResponse
{
private HttpResponse delegate;
private final HttpResponse delegate;
public DelegatedJettyClientUpgradeResponse(HttpResponse response)
{
@ -79,24 +78,6 @@ public class DelegatedJettyClientUpgradeResponse implements UpgradeResponse
return this.delegate.getStatus();
}
@Override
public void addHeader(String name, String value)
{
}
@Override
public void sendForbidden(String message) throws IOException
{
}
@Override
public void setAcceptedSubProtocol(String protocol)
{
}
@Override
public List<ExtensionConfig> getExtensions()
{
@ -104,24 +85,6 @@ public class DelegatedJettyClientUpgradeResponse implements UpgradeResponse
if (rawExtensions == null || rawExtensions.isEmpty())
return Collections.emptyList();
return rawExtensions.stream().map((parameterizedName) -> ExtensionConfig.parse(parameterizedName)).collect(Collectors.toList());
}
@Override
public void setExtensions(List<org.eclipse.jetty.websocket.api.extensions.ExtensionConfig> extensions)
{
}
@Override
public void setHeader(String name, String value)
{
}
@Override
public void setStatusCode(int statusCode)
{
return rawExtensions.stream().map(ExtensionConfig::parse).collect(Collectors.toList());
}
}

View File

@ -30,11 +30,11 @@ import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler;
import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
public class JettyClientUpgradeRequest extends org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest
public class JettyClientUpgradeRequest extends CoreClientUpgradeRequest
{
private final DelegatedJettyClientUpgradeRequest handshakeRequest;
private final JettyWebSocketFrameHandler frameHandler;
public JettyClientUpgradeRequest(WebSocketCoreClient coreClient, ClientUpgradeRequest request, URI requestURI, JettyWebSocketFrameHandlerFactory frameHandlerFactory,
@ -58,17 +58,9 @@ public class JettyClientUpgradeRequest extends org.eclipse.jetty.websocket.core.
timeout(request.getTimeout(), TimeUnit.MILLISECONDS);
}
handshakeRequest = new DelegatedJettyClientUpgradeRequest(this);
frameHandler = frameHandlerFactory.newJettyFrameHandler(websocketPojo);
}
@Override
protected void customize(EndPoint endPoint)
{
super.customize(endPoint);
handshakeRequest.configure(endPoint);
}
@Override
public void upgrade(HttpResponse response, EndPoint endPoint)
{

View File

@ -18,310 +18,99 @@
package org.eclipse.jetty.websocket.server;
import java.net.HttpCookie;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
import java.security.Principal;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
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.internal.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
public class JettyServerUpgradeRequest
public interface JettyServerUpgradeRequest extends UpgradeRequest
{
private ServletUpgradeRequest upgradeRequest;
JettyServerUpgradeRequest(ServletUpgradeRequest request)
{
upgradeRequest = request;
}
/**
* Access the Servlet HTTP Session (if present)
* <p>
* Note: Never present on a Client UpgradeRequest.
*
* @return the Servlet HTTPSession on server side UpgradeRequests
*/
Object getSession();
/**
* @return The {@link X509Certificate} instance at request attribute "javax.servlet.request.X509Certificate" or null.
*/
public X509Certificate[] getCertificates()
{
return upgradeRequest.getCertificates();
}
/**
* @return Request cookies
* @see HttpServletRequest#getCookies()
*/
public List<HttpCookie> getCookies()
{
return upgradeRequest.getCookies();
}
/**
* @return The extensions offered
* @see Negotiation#getOfferedExtensions()
*/
public List<ExtensionConfig> getExtensions()
{
return upgradeRequest.getExtensions().stream().map(JettyExtensionConfig::new).collect(Collectors.toList());
}
/**
* @param name Header name
* @return Header value or null
* @see HttpServletRequest#getHeader(String)
*/
public String getHeader(String name)
{
return upgradeRequest.getHeader(name);
}
/**
* @param name Header name
* @return Header value as integer or -1
* @see HttpServletRequest#getHeader(String)
*/
public int getHeaderInt(String name)
{
return upgradeRequest.getHeaderInt(name);
}
/**
* @return Map of headers
*/
public Map<String, List<String>> getHeadersMap()
{
return upgradeRequest.getHeadersMap();
}
/**
* @param name Header name
* @return List of header values or null
*/
public List<String> getHeaders(String name)
{
return upgradeRequest.getHeaders(name);
}
/**
* @return The requested host
* @see HttpServletRequest#getRequestURL()
*/
public String getHost()
{
return upgradeRequest.getHost();
}
X509Certificate[] getCertificates();
/**
* @return Immutable version of {@link HttpServletRequest}
*/
public HttpServletRequest getHttpServletRequest()
{
return upgradeRequest.getHttpServletRequest();
}
/**
* @return The HTTP protocol version
* @see HttpServletRequest#getProtocol()
*/
public String getHttpVersion()
{
return upgradeRequest.getHttpVersion();
}
HttpServletRequest getHttpServletRequest();
/**
* @return The requested Locale
* @see HttpServletRequest#getLocale()
*/
public Locale getLocale()
{
return upgradeRequest.getLocale();
}
Locale getLocale();
/**
* @return The requested Locales
* @see HttpServletRequest#getLocales()
*/
public Enumeration<Locale> getLocales()
{
return upgradeRequest.getLocales();
}
Enumeration<Locale> getLocales();
/**
* @return The local requested address, which is typically an {@link InetSocketAddress}, but may be another derivation of {@link SocketAddress}
* @see ServletRequest#getLocalAddr()
* @see ServletRequest#getLocalPort()
*/
public SocketAddress getLocalSocketAddress()
{
return upgradeRequest.getLocalSocketAddress();
}
/**
* @return The requested method
* @see HttpServletRequest#getMethod()
*/
public String getMethod()
{
return upgradeRequest.getMethod();
}
/**
* @return The origin header value
*/
public String getOrigin()
{
return upgradeRequest.getOrigin();
}
/**
* @return The request parameter map
* @see ServletRequest#getParameterMap()
*/
public Map<String, List<String>> getParameterMap()
{
return upgradeRequest.getParameterMap();
}
/**
* @return WebSocket protocol version from "Sec-WebSocket-Version" header
*/
public String getProtocolVersion()
{
return upgradeRequest.getProtocolVersion();
}
/**
* @return The request query string
* @see HttpServletRequest#getQueryString()
*/
public String getQueryString()
{
return upgradeRequest.getQueryString();
}
SocketAddress getLocalSocketAddress();
/**
* @return The remote request address, which is typically an {@link InetSocketAddress}, but may be another derivation of {@link SocketAddress}
* @see ServletRequest#getRemoteAddr()
* @see ServletRequest#getRemotePort()
*/
public SocketAddress getRemoteSocketAddress()
{
return upgradeRequest.getRemoteSocketAddress();
}
SocketAddress getRemoteSocketAddress();
/**
* @return The request URI path within the context
*/
public String getRequestPath()
{
return upgradeRequest.getRequestPath();
}
/**
* @return The request URI
* @see HttpServletRequest#getRequestURL()
*/
public URI getRequestURI()
{
return upgradeRequest.getRequestURI();
}
String getRequestPath();
/**
* @param name Attribute name
* @return Attribute value or null
* @see ServletRequest#getAttribute(String)
*/
public Object getServletAttribute(String name)
{
return upgradeRequest.getServletAttribute(name);
}
Object getServletAttribute(String name);
/**
* @return Request attribute map
*/
public Map<String, Object> getServletAttributes()
{
return upgradeRequest.getServletAttributes();
}
Map<String, Object> getServletAttributes();
/**
* @return Request parameters
* @see ServletRequest#getParameterMap()
*/
public Map<String, List<String>> getServletParameters()
{
return upgradeRequest.getServletParameters();
}
/**
* @return The HttpSession, which may be null or invalidated
* @see HttpServletRequest#getSession(boolean)
*/
public HttpSession getSession()
{
return upgradeRequest.getSession();
}
/**
* @return Get WebSocket negotiation offered sub protocols
*/
public List<String> getSubProtocols()
{
return upgradeRequest.getSubProtocols();
}
/**
* @return The User's {@link Principal} or null
* @see HttpServletRequest#getUserPrincipal()
*/
public Principal getUserPrincipal()
{
return upgradeRequest.getUserPrincipal();
}
/**
* @param subprotocol A sub protocol name
* @return True if the sub protocol was offered
*/
public boolean hasSubProtocol(String subprotocol)
{
return upgradeRequest.hasSubProtocol(subprotocol);
}
/**
* @return True if the request is secure
* @see ServletRequest#isSecure()
*/
public boolean isSecure()
{
return upgradeRequest.isSecure();
}
Map<String, List<String>> getServletParameters();
/**
* @param role The user role
* @return True if the requests user has the role
* @see HttpServletRequest#isUserInRole(String)
*/
public boolean isUserInRole(String role)
{
return upgradeRequest.isUserInRole(role);
}
boolean isUserInRole(String role);
/**
* @param name Attribute name
* @param value Attribute value to set
* @see ServletRequest#setAttribute(String, Object)
*/
public void setServletAttribute(String name, Object value)
{
upgradeRequest.setServletAttribute(name, value);
}
void setServletAttribute(String name, Object value);
}

View File

@ -20,102 +20,97 @@ package org.eclipse.jetty.websocket.server;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
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.internal.ServletUpgradeResponse;
public class JettyServerUpgradeResponse
public interface JettyServerUpgradeResponse extends UpgradeResponse
{
private ServletUpgradeResponse upgradeResponse;
/**
* Add a header value to the response.
*
* @param name the header name
* @param value the header value
*/
void addHeader(String name, String value);
JettyServerUpgradeResponse(ServletUpgradeResponse response)
{
upgradeResponse = response;
}
/**
* Set a header
* <p>
* Overrides previous value of header (if set)
*
* @param name the header name
* @param value the header value
*/
void setHeader(String name, String value);
public void addHeader(String name, String value)
{
upgradeResponse.addHeader(name, value);
}
/**
* Set a header
* <p>
* Overrides previous value of header (if set)
*
* @param name the header name
* @param values the header values
*/
void setHeader(String name, List<String> values);
public void setHeader(String name, String value)
{
upgradeResponse.setHeader(name, value);
}
/**
* Issue a forbidden upgrade response.
* <p>
* This means that the websocket endpoint was valid, but the conditions to use a WebSocket resulted in a forbidden
* access.
* <p>
* Use this when the origin or authentication is invalid.
*
* @param message the short 1 line detail message about the forbidden response
* @throws IOException if unable to send the forbidden
*/
void sendForbidden(String message) throws IOException;
public void setHeader(String name, List<String> values)
{
upgradeResponse.setHeader(name, values);
}
/**
* Sends an error response to the client using the specified status.
* @param statusCode the error status code
* @param message the descriptive message
* @throws IOException If an input or output exception occurs
* @throws IllegalStateException If the response was committed
*/
void sendError(int statusCode, String message) throws IOException;
public String getAcceptedSubProtocol()
{
return upgradeResponse.getAcceptedSubProtocol();
}
/**
* Set the accepted WebSocket Protocol.
*
* @param protocol the protocol to list as accepted
*/
void setAcceptedSubProtocol(String protocol);
public List<ExtensionConfig> getExtensions()
{
return upgradeResponse.getExtensions().stream().map(JettyExtensionConfig::new).collect(Collectors.toList());
}
/**
* Set the list of extensions that are approved for use with this websocket.
* <p>
* Notes:
* <ul>
* <li>Per the spec you cannot add extensions that have not been seen in the {@link UpgradeRequest}, just remove
* entries you don't want to use</li>
* <li>If this is unused, or a null is passed, then the list negotiation will follow default behavior and use the
* complete list of extensions that are
* available in this WebSocket server implementation.</li>
* </ul>
*
* @param extensions the list of extensions to use.
*/
void setExtensions(List<ExtensionConfig> extensions);
public String getHeader(String name)
{
return upgradeResponse.getHeader(name);
}
/**
* Set the HTTP Response status code
*
* @param statusCode the status code
*/
void setStatusCode(int statusCode);
public Set<String> getHeaderNames()
{
return upgradeResponse.getHeaderNames();
}
public Map<String, List<String>> getHeadersMap()
{
return upgradeResponse.getHeadersMap();
}
public List<String> getHeaders(String name)
{
return upgradeResponse.getHeaders(name);
}
public int getStatusCode()
{
return upgradeResponse.getStatusCode();
}
public boolean isCommitted()
{
return upgradeResponse.isCommitted();
}
public void sendError(int statusCode, String message) throws IOException
{
upgradeResponse.sendError(statusCode, message);
}
public void sendForbidden(String message) throws IOException
{
upgradeResponse.sendForbidden(message);
}
public void setAcceptedSubProtocol(String protocol)
{
upgradeResponse.setAcceptedSubProtocol(protocol);
}
public void setExtensions(List<ExtensionConfig> configs)
{
upgradeResponse.setExtensions(configs.stream()
.map(c -> new org.eclipse.jetty.websocket.core.ExtensionConfig(c.getName(), c.getParameters()))
.collect(Collectors.toList()));
}
public void setStatusCode(int statusCode)
{
upgradeResponse.setStatusCode(statusCode);
}
/**
* Returns a boolean indicating if the response has been committed.
* A committed response has already had its status code and headers written.
* @return a boolean indicating if the response has been committed.
*/
boolean isCommitted();
}

View File

@ -41,6 +41,8 @@ import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.core.server.WebSocketServerComponents;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.eclipse.jetty.websocket.server.internal.DelegatedServerUpgradeRequest;
import org.eclipse.jetty.websocket.server.internal.DelegatedServerUpgradeResponse;
import org.eclipse.jetty.websocket.server.internal.JettyServerFrameHandlerFactory;
import org.eclipse.jetty.websocket.util.ReflectUtils;
import org.eclipse.jetty.websocket.util.server.WebSocketUpgradeFilter;
@ -89,7 +91,6 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
private final ServletContextHandler contextHandler;
private final WebSocketMapping webSocketMapping;
private final WebSocketComponents webSocketComponents;
private final FrameHandlerFactory frameHandlerFactory;
private final Executor executor;
private final Configuration.ConfigurationCustomizer customizer = new Configuration.ConfigurationCustomizer();
@ -108,7 +109,6 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
{
this.contextHandler = contextHandler;
this.webSocketMapping = webSocketMapping;
this.webSocketComponents = webSocketComponents;
this.executor = executor;
// Ensure there is a FrameHandlerFactory
@ -133,7 +133,7 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
WebSocketUpgradeFilter.ensureFilter(contextHandler.getServletContext());
webSocketMapping.addMapping(ps,
(req, resp) -> creator.createWebSocket(new JettyServerUpgradeRequest(req), new JettyServerUpgradeResponse(resp)),
(req, resp) -> creator.createWebSocket(new DelegatedServerUpgradeRequest(req), new DelegatedServerUpgradeResponse(resp)),
frameHandlerFactory, customizer);
}

View File

@ -32,11 +32,13 @@ 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.core.server.WebSocketServerComponents;
import org.eclipse.jetty.websocket.server.internal.DelegatedServerUpgradeRequest;
import org.eclipse.jetty.websocket.server.internal.DelegatedServerUpgradeResponse;
import org.eclipse.jetty.websocket.server.internal.JettyServerFrameHandlerFactory;
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.ServerUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketCreator;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping;
import org.slf4j.Logger;
@ -276,9 +278,9 @@ public abstract class JettyWebSocketServlet extends HttpServlet
}
@Override
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
public Object createWebSocket(ServerUpgradeRequest req, ServerUpgradeResponse resp)
{
return creator.createWebSocket(new JettyServerUpgradeRequest(req), new JettyServerUpgradeResponse(resp));
return creator.createWebSocket(new DelegatedServerUpgradeRequest(req), new DelegatedServerUpgradeResponse(resp));
}
}
}

View File

@ -0,0 +1,235 @@
//
// ========================================================================
// 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.server.internal;
import java.net.HttpCookie;
import java.net.SocketAddress;
import java.net.URI;
import java.security.Principal;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
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.server.JettyServerUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeRequest;
public class DelegatedServerUpgradeRequest implements JettyServerUpgradeRequest
{
private final ServerUpgradeRequest upgradeRequest;
public DelegatedServerUpgradeRequest(ServerUpgradeRequest request)
{
upgradeRequest = request;
}
@Override
public List<HttpCookie> getCookies()
{
return upgradeRequest.getCookies();
}
@Override
public List<ExtensionConfig> getExtensions()
{
return upgradeRequest.getExtensions().stream()
.map(JettyExtensionConfig::new)
.collect(Collectors.toList());
}
@Override
public String getHeader(String name)
{
return upgradeRequest.getHeader(name);
}
@Override
public int getHeaderInt(String name)
{
return upgradeRequest.getHeaderInt(name);
}
@Override
public Map<String, List<String>> getHeaders()
{
return upgradeRequest.getHeadersMap();
}
@Override
public List<String> getHeaders(String name)
{
return upgradeRequest.getHeaders(name);
}
@Override
public String getHost()
{
return upgradeRequest.getHost();
}
@Override
public String getHttpVersion()
{
return upgradeRequest.getHttpVersion();
}
@Override
public String getMethod()
{
return upgradeRequest.getMethod();
}
@Override
public String getOrigin()
{
return upgradeRequest.getOrigin();
}
@Override
public Map<String, List<String>> getParameterMap()
{
return upgradeRequest.getParameterMap();
}
@Override
public String getProtocolVersion()
{
return upgradeRequest.getProtocolVersion();
}
@Override
public String getQueryString()
{
return upgradeRequest.getQueryString();
}
@Override
public URI getRequestURI()
{
return upgradeRequest.getRequestURI();
}
@Override
public HttpSession getSession()
{
return upgradeRequest.getSession();
}
@Override
public List<String> getSubProtocols()
{
return upgradeRequest.getSubProtocols();
}
@Override
public Principal getUserPrincipal()
{
return upgradeRequest.getUserPrincipal();
}
@Override
public boolean hasSubProtocol(String subprotocol)
{
return upgradeRequest.hasSubProtocol(subprotocol);
}
@Override
public boolean isSecure()
{
return upgradeRequest.isSecure();
}
@Override
public X509Certificate[] getCertificates()
{
return upgradeRequest.getCertificates();
}
@Override
public HttpServletRequest getHttpServletRequest()
{
return upgradeRequest.getHttpServletRequest();
}
@Override
public Locale getLocale()
{
return upgradeRequest.getLocale();
}
@Override
public Enumeration<Locale> getLocales()
{
return upgradeRequest.getLocales();
}
@Override
public SocketAddress getLocalSocketAddress()
{
return upgradeRequest.getLocalSocketAddress();
}
@Override
public SocketAddress getRemoteSocketAddress()
{
return upgradeRequest.getRemoteSocketAddress();
}
@Override
public String getRequestPath()
{
return upgradeRequest.getRequestPath();
}
@Override
public Object getServletAttribute(String name)
{
return upgradeRequest.getServletAttribute(name);
}
@Override
public Map<String, Object> getServletAttributes()
{
return upgradeRequest.getServletAttributes();
}
@Override
public Map<String, List<String>> getServletParameters()
{
return upgradeRequest.getServletParameters();
}
@Override
public boolean isUserInRole(String role)
{
return upgradeRequest.isUserInRole(role);
}
@Override
public void setServletAttribute(String name, Object value)
{
upgradeRequest.setServletAttribute(name, value);
}
}

View File

@ -24,100 +24,115 @@ import java.util.Map;
import java.util.Set;
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.internal.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse;
import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeResponse;
public class UpgradeResponseAdapter implements UpgradeResponse
public class DelegatedServerUpgradeResponse implements JettyServerUpgradeResponse
{
private final ServletUpgradeResponse servletResponse;
private final ServerUpgradeResponse upgradeResponse;
public UpgradeResponseAdapter(ServletUpgradeResponse servletResponse)
public DelegatedServerUpgradeResponse(ServerUpgradeResponse response)
{
this.servletResponse = servletResponse;
upgradeResponse = response;
}
@Override
public void addHeader(String name, String value)
{
this.servletResponse.addHeader(name, value);
}
@Override
public String getAcceptedSubProtocol()
{
return this.servletResponse.getAcceptedSubProtocol();
}
@Override
public List<ExtensionConfig> getExtensions()
{
return this.servletResponse.getExtensions().stream()
.map((ext) -> new JettyExtensionConfig(ext.getName(), ext.getParameters()))
.collect(Collectors.toList());
}
@Override
public String getHeader(String name)
{
return this.servletResponse.getHeader(name);
}
@Override
public Set<String> getHeaderNames()
{
return this.servletResponse.getHeaderNames();
}
@Override
public Map<String, List<String>> getHeaders()
{
return this.servletResponse.getHeadersMap();
}
@Override
public List<String> getHeaders(String name)
{
return this.servletResponse.getHeaders(name);
}
@Override
public int getStatusCode()
{
return this.servletResponse.getStatusCode();
}
@Override
public void sendForbidden(String message) throws IOException
{
this.servletResponse.sendForbidden(message);
}
@Override
public void setAcceptedSubProtocol(String protocol)
{
this.servletResponse.setAcceptedSubProtocol(protocol);
}
@Override
public void setExtensions(List<ExtensionConfig> extensions)
{
List<org.eclipse.jetty.websocket.core.ExtensionConfig> coreExtensionConfigs = extensions.stream()
.map((ext) -> new org.eclipse.jetty.websocket.core.ExtensionConfig(ext.getName(), ext.getParameters()))
.collect(Collectors.toList());
this.servletResponse.setExtensions(coreExtensionConfigs);
upgradeResponse.addHeader(name, value);
}
@Override
public void setHeader(String name, String value)
{
this.servletResponse.setHeader(name, value);
upgradeResponse.setHeader(name, value);
}
@Override
public void setHeader(String name, List<String> values)
{
upgradeResponse.setHeader(name, values);
}
@Override
public String getAcceptedSubProtocol()
{
return upgradeResponse.getAcceptedSubProtocol();
}
@Override
public List<ExtensionConfig> getExtensions()
{
return upgradeResponse.getExtensions().stream().map(JettyExtensionConfig::new).collect(Collectors.toList());
}
@Override
public String getHeader(String name)
{
return upgradeResponse.getHeader(name);
}
@Override
public Set<String> getHeaderNames()
{
return upgradeResponse.getHeaderNames();
}
@Override
public Map<String, List<String>> getHeaders()
{
return upgradeResponse.getHeadersMap();
}
@Override
public List<String> getHeaders(String name)
{
return upgradeResponse.getHeaders(name);
}
@Override
public int getStatusCode()
{
return upgradeResponse.getStatusCode();
}
@Override
public void sendForbidden(String message) throws IOException
{
upgradeResponse.sendForbidden(message);
}
@Override
public void setAcceptedSubProtocol(String protocol)
{
upgradeResponse.setAcceptedSubProtocol(protocol);
}
@Override
public void setExtensions(List<ExtensionConfig> configs)
{
upgradeResponse.setExtensions(configs.stream()
.map(c -> new org.eclipse.jetty.websocket.core.ExtensionConfig(c.getName(), c.getParameters()))
.collect(Collectors.toList()));
}
@Override
public void setStatusCode(int statusCode)
{
this.servletResponse.setStatusCode(statusCode);
upgradeResponse.setStatusCode(statusCode);
}
@Override
public boolean isCommitted()
{
return upgradeResponse.isCommitted();
}
@Override
public void sendError(int statusCode, String message) throws IOException
{
upgradeResponse.sendError(statusCode, message);
}
}

View File

@ -28,12 +28,10 @@ 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.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.ServerUpgradeRequest;
import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeResponse;
public class JettyServerFrameHandlerFactory
extends JettyWebSocketFrameHandlerFactory
implements FrameHandlerFactory, LifeCycle.Listener
public class JettyServerFrameHandlerFactory extends JettyWebSocketFrameHandlerFactory implements FrameHandlerFactory, LifeCycle.Listener
{
public static JettyServerFrameHandlerFactory getFactory(ServletContext context)
{
@ -47,11 +45,11 @@ public class JettyServerFrameHandlerFactory
}
@Override
public FrameHandler newFrameHandler(Object websocketPojo, ServletUpgradeRequest upgradeRequest, ServletUpgradeResponse upgradeResponse)
public FrameHandler newFrameHandler(Object websocketPojo, ServerUpgradeRequest upgradeRequest, ServerUpgradeResponse upgradeResponse)
{
JettyWebSocketFrameHandler frameHandler = super.newJettyFrameHandler(websocketPojo);
frameHandler.setUpgradeRequest(new UpgradeRequestAdapter(upgradeRequest));
frameHandler.setUpgradeResponse(new UpgradeResponseAdapter(upgradeResponse));
frameHandler.setUpgradeRequest(new DelegatedServerUpgradeRequest(upgradeRequest));
frameHandler.setUpgradeResponse(new DelegatedServerUpgradeResponse(upgradeResponse));
return frameHandler;
}

View File

@ -1,217 +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.server.internal;
import java.net.HttpCookie;
import java.net.URI;
import java.security.Principal;
import java.util.List;
import java.util.Map;
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.internal.ServletUpgradeRequest;
public class UpgradeRequestAdapter implements UpgradeRequest
{
private final ServletUpgradeRequest servletRequest;
public UpgradeRequestAdapter(ServletUpgradeRequest servletRequest)
{
this.servletRequest = servletRequest;
}
@Override
public void addExtensions(ExtensionConfig... configs)
{
throw new UnsupportedOperationException("Not supported from Servlet API");
}
@Override
public void addExtensions(String... configs)
{
throw new UnsupportedOperationException("Not supported from Servlet API");
}
@Override
public List<HttpCookie> getCookies()
{
return this.servletRequest.getCookies();
}
@Override
public List<ExtensionConfig> getExtensions()
{
return this.servletRequest.getExtensions().stream()
.map((ext) -> new JettyExtensionConfig(ext.getName(), ext.getParameters()))
.collect(Collectors.toList());
}
@Override
public String getHeader(String name)
{
return this.servletRequest.getHeader(name);
}
@Override
public int getHeaderInt(String name)
{
return this.servletRequest.getHeaderInt(name);
}
@Override
public Map<String, List<String>> getHeaders()
{
return this.servletRequest.getHeadersMap();
}
@Override
public List<String> getHeaders(String name)
{
return this.servletRequest.getHeaders(name);
}
@Override
public String getHost()
{
return this.servletRequest.getHost();
}
@Override
public String getHttpVersion()
{
return this.servletRequest.getHttpVersion();
}
@Override
public String getMethod()
{
return this.servletRequest.getMethod();
}
@Override
public String getOrigin()
{
return this.servletRequest.getOrigin();
}
@Override
public Map<String, List<String>> getParameterMap()
{
return this.servletRequest.getParameterMap();
}
@Override
public String getProtocolVersion()
{
return this.servletRequest.getProtocolVersion();
}
@Override
public String getQueryString()
{
return this.servletRequest.getQueryString();
}
@Override
public URI getRequestURI()
{
return this.servletRequest.getRequestURI();
}
@Override
public Object getSession()
{
return this.servletRequest.getSession();
}
@Override
public List<String> getSubProtocols()
{
return this.servletRequest.getSubProtocols();
}
@Override
public Principal getUserPrincipal()
{
return this.servletRequest.getUserPrincipal();
}
@Override
public boolean hasSubProtocol(String test)
{
return this.servletRequest.hasSubProtocol(test);
}
@Override
public boolean isSecure()
{
return this.servletRequest.isSecure();
}
@Override
public void setCookies(List<HttpCookie> cookies)
{
throw new UnsupportedOperationException("Not supported from Servlet API");
}
@Override
public void setExtensions(List<ExtensionConfig> configs)
{
throw new UnsupportedOperationException("Not supported from Servlet API");
}
@Override
public void setHeader(String name, List<String> values)
{
throw new UnsupportedOperationException("Not supported from Servlet API");
}
@Override
public void setHeader(String name, String value)
{
throw new UnsupportedOperationException("Not supported from Servlet API");
}
@Override
public void setHeaders(Map<String, List<String>> headers)
{
throw new UnsupportedOperationException("Not supported from Servlet API");
}
@Override
public void setSession(Object session)
{
throw new UnsupportedOperationException("Not supported from Servlet API");
}
@Override
public void setSubProtocols(List<String> protocols)
{
throw new UnsupportedOperationException("Not supported from Servlet API");
}
@Override
public void setSubProtocols(String... protocols)
{
throw new UnsupportedOperationException("Not supported from Servlet API");
}
}

View File

@ -65,8 +65,8 @@ public class WebSocketStatsTest
private ServerConnector connector;
private WebSocketClient client;
private ConnectionStatistics statistics;
private CountDownLatch wsUpgradeComplete = new CountDownLatch(1);
private CountDownLatch wsConnectionClosed = new CountDownLatch(1);
private final CountDownLatch wsUpgradeComplete = new CountDownLatch(1);
private final CountDownLatch wsConnectionClosed = new CountDownLatch(1);
@BeforeEach
public void start() throws Exception

View File

@ -34,6 +34,5 @@ public interface FrameHandlerFactory
* @return the API specific FrameHandler, or null if this implementation is unable to create
* the FrameHandler (allowing another {@link FrameHandlerFactory} to try)
*/
FrameHandler newFrameHandler(Object websocketPojo, ServletUpgradeRequest upgradeRequest,
ServletUpgradeResponse upgradeResponse);
FrameHandler newFrameHandler(Object websocketPojo, ServerUpgradeRequest upgradeRequest, ServerUpgradeResponse upgradeResponse);
}

View File

@ -46,7 +46,7 @@ import org.eclipse.jetty.websocket.core.server.Negotiation;
/**
* Holder of request data for a WebSocket upgrade request.
*/
public class ServletUpgradeRequest
public class ServerUpgradeRequest
{
private final URI requestURI;
private final String queryString;
@ -56,7 +56,7 @@ public class ServletUpgradeRequest
private List<HttpCookie> cookies;
private Map<String, List<String>> parameterMap;
public ServletUpgradeRequest(Negotiation negotiation) throws BadMessageException
public ServerUpgradeRequest(Negotiation negotiation) throws BadMessageException
{
this.negotiation = negotiation;
HttpServletRequest httpRequest = negotiation.getRequest();

View File

@ -36,12 +36,12 @@ import org.eclipse.jetty.websocket.core.server.Negotiation;
/**
* Servlet Specific UpgradeResponse implementation.
*/
public class ServletUpgradeResponse
public class ServerUpgradeResponse
{
private final HttpServletResponse response;
private final Negotiation negotiation;
public ServletUpgradeResponse(Negotiation negotiation)
public ServerUpgradeResponse(Negotiation negotiation)
{
this.negotiation = negotiation;
this.response = negotiation.getResponse();

View File

@ -81,7 +81,7 @@ public class UpgradeHttpServletRequest implements HttpServletRequest
private final Map<String, Object> attributes = new HashMap<>(2);
private final List<Locale> locales = new ArrayList<>(2);
private HttpSession session;
private final HttpSession session;
private final InetSocketAddress localAddress;
private final String localName;

View File

@ -34,5 +34,5 @@ public interface WebSocketCreator
* @param resp the response details
* @return a websocket object to use, or null if no websocket should be created from this request.
*/
Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp);
Object createWebSocket(ServerUpgradeRequest req, ServerUpgradeResponse resp);
}

View File

@ -265,8 +265,8 @@ public class WebSocketMapping implements Dumpable, LifeCycle.Listener
if (servletContext == null)
throw new IllegalStateException("null servletContext from request");
ServletUpgradeRequest upgradeRequest = new ServletUpgradeRequest(negotiation);
ServletUpgradeResponse upgradeResponse = new ServletUpgradeResponse(negotiation);
ServerUpgradeRequest upgradeRequest = new ServerUpgradeRequest(negotiation);
ServerUpgradeResponse upgradeResponse = new ServerUpgradeResponse(negotiation);
AtomicReference<Object> result = new AtomicReference<>();
((ContextHandler.Context)servletContext).getContextHandler().handle(() ->