Changing to ClientUpgrade(Request|Response)
This commit is contained in:
parent
acaeb7663a
commit
d8b1444609
|
@ -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<UpgradeResponse> connect(URI websocketUri) throws IOException;
|
||||
public Future<ClientUpgradeResponse> 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();
|
||||
|
||||
|
|
|
@ -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<UpgradeResponse> connectPhysical(DefaultWebSocketClient client) throws IOException
|
||||
public Future<ClientUpgradeResponse> 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<UpgradeResponse> connectVirtual(WebSocketClient client)
|
||||
public Future<ClientUpgradeResponse> connectVirtual(WebSocketClient client)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
|
|
@ -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<UpgradeResponse> implements WebSocketClient
|
||||
public class DefaultWebSocketClient extends FuturePromise<ClientUpgradeResponse> implements WebSocketClient
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(DefaultWebSocketClient.class);
|
||||
|
||||
|
@ -74,19 +71,7 @@ public class DefaultWebSocketClient extends FuturePromise<UpgradeResponse> 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<UpgradeResponse> connect(URI websocketUri) throws IOException
|
||||
public Future<ClientUpgradeResponse> connect(URI websocketUri) throws IOException
|
||||
{
|
||||
if (!factory.isStarted())
|
||||
{
|
||||
|
@ -113,7 +98,7 @@ public class DefaultWebSocketClient extends FuturePromise<UpgradeResponse> imple
|
|||
this.websocketUri = websocketUri;
|
||||
|
||||
// Validate websocket URI
|
||||
Future<UpgradeResponse> result = null;
|
||||
Future<ClientUpgradeResponse> result = null;
|
||||
|
||||
LOG.debug("connect({})",websocketUri);
|
||||
|
||||
|
@ -147,11 +132,6 @@ public class DefaultWebSocketClient extends FuturePromise<UpgradeResponse> 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<UpgradeResponse> 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<UpgradeResponse> imple
|
|||
{
|
||||
this.upgradeResponse = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void succeeded(ClientUpgradeResponse response)
|
||||
{
|
||||
LOG.debug("completed() - {}",response);
|
||||
super.succeeded(response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> 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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> future = client.connect(wsUri);
|
||||
|
||||
ServerConnection ssocket = server.accept();
|
||||
ssocket.upgrade();
|
||||
|
|
|
@ -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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> 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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> 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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> 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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> 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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> future = client.connect(wsUri);
|
||||
|
||||
ServerConnection ssocket = server.accept();
|
||||
Assert.assertNotNull(ssocket);
|
||||
|
|
|
@ -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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> future = client.connect(wsUri);
|
||||
|
||||
ServerConnection sconnection = server.accept();
|
||||
sconnection.setSoTimeout(60000);
|
||||
|
|
|
@ -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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> 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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> future = client.connect(wsUri);
|
||||
|
||||
ServerConnection sconnection = server.accept();
|
||||
sconnection.setSoTimeout(60000);
|
||||
|
|
|
@ -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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> future = client.connect(wsUri);
|
||||
|
||||
ServerConnection ssocket = server.accept();
|
||||
ssocket.upgrade();
|
||||
|
|
|
@ -79,7 +79,7 @@ public class WebSocketClientTest
|
|||
URI wsUri = server.getWsUri();
|
||||
UpgradeRequest request = client.getUpgradeRequest();
|
||||
request.setSubProtocols("echo");
|
||||
Future<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> 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<UpgradeResponse> future = client.connect(server.getWsUri());
|
||||
Future<ClientUpgradeResponse> 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<UpgradeResponse> future = client.connect(wsUri);
|
||||
Future<ClientUpgradeResponse> future = client.connect(wsUri);
|
||||
|
||||
ServerConnection ssocket = server.accept();
|
||||
ssocket.upgrade();
|
||||
|
|
Loading…
Reference in New Issue