From 5ff0ce4142ec7a18f9f24fae65a62bac1971776c Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 29 Jul 2020 22:22:14 +1000 Subject: [PATCH 1/6] Issue #5044 - implement is secure on DelegatedJettyClientUpgradeRequest Signed-off-by: Lachlan Roberts --- .../client/impl/DelegatedJettyClientUpgradeRequest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java index bdd1a38227da..d45dd692ea46 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java @@ -27,6 +27,7 @@ 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; @@ -163,8 +164,7 @@ public boolean hasSubProtocol(String test) @Override public boolean isSecure() { - // TODO: figure out how to obtain from HttpClient's HttpRequest - return false; + return HttpClient.isSchemeSecure(delegate.getScheme()); } @Override @@ -204,7 +204,7 @@ public List getExtensions() if (rawExtensions == null || rawExtensions.isEmpty()) return Collections.emptyList(); - return rawExtensions.stream().map((parameterizedName) -> ExtensionConfig.parse(parameterizedName)).collect(Collectors.toList()); + return rawExtensions.stream().map(ExtensionConfig::parse).collect(Collectors.toList()); } @Override From 414a0f35f9ab14ae75756bb84bafd378e9aecd53 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 29 Jul 2020 22:44:42 +1000 Subject: [PATCH 2/6] Issue #5044 - move all setter methods on the UpgradeRequest interface to ClientUpgradeRequest Signed-off-by: Lachlan Roberts --- .../jetty/websocket/api/UpgradeRequest.java | 90 ---------- .../client/ClientUpgradeRequest.java | 170 +++++++++++------- .../DelegatedJettyClientUpgradeRequest.java | 65 ------- .../impl/JettyClientUpgradeRequest.java | 9 - .../internal/UpgradeRequestAdapter.java | 102 +++-------- 5 files changed, 128 insertions(+), 308 deletions(-) diff --git a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java index 9db3f0a81f38..89090c0713e4 100644 --- a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java @@ -31,26 +31,6 @@ */ public interface UpgradeRequest { - /** - * Add WebSocket Extension Configuration(s) to Upgrade Request. - *

- * 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 - *

- * 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 * @@ -207,74 +187,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 cookies); - - /** - * Set the list of WebSocket Extension configurations on the request. - * - * @param configs the list of extension configurations - */ - void setExtensions(List configs); - - /** - * Set a specific header with multi-value field - *

- * 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 values); - - /** - * Set a specific header value - *

- * 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. - *

- * Only sets those headers provided, does not remove - * headers that exist on request and are not provided in the - * parameter for this method. - *

- * Convenience method vs calling {@link #setHeader(String, List)} multiple times. - * - * @param headers the headers to set - */ - void setHeaders(Map> headers); - - /** - * Set the Session associated with this request. - *

- * 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 protocols); - - /** - * Set the offered WebSocket Sub-Protocol list. - * - * @param protocols the offered sub-protocol list - */ - void setSubProtocols(String... protocols); } diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java index fb41b6af2cd6..db550f1fcee5 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java @@ -32,6 +32,7 @@ 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 ClientUpgradeRequest(URI uri) 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 getCookies() { return cookies; } - @Override - public void setCookies(List cookies) - { - this.cookies.clear(); - if (cookies != null && !cookies.isEmpty()) - { - this.cookies.addAll(cookies); - } - } - @Override public List getExtensions() { return extensions; } - @Override - public void setExtensions(List configs) - { - this.extensions.clear(); - if (configs != null) - { - this.extensions.addAll(configs); - } - } - @Override public String getHeader(String name) { @@ -219,28 +185,6 @@ public Principal getUserPrincipal() 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 subProtocols) - { - this.subProtocols.clear(); - if (subProtocols != null) - { - this.subProtocols.addAll(subProtocols); - } - } - @Override public boolean hasSubProtocol(String test) { @@ -260,13 +204,84 @@ public boolean isSecure() throw new UnsupportedOperationException("Request.isSecure not available on Client request"); } - @Override + /** + * Add WebSocket Extension Configuration(s) to Upgrade Request. + *

+ * 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 + *

+ * 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 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 configs) + { + this.extensions.clear(); + if (configs != null) + { + this.extensions.addAll(configs); + } + } + + /** + * Set a specific header with multi-value field + *

+ * 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 values) { headers.put(name, values); } - @Override + /** + * Set a specific header value + *

+ * 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 values = new ArrayList<>(); @@ -274,7 +289,17 @@ public void setHeader(String name, String value) setHeader(name, values); } - @Override + /** + * Sets multiple headers on the request. + *

+ * Only sets those headers provided, does not remove + * headers that exist on request and are not provided in the + * parameter for this method. + *

+ * Convenience method vs calling {@link #setHeader(String, List)} multiple times. + * + * @param headers the headers to set + */ public void setHeaders(Map> headers) { this.headers.clear(); @@ -286,10 +311,29 @@ public void setHeaders(Map> headers) } } - @Override - public void setSession(Object session) + /** + * Set the offered WebSocket Sub-Protocol list. + * + * @param protocols the offered sub-protocol list + */ + public void setSubProtocols(List 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); } /** diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java index d45dd692ea46..eee1d61c3167 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java @@ -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; @@ -46,8 +45,6 @@ public class DelegatedJettyClientUpgradeRequest implements UpgradeRequest { private final ClientUpgradeRequest delegate; - private SocketAddress localSocketAddress; - private SocketAddress remoteSocketAddress; public DelegatedJettyClientUpgradeRequest(ClientUpgradeRequest delegate) { @@ -101,8 +98,6 @@ public String getHttpVersion() public void configure(EndPoint endpoint) { - this.localSocketAddress = endpoint.getLocalAddress(); - this.remoteSocketAddress = endpoint.getRemoteAddress(); } @Override @@ -167,18 +162,6 @@ public boolean isSecure() return HttpClient.isSchemeSecure(delegate.getScheme()); } - @Override - public void addExtensions(org.eclipse.jetty.websocket.api.extensions.ExtensionConfig... configs) - { - // TODO - } - - @Override - public void addExtensions(String... configs) - { - // TODO - } - @Override public Object getSession() { @@ -191,12 +174,6 @@ public Principal getUserPrincipal() return null; } - @Override - public void setCookies(List cookies) - { - // TODO - } - @Override public List getExtensions() { @@ -206,46 +183,4 @@ public List getExtensions() return rawExtensions.stream().map(ExtensionConfig::parse).collect(Collectors.toList()); } - - @Override - public void setExtensions(List configs) - { - // TODO - } - - @Override - public void setHeader(String name, List values) - { - // TODO - } - - @Override - public void setHeader(String name, String value) - { - // TODO - } - - @Override - public void setHeaders(Map> headers) - { - // TODO - } - - @Override - public void setSession(Object session) - { - // TODO - } - - @Override - public void setSubProtocols(List protocols) - { - // TODO - } - - @Override - public void setSubProtocols(String... protocols) - { - // TODO - } } diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java index f91f12214348..5ddab348b432 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java @@ -34,7 +34,6 @@ public class JettyClientUpgradeRequest extends org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest { - private final DelegatedJettyClientUpgradeRequest handshakeRequest; private final JettyWebSocketFrameHandler frameHandler; public JettyClientUpgradeRequest(WebSocketCoreClient coreClient, ClientUpgradeRequest request, URI requestURI, JettyWebSocketFrameHandlerFactory frameHandlerFactory, @@ -58,17 +57,9 @@ public JettyClientUpgradeRequest(WebSocketCoreClient coreClient, ClientUpgradeRe 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) { diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java index bddf712cf152..31431f250f49 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java @@ -32,35 +32,23 @@ public class UpgradeRequestAdapter implements UpgradeRequest { - private final ServletUpgradeRequest servletRequest; + 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"); + _servletRequest = servletRequest; } @Override public List getCookies() { - return this.servletRequest.getCookies(); + return _servletRequest.getCookies(); } @Override public List getExtensions() { - return this.servletRequest.getExtensions().stream() + return _servletRequest.getExtensions().stream() .map((ext) -> new JettyExtensionConfig(ext.getName(), ext.getParameters())) .collect(Collectors.toList()); } @@ -68,150 +56,102 @@ public List getExtensions() @Override public String getHeader(String name) { - return this.servletRequest.getHeader(name); + return _servletRequest.getHeader(name); } @Override public int getHeaderInt(String name) { - return this.servletRequest.getHeaderInt(name); + return _servletRequest.getHeaderInt(name); } @Override public Map> getHeaders() { - return this.servletRequest.getHeadersMap(); + return _servletRequest.getHeadersMap(); } @Override public List getHeaders(String name) { - return this.servletRequest.getHeaders(name); + return _servletRequest.getHeaders(name); } @Override public String getHost() { - return this.servletRequest.getHost(); + return _servletRequest.getHost(); } @Override public String getHttpVersion() { - return this.servletRequest.getHttpVersion(); + return _servletRequest.getHttpVersion(); } @Override public String getMethod() { - return this.servletRequest.getMethod(); + return _servletRequest.getMethod(); } @Override public String getOrigin() { - return this.servletRequest.getOrigin(); + return _servletRequest.getOrigin(); } @Override public Map> getParameterMap() { - return this.servletRequest.getParameterMap(); + return _servletRequest.getParameterMap(); } @Override public String getProtocolVersion() { - return this.servletRequest.getProtocolVersion(); + return _servletRequest.getProtocolVersion(); } @Override public String getQueryString() { - return this.servletRequest.getQueryString(); + return _servletRequest.getQueryString(); } @Override public URI getRequestURI() { - return this.servletRequest.getRequestURI(); + return _servletRequest.getRequestURI(); } @Override public Object getSession() { - return this.servletRequest.getSession(); + return _servletRequest.getSession(); } @Override public List getSubProtocols() { - return this.servletRequest.getSubProtocols(); + return _servletRequest.getSubProtocols(); } @Override public Principal getUserPrincipal() { - return this.servletRequest.getUserPrincipal(); + return _servletRequest.getUserPrincipal(); } @Override public boolean hasSubProtocol(String test) { - return this.servletRequest.hasSubProtocol(test); + return _servletRequest.hasSubProtocol(test); } @Override public boolean isSecure() { - return this.servletRequest.isSecure(); - } - - @Override - public void setCookies(List cookies) - { - throw new UnsupportedOperationException("Not supported from Servlet API"); - } - - @Override - public void setExtensions(List configs) - { - throw new UnsupportedOperationException("Not supported from Servlet API"); - } - - @Override - public void setHeader(String name, List 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> 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 protocols) - { - throw new UnsupportedOperationException("Not supported from Servlet API"); - } - - @Override - public void setSubProtocols(String... protocols) - { - throw new UnsupportedOperationException("Not supported from Servlet API"); + return _servletRequest.isSecure(); } } From 9027e170955d8cd975e6d4fae49428a7a0aea3c9 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 29 Jul 2020 22:51:39 +1000 Subject: [PATCH 3/6] Issue #5044 - rename the ClientUpgradeRequest to CoreClientUpgradeRequest Signed-off-by: Lachlan Roberts --- ...est.java => CoreClientUpgradeRequest.java} | 10 ++++---- .../core/client/HttpUpgraderOverHTTP.java | 4 ++-- .../core/client/HttpUpgraderOverHTTP2.java | 4 ++-- .../core/client/WebSocketCoreClient.java | 4 ++-- .../websocket/core/AutoFragmentTest.java | 8 +++---- .../core/WebSocketNegotiationTest.java | 22 ++++++++--------- .../core/chat/ChatWebSocketClient.java | 4 ++-- .../PerMessageDeflaterBufferSizeTest.java | 10 ++++---- .../core/proxy/WebSocketProxyTest.java | 12 +++++----- .../internal/JavaxClientUpgradeRequest.java | 4 ++-- .../websocket/javax/tests/NetworkFuzzer.java | 4 ++-- .../javax/tests/server/ConfiguratorTest.java | 24 +++++++++---------- .../DelegatedJettyClientUpgradeRequest.java | 6 ++--- .../impl/JettyClientUpgradeRequest.java | 3 ++- .../server/JettyServerUpgradeRequest.java | 2 +- .../JettyServerFrameHandlerFactory.java | 4 +--- 16 files changed, 62 insertions(+), 63 deletions(-) rename jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/{ClientUpgradeRequest.java => CoreClientUpgradeRequest.java} (97%) diff --git a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/CoreClientUpgradeRequest.java similarity index 97% rename from jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java rename to jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/CoreClientUpgradeRequest.java index 0c3d475f6b7b..14f08d7cadfe 100644 --- a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java +++ b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/CoreClientUpgradeRequest.java @@ -61,11 +61,11 @@ 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 FrameHandler getFrameHandler() }; } - private static final Logger LOG = LoggerFactory.getLogger(ClientUpgradeRequest.class); + private static final Logger LOG = LoggerFactory.getLogger(CoreClientUpgradeRequest.class); protected final CompletableFuture futureCoreSession; private final WebSocketCoreClient wsClient; private FrameHandler frameHandler; @@ -83,7 +83,7 @@ public FrameHandler getFrameHandler() private final List upgradeListeners = new ArrayList<>(); private List requestedExtensions = new ArrayList<>(); - public ClientUpgradeRequest(WebSocketCoreClient webSocketClient, URI requestURI) + public CoreClientUpgradeRequest(WebSocketCoreClient webSocketClient, URI requestURI) { super(webSocketClient.getHttpClient(), new HttpConversation(), requestURI); diff --git a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP.java b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP.java index 54048a416929..318fd537a8ed 100644 --- a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP.java +++ b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP.java @@ -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; } diff --git a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP2.java b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP2.java index 422e4a14187b..6b3cd28ba018 100644 --- a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP2.java +++ b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP2.java @@ -31,9 +31,9 @@ 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; } diff --git a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/WebSocketCoreClient.java b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/WebSocketCoreClient.java index 7795e5460c21..9d90e0faa2cc 100644 --- a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/WebSocketCoreClient.java +++ b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/WebSocketCoreClient.java @@ -71,11 +71,11 @@ public WebSocketCoreClient(HttpClient httpClient, WebSocketComponents webSocketC public CompletableFuture 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 connect(ClientUpgradeRequest request) throws IOException + public CompletableFuture connect(CoreClientUpgradeRequest request) throws IOException { if (!isStarted()) throw new IllegalStateException(WebSocketCoreClient.class.getSimpleName() + "@" + this.hashCode() + " is not started"); diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/AutoFragmentTest.java b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/AutoFragmentTest.java index 06de7da071b5..9de6190a831f 100644 --- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/AutoFragmentTest.java +++ b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/AutoFragmentTest.java @@ -29,7 +29,7 @@ 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 void testIncomingAutoFragmentToMaxFrameSize() throws Exception 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 connect = client.connect(upgradeRequest); connect.get(5, TimeUnit.SECONDS); @@ -218,7 +218,7 @@ public void testIncomingAutoFragmentWithPermessageDeflate() throws Exception 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 connect = client.connect(upgradeRequest); connect.get(5, TimeUnit.SECONDS); @@ -281,7 +281,7 @@ public void testOutgoingAutoFragmentWithPermessageDeflate() throws Exception // 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 connect = client.connect(upgradeRequest); connect.get(5, TimeUnit.SECONDS); diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java index 46659dfd4301..bc853bf3b56c 100644 --- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java +++ b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java @@ -37,7 +37,7 @@ 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 void testExtensionSelection() throws Exception { 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 void testNotOfferedParameter() throws Exception { 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 void testInvalidExtensionParameter() throws Exception { 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 void testNotAcceptingExtensions() throws Exception { 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 void testAcceptTwoExtensionsOfSameName() throws Exception { 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 void testSubProtocolNotOffered() throws Exception { 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 void testSubProtocolNotOffered() throws Exception 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 headers = new CompletableFuture<>(); upgradeRequest.addListener(new UpgradeListener() @@ -378,7 +378,7 @@ public void testListenerExtensionSelection() 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"); CompletableFuture extensionHeader = new CompletableFuture<>(); @@ -409,7 +409,7 @@ public void onHandshakeResponse(HttpRequest request, HttpResponse response) 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 void testClientRequestedInternalExtensions(String reqExts, String negExts TestFrameHandler clientHandler = new TestFrameHandler(); CompletableFuture 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(",")); diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/chat/ChatWebSocketClient.java b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/chat/ChatWebSocketClient.java index 3734c4993246..9e4f85659d50 100644 --- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/chat/ChatWebSocketClient.java +++ b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/chat/ChatWebSocketClient.java @@ -29,7 +29,7 @@ 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 ChatWebSocketClient(String hostname, int port) throws Exception 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); diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflaterBufferSizeTest.java b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflaterBufferSizeTest.java index 5f28a82b5444..ccdbbb8329dc 100644 --- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflaterBufferSizeTest.java +++ b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflaterBufferSizeTest.java @@ -34,7 +34,7 @@ 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 void testClientDeflateBufferSize() throws Exception { 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 futureRequestHeaders = new CompletableFuture<>(); @@ -157,7 +157,7 @@ public void testClientInflateBufferSize() throws Exception { 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 futureRequestHeaders = new CompletableFuture<>(); @@ -212,7 +212,7 @@ public void testServerDeflateBufferSize() throws Exception { 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 futureResponseHeaders = new CompletableFuture<>(); @@ -267,7 +267,7 @@ public void testServerInflateBufferSize() throws Exception { 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 futureResponseHeaders = new CompletableFuture<>(); diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java index ea7a478f93f6..94dca3739c7b 100644 --- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java +++ b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java @@ -45,7 +45,7 @@ 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 void testEcho() throws Exception 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 response = _client.connect(upgradeRequest); @@ -201,7 +201,7 @@ public void testFailServerUpgrade() throws Exception 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 response = _client.connect(upgradeRequest); response.get(5, TimeUnit.SECONDS); @@ -240,7 +240,7 @@ public void onOpen(CoreSession coreSession, Callback callback) 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 response = _client.connect(upgradeRequest); Exception e = assertThrows(ExecutionException.class, () -> response.get(5, TimeUnit.SECONDS)); @@ -271,7 +271,7 @@ public void testServerError() throws Exception 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 response = _client.connect(upgradeRequest); @@ -335,7 +335,7 @@ public void onFrame(Frame frame, Callback callback) } }; - 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 response = _client.connect(upgradeRequest); response.get(5, TimeUnit.SECONDS); diff --git a/jetty-websocket/websocket-javax-client/src/main/java/org/eclipse/jetty/websocket/javax/client/internal/JavaxClientUpgradeRequest.java b/jetty-websocket/websocket-javax-client/src/main/java/org/eclipse/jetty/websocket/javax/client/internal/JavaxClientUpgradeRequest.java index d2c8856db665..c8b3da5b9a42 100644 --- a/jetty-websocket/websocket-javax-client/src/main/java/org/eclipse/jetty/websocket/javax/client/internal/JavaxClientUpgradeRequest.java +++ b/jetty-websocket/websocket-javax-client/src/main/java/org/eclipse/jetty/websocket/javax/client/internal/JavaxClientUpgradeRequest.java @@ -24,12 +24,12 @@ 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; diff --git a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/NetworkFuzzer.java b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/NetworkFuzzer.java index f1be31e72e40..4b8f76c4f3a5 100644 --- a/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/NetworkFuzzer.java +++ b/jetty-websocket/websocket-javax-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/NetworkFuzzer.java @@ -39,7 +39,7 @@ 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 void sendSegmented(List frames, int segmentSize) throws IOExceptio } } - public static class RawUpgradeRequest extends ClientUpgradeRequest + public static class RawUpgradeRequest extends CoreClientUpgradeRequest { private final FrameCapture frameCapture = new FrameCapture(); private final CompletableFuture futureCapture; diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/ConfiguratorTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/ConfiguratorTest.java index 82f3fd3f76c4..45cc8ca17789 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/ConfiguratorTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/ConfiguratorTest.java @@ -54,7 +54,7 @@ import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; -import org.eclipse.jetty.websocket.core.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 void testEmptyConfigurator() throws Exception 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 clientConnectFuture = client.connect(upgradeRequest); @@ -454,7 +454,7 @@ public void testNoExtensionsConfigurator() throws Exception 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 clientConnectFuture = client.connect(upgradeRequest); @@ -478,7 +478,7 @@ public void testCaptureRequestHeadersConfigurator() throws Exception 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 clientConnectFuture = client.connect(upgradeRequest); @@ -503,7 +503,7 @@ public void testUniqueUserPropsConfigurator() throws Exception // First Request FrameHandlerTracker clientSocket = new FrameHandlerTracker(); - ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket); + CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(client, wsUri, clientSocket); Future clientConnectFuture = client.connect(upgradeRequest); CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); @@ -522,7 +522,7 @@ public void testUniqueUserPropsConfigurator() throws Exception // 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 void testUserPropsAddress() throws Exception 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 clientConnectFuture = client.connect(upgradeRequest); CoreSession coreSession = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS); @@ -591,7 +591,7 @@ public void testProtocolSingle() throws Exception 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 clientConnectFuture = client.connect(upgradeRequest); @@ -610,7 +610,7 @@ public void testProtocolTriple() throws Exception 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 clientConnectFuture = client.connect(upgradeRequest); @@ -629,7 +629,7 @@ public void testProtocolLowercaseHeader() throws Exception 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 clientConnectFuture = client.connect(upgradeRequest); @@ -648,7 +648,7 @@ public void testProtocolAltHeaderCase() throws Exception 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 clientConnectFuture = client.connect(upgradeRequest); @@ -681,7 +681,7 @@ public void testDecoderWithProtocol() throws Exception 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 clientConnectFuture = client.connect(upgradeRequest); diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java index eee1d61c3167..f245e9bcef15 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java @@ -34,7 +34,7 @@ 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,9 +44,9 @@ */ public class DelegatedJettyClientUpgradeRequest implements UpgradeRequest { - private final ClientUpgradeRequest delegate; + private final CoreClientUpgradeRequest delegate; - public DelegatedJettyClientUpgradeRequest(ClientUpgradeRequest delegate) + public DelegatedJettyClientUpgradeRequest(CoreClientUpgradeRequest delegate) { this.delegate = delegate; } diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java index 5ddab348b432..36f971f9c42c 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java @@ -30,9 +30,10 @@ 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 JettyWebSocketFrameHandler frameHandler; diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java index 13e0b330d610..f4802b57293f 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java @@ -40,7 +40,7 @@ public class JettyServerUpgradeRequest { - private ServletUpgradeRequest upgradeRequest; + private final ServletUpgradeRequest upgradeRequest; JettyServerUpgradeRequest(ServletUpgradeRequest request) { diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java index ce4d9989c648..e1f57d3f6503 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java @@ -31,9 +31,7 @@ import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest; import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeResponse; -public class JettyServerFrameHandlerFactory - extends JettyWebSocketFrameHandlerFactory - implements FrameHandlerFactory, LifeCycle.Listener +public class JettyServerFrameHandlerFactory extends JettyWebSocketFrameHandlerFactory implements FrameHandlerFactory, LifeCycle.Listener { public static JettyServerFrameHandlerFactory getFactory(ServletContext context) { From 3074aa7fae3b637409bfafa9f23ee16f1481fe0e Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 30 Jul 2020 13:28:39 +1000 Subject: [PATCH 4/6] Issue #5044 - Jetty Server upgrade request/response now implement the API interfaces Signed-off-by: Lachlan Roberts --- .../internal/JavaxServerUpgradeRequest.java | 6 +- .../internal/JavaxWebSocketCreator.java | 6 +- ...vaxWebSocketServerFrameHandlerFactory.java | 6 +- .../server/internal/JsrHandshakeRequest.java | 6 +- .../server/internal/JsrHandshakeResponse.java | 6 +- .../DelegatedJettyClientUpgradeResponse.java | 2 +- .../server/JettyServerUpgradeRequest.java | 233 +++++++----------- .../server/JettyServerUpgradeResponse.java | 54 ++-- .../server/JettyWebSocketServlet.java | 6 +- .../JettyServerFrameHandlerFactory.java | 6 +- .../internal/UpgradeRequestAdapter.java | 6 +- .../internal/UpgradeResponseAdapter.java | 6 +- .../server/internal/FrameHandlerFactory.java | 3 +- ...Request.java => ServerUpgradeRequest.java} | 4 +- ...sponse.java => ServerUpgradeResponse.java} | 4 +- .../internal/UpgradeHttpServletRequest.java | 2 +- .../server/internal/WebSocketCreator.java | 2 +- .../server/internal/WebSocketMapping.java | 4 +- 18 files changed, 160 insertions(+), 202 deletions(-) rename jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/{ServletUpgradeRequest.java => ServerUpgradeRequest.java} (98%) rename jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/{ServletUpgradeResponse.java => ServerUpgradeResponse.java} (98%) diff --git a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxServerUpgradeRequest.java b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxServerUpgradeRequest.java index b38d3779863f..fb530a6b3848 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxServerUpgradeRequest.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxServerUpgradeRequest.java @@ -22,13 +22,13 @@ 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; } diff --git a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketCreator.java b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketCreator.java index 4a1387c86a6e..b8c950a9ebfd 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketCreator.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketCreator.java @@ -38,8 +38,8 @@ 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 JavaxWebSocketCreator(JavaxWebSocketContainer containerScope, ServerEndpo } @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); diff --git a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerFrameHandlerFactory.java b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerFrameHandlerFactory.java index 480d5acad5a7..e9e69a3a1cf4 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerFrameHandlerFactory.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerFrameHandlerFactory.java @@ -27,8 +27,8 @@ 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 JavaxWebSocketFrameHandlerMetadata getMetadata(Class endpointClass, En } @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)); } diff --git a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JsrHandshakeRequest.java b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JsrHandshakeRequest.java index dbb8e1f1fb37..280cecd27e45 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JsrHandshakeRequest.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JsrHandshakeRequest.java @@ -25,13 +25,13 @@ 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; } diff --git a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JsrHandshakeResponse.java b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JsrHandshakeResponse.java index 80ec6a7502b5..b55ec99f3fd2 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JsrHandshakeResponse.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JsrHandshakeResponse.java @@ -23,14 +23,14 @@ 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> headerMap; - public JsrHandshakeResponse(ServletUpgradeResponse resp) + public JsrHandshakeResponse(ServerUpgradeResponse resp) { this.delegate = resp; this.headerMap = new HashMap<>(); diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeResponse.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeResponse.java index 67cad5ee72d7..fb86e2fea994 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeResponse.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeResponse.java @@ -36,7 +36,7 @@ */ public class DelegatedJettyClientUpgradeResponse implements UpgradeResponse { - private HttpResponse delegate; + private final HttpResponse delegate; public DelegatedJettyClientUpgradeResponse(HttpResponse response) { diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java index f4802b57293f..ef58f270753f 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java @@ -33,178 +33,176 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; +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.core.server.Negotiation; -import org.eclipse.jetty.websocket.util.server.internal.ServletUpgradeRequest; +import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeRequest; -public class JettyServerUpgradeRequest +public class JettyServerUpgradeRequest implements UpgradeRequest { - private final ServletUpgradeRequest upgradeRequest; + private final ServerUpgradeRequest upgradeRequest; - JettyServerUpgradeRequest(ServletUpgradeRequest request) + JettyServerUpgradeRequest(ServerUpgradeRequest request) { upgradeRequest = request; } - /** - * @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() - */ + @Override public List getCookies() { return upgradeRequest.getCookies(); } - /** - * @return The extensions offered - * @see Negotiation#getOfferedExtensions() - */ + @Override public List getExtensions() { return upgradeRequest.getExtensions().stream().map(JettyExtensionConfig::new).collect(Collectors.toList()); } - /** - * @param name Header name - * @return Header value or null - * @see HttpServletRequest#getHeader(String) - */ + @Override public String getHeader(String name) { return upgradeRequest.getHeader(name); } - /** - * @param name Header name - * @return Header value as integer or -1 - * @see HttpServletRequest#getHeader(String) - */ + @Override public int getHeaderInt(String name) { return upgradeRequest.getHeaderInt(name); } - /** - * @return Map of headers - */ - public Map> getHeadersMap() + @Override + public Map> getHeaders() { return upgradeRequest.getHeadersMap(); } - /** - * @param name Header name - * @return List of header values or null - */ + @Override public List getHeaders(String name) { return upgradeRequest.getHeaders(name); } - /** - * @return The requested host - * @see HttpServletRequest#getRequestURL() - */ + @Override public String getHost() { return upgradeRequest.getHost(); } - /** - * @return Immutable version of {@link HttpServletRequest} - */ - public HttpServletRequest getHttpServletRequest() + @Override + public String getHttpVersion() { - return upgradeRequest.getHttpServletRequest(); + return upgradeRequest.getHttpVersion(); } - /** - * @return The HTTP protocol version - * @see HttpServletRequest#getProtocol() - */ - public String getHttpVersion() + @Override + public String getMethod() { - return upgradeRequest.getHttpVersion(); + return upgradeRequest.getMethod(); } - /** - * @return The requested Locale - * @see HttpServletRequest#getLocale() - */ - public Locale getLocale() + @Override + public String getOrigin() { - return upgradeRequest.getLocale(); + return upgradeRequest.getOrigin(); } - /** - * @return The requested Locales - * @see HttpServletRequest#getLocales() - */ - public Enumeration getLocales() + @Override + public Map> getParameterMap() { - return upgradeRequest.getLocales(); + return upgradeRequest.getParameterMap(); } - /** - * @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() + @Override + public String getProtocolVersion() { - return upgradeRequest.getLocalSocketAddress(); + 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 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(); } /** - * @return The requested method - * @see HttpServletRequest#getMethod() + * @return The {@link X509Certificate} instance at request attribute "javax.servlet.request.X509Certificate" or null. */ - public String getMethod() + public X509Certificate[] getCertificates() { - return upgradeRequest.getMethod(); + return upgradeRequest.getCertificates(); } /** - * @return The origin header value + * @return Immutable version of {@link HttpServletRequest} */ - public String getOrigin() + public HttpServletRequest getHttpServletRequest() { - return upgradeRequest.getOrigin(); + return upgradeRequest.getHttpServletRequest(); } /** - * @return The request parameter map - * @see ServletRequest#getParameterMap() + * @return The requested Locale + * @see HttpServletRequest#getLocale() */ - public Map> getParameterMap() + public Locale getLocale() { - return upgradeRequest.getParameterMap(); + return upgradeRequest.getLocale(); } /** - * @return WebSocket protocol version from "Sec-WebSocket-Version" header + * @return The requested Locales + * @see HttpServletRequest#getLocales() */ - public String getProtocolVersion() + public Enumeration getLocales() { - return upgradeRequest.getProtocolVersion(); + return upgradeRequest.getLocales(); } /** - * @return The request query string - * @see HttpServletRequest#getQueryString() + * @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 String getQueryString() + public SocketAddress getLocalSocketAddress() { - return upgradeRequest.getQueryString(); + return upgradeRequest.getLocalSocketAddress(); } /** @@ -225,15 +223,6 @@ public String getRequestPath() return upgradeRequest.getRequestPath(); } - /** - * @return The request URI - * @see HttpServletRequest#getRequestURL() - */ - public URI getRequestURI() - { - return upgradeRequest.getRequestURI(); - } - /** * @param name Attribute name * @return Attribute value or null @@ -261,50 +250,6 @@ public Map> 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 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(); - } - /** * @param role The user role * @return True if the requests user has the role diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeResponse.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeResponse.java index 01e015302ed9..45bd1b9a8995 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeResponse.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeResponse.java @@ -24,89 +24,87 @@ 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.util.server.internal.ServerUpgradeResponse; -public class JettyServerUpgradeResponse +public class JettyServerUpgradeResponse implements UpgradeResponse { - private ServletUpgradeResponse upgradeResponse; + private final ServerUpgradeResponse upgradeResponse; - JettyServerUpgradeResponse(ServletUpgradeResponse response) + JettyServerUpgradeResponse(ServerUpgradeResponse response) { upgradeResponse = response; } + @Override public void addHeader(String name, String value) { upgradeResponse.addHeader(name, value); } + @Override public void setHeader(String name, String value) { upgradeResponse.setHeader(name, value); } - public void setHeader(String name, List values) - { - upgradeResponse.setHeader(name, values); - } - + @Override public String getAcceptedSubProtocol() { return upgradeResponse.getAcceptedSubProtocol(); } + @Override public List getExtensions() { return upgradeResponse.getExtensions().stream().map(JettyExtensionConfig::new).collect(Collectors.toList()); } + @Override public String getHeader(String name) { return upgradeResponse.getHeader(name); } + @Override public Set getHeaderNames() { return upgradeResponse.getHeaderNames(); } - public Map> getHeadersMap() + @Override + public Map> getHeaders() { return upgradeResponse.getHeadersMap(); } + @Override public List getHeaders(String name) { return upgradeResponse.getHeaders(name); } + @Override 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); - } - + @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 configs) { upgradeResponse.setExtensions(configs.stream() @@ -114,8 +112,24 @@ public void setExtensions(List configs) .collect(Collectors.toList())); } + @Override public void setStatusCode(int statusCode) { upgradeResponse.setStatusCode(statusCode); } + + public void setHeader(String name, List values) + { + upgradeResponse.setHeader(name, values); + } + + public boolean isCommitted() + { + return upgradeResponse.isCommitted(); + } + + public void sendError(int statusCode, String message) throws IOException + { + upgradeResponse.sendError(statusCode, message); + } } diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java index be184470323d..10a84a3dc2e6 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java @@ -35,8 +35,8 @@ 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,7 +276,7 @@ private JettyWebSocketCreator getJettyWebSocketCreator() } @Override - public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) + public Object createWebSocket(ServerUpgradeRequest req, ServerUpgradeResponse resp) { return creator.createWebSocket(new JettyServerUpgradeRequest(req), new JettyServerUpgradeResponse(resp)); } diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java index e1f57d3f6503..97dfd7d02654 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java @@ -28,8 +28,8 @@ 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 { @@ -45,7 +45,7 @@ public JettyServerFrameHandlerFactory(WebSocketContainer container) } @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)); diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java index 31431f250f49..8af72e2749a9 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java @@ -28,13 +28,13 @@ 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; +import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeRequest; public class UpgradeRequestAdapter implements UpgradeRequest { - private final ServletUpgradeRequest _servletRequest; + private final ServerUpgradeRequest _servletRequest; - public UpgradeRequestAdapter(ServletUpgradeRequest servletRequest) + public UpgradeRequestAdapter(ServerUpgradeRequest servletRequest) { _servletRequest = servletRequest; } diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeResponseAdapter.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeResponseAdapter.java index 586d78e91c1f..680b89099ac3 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeResponseAdapter.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeResponseAdapter.java @@ -27,13 +27,13 @@ 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.util.server.internal.ServerUpgradeResponse; public class UpgradeResponseAdapter implements UpgradeResponse { - private final ServletUpgradeResponse servletResponse; + private final ServerUpgradeResponse servletResponse; - public UpgradeResponseAdapter(ServletUpgradeResponse servletResponse) + public UpgradeResponseAdapter(ServerUpgradeResponse servletResponse) { this.servletResponse = servletResponse; } diff --git a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/FrameHandlerFactory.java b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/FrameHandlerFactory.java index bebcf7fe2039..1eb7c367fee8 100644 --- a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/FrameHandlerFactory.java +++ b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/FrameHandlerFactory.java @@ -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); } diff --git a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServletUpgradeRequest.java b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServerUpgradeRequest.java similarity index 98% rename from jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServletUpgradeRequest.java rename to jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServerUpgradeRequest.java index a4418a9e6e7f..81a9b31e98f5 100644 --- a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServletUpgradeRequest.java +++ b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServerUpgradeRequest.java @@ -46,7 +46,7 @@ /** * 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 cookies; private Map> parameterMap; - public ServletUpgradeRequest(Negotiation negotiation) throws BadMessageException + public ServerUpgradeRequest(Negotiation negotiation) throws BadMessageException { this.negotiation = negotiation; HttpServletRequest httpRequest = negotiation.getRequest(); diff --git a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServletUpgradeResponse.java b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServerUpgradeResponse.java similarity index 98% rename from jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServletUpgradeResponse.java rename to jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServerUpgradeResponse.java index f78615f46c6d..730959062588 100644 --- a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServletUpgradeResponse.java +++ b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/ServerUpgradeResponse.java @@ -36,12 +36,12 @@ /** * 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(); diff --git a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/UpgradeHttpServletRequest.java b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/UpgradeHttpServletRequest.java index 72eafaff707f..93482fcc5a55 100644 --- a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/UpgradeHttpServletRequest.java +++ b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/UpgradeHttpServletRequest.java @@ -81,7 +81,7 @@ public class UpgradeHttpServletRequest implements HttpServletRequest private final Map attributes = new HashMap<>(2); private final List locales = new ArrayList<>(2); - private HttpSession session; + private final HttpSession session; private final InetSocketAddress localAddress; private final String localName; diff --git a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/WebSocketCreator.java b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/WebSocketCreator.java index b991530193fc..9479a66d3676 100644 --- a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/WebSocketCreator.java +++ b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/WebSocketCreator.java @@ -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); } diff --git a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/WebSocketMapping.java b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/WebSocketMapping.java index d76cbd53e9fe..49283dbf8e1d 100644 --- a/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/WebSocketMapping.java +++ b/jetty-websocket/websocket-util-server/src/main/java/org/eclipse/jetty/websocket/util/server/internal/WebSocketMapping.java @@ -265,8 +265,8 @@ public FrameHandler negotiate(Negotiation negotiation) throws IOException 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 result = new AtomicReference<>(); ((ContextHandler.Context)servletContext).getContextHandler().handle(() -> From ce8cb063ead5398a5e8c0d8b11cc7924dd214239 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 30 Jul 2020 17:34:17 +1000 Subject: [PATCH 5/6] Issue #5044 - extend Jetty WS API Request/Response interfaces for jetty-websocket-server Signed-off-by: Lachlan Roberts --- .../jetty/websocket/api/UpgradeRequest.java | 9 - .../jetty/websocket/api/UpgradeResponse.java | 62 ----- .../client/ClientUpgradeRequest.java | 6 - .../DelegatedJettyClientUpgradeRequest.java | 6 - .../DelegatedJettyClientUpgradeResponse.java | 39 +-- .../server/JettyServerUpgradeRequest.java | 198 ++------------- .../server/JettyServerUpgradeResponse.java | 195 +++++++-------- .../server/JettyWebSocketServerContainer.java | 6 +- .../server/JettyWebSocketServlet.java | 4 +- .../DelegatedServerUpgradeRequest.java | 235 ++++++++++++++++++ ...va => DelegatedServerUpgradeResponse.java} | 67 +++-- .../JettyServerFrameHandlerFactory.java | 4 +- .../internal/UpgradeRequestAdapter.java | 157 ------------ .../websocket/tests/WebSocketStatsTest.java | 4 +- 14 files changed, 396 insertions(+), 596 deletions(-) create mode 100644 jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/DelegatedServerUpgradeRequest.java rename jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/{UpgradeResponseAdapter.java => DelegatedServerUpgradeResponse.java} (55%) delete mode 100644 jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java diff --git a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java index 89090c0713e4..b96f9e673735 100644 --- a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java @@ -148,15 +148,6 @@ public interface UpgradeRequest */ URI getRequestURI(); - /** - * Access the Servlet HTTP Session (if present) - *

- * 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. * diff --git a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeResponse.java b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeResponse.java index 922f3764edc9..6a8ab84dc149 100644 --- a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeResponse.java +++ b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeResponse.java @@ -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 @@ */ 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. - *

- * This means that the websocket endpoint was valid, but the conditions to use a WebSocket resulted in a forbidden - * access. - *

- * 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. - *

- * Notes: - *

    - *
  • 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
  • - *
  • 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.
  • - *
- * - * @param extensions the list of extensions to use. - */ - void setExtensions(List extensions); - - /** - * Set a header - *

- * 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); } diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java index db550f1fcee5..06dc403d96df 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java @@ -167,12 +167,6 @@ public URI getRequestURI() return requestURI; } - @Override - public Object getSession() - { - throw new UnsupportedOperationException("HttpSession not available on Client request"); - } - @Override public List getSubProtocols() { diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java index f245e9bcef15..06a18e11d619 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeRequest.java @@ -162,12 +162,6 @@ public boolean isSecure() return HttpClient.isSchemeSecure(delegate.getScheme()); } - @Override - public Object getSession() - { - return null; - } - @Override public Principal getUserPrincipal() { diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeResponse.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeResponse.java index fb86e2fea994..79eb3f5d54c0 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeResponse.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/DelegatedJettyClientUpgradeResponse.java @@ -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; @@ -79,24 +78,6 @@ public int getStatusCode() 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 getExtensions() { @@ -104,24 +85,6 @@ public List getExtensions() if (rawExtensions == null || rawExtensions.isEmpty()) return Collections.emptyList(); - return rawExtensions.stream().map((parameterizedName) -> ExtensionConfig.parse(parameterizedName)).collect(Collectors.toList()); - } - - @Override - public void setExtensions(List extensions) - { - - } - - @Override - public void setHeader(String name, String value) - { - - } - - @Override - public void setStatusCode(int statusCode) - { - + return rawExtensions.stream().map(ExtensionConfig::parse).collect(Collectors.toList()); } } diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java index ef58f270753f..53c2bac0a2ec 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeRequest.java @@ -18,255 +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.UpgradeRequest; -import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; -import org.eclipse.jetty.websocket.common.JettyExtensionConfig; -import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeRequest; -public class JettyServerUpgradeRequest implements UpgradeRequest +public interface JettyServerUpgradeRequest extends UpgradeRequest { - private final ServerUpgradeRequest upgradeRequest; - - JettyServerUpgradeRequest(ServerUpgradeRequest request) - { - upgradeRequest = request; - } - - @Override - public List getCookies() - { - return upgradeRequest.getCookies(); - } - - @Override - public List 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> getHeaders() - { - return upgradeRequest.getHeadersMap(); - } - - @Override - public List 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> 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 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(); - } + /** + * Access the Servlet HTTP Session (if present) + *

+ * 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(); - } + X509Certificate[] getCertificates(); /** * @return Immutable version of {@link HttpServletRequest} */ - public HttpServletRequest getHttpServletRequest() - { - return upgradeRequest.getHttpServletRequest(); - } + 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 getLocales() - { - return upgradeRequest.getLocales(); - } + Enumeration 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(); - } + 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(); - } + 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 getServletAttributes() - { - return upgradeRequest.getServletAttributes(); - } + Map getServletAttributes(); /** * @return Request parameters * @see ServletRequest#getParameterMap() */ - public Map> getServletParameters() - { - return upgradeRequest.getServletParameters(); - } + Map> 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); } diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeResponse.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeResponse.java index 45bd1b9a8995..bd6fe1c9e7e1 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeResponse.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerUpgradeResponse.java @@ -20,116 +20,97 @@ 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.ServerUpgradeResponse; -public class JettyServerUpgradeResponse implements UpgradeResponse +public interface JettyServerUpgradeResponse extends UpgradeResponse { - private final ServerUpgradeResponse upgradeResponse; - - JettyServerUpgradeResponse(ServerUpgradeResponse response) - { - upgradeResponse = response; - } - - @Override - public void addHeader(String name, String value) - { - upgradeResponse.addHeader(name, value); - } - - @Override - public void setHeader(String name, String value) - { - upgradeResponse.setHeader(name, value); - } - - @Override - public String getAcceptedSubProtocol() - { - return upgradeResponse.getAcceptedSubProtocol(); - } - - @Override - public List getExtensions() - { - return upgradeResponse.getExtensions().stream().map(JettyExtensionConfig::new).collect(Collectors.toList()); - } - - @Override - public String getHeader(String name) - { - return upgradeResponse.getHeader(name); - } - - @Override - public Set getHeaderNames() - { - return upgradeResponse.getHeaderNames(); - } - - @Override - public Map> getHeaders() - { - return upgradeResponse.getHeadersMap(); - } - - @Override - public List 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 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) - { - upgradeResponse.setStatusCode(statusCode); - } - - public void setHeader(String name, List values) - { - upgradeResponse.setHeader(name, values); - } - - public boolean isCommitted() - { - return upgradeResponse.isCommitted(); - } - - public void sendError(int statusCode, String message) throws IOException - { - upgradeResponse.sendError(statusCode, message); - } + /** + * Add a header value to the response. + * + * @param name the header name + * @param value the header value + */ + void addHeader(String name, String value); + + /** + * Set a header + *

+ * Overrides previous value of header (if set) + * + * @param name the header name + * @param value the header value + */ + void setHeader(String name, String value); + + /** + * Set a header + *

+ * Overrides previous value of header (if set) + * + * @param name the header name + * @param values the header values + */ + void setHeader(String name, List values); + + /** + * Issue a forbidden upgrade response. + *

+ * This means that the websocket endpoint was valid, but the conditions to use a WebSocket resulted in a forbidden + * access. + *

+ * 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; + + /** + * 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; + + /** + * 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. + *

+ * Notes: + *

    + *
  • 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
  • + *
  • 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.
  • + *
+ * + * @param extensions the list of extensions to use. + */ + void setExtensions(List extensions); + + /** + * Set the HTTP Response status code + * + * @param statusCode the status code + */ + void setStatusCode(int 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(); } diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServerContainer.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServerContainer.java index 5eadef61ef3b..453fbfd962a0 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServerContainer.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServerContainer.java @@ -41,6 +41,8 @@ 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.internal.FrameHandlerFactory; @@ -87,7 +89,6 @@ public static JettyWebSocketServerContainer ensureContainer(ServletContext servl private static final Logger LOG = LoggerFactory.getLogger(JettyWebSocketServerContainer.class); private final WebSocketMapping webSocketMapping; - private final WebSocketComponents webSocketComponents; private final FrameHandlerFactory frameHandlerFactory; private final Executor executor; private final Configuration.ConfigurationCustomizer customizer = new Configuration.ConfigurationCustomizer(); @@ -105,7 +106,6 @@ public static JettyWebSocketServerContainer ensureContainer(ServletContext servl JettyWebSocketServerContainer(ServletContextHandler contextHandler, WebSocketMapping webSocketMapping, WebSocketComponents webSocketComponents, Executor executor) { this.webSocketMapping = webSocketMapping; - this.webSocketComponents = webSocketComponents; this.executor = executor; // Ensure there is a FrameHandlerFactory @@ -129,7 +129,7 @@ public void addMapping(String pathSpec, JettyWebSocketCreator creator) throw new WebSocketException("Duplicate WebSocket Mapping for PathSpec"); 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); } diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java index 10a84a3dc2e6..0cbdd6b12127 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java @@ -32,6 +32,8 @@ 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; @@ -278,7 +280,7 @@ private JettyWebSocketCreator getJettyWebSocketCreator() @Override 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)); } } } diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/DelegatedServerUpgradeRequest.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/DelegatedServerUpgradeRequest.java new file mode 100644 index 000000000000..2973aa53eba2 --- /dev/null +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/DelegatedServerUpgradeRequest.java @@ -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 getCookies() + { + return upgradeRequest.getCookies(); + } + + @Override + public List 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> getHeaders() + { + return upgradeRequest.getHeadersMap(); + } + + @Override + public List 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> 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 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 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 getServletAttributes() + { + return upgradeRequest.getServletAttributes(); + } + + @Override + public Map> 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); + } +} diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeResponseAdapter.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/DelegatedServerUpgradeResponse.java similarity index 55% rename from jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeResponseAdapter.java rename to jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/DelegatedServerUpgradeResponse.java index 680b89099ac3..e72af1202aa4 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeResponseAdapter.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/DelegatedServerUpgradeResponse.java @@ -24,100 +24,115 @@ 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.server.JettyServerUpgradeResponse; import org.eclipse.jetty.websocket.util.server.internal.ServerUpgradeResponse; -public class UpgradeResponseAdapter implements UpgradeResponse +public class DelegatedServerUpgradeResponse implements JettyServerUpgradeResponse { - private final ServerUpgradeResponse servletResponse; + private final ServerUpgradeResponse upgradeResponse; - public UpgradeResponseAdapter(ServerUpgradeResponse servletResponse) + public DelegatedServerUpgradeResponse(ServerUpgradeResponse response) { - this.servletResponse = servletResponse; + upgradeResponse = response; } @Override public void addHeader(String name, String value) { - this.servletResponse.addHeader(name, value); + upgradeResponse.addHeader(name, value); + } + + @Override + public void setHeader(String name, String value) + { + upgradeResponse.setHeader(name, value); + } + + @Override + public void setHeader(String name, List values) + { + upgradeResponse.setHeader(name, values); } @Override public String getAcceptedSubProtocol() { - return this.servletResponse.getAcceptedSubProtocol(); + return upgradeResponse.getAcceptedSubProtocol(); } @Override public List getExtensions() { - return this.servletResponse.getExtensions().stream() - .map((ext) -> new JettyExtensionConfig(ext.getName(), ext.getParameters())) - .collect(Collectors.toList()); + return upgradeResponse.getExtensions().stream().map(JettyExtensionConfig::new).collect(Collectors.toList()); } @Override public String getHeader(String name) { - return this.servletResponse.getHeader(name); + return upgradeResponse.getHeader(name); } @Override public Set getHeaderNames() { - return this.servletResponse.getHeaderNames(); + return upgradeResponse.getHeaderNames(); } @Override public Map> getHeaders() { - return this.servletResponse.getHeadersMap(); + return upgradeResponse.getHeadersMap(); } @Override public List getHeaders(String name) { - return this.servletResponse.getHeaders(name); + return upgradeResponse.getHeaders(name); } @Override public int getStatusCode() { - return this.servletResponse.getStatusCode(); + return upgradeResponse.getStatusCode(); } @Override public void sendForbidden(String message) throws IOException { - this.servletResponse.sendForbidden(message); + upgradeResponse.sendForbidden(message); } @Override public void setAcceptedSubProtocol(String protocol) { - this.servletResponse.setAcceptedSubProtocol(protocol); + upgradeResponse.setAcceptedSubProtocol(protocol); } @Override - public void setExtensions(List extensions) + public void setExtensions(List configs) { - List coreExtensionConfigs = extensions.stream() - .map((ext) -> new org.eclipse.jetty.websocket.core.ExtensionConfig(ext.getName(), ext.getParameters())) - .collect(Collectors.toList()); - this.servletResponse.setExtensions(coreExtensionConfigs); + upgradeResponse.setExtensions(configs.stream() + .map(c -> new org.eclipse.jetty.websocket.core.ExtensionConfig(c.getName(), c.getParameters())) + .collect(Collectors.toList())); } @Override - public void setHeader(String name, String value) + public void setStatusCode(int statusCode) { - this.servletResponse.setHeader(name, value); + upgradeResponse.setStatusCode(statusCode); } @Override - public void setStatusCode(int statusCode) + public boolean isCommitted() + { + return upgradeResponse.isCommitted(); + } + + @Override + public void sendError(int statusCode, String message) throws IOException { - this.servletResponse.setStatusCode(statusCode); + upgradeResponse.sendError(statusCode, message); } } diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java index 97dfd7d02654..b7e594aedb16 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/JettyServerFrameHandlerFactory.java @@ -48,8 +48,8 @@ public JettyServerFrameHandlerFactory(WebSocketContainer container) 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; } diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java deleted file mode 100644 index 8af72e2749a9..000000000000 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/internal/UpgradeRequestAdapter.java +++ /dev/null @@ -1,157 +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.ServerUpgradeRequest; - -public class UpgradeRequestAdapter implements UpgradeRequest -{ - private final ServerUpgradeRequest _servletRequest; - - public UpgradeRequestAdapter(ServerUpgradeRequest servletRequest) - { - _servletRequest = servletRequest; - } - - @Override - public List getCookies() - { - return _servletRequest.getCookies(); - } - - @Override - public List getExtensions() - { - return _servletRequest.getExtensions().stream() - .map((ext) -> new JettyExtensionConfig(ext.getName(), ext.getParameters())) - .collect(Collectors.toList()); - } - - @Override - public String getHeader(String name) - { - return _servletRequest.getHeader(name); - } - - @Override - public int getHeaderInt(String name) - { - return _servletRequest.getHeaderInt(name); - } - - @Override - public Map> getHeaders() - { - return _servletRequest.getHeadersMap(); - } - - @Override - public List getHeaders(String name) - { - return _servletRequest.getHeaders(name); - } - - @Override - public String getHost() - { - return _servletRequest.getHost(); - } - - @Override - public String getHttpVersion() - { - return _servletRequest.getHttpVersion(); - } - - @Override - public String getMethod() - { - return _servletRequest.getMethod(); - } - - @Override - public String getOrigin() - { - return _servletRequest.getOrigin(); - } - - @Override - public Map> getParameterMap() - { - return _servletRequest.getParameterMap(); - } - - @Override - public String getProtocolVersion() - { - return _servletRequest.getProtocolVersion(); - } - - @Override - public String getQueryString() - { - return _servletRequest.getQueryString(); - } - - @Override - public URI getRequestURI() - { - return _servletRequest.getRequestURI(); - } - - @Override - public Object getSession() - { - return _servletRequest.getSession(); - } - - @Override - public List getSubProtocols() - { - return _servletRequest.getSubProtocols(); - } - - @Override - public Principal getUserPrincipal() - { - return _servletRequest.getUserPrincipal(); - } - - @Override - public boolean hasSubProtocol(String test) - { - return _servletRequest.hasSubProtocol(test); - } - - @Override - public boolean isSecure() - { - return _servletRequest.isSecure(); - } -} diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStatsTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStatsTest.java index ecf1fdb652a4..a84f7550be20 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStatsTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStatsTest.java @@ -65,8 +65,8 @@ public void configure(JettyWebSocketServletFactory factory) 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 From fd5c07eceba5ad41b6172b0f2182e868b17284aa Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 6 Aug 2020 08:25:40 +1000 Subject: [PATCH 6/6] removed dangling javadoc comment Signed-off-by: Lachlan Roberts --- .../common/JavaxWebSocketFrameHandler.java | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java index 4fe629afd7c6..fb46a2860ef8 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java @@ -65,33 +65,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. - *

- * 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. - *

- *

- * Can be null if client side, or no named variables were configured on the server side. - *

- */ - /** - * The Map of path parameter values that arrived during the server side upgrade process. - *

- * 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. - *

- *

- * 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). - *

- *

- * 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. - *

- */ private MethodHandle openHandle; private MethodHandle closeHandle; private MethodHandle errorHandle;