JSR-356 using Spec 6.4 properly for access to ServerContainer

This commit is contained in:
Joakim Erdfelt 2013-07-26 14:03:45 -07:00
parent 6076e05bf6
commit 6029826aa4
2 changed files with 21 additions and 9 deletions

View File

@ -43,7 +43,7 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
{ {
public static ServerContainer get(WebAppContext context) public static ServerContainer get(WebAppContext context)
{ {
return (ServerContainer)context.getAttribute(WebSocketConfiguration.JAVAX_WEBSOCKET_SERVER_CONTAINER); return (ServerContainer)context.getAttribute(javax.websocket.server.ServerContainer.class.getName());
} }
private final MappedWebSocketCreator mappedCreator; private final MappedWebSocketCreator mappedCreator;

View File

@ -24,6 +24,7 @@ import javax.servlet.DispatcherType;
import org.eclipse.jetty.annotations.AnnotationConfiguration; import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.servlet.FilterHolder; 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.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.webapp.AbstractConfiguration; import org.eclipse.jetty.webapp.AbstractConfiguration;
@ -36,11 +37,9 @@ import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
*/ */
public class WebSocketConfiguration extends AbstractConfiguration public class WebSocketConfiguration extends AbstractConfiguration
{ {
public static final String JAVAX_WEBSOCKET_SERVER_CONTAINER = "javax.websocket.server.ServerContainer";
private static final Logger LOG = Log.getLogger(WebSocketConfiguration.class); private static final Logger LOG = Log.getLogger(WebSocketConfiguration.class);
@Override public void configureContext(ServletContextHandler context, boolean startContainer)
public void configure(WebAppContext context) throws Exception
{ {
WebSocketUpgradeFilter filter = new WebSocketUpgradeFilter(); WebSocketUpgradeFilter filter = new WebSocketUpgradeFilter();
FilterHolder fholder = new FilterHolder(filter); FilterHolder fholder = new FilterHolder(filter);
@ -49,14 +48,27 @@ public class WebSocketConfiguration extends AbstractConfiguration
String pathSpec = "/*"; String pathSpec = "/*";
context.addFilter(fholder,pathSpec,EnumSet.of(DispatcherType.REQUEST)); context.addFilter(fholder,pathSpec,EnumSet.of(DispatcherType.REQUEST));
LOG.debug("Adding {} mapped to {} to {}",filter,pathSpec,context); LOG.debug("Adding {} mapped to {} to {}",filter,pathSpec,context);
// Store reference to the WebSocketUpgradeFilter // Store reference to the WebSocketUpgradeFilter
context.setAttribute(WebSocketUpgradeFilter.class.getName(),filter); context.setAttribute(WebSocketUpgradeFilter.class.getName(),filter);
// Store reference to the ServerContainer // Create the Jetty ServerContainer implementation
ServerContainer container = new ServerContainer(filter); ServerContainer jettyContainer = new ServerContainer(filter);
filter.setWebSocketServerFactoryListener(container); filter.setWebSocketServerFactoryListener(jettyContainer);
context.setAttribute(JAVAX_WEBSOCKET_SERVER_CONTAINER,container);
// Store a reference to the ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
context.setAttribute(javax.websocket.server.ServerContainer.class.getName(),jettyContainer);
if (startContainer)
{
jettyContainer.start();
}
}
@Override
public void configure(WebAppContext context) throws Exception
{
configureContext(context,false);
} }
@Override @Override