add support for WebSocket UpgradeListeners for jetty WebSocketClient

Signed-off-by: lachan-roberts <lachlan@webtide.com>
This commit is contained in:
lachan-roberts 2019-03-01 18:34:07 +11:00
parent 39d122a9fb
commit ddb75984d1
1 changed files with 17 additions and 0 deletions

View File

@ -50,6 +50,7 @@ import org.eclipse.jetty.websocket.common.SessionTracker;
import org.eclipse.jetty.websocket.common.WebSocketContainer; import org.eclipse.jetty.websocket.common.WebSocketContainer;
import org.eclipse.jetty.websocket.common.WebSocketSessionListener; import org.eclipse.jetty.websocket.common.WebSocketSessionListener;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.client.UpgradeListener;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
public class WebSocketClient extends ContainerLifeCycle implements WebSocketPolicy, WebSocketContainer public class WebSocketClient extends ContainerLifeCycle implements WebSocketPolicy, WebSocketContainer
@ -117,8 +118,24 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli
* @throws IOException if unable to connect * @throws IOException if unable to connect
*/ */
public CompletableFuture<Session> connect(Object websocket, URI toUri, UpgradeRequest request) throws IOException public CompletableFuture<Session> connect(Object websocket, URI toUri, UpgradeRequest request) throws IOException
{
return connect(websocket, toUri, request, null);
}
/**
* Connect to remote websocket endpoint
*
* @param websocket the websocket object
* @param toUri the websocket uri to connect to
* @param request the upgrade request information
* @param listener the upgrade listener
* @return the future for the session, available on success of connect
* @throws IOException if unable to connect
*/
public CompletableFuture<Session> connect(Object websocket, URI toUri, UpgradeRequest request, UpgradeListener listener) throws IOException
{ {
JettyClientUpgradeRequest upgradeRequest = new JettyClientUpgradeRequest(this, coreClient, request, toUri, websocket); JettyClientUpgradeRequest upgradeRequest = new JettyClientUpgradeRequest(this, coreClient, request, toUri, websocket);
upgradeRequest.addListener(listener);
coreClient.connect(upgradeRequest); coreClient.connect(upgradeRequest);
return upgradeRequest.getFutureSession(); return upgradeRequest.getFutureSession();
} }