Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2015-03-10 23:34:39 +0000
committerJoakim Erdfelt2015-03-12 17:09:52 +0000
commit0301de099d876124b5a0b26da171105c63ab0632 (patch)
treef2f3770159fbb1fe40ad2283fa92b6691eba0cb7 /jetty-websocket
parentdc81cda742b354138fd3f78c815aa9d81ae2e078 (diff)
downloadorg.eclipse.jetty.project-0301de099d876124b5a0b26da171105c63ab0632.tar.gz
org.eclipse.jetty.project-0301de099d876124b5a0b26da171105c63ab0632.tar.xz
org.eclipse.jetty.project-0301de099d876124b5a0b26da171105c63ab0632.zip
Delaying decoration of websocket endpoints
Diffstat (limited to 'jetty-websocket')
-rw-r--r--jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/JsrCreator.java7
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java13
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AbstractEventDriver.java1
-rw-r--r--jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java26
4 files changed, 21 insertions, 26 deletions
diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/JsrCreator.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/JsrCreator.java
index 1d32ed3f31..c2f95755de 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/JsrCreator.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/JsrCreator.java
@@ -140,11 +140,8 @@ public class JsrCreator implements WebSocketCreator
Class<?> endpointClass = config.getEndpointClass();
Configurator configr = config.getConfigurator();
Object endpoint = configr.getEndpointInstance(endpointClass);
- if (configr instanceof ContainerDefaultConfigurator)
- {
- // default impl always decorates (custom ones do not)
- endpoint = containerScope.getObjectFactory().decorate(endpoint);
- }
+ // Do not decorate here (let the Connection and Session start first)
+ // This will allow CDI to see Session for injection into Endpoint classes.
PathSpec pathSpec = hsreq.getRequestPathSpec();
if (pathSpec instanceof WebSocketPathSpec)
{
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
index 93b2899572..c146061693 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
@@ -54,6 +54,7 @@ import org.eclipse.jetty.websocket.common.io.IOState;
import org.eclipse.jetty.websocket.common.io.IOState.ConnectionStateListener;
import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
import org.eclipse.jetty.websocket.common.scopes.WebSocketSessionScope;
+import org.eclipse.jetty.websocket.common.util.ThreadClassLoaderScope;
@ManagedObject("A Jetty WebSocket Session")
public class WebSocketSession extends ContainerLifeCycle implements Session, WebSocketSessionScope, IncomingFrames, ConnectionStateListener
@@ -127,7 +128,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
{
executor.execute(runnable);
}
-
+
@Override
public void dump(Appendable out, String indent) throws IOException
{
@@ -426,10 +427,8 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
return;
}
- ClassLoader old = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(classLoader);
-
+ try(ThreadClassLoaderScope scope = new ThreadClassLoaderScope(classLoader))
+ {
// Upgrade success
connection.getIOState().onConnected();
@@ -460,10 +459,6 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
close(statusCode,t.getMessage());
}
- finally
- {
- Thread.currentThread().setContextClassLoader(old);
- }
}
public void setExtensionFactory(ExtensionFactory extensionFactory)
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AbstractEventDriver.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AbstractEventDriver.java
index d446264743..a98141cedb 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AbstractEventDriver.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AbstractEventDriver.java
@@ -215,6 +215,7 @@ public abstract class AbstractEventDriver implements IncomingFrames, EventDriver
if (LOG.isDebugEnabled())
LOG.debug("openSession({})",session);
this.session = session;
+ this.session.getContainerScope().getObjectFactory().decorate(this.websocket);
try
{
this.onConnect();
diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java
index 7f8fd830af..ecc8916465 100644
--- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java
+++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java
@@ -635,21 +635,23 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
extensionStack.setNextOutgoing(wsConnection);
// Start Components
- try
- {
- session.start();
- }
- catch (Exception e)
- {
- throw new IOException("Unable to start Session", e);
- }
- try
+ session.addBean(extensionStack);
+ this.addBean(session);
+
+ if (session.isFailed())
{
- extensionStack.start();
+ throw new IOException("Session failed to start");
}
- catch (Exception e)
+ else if (!session.isRunning())
{
- throw new IOException("Unable to start Extension Stack", e);
+ try
+ {
+ session.start();
+ }
+ catch (Exception e)
+ {
+ throw new IOException("Unable to start Session",e);
+ }
}
// Tell jetty about the new upgraded connection

Back to the top