Skip to content

Commit

Permalink
Issue #3458 - make jetty-websocket-client hide websocket-core
Browse files Browse the repository at this point in the history
Signed-off-by: lachan-roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Mar 17, 2019
1 parent 89bee3f commit 7aa6c62
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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)
{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.function.Consumer;

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.Connection;
import org.eclipse.jetty.util.DecoratedObjectFactory;
Expand Down Expand Up @@ -124,15 +126,29 @@ public CompletableFuture<Session> connect(Object websocket, URI toUri, UpgradeRe
* @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 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))
coreClient.addBean(listener);

JettyClientUpgradeRequest upgradeRequest = new JettyClientUpgradeRequest(this, coreClient, request, toUri, websocket);
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);
return upgradeRequest.getFutureSession();
}
Expand Down Expand Up @@ -283,11 +299,6 @@ public Executor getExecutor()
return getHttpClient().getExecutor();
}

public WebSocketExtensionRegistry getExtensionRegistry()
{
return extensionRegistry;
}

public HttpClient getHttpClient()
{
return coreClient.getHttpClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
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.core.client.UpgradeListener;
import org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer;
import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -108,7 +108,7 @@ public void testJettyExtensionConfig() throws Exception
request.addExtensions(ExtensionConfig.parse("permessage-deflate"));

CountDownLatch correctResponseExtensions = new CountDownLatch(1);
UpgradeListener listener = new UpgradeListener()
JettyUpgradeListener listener = new JettyUpgradeListener()
{
@Override
public void onHandshakeResponse(HttpRequest request, HttpResponse response)
Expand Down

0 comments on commit 7aa6c62

Please sign in to comment.