Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Filter name to identify the WebSocketUpgradeFilter. #5648

Merged
merged 10 commits into from
Nov 23, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.eclipse.jetty.websocket.core.server.WebSocketServerComponents;
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer;
import org.eclipse.jetty.websocket.util.server.WebSocketUpgradeFilter;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMappings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -153,7 +153,7 @@ private static ServerContainer initialize(ServletContextHandler context)
{
WebSocketComponents components = WebSocketServerComponents.ensureWebSocketComponents(context.getServer(), context.getServletContext());
FilterHolder filterHolder = WebSocketUpgradeFilter.ensureFilter(context.getServletContext());
WebSocketMapping mapping = WebSocketMapping.ensureMapping(context.getServletContext(), WebSocketMapping.DEFAULT_KEY);
WebSocketMappings mapping = WebSocketMappings.ensureMapping(context.getServletContext());
serverContainer = JavaxWebSocketServerContainer.ensureContainer(context.getServletContext());

if (LOG.isDebugEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
import org.eclipse.jetty.websocket.util.InvalidSignatureException;
import org.eclipse.jetty.websocket.util.ReflectUtils;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMappings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -98,7 +98,7 @@ public static JavaxWebSocketServerContainer ensureContainer(ServletContext servl

// Create the Jetty ServerContainer implementation
container = new JavaxWebSocketServerContainer(
WebSocketMapping.ensureMapping(servletContext, WebSocketMapping.DEFAULT_KEY),
WebSocketMappings.ensureMapping(servletContext),
WebSocketServerComponents.getWebSocketComponents(servletContext),
coreClientSupplier);
contextHandler.addManaged(container);
Expand All @@ -109,39 +109,39 @@ public static JavaxWebSocketServerContainer ensureContainer(ServletContext servl
return container;
}

private final WebSocketMapping webSocketMapping;
private final WebSocketMappings webSocketMappings;
private final JavaxWebSocketServerFrameHandlerFactory frameHandlerFactory;
private List<Class<?>> deferredEndpointClasses;
private List<ServerEndpointConfig> deferredEndpointConfigs;

/**
* Main entry point for {@link JavaxWebSocketServletContainerInitializer}.
*
* @param webSocketMapping the {@link WebSocketMapping} that this container belongs to
* @param webSocketMappings the {@link WebSocketMappings} that this container belongs to
*/
public JavaxWebSocketServerContainer(WebSocketMapping webSocketMapping)
public JavaxWebSocketServerContainer(WebSocketMappings webSocketMappings)
{
this(webSocketMapping, new WebSocketComponents());
this(webSocketMappings, new WebSocketComponents());
}

public JavaxWebSocketServerContainer(WebSocketMapping webSocketMapping, WebSocketComponents components)
public JavaxWebSocketServerContainer(WebSocketMappings webSocketMappings, WebSocketComponents components)
{
super(components);
this.webSocketMapping = webSocketMapping;
this.webSocketMappings = webSocketMappings;
this.frameHandlerFactory = new JavaxWebSocketServerFrameHandlerFactory(this);
}

/**
* Main entry point for {@link JavaxWebSocketServletContainerInitializer}.
*
* @param webSocketMapping the {@link WebSocketMapping} that this container belongs to
* @param webSocketMappings the {@link WebSocketMappings} that this container belongs to
* @param components the {@link WebSocketComponents} instance to use
* @param coreClientSupplier the supplier of the {@link WebSocketCoreClient} instance to use
*/
public JavaxWebSocketServerContainer(WebSocketMapping webSocketMapping, WebSocketComponents components, Function<WebSocketComponents, WebSocketCoreClient> coreClientSupplier)
public JavaxWebSocketServerContainer(WebSocketMappings webSocketMappings, WebSocketComponents components, Function<WebSocketComponents, WebSocketCoreClient> coreClientSupplier)
{
super(components, coreClientSupplier);
this.webSocketMapping = webSocketMapping;
this.webSocketMappings = webSocketMappings;
this.frameHandlerFactory = new JavaxWebSocketServerFrameHandlerFactory(this);
}

Expand Down Expand Up @@ -264,7 +264,7 @@ private void addEndpointMapping(ServerEndpointConfig config) throws DeploymentEx
frameHandlerFactory.getMetadata(config.getEndpointClass(), config);
JavaxWebSocketCreator creator = new JavaxWebSocketCreator(this, config, getExtensionRegistry());
PathSpec pathSpec = new UriTemplatePathSpec(config.getPath());
webSocketMapping.addMapping(pathSpec, creator, frameHandlerFactory, defaultCustomizer);
webSocketMappings.addMapping(pathSpec, creator, frameHandlerFactory, defaultCustomizer);
}
catch (InvalidSignatureException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void testEcho() throws Exception
{
wsb.start();

FilterHolder filterWebXml = app.getWebAppContext().getServletHandler().getFilter("wsuf-test");
FilterHolder filterWebXml = app.getWebAppContext().getServletHandler().getFilter(WebSocketUpgradeFilter.class.getName());
assertThat("Filter[wsuf-test]", filterWebXml, notNullValue());

FilterHolder filterSCI = app.getWebAppContext().getServletHandler().getFilter("Jetty_WebSocketUpgradeFilter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@
</context-param>

<filter>
<filter-name>wsuf-test</filter-name>
<filter-name>org.eclipse.jetty.websocket.util.server.WebSocketUpgradeFilter</filter-name>
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
<filter-class>org.eclipse.jetty.websocket.util.server.WebSocketUpgradeFilter</filter-class>
<init-param>
<param-name>jetty.websocket.WebSocketMapping</param-name>
<param-value>jetty.websocket.defaultMapping</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>wsuf-test</filter-name>
<filter-name>org.eclipse.jetty.websocket.util.server.WebSocketUpgradeFilter</filter-name>
<url-pattern>/echo/*</url-pattern>
</filter-mapping>
</web-app>
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import org.eclipse.jetty.websocket.util.ReflectUtils;
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.WebSocketMapping;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMappings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -77,7 +77,7 @@ public static JettyWebSocketServerContainer ensureContainer(ServletContext servl
// Create the Jetty ServerContainer implementation
container = new JettyWebSocketServerContainer(
contextHandler,
WebSocketMapping.ensureMapping(servletContext, WebSocketMapping.DEFAULT_KEY),
WebSocketMappings.ensureMapping(servletContext),
WebSocketServerComponents.getWebSocketComponents(servletContext), executor);
servletContext.setAttribute(JETTY_WEBSOCKET_CONTAINER_ATTRIBUTE, container);
contextHandler.addManaged(container);
Expand All @@ -90,7 +90,7 @@ public static JettyWebSocketServerContainer ensureContainer(ServletContext servl
private static final Logger LOG = LoggerFactory.getLogger(JettyWebSocketServerContainer.class);

private final ServletContextHandler contextHandler;
private final WebSocketMapping webSocketMapping;
private final WebSocketMappings webSocketMappings;
private final WebSocketComponents components;
private final FrameHandlerFactory frameHandlerFactory;
private final Executor executor;
Expand All @@ -102,14 +102,14 @@ public static JettyWebSocketServerContainer ensureContainer(ServletContext servl
/**
* Main entry point for {@link JettyWebSocketServletContainerInitializer}.
*
* @param webSocketMapping the {@link WebSocketMapping} that this container belongs to
* @param webSocketMappings the {@link WebSocketMappings} that this container belongs to
* @param components the {@link WebSocketComponents} instance to use
* @param executor the {@link Executor} to use
*/
JettyWebSocketServerContainer(ServletContextHandler contextHandler, WebSocketMapping webSocketMapping, WebSocketComponents components, Executor executor)
JettyWebSocketServerContainer(ServletContextHandler contextHandler, WebSocketMappings webSocketMappings, WebSocketComponents components, Executor executor)
{
this.contextHandler = contextHandler;
this.webSocketMapping = webSocketMapping;
this.webSocketMappings = webSocketMappings;
this.executor = executor;
this.components = components;

Expand All @@ -129,12 +129,12 @@ public static JettyWebSocketServerContainer ensureContainer(ServletContext servl

public void addMapping(String pathSpec, JettyWebSocketCreator creator)
{
PathSpec ps = WebSocketMapping.parsePathSpec(pathSpec);
if (webSocketMapping.getMapping(ps) != null)
PathSpec ps = WebSocketMappings.parsePathSpec(pathSpec);
if (webSocketMappings.getMapping(ps) != null)
throw new WebSocketException("Duplicate WebSocket Mapping for PathSpec");

WebSocketUpgradeFilter.ensureFilter(contextHandler.getServletContext());
webSocketMapping.addMapping(ps,
webSocketMappings.addMapping(ps,
(req, resp) -> creator.createWebSocket(new DelegatedServerUpgradeRequest(req), new DelegatedServerUpgradeResponse(resp)),
frameHandlerFactory, customizer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
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.eclipse.jetty.websocket.util.server.internal.WebSocketMappings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Abstract Servlet used to bridge the Servlet API to the WebSocket API.
* <p>
* To use this servlet, you will be required to register your websockets with the {@link WebSocketMapping} so that it can create your websockets under the
* To use this servlet, you will be required to register your websockets with the {@link WebSocketMappings} so that it can create your websockets under the
* appropriate conditions.
* </p>
* <p>The most basic implementation would be as follows:</p>
Expand All @@ -68,11 +68,11 @@
* }
* </pre>
* <p>
* Only request that conforms to a "WebSocket: Upgrade" handshake request will trigger the {@link WebSocketMapping} handling of creating
* Only request that conforms to a "WebSocket: Upgrade" handshake request will trigger the {@link WebSocketMappings} handling of creating
* WebSockets. All other requests are treated as normal servlet requests. The configuration defined by this servlet init parameters will
* be used as the customizer for any mappings created by {@link JettyWebSocketServletFactory#addMapping(String, JettyWebSocketCreator)} during
* {@link #configure(JettyWebSocketServletFactory)} calls. The request upgrade may be peformed by this servlet, or is may be performed by a
* {@link WebSocketUpgradeFilter} instance that will share the same {@link WebSocketMapping} instance. If the filter is used, then the
* {@link WebSocketUpgradeFilter} instance that will share the same {@link WebSocketMappings} instance. If the filter is used, then the
* filter configuraton is used as the default configuration prior to this servlets configuration being applied.
* </p>
* <p>
Expand All @@ -99,7 +99,7 @@ public abstract class JettyWebSocketServlet extends HttpServlet
private static final Logger LOG = LoggerFactory.getLogger(JettyWebSocketServlet.class);
private final CustomizedWebSocketServletFactory customizer = new CustomizedWebSocketServletFactory();

private WebSocketMapping mapping;
private WebSocketMappings mapping;
private WebSocketComponents components;

/**
Expand Down Expand Up @@ -133,7 +133,7 @@ public void init() throws ServletException
ServletContext servletContext = getServletContext();

components = WebSocketServerComponents.getWebSocketComponents(servletContext);
mapping = new WebSocketMapping(components);
mapping = new WebSocketMappings(components);

String max = getInitParameter("idleTimeout");
if (max == null)
Expand Down Expand Up @@ -208,7 +208,7 @@ public Set<String> getAvailableExtensionNames()
@Override
public void addMapping(String pathSpec, JettyWebSocketCreator creator)
{
mapping.addMapping(WebSocketMapping.parsePathSpec(pathSpec), new WrappedJettyCreator(creator), getFactory(), this);
mapping.addMapping(WebSocketMappings.parsePathSpec(pathSpec), new WrappedJettyCreator(creator), getFactory(), this);
}

@Override
Expand Down Expand Up @@ -249,7 +249,7 @@ public void setCreator(JettyWebSocketCreator creator)
@Override
public JettyWebSocketCreator getMapping(String pathSpec)
{
WebSocketCreator creator = mapping.getMapping(WebSocketMapping.parsePathSpec(pathSpec));
WebSocketCreator creator = mapping.getMapping(WebSocketMappings.parsePathSpec(pathSpec));
if (creator instanceof WrappedJettyCreator)
return ((WrappedJettyCreator)creator).getJettyWebSocketCreator();

Expand All @@ -259,7 +259,7 @@ public JettyWebSocketCreator getMapping(String pathSpec)
@Override
public boolean removeMapping(String pathSpec)
{
return mapping.removeMapping(WebSocketMapping.parsePathSpec(pathSpec));
return mapping.removeMapping(WebSocketMappings.parsePathSpec(pathSpec));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.server.WebSocketServerComponents;
import org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMapping;
import org.eclipse.jetty.websocket.util.server.internal.WebSocketMappings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -48,7 +48,7 @@ public interface Configurator
* during the {@link ServletContext} initialization phase.
*
* @param context the context to add listener to.
* @param configurator a lambda that is called to allow the {@link WebSocketMapping} to
* @param configurator a lambda that is called to allow the {@link WebSocketMappings} to
* be configured during {@link ServletContext} initialization phase
*/
public static void configure(ServletContextHandler context, Configurator configurator)
Expand Down
Loading