WebSocket - refactoring bits and pieces to make testing easier.
This commit is contained in:
parent
ed95ffbfea
commit
dfd3d5af29
|
@ -18,20 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.jsr356.server;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.webapp.AbstractConfiguration;
|
||||
import org.eclipse.jetty.webapp.Configuration;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.DiscoveredEndpoints;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.ServerEndpointAnnotationHandler;
|
||||
import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
|
||||
|
@ -41,22 +32,9 @@ import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
|
|||
*/
|
||||
public class WebSocketConfiguration extends AbstractConfiguration
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(WebSocketConfiguration.class);
|
||||
|
||||
public static ServerContainer configureContext(ServletContextHandler context)
|
||||
{
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
|
||||
WebSocketUpgradeFilter filter = new WebSocketUpgradeFilter(policy);
|
||||
FilterHolder fholder = new FilterHolder(filter);
|
||||
fholder.setName("Jetty_WebSocketUpgradeFilter");
|
||||
fholder.setDisplayName("WebSocket Upgrade Filter");
|
||||
String pathSpec = "/*";
|
||||
context.addFilter(fholder,pathSpec,EnumSet.of(DispatcherType.REQUEST));
|
||||
LOG.debug("Adding {} mapped to {} to {}",filter,pathSpec,context);
|
||||
|
||||
// Store reference to the WebSocketUpgradeFilter
|
||||
context.setAttribute(WebSocketUpgradeFilter.class.getName(),filter);
|
||||
WebSocketUpgradeFilter filter = WebSocketUpgradeFilter.configureContext(context);
|
||||
|
||||
// Create the Jetty ServerContainer implementation
|
||||
ServerContainer jettyContainer = new ServerContainer(filter,filter.getFactory());
|
||||
|
|
|
@ -34,7 +34,10 @@ public abstract class ExtensionFactory implements Iterable<Class<? extends Exten
|
|||
availableExtensions = new HashMap<>();
|
||||
for (Extension ext : extensionLoader)
|
||||
{
|
||||
availableExtensions.put(ext.getName(),ext.getClass());
|
||||
if (ext != null)
|
||||
{
|
||||
availableExtensions.put(ext.getName(),ext.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,11 @@
|
|||
<artifactId>websocket-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
|
@ -63,12 +68,6 @@
|
|||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
package org.eclipse.jetty.websocket.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
|
@ -28,12 +31,15 @@ import javax.servlet.ServletResponse;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.server.pathmap.PathMappings;
|
||||
import org.eclipse.jetty.websocket.server.pathmap.PathMappings.MappedResource;
|
||||
|
@ -47,6 +53,25 @@ import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
|||
public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter, MappedWebSocketCreator, Dumpable
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(WebSocketUpgradeFilter.class);
|
||||
|
||||
public static WebSocketUpgradeFilter configureContext(ServletContextHandler context)
|
||||
{
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
|
||||
WebSocketUpgradeFilter filter = new WebSocketUpgradeFilter(policy);
|
||||
FilterHolder fholder = new FilterHolder(filter);
|
||||
fholder.setName("Jetty_WebSocketUpgradeFilter");
|
||||
fholder.setDisplayName("WebSocket Upgrade Filter");
|
||||
String pathSpec = "/*";
|
||||
context.addFilter(fholder,pathSpec,EnumSet.of(DispatcherType.REQUEST));
|
||||
LOG.debug("Adding {} mapped to {} to {}",filter,pathSpec,context);
|
||||
|
||||
// Store reference to the WebSocketUpgradeFilter
|
||||
context.setAttribute(WebSocketUpgradeFilter.class.getName(),filter);
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
private final WebSocketServerFactory factory;
|
||||
private final PathMappings<WebSocketCreator> pathmap = new PathMappings<>();
|
||||
|
||||
|
@ -66,7 +91,7 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
|
|||
public void destroy()
|
||||
{
|
||||
factory.cleanup();
|
||||
pathmap.getMappings().clear();
|
||||
pathmap.reset();
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
|
|
@ -142,6 +142,11 @@ public class PathMappings<E> implements Iterable<MappedResource<E>>, Dumpable
|
|||
{
|
||||
return mappings;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
mappings.clear();
|
||||
}
|
||||
|
||||
public MappedResource<E> getMatch(String path)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue