From d8b14446092baf5d7ae6d816383e4e895e4212da Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 27 Nov 2012 15:00:22 -0700 Subject: [PATCH] Changing to ClientUpgrade(Request|Response) --- .../websocket/client/WebSocketClient.java | 8 +-- .../client/internal/ConnectionManager.java | 7 +-- .../internal/DefaultWebSocketClient.java | 62 ++++--------------- .../client/internal/io/UpgradeConnection.java | 24 ++++--- .../websocket/client/BadNetworkTest.java | 5 +- .../websocket/client/ClientConnectTest.java | 11 ++-- .../websocket/client/SlowClientTest.java | 3 +- .../websocket/client/SlowServerTest.java | 5 +- .../jetty/websocket/client/TimeoutTest.java | 3 +- .../websocket/client/WebSocketClientTest.java | 6 +- 10 files changed, 43 insertions(+), 91 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 4ad63d84ee6..842137b1e9e 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,15 +22,13 @@ import java.io.IOException; import java.net.URI; import java.util.concurrent.Future; -import org.eclipse.jetty.websocket.api.UpgradeRequest; -import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.client.masks.Masker; import org.eclipse.jetty.websocket.common.events.EventDriver; public interface WebSocketClient { - public Future connect(URI websocketUri) throws IOException; + public Future connect(URI websocketUri) throws IOException; public WebSocketClientFactory getFactory(); @@ -38,9 +36,9 @@ public interface WebSocketClient public WebSocketPolicy getPolicy(); - public UpgradeRequest getUpgradeRequest(); + public ClientUpgradeRequest getUpgradeRequest(); - public UpgradeResponse getUpgradeResponse(); + public ClientUpgradeResponse getUpgradeResponse(); public EventDriver getWebSocket(); diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ConnectionManager.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ConnectionManager.java index fd554827721..20eb0e26a2c 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ConnectionManager.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ConnectionManager.java @@ -32,14 +32,13 @@ import java.util.concurrent.Executor; import java.util.concurrent.Future; import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.Scheduler; -import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.api.WebSocketPolicy; +import org.eclipse.jetty.websocket.client.ClientUpgradeResponse; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.client.internal.io.WebSocketClientSelectorManager; @@ -115,7 +114,7 @@ public class ConnectionManager extends ContainerLifeCycle } } - public Future connectPhysical(DefaultWebSocketClient client) throws IOException + public Future connectPhysical(DefaultWebSocketClient client) throws IOException { SocketChannel channel = SocketChannel.open(); SocketAddress bindAddress = client.getFactory().getBindAddress(); @@ -138,7 +137,7 @@ public class ConnectionManager extends ContainerLifeCycle return client; } - public Future connectVirtual(WebSocketClient client) + public Future connectVirtual(WebSocketClient client) { // TODO Auto-generated method stub return null; diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/DefaultWebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/DefaultWebSocketClient.java index be6ac1be758..d96705b92d1 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/DefaultWebSocketClient.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/DefaultWebSocketClient.java @@ -23,13 +23,10 @@ import java.net.URI; import java.util.Locale; import java.util.concurrent.Future; -import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.FuturePromise; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.api.UpgradeRequest; -import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.api.WebSocketConnection; import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; @@ -43,7 +40,7 @@ import org.eclipse.jetty.websocket.common.events.EventDriver; /** * WebSocketClient for working with Upgrade (request and response), and establishing connections to the websocket URI of your choice. */ -public class DefaultWebSocketClient extends FuturePromise implements WebSocketClient +public class DefaultWebSocketClient extends FuturePromise implements WebSocketClient { private static final Logger LOG = Log.getLogger(DefaultWebSocketClient.class); @@ -74,19 +71,7 @@ public class DefaultWebSocketClient extends FuturePromise imple } @Override - public void succeeded(UpgradeResponse response) - { - LOG.debug("completed() - {}",response); - super.succeeded(response); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jetty.websocket.client.internal.WebSocketClient#connect(java.net.URI) - */ - @Override - public Future connect(URI websocketUri) throws IOException + public Future connect(URI websocketUri) throws IOException { if (!factory.isStarted()) { @@ -113,7 +98,7 @@ public class DefaultWebSocketClient extends FuturePromise imple this.websocketUri = websocketUri; // Validate websocket URI - Future result = null; + Future result = null; LOG.debug("connect({})",websocketUri); @@ -147,11 +132,6 @@ public class DefaultWebSocketClient extends FuturePromise imple return this.connection; } - /* - * (non-Javadoc) - * - * @see org.eclipse.jetty.websocket.client.internal.WebSocketClient#getFactory() - */ @Override public WebSocketClientFactory getFactory() { @@ -164,55 +144,30 @@ public class DefaultWebSocketClient extends FuturePromise imple return masker; } - /* - * (non-Javadoc) - * - * @see org.eclipse.jetty.websocket.client.internal.WebSocketClient#getPolicy() - */ @Override public WebSocketPolicy getPolicy() { return this.policy; } - /* - * (non-Javadoc) - * - * @see org.eclipse.jetty.websocket.client.internal.WebSocketClient#getUpgradeRequest() - */ @Override - public UpgradeRequest getUpgradeRequest() + public ClientUpgradeRequest getUpgradeRequest() { return upgradeRequest; } - /* - * (non-Javadoc) - * - * @see org.eclipse.jetty.websocket.client.internal.WebSocketClient#getUpgradeResponse() - */ @Override - public UpgradeResponse getUpgradeResponse() + public ClientUpgradeResponse getUpgradeResponse() { return upgradeResponse; } - /* - * (non-Javadoc) - * - * @see org.eclipse.jetty.websocket.client.internal.WebSocketClient#getWebSocket() - */ @Override public EventDriver getWebSocket() { return websocket; } - /* - * (non-Javadoc) - * - * @see org.eclipse.jetty.websocket.client.internal.WebSocketClient#getWebSocketUri() - */ @Override public URI getWebSocketUri() { @@ -229,4 +184,11 @@ public class DefaultWebSocketClient extends FuturePromise imple { this.upgradeResponse = response; } + + @Override + public void succeeded(ClientUpgradeResponse response) + { + LOG.debug("completed() - {}",response); + super.succeeded(response); + } } diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/UpgradeConnection.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/UpgradeConnection.java index 4b67b67550b..6c9c94dd235 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/UpgradeConnection.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/UpgradeConnection.java @@ -30,13 +30,11 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.FutureCallback; -import org.eclipse.jetty.util.FuturePromise; import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.api.UpgradeException; -import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.api.extensions.Extension; import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; @@ -57,15 +55,6 @@ public class UpgradeConnection extends AbstractConnection { public class SendUpgradeRequest extends FutureCallback implements Runnable { - @Override - public void succeeded() - { - // Writing the request header is complete. - super.succeeded(); - // start the interest in fill - fillInterested(); - } - @Override public void run() { @@ -76,6 +65,15 @@ public class UpgradeConnection extends AbstractConnection ByteBuffer buf = BufferUtil.toBuffer(rawRequest,StringUtil.__UTF8_CHARSET); getEndPoint().write(this,buf); } + + @Override + public void succeeded() + { + // Writing the request header is complete. + super.succeeded(); + // start the interest in fill + fillInterested(); + } } private static final Logger LOG = Log.getLogger(UpgradeConnection.class); @@ -93,7 +91,7 @@ public class UpgradeConnection extends AbstractConnection try { - this.request = (ClientUpgradeRequest)client.getUpgradeRequest(); + this.request = client.getUpgradeRequest(); } catch (ClassCastException e) { @@ -115,7 +113,7 @@ public class UpgradeConnection extends AbstractConnection } } - private void notifyConnect(UpgradeResponse response) + private void notifyConnect(ClientUpgradeResponse response) { client.succeeded(response); } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java index dbc9c047fe9..8f776325aa3 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java @@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.websocket.api.StatusCode; -import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.api.WebSocketConnection; import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer; import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection; @@ -84,7 +83,7 @@ public class BadNetworkTest WebSocketClient client = factory.newWebSocketClient(wsocket); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); ServerConnection ssocket = server.accept(); ssocket.upgrade(); @@ -115,7 +114,7 @@ public class BadNetworkTest WebSocketClient client = factory.newWebSocketClient(wsocket); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); ServerConnection ssocket = server.accept(); ssocket.upgrade(); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java index 58556be41e4..4f067b5d1a4 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java @@ -28,7 +28,6 @@ import java.util.concurrent.TimeoutException; import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.websocket.api.UpgradeException; -import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer; import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection; import org.junit.After; @@ -82,7 +81,7 @@ public class ClientConnectTest WebSocketClient client = factory.newWebSocketClient(wsocket); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); ServerConnection connection = server.accept(); connection.readRequest(); @@ -109,7 +108,7 @@ public class ClientConnectTest WebSocketClient client = factory.newWebSocketClient(wsocket); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); ServerConnection connection = server.accept(); connection.readRequest(); @@ -136,7 +135,7 @@ public class ClientConnectTest WebSocketClient client = factory.newWebSocketClient(wsocket); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); // Intentionally not accept incoming socket. // server.accept(); @@ -162,7 +161,7 @@ public class ClientConnectTest // Intentionally bad port URI wsUri = new URI("ws://127.0.0.1:1"); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); // The attempt to get upgrade response future should throw error try @@ -184,7 +183,7 @@ public class ClientConnectTest WebSocketClient client = factory.newWebSocketClient(wsocket); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); ServerConnection ssocket = server.accept(); Assert.assertNotNull(ssocket); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java index 5427fd82160..213f36ac88c 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java @@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.eclipse.jetty.websocket.api.StatusCode; -import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer; import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection; import org.junit.After; @@ -82,7 +81,7 @@ public class SlowClientTest client.getPolicy().setIdleTimeout(60000); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); ServerConnection sconnection = server.accept(); sconnection.setSoTimeout(60000); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java index 3542987e1ae..2469947f8f6 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java @@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.eclipse.jetty.websocket.api.StatusCode; -import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer; import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection; import org.junit.After; @@ -82,7 +81,7 @@ public class SlowServerTest client.getPolicy().setIdleTimeout(60000); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); ServerConnection sconnection = server.accept(); sconnection.setSoTimeout(60000); @@ -133,7 +132,7 @@ public class SlowServerTest client.getPolicy().setIdleTimeout(60000); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); ServerConnection sconnection = server.accept(); sconnection.setSoTimeout(60000); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TimeoutTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TimeoutTest.java index b789a660762..175d3e1ead4 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TimeoutTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TimeoutTest.java @@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.websocket.api.StatusCode; -import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer; import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection; import org.junit.After; @@ -87,7 +86,7 @@ public class TimeoutTest WebSocketClient client = factory.newWebSocketClient(wsocket); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); ServerConnection ssocket = server.accept(); ssocket.upgrade(); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java index d0913b91564..55c81cd0883 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java @@ -79,7 +79,7 @@ public class WebSocketClientTest URI wsUri = server.getWsUri(); UpgradeRequest request = client.getUpgradeRequest(); request.setSubProtocols("echo"); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); final ServerConnection srvSock = server.accept(); srvSock.upgrade(); @@ -106,7 +106,7 @@ public class WebSocketClientTest { TrackingSocket wsocket = new TrackingSocket(); WebSocketClient client = factory.newWebSocketClient(wsocket); - Future future = client.connect(server.getWsUri()); + Future future = client.connect(server.getWsUri()); // Server final ServerConnection srvSock = server.accept(); @@ -142,7 +142,7 @@ public class WebSocketClientTest WebSocketClient client = factSmall.newWebSocketClient(wsocket); URI wsUri = server.getWsUri(); - Future future = client.connect(wsUri); + Future future = client.connect(wsUri); ServerConnection ssocket = server.accept(); ssocket.upgrade();