Issue #3458 - make jetty-websocket-client hide websocket-core
Signed-off-by: lachan-roberts <lachlan@webtide.com>
This commit is contained in:
parent
20e9770b73
commit
dab3b64d70
|
@ -0,0 +1,42 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// All rights reserved. This program and the accompanying materials
|
||||||
|
// are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
// and Apache License v2.0 which accompanies this distribution.
|
||||||
|
//
|
||||||
|
// The Eclipse Public License is available at
|
||||||
|
// http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
//
|
||||||
|
// The Apache License v2.0 is available at
|
||||||
|
// http://www.opensource.org/licenses/apache2.0.php
|
||||||
|
//
|
||||||
|
// You may elect to redistribute this code under either of these licenses.
|
||||||
|
// ========================================================================
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.eclipse.jetty.websocket.client;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.client.HttpRequest;
|
||||||
|
import org.eclipse.jetty.client.HttpResponse;
|
||||||
|
|
||||||
|
public interface JettyUpgradeListener
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Event that triggers before the Handshake request is sent.
|
||||||
|
*
|
||||||
|
* @param request the request
|
||||||
|
*/
|
||||||
|
default void onHandshakeRequest(HttpRequest request)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event that triggers after the Handshake response has been received.
|
||||||
|
*
|
||||||
|
* @param request the request that was used
|
||||||
|
* @param response the response that was received
|
||||||
|
*/
|
||||||
|
default void onHandshakeResponse(HttpRequest request, HttpResponse response)
|
||||||
|
{}
|
||||||
|
}
|
|
@ -32,6 +32,8 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
|
import org.eclipse.jetty.client.HttpRequest;
|
||||||
|
import org.eclipse.jetty.client.HttpResponse;
|
||||||
import org.eclipse.jetty.io.ByteBufferPool;
|
import org.eclipse.jetty.io.ByteBufferPool;
|
||||||
import org.eclipse.jetty.io.Connection;
|
import org.eclipse.jetty.io.Connection;
|
||||||
import org.eclipse.jetty.util.DecoratedObjectFactory;
|
import org.eclipse.jetty.util.DecoratedObjectFactory;
|
||||||
|
@ -124,15 +126,29 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli
|
||||||
* @return the future for the session, available on success of connect
|
* @return the future for the session, available on success of connect
|
||||||
* @throws IOException if unable to connect
|
* @throws IOException if unable to connect
|
||||||
*/
|
*/
|
||||||
public CompletableFuture<Session> connect(Object websocket, URI toUri, UpgradeRequest request, UpgradeListener upgradeListener) throws IOException
|
public CompletableFuture<Session> connect(Object websocket, URI toUri, UpgradeRequest request, JettyUpgradeListener upgradeListener) throws IOException
|
||||||
{
|
{
|
||||||
for (Connection.Listener listener : getBeans(Connection.Listener.class))
|
for (Connection.Listener listener : getBeans(Connection.Listener.class))
|
||||||
coreClient.addBean(listener);
|
coreClient.addBean(listener);
|
||||||
|
|
||||||
JettyClientUpgradeRequest upgradeRequest = new JettyClientUpgradeRequest(this, coreClient, request, toUri, websocket);
|
JettyClientUpgradeRequest upgradeRequest = new JettyClientUpgradeRequest(this, coreClient, request, toUri, websocket);
|
||||||
if (upgradeListener != null)
|
if (upgradeListener != null)
|
||||||
upgradeRequest.addListener(upgradeListener);
|
{
|
||||||
|
upgradeRequest.addListener(new UpgradeListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onHandshakeRequest(HttpRequest request)
|
||||||
|
{
|
||||||
|
upgradeListener.onHandshakeRequest(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHandshakeResponse(HttpRequest request, HttpResponse response)
|
||||||
|
{
|
||||||
|
upgradeListener.onHandshakeResponse(request, response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
coreClient.connect(upgradeRequest);
|
coreClient.connect(upgradeRequest);
|
||||||
return upgradeRequest.getFutureSession();
|
return upgradeRequest.getFutureSession();
|
||||||
}
|
}
|
||||||
|
@ -283,11 +299,6 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli
|
||||||
return getHttpClient().getExecutor();
|
return getHttpClient().getExecutor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebSocketExtensionRegistry getExtensionRegistry()
|
|
||||||
{
|
|
||||||
return extensionRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpClient getHttpClient()
|
public HttpClient getHttpClient()
|
||||||
{
|
{
|
||||||
return coreClient.getHttpClient();
|
return coreClient.getHttpClient();
|
||||||
|
|
|
@ -34,8 +34,8 @@ import org.eclipse.jetty.websocket.api.Session;
|
||||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||||
|
import org.eclipse.jetty.websocket.client.JettyUpgradeListener;
|
||||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||||
import org.eclipse.jetty.websocket.core.client.UpgradeListener;
|
|
||||||
import org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer;
|
import org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer;
|
||||||
import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer;
|
import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
@ -108,7 +108,7 @@ public class JettyWebSocketExtensionConfigTest
|
||||||
request.addExtensions(ExtensionConfig.parse("permessage-deflate"));
|
request.addExtensions(ExtensionConfig.parse("permessage-deflate"));
|
||||||
|
|
||||||
CountDownLatch correctResponseExtensions = new CountDownLatch(1);
|
CountDownLatch correctResponseExtensions = new CountDownLatch(1);
|
||||||
UpgradeListener listener = new UpgradeListener()
|
JettyUpgradeListener listener = new JettyUpgradeListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onHandshakeResponse(HttpRequest request, HttpResponse response)
|
public void onHandshakeResponse(HttpRequest request, HttpResponse response)
|
||||||
|
|
Loading…
Reference in New Issue