Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2013-09-09 02:27:15 +0000
committerGreg Wilkins2013-09-09 02:27:15 +0000
commita1cba900c5266ddba97a58f0e67e55b35418fc7e (patch)
treef063c66e262d25f9f2473410d812756b965f4854
parent400f0ce5a29d5d8e65ef8bb918026c1461a5111a (diff)
downloadorg.eclipse.jetty.project-a1cba900c5266ddba97a58f0e67e55b35418fc7e.tar.gz
org.eclipse.jetty.project-a1cba900c5266ddba97a58f0e67e55b35418fc7e.tar.xz
org.eclipse.jetty.project-a1cba900c5266ddba97a58f0e67e55b35418fc7e.zip
416812 Only start WebSocketContainer if enabled by attribute
-rw-r--r--jetty-websocket/javax-websocket-server-impl/src/main/config/etc/jetty-websockets.xml7
-rw-r--r--jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/WebSocketConfiguration.java46
-rw-r--r--jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/ServerApplicationConfigListener.java5
-rw-r--r--jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/WSServer.java1
-rw-r--r--tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/webapps/test.xml7
5 files changed, 54 insertions, 12 deletions
diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/config/etc/jetty-websockets.xml b/jetty-websocket/javax-websocket-server-impl/src/main/config/etc/jetty-websockets.xml
index 190a58e5bb..797f84efd8 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/main/config/etc/jetty-websockets.xml
+++ b/jetty-websocket/javax-websocket-server-impl/src/main/config/etc/jetty-websockets.xml
@@ -16,5 +16,12 @@
</Arg>
</Call>
</Call>
+
+ <!-- Enable/Disable JSR356 Container for all contexts -->
+ <!-- This attribute may be enabled/disabled either on the server or on individual contexts -->
+ <Call name="setAttribute">
+ <Arg>org.eclipse.jetty.websocket.jsr356</Arg>
+ <Arg type="Boolean">false</Arg>
+ </Call>
</Configure>
diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/WebSocketConfiguration.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/WebSocketConfiguration.java
index 2040ca9564..971d6d11c5 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/WebSocketConfiguration.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/WebSocketConfiguration.java
@@ -30,10 +30,15 @@ import org.eclipse.jetty.websocket.jsr356.server.deploy.ServerEndpointAnnotation
import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
/**
- * WebSocket Server Configuration component
+ * WebSocket Server Configuration component.
+ * This configuration will configure a context for JSR356 Websockets if
+ * the attribute "org.eclipse.jetty.websocket.jsr356" is set to true. This
+ * attribute may be set on an individual context or on the server to affect
+ * all deployed contexts.
*/
public class WebSocketConfiguration extends AbstractConfiguration
{
+ public static final String ENABLE="org.eclipse.jetty.websocket.jsr356";
private static final Logger LOG = Log.getLogger(WebSocketConfiguration.class);
public static ServerContainer configureContext(ServletContextHandler context)
@@ -53,27 +58,46 @@ public class WebSocketConfiguration extends AbstractConfiguration
return jettyContainer;
}
+ public static boolean isJSR356Context(WebAppContext context)
+ {
+ Object enable=context.getAttribute(ENABLE);
+ if (enable instanceof Boolean)
+ return ((Boolean)enable).booleanValue();
+
+ enable=context.getServer().getAttribute(ENABLE);
+ if (enable instanceof Boolean)
+ return ((Boolean)enable).booleanValue();
+
+ return false;
+ }
+
@Override
public void configure(WebAppContext context) throws Exception
{
- LOG.debug("Configure javax.websocket for WebApp {}",context);
- WebSocketConfiguration.configureContext(context);
+ if (isJSR356Context(context))
+ {
+ LOG.debug("Configure javax.websocket for WebApp {}",context);
+ WebSocketConfiguration.configureContext(context);
+ }
}
@Override
public void preConfigure(WebAppContext context) throws Exception
{
- boolean scanningAdded = false;
- // Add the annotation scanning handlers (if annotation scanning enabled)
- for (Configuration config : context.getConfigurations())
+ if (isJSR356Context(context))
{
- if (config instanceof AnnotationConfiguration)
+ boolean scanningAdded = false;
+ // Add the annotation scanning handlers (if annotation scanning enabled)
+ for (Configuration config : context.getConfigurations())
{
- AnnotationConfiguration annocfg = (AnnotationConfiguration)config;
- annocfg.addDiscoverableAnnotationHandler(new ServerEndpointAnnotationHandler(context));
- scanningAdded = true;
+ if (config instanceof AnnotationConfiguration)
+ {
+ AnnotationConfiguration annocfg = (AnnotationConfiguration)config;
+ annocfg.addDiscoverableAnnotationHandler(new ServerEndpointAnnotationHandler(context));
+ scanningAdded = true;
+ }
}
+ LOG.debug("@ServerEndpoint scanning added: {}", scanningAdded);
}
- LOG.debug("@ServerEndpoint scanning added: {}", scanningAdded);
}
}
diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/ServerApplicationConfigListener.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/ServerApplicationConfigListener.java
index 5b82dff24c..5eebf2935f 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/ServerApplicationConfigListener.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/ServerApplicationConfigListener.java
@@ -35,7 +35,9 @@ import javax.websocket.server.ServerEndpointConfig;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
+import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
+import org.eclipse.jetty.websocket.jsr356.server.WebSocketConfiguration;
import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
@HandlesTypes(
@@ -47,6 +49,9 @@ public class ServerApplicationConfigListener implements ServletContainerInitiali
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException
{
+ if (!WebSocketConfiguration.isJSR356Context(WebAppContext.getCurrentWebAppContext()))
+ return;
+
WebSocketUpgradeFilter filter = (WebSocketUpgradeFilter)ctx.getAttribute(WebSocketUpgradeFilter.class.getName());
if (filter == null)
{
diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/WSServer.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/WSServer.java
index d35fe99cab..1fa5333de3 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/WSServer.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/WSServer.java
@@ -110,6 +110,7 @@ public class WSServer
WebAppContext context = new WebAppContext();
context.setContextPath(this.contextPath);
context.setBaseResource(Resource.newResource(this.contextDir));
+ context.setAttribute(WebSocketConfiguration.ENABLE,Boolean.TRUE);
// @formatter:off
context.setConfigurations(new Configuration[] {
diff --git a/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/webapps/test.xml b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/webapps/test.xml
index 09f59b7ce9..42e03cb333 100644
--- a/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/webapps/test.xml
+++ b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/webapps/test.xml
@@ -28,8 +28,13 @@ detected.
<Set name="copyWebDir">false</Set>
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
<Set name="overrideDescriptor"><Property name="jetty.base" default="."/>/etc/override-web.xml</Set>
-
+ <!-- Enable/Disable JSR356 Container for this context -->
+ <Call name="setAttribute">
+ <Arg>org.eclipse.jetty.websocket.jsr356</Arg>
+ <Arg type="Boolean">true</Arg>
+ </Call>
+
<!-- virtual hosts
<Set name="virtualHosts">
<Array type="String">

Back to the top