Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2014-12-19 20:54:34 +0000
committerJoakim Erdfelt2015-03-12 17:09:30 +0000
commit1f3097ff162ea4198f9979fed09b19ef49f69572 (patch)
treedbcb85cc083a3348e6d2bd33261991147be4629e /jetty-websocket/websocket-client/src
parent0c930c86400873e6afb993608f43bd79605abc55 (diff)
downloadorg.eclipse.jetty.project-1f3097ff162ea4198f9979fed09b19ef49f69572.tar.gz
org.eclipse.jetty.project-1f3097ff162ea4198f9979fed09b19ef49f69572.tar.xz
org.eclipse.jetty.project-1f3097ff162ea4198f9979fed09b19ef49f69572.zip
453834 - CDI Support for WebSocket
+ Adding scopes to websocket to help with CDI integration
Diffstat (limited to 'jetty-websocket/websocket-client/src')
-rw-r--r--jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java50
-rw-r--r--jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java6
2 files changed, 46 insertions, 10 deletions
diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java
index 74a759fb38..e9f192689f 100644
--- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java
+++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.CookieStore;
import java.net.SocketAddress;
import java.net.URI;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
@@ -31,6 +32,7 @@ import java.util.concurrent.Future;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.io.SelectorManager;
+import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.HttpCookieStore;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
@@ -57,15 +59,16 @@ import org.eclipse.jetty.websocket.common.WebSocketSessionFactory;
import org.eclipse.jetty.websocket.common.events.EventDriver;
import org.eclipse.jetty.websocket.common.events.EventDriverFactory;
import org.eclipse.jetty.websocket.common.extensions.WebSocketExtensionFactory;
+import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
/**
* WebSocketClient provides a means of establishing connections to remote websocket endpoints.
*/
-public class WebSocketClient extends ContainerLifeCycle implements SessionListener
+public class WebSocketClient extends ContainerLifeCycle implements SessionListener, WebSocketContainerScope
{
private static final Logger LOG = Log.getLogger(WebSocketClient.class);
- private final WebSocketPolicy policy;
+ private final WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
private final SslContextFactory sslContextFactory;
private final WebSocketExtensionFactory extensionRegistry;
private boolean daemon = false;
@@ -73,6 +76,7 @@ public class WebSocketClient extends ContainerLifeCycle implements SessionListen
private SessionFactory sessionFactory;
private ByteBufferPool bufferPool;
private Executor executor;
+ private DecoratedObjectFactory objectFactory;
private Scheduler scheduler;
private CookieStore cookieStore;
private ConnectionManager connectionManager;
@@ -83,9 +87,9 @@ public class WebSocketClient extends ContainerLifeCycle implements SessionListen
public WebSocketClient()
{
- this(null,null);
+ this((SslContextFactory)null,null);
}
-
+
public WebSocketClient(Executor executor)
{
this(null,executor);
@@ -106,13 +110,28 @@ public class WebSocketClient extends ContainerLifeCycle implements SessionListen
this(sslContextFactory,executor,new MappedByteBufferPool());
}
+ public WebSocketClient(WebSocketContainerScope scope)
+ {
+ this(scope.getSslContextFactory(), scope.getExecutor(), scope.getBufferPool(), scope.getObjectFactory());
+ }
+
+ public WebSocketClient(WebSocketContainerScope scope, SslContextFactory sslContextFactory)
+ {
+ this(sslContextFactory, scope.getExecutor(), scope.getBufferPool(), scope.getObjectFactory());
+ }
+
public WebSocketClient(SslContextFactory sslContextFactory, Executor executor, ByteBufferPool bufferPool)
{
+ this(sslContextFactory, executor, bufferPool, new DecoratedObjectFactory());
+ }
+
+ public WebSocketClient(SslContextFactory sslContextFactory, Executor executor, ByteBufferPool bufferPool, DecoratedObjectFactory objectFactory)
+ {
this.executor = executor;
this.sslContextFactory = sslContextFactory;
- this.policy = WebSocketPolicy.newClientPolicy();
this.bufferPool = bufferPool;
- this.extensionRegistry = new WebSocketExtensionFactory(policy,bufferPool);
+ this.objectFactory = objectFactory;
+ this.extensionRegistry = new WebSocketExtensionFactory(this);
// Bug #431459 - unregistering compression extensions till they are more stable
this.extensionRegistry.unregister("deflate-frame");
@@ -121,7 +140,6 @@ public class WebSocketClient extends ContainerLifeCycle implements SessionListen
this.masker = new RandomMasker();
this.eventDriverFactory = new EventDriverFactory(policy);
- this.sessionFactory = new WebSocketSessionFactory(this);
addBean(this.executor);
addBean(this.sslContextFactory);
@@ -251,6 +269,16 @@ public class WebSocketClient extends ContainerLifeCycle implements SessionListen
cookieStore = new HttpCookieStore.Empty();
}
+ if(this.sessionFactory == null)
+ {
+ this.sessionFactory = new WebSocketSessionFactory(this);
+ }
+
+ if(this.objectFactory == null)
+ {
+ this.objectFactory = new DecoratedObjectFactory();
+ }
+
super.doStart();
if (LOG.isDebugEnabled())
@@ -390,9 +418,15 @@ public class WebSocketClient extends ContainerLifeCycle implements SessionListen
return this.policy.getMaxTextMessageSize();
}
+ @Override
+ public DecoratedObjectFactory getObjectFactory()
+ {
+ return this.objectFactory;
+ }
+
public Set<WebSocketSession> getOpenSessions()
{
- return new HashSet<>(getBeans(WebSocketSession.class));
+ return Collections.unmodifiableSet(new HashSet<>(getBeans(WebSocketSession.class)));
}
public WebSocketPolicy getPolicy()
diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java
index 011dc0b1ae..170c28bb1d 100644
--- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java
+++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java
@@ -87,13 +87,15 @@ public class SessionTest
RemoteEndpoint remote = cliSock.getSession().getRemote();
remote.sendStringByFuture("Hello World!");
if (remote.getBatchMode() == BatchMode.ON)
+ {
remote.flush();
+ }
srvSock.echoMessage(1,500,TimeUnit.MILLISECONDS);
// wait for response from server
cliSock.waitForMessage(500,TimeUnit.MILLISECONDS);
Set<WebSocketSession> open = client.getOpenSessions();
- Assert.assertThat("Open Sessions.size", open.size(), is(1));
+ Assert.assertThat("(Before Close) Open Sessions.size", open.size(), is(1));
cliSock.assertMessage("Hello World!");
cliSock.close();
@@ -101,7 +103,7 @@ public class SessionTest
cliSock.waitForClose(500,TimeUnit.MILLISECONDS);
open = client.getOpenSessions();
- Assert.assertThat("Open Sessions.size", open.size(), is(0));
+ Assert.assertThat("(After Close) Open Sessions.size", open.size(), is(0));
}
finally
{

Back to the top