From 272895ce02d972eadc01bef705222a6c57332e55 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 26 Aug 2024 12:42:53 +0300 Subject: [PATCH] Issue #12023 - Remove deprecated classes/methods. (#12149) Removed deprecated classes/methods from jetty-client. Signed-off-by: Simone Bordet --- .../AbstractConnectorHttpClientTransport.java | 7 - .../jetty/client/FutureResponseListener.java | 121 ------------ .../org/eclipse/jetty/client/HttpClient.java | 8 +- .../jetty/client/HttpClientTransport.java | 19 +- .../transport/HttpClientTransportDynamic.java | 28 +-- .../client/transport/HttpDestination.java | 12 -- .../HttpClientTransportOverHTTP2.java | 6 - .../HttpClientTransportOverHTTP3.java | 7 - .../org/eclipse/jetty/io/ClientConnector.java | 184 ------------------ .../QuicClientConnectorConfigurator.java | 136 ------------- .../jetty/quic/client/End2EndClientTest.java | 20 +- .../End2EndClientWithClientCertAuthTest.java | 21 +- .../quic/server/QuicServerConnector.java | 28 --- .../unixdomain/server/UnixDomainTest.java | 4 +- 14 files changed, 31 insertions(+), 570 deletions(-) delete mode 100644 jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/FutureResponseListener.java delete mode 100644 jetty-core/jetty-quic/jetty-quic-client/src/main/java/org/eclipse/jetty/quic/client/QuicClientConnectorConfigurator.java diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectorHttpClientTransport.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectorHttpClientTransport.java index e6d717f3aeb..51b3132806d 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectorHttpClientTransport.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectorHttpClientTransport.java @@ -13,7 +13,6 @@ package org.eclipse.jetty.client; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.time.Duration; import java.util.Map; @@ -73,10 +72,4 @@ public abstract class AbstractConnectorHttpClientTransport extends AbstractHttpC context.put(ClientConnector.CLIENT_CONNECTOR_CONTEXT_KEY, connector); destination.getOrigin().getTransport().connect(address, context); } - - @Override - public void connect(InetSocketAddress address, Map context) - { - connect((SocketAddress)address, context); - } } diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/FutureResponseListener.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/FutureResponseListener.java deleted file mode 100644 index ee5f7f5434e..00000000000 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/FutureResponseListener.java +++ /dev/null @@ -1,121 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.client; - -import java.util.concurrent.CancellationException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.eclipse.jetty.client.internal.HttpContentResponse; - -/** - * A {@link BufferingResponseListener} that is also a {@link Future}, to allow applications - * to block (indefinitely or for a timeout) until {@link #onComplete(Result)} is called, - * or to {@link #cancel(boolean) abort} the request/response conversation. - *

- * Typical usage is: - *

- * Request request = httpClient.newRequest(...)...;
- * FutureResponseListener listener = new FutureResponseListener(request);
- * request.send(listener); // Asynchronous send
- * ContentResponse response = listener.get(5, TimeUnit.SECONDS); // Timed block
- * 
- * - * @deprecated Use {@link CompletableResponseListener} instead - */ -@Deprecated -public class FutureResponseListener extends BufferingResponseListener implements Future -{ - private final AtomicBoolean cancelled = new AtomicBoolean(); - private final CountDownLatch latch = new CountDownLatch(1); - private final Request request; - private ContentResponse response; - private Throwable failure; - - public FutureResponseListener(Request request) - { - this(request, 2 * 1024 * 1024); - } - - public FutureResponseListener(Request request, int maxLength) - { - super(maxLength); - this.request = request; - } - - public Request getRequest() - { - return request; - } - - @Override - public void onComplete(Result result) - { - response = new HttpContentResponse(result.getResponse(), getContent(), getMediaType(), getEncoding()); - failure = result.getFailure(); - latch.countDown(); - } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) - { - if (cancelled.compareAndSet(false, true)) - { - request.abort(new CancellationException()); - return true; - } - return false; - } - - @Override - public boolean isCancelled() - { - return cancelled.get(); - } - - @Override - public boolean isDone() - { - return latch.getCount() == 0 || isCancelled(); - } - - @Override - public ContentResponse get() throws InterruptedException, ExecutionException - { - latch.await(); - return getResult(); - } - - @Override - public ContentResponse get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - { - boolean expired = !latch.await(timeout, unit); - if (expired) - throw new TimeoutException(); - return getResult(); - } - - private ContentResponse getResult() throws ExecutionException - { - if (isCancelled()) - throw (CancellationException)new CancellationException().initCause(failure); - if (failure != null) - throw new ExecutionException(failure); - return response; - } -} diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index b6c40a2eb1d..efe48a6c0b9 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -471,13 +471,7 @@ public class HttpClient extends ContainerLifeCycle implements AutoCloseable port = normalizePort(scheme, port); Transport transport = request.getTransport(); if (transport == null) - { - // Ask the ClientConnector for backwards compatibility - // until ClientConnector.Configurator is removed. - transport = connector.newTransport(); - if (transport == null) - transport = Transport.TCP_IP; - } + transport = Transport.TCP_IP; return new Origin(scheme, new Origin.Address(host, port), request.getTag(), protocol, transport); } diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClientTransport.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClientTransport.java index 45451fa2ead..d8f79521989 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClientTransport.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClientTransport.java @@ -13,7 +13,6 @@ package org.eclipse.jetty.client; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Map; @@ -71,24 +70,8 @@ public interface HttpClientTransport extends ClientConnectionFactory * * @param address the address to connect to * @param context the context information to establish the connection - * @deprecated use {@link #connect(SocketAddress, Map)} instead. */ - @Deprecated - public void connect(InetSocketAddress address, Map context); - - /** - * Establishes a physical connection to the given {@code address}. - * - * @param address the address to connect to - * @param context the context information to establish the connection - */ - public default void connect(SocketAddress address, Map context) - { - if (address instanceof InetSocketAddress) - connect((InetSocketAddress)address, context); - else - throw new UnsupportedOperationException("Unsupported SocketAddress " + address); - } + public void connect(SocketAddress address, Map context); /** * @return the factory for ConnectionPool instances diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpClientTransportDynamic.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpClientTransportDynamic.java index 31f2d5fbcf3..d32e6365ff6 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpClientTransportDynamic.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpClientTransportDynamic.java @@ -15,7 +15,6 @@ package org.eclipse.jetty.client.transport; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Optional; @@ -91,19 +90,6 @@ public class HttpClientTransportDynamic extends AbstractConnectorHttpClientTrans this(new ClientConnector(), HttpClientConnectionFactory.HTTP11); } - /** - *

Creates a dynamic transport that speaks the given protocols, in order of preference - * (first the most preferred).

- * - * @param infos the protocols this dynamic transport speaks - * @deprecated use {@link #HttpClientTransportDynamic(ClientConnector, ClientConnectionFactory.Info...)} - */ - @Deprecated(since = "12.0.7", forRemoval = true) - public HttpClientTransportDynamic(ClientConnectionFactory.Info... infos) - { - this(findClientConnector(infos), infos); - } - /** *

Creates a dynamic transport with the given {@link ClientConnector} and the given protocols, * in order of preference (first the most preferred).

@@ -121,14 +107,6 @@ public class HttpClientTransportDynamic extends AbstractConnectorHttpClientTrans ); } - private static ClientConnector findClientConnector(ClientConnectionFactory.Info[] infos) - { - return Arrays.stream(infos) - .flatMap(info -> info.getContainedBeans(ClientConnector.class).stream()) - .findFirst() - .orElseGet(ClientConnector::new); - } - @Override public Origin newOrigin(Request request) { @@ -216,11 +194,7 @@ public class HttpClientTransportDynamic extends AbstractConnectorHttpClientTrans Transport transport = request.getTransport(); if (transport == null) { - // Ask the ClientConnector for backwards compatibility - // until ClientConnector.Configurator is removed. - transport = getClientConnector().newTransport(); - if (transport == null) - transport = matchingInfos.get(0).newTransport(); + transport = matchingInfos.get(0).newTransport(); request.transport(transport); } diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpDestination.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpDestination.java index 3758bd2c597..564b86128d0 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpDestination.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpDestination.java @@ -70,18 +70,6 @@ public class HttpDestination extends ContainerLifeCycle implements Destination, private boolean stale; private long activeNanoTime; - /** - * @param client the {@link HttpClient} - * @param origin the {@link Origin} - * @param intrinsicallySecure whether the destination is intrinsically secure - * @deprecated use {@link #HttpDestination(HttpClient, Origin)} instead - */ - @Deprecated(since = "12.0.7", forRemoval = true) - public HttpDestination(HttpClient client, Origin origin, boolean intrinsicallySecure) - { - this(client, origin); - } - /** *

Creates a new HTTP destination.

* diff --git a/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/HttpClientTransportOverHTTP2.java b/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/HttpClientTransportOverHTTP2.java index a5178b52241..a911b2fb968 100644 --- a/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/HttpClientTransportOverHTTP2.java +++ b/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/HttpClientTransportOverHTTP2.java @@ -124,12 +124,6 @@ public class HttpClientTransportOverHTTP2 extends AbstractHttpClientTransport connect(address, destination.getClientConnectionFactory(), listenerPromise, listenerPromise, context); } - @Override - public void connect(InetSocketAddress address, Map context) - { - connect((SocketAddress)address, context); - } - protected void connect(SocketAddress address, ClientConnectionFactory factory, Session.Listener listener, Promise promise, Map context) { HttpDestination destination = (HttpDestination)context.get(HTTP_DESTINATION_CONTEXT_KEY); diff --git a/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/HttpClientTransportOverHTTP3.java b/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/HttpClientTransportOverHTTP3.java index 490ae2970f4..cc39dd68126 100644 --- a/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/HttpClientTransportOverHTTP3.java +++ b/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/HttpClientTransportOverHTTP3.java @@ -13,7 +13,6 @@ package org.eclipse.jetty.http3.client.transport; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.time.Duration; import java.util.List; @@ -99,12 +98,6 @@ public class HttpClientTransportOverHTTP3 extends AbstractHttpClientTransport im return new HttpDestination(getHttpClient(), origin); } - @Override - public void connect(InetSocketAddress address, Map context) - { - connect((SocketAddress)address, context); - } - @Override public void connect(SocketAddress address, Map context) { diff --git a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java index b08dac5a583..74c3b7083d2 100644 --- a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java +++ b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java @@ -18,18 +18,14 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.SocketException; import java.net.SocketOption; -import java.net.StandardProtocolFamily; import java.net.StandardSocketOptions; -import java.net.UnixDomainSocketAddress; import java.nio.channels.DatagramChannel; import java.nio.channels.NetworkChannel; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; -import java.nio.file.Path; import java.time.Duration; import java.util.Map; -import java.util.Objects; import java.util.concurrent.Executor; import org.eclipse.jetty.util.IO; @@ -79,20 +75,6 @@ public class ClientConnector extends ContainerLifeCycle public static final String APPLICATION_PROTOCOLS_CONTEXT_KEY = CLIENT_CONNECTOR_CONTEXT_KEY + ".applicationProtocols"; private static final Logger LOG = LoggerFactory.getLogger(ClientConnector.class); - /** - *

Creates a ClientConnector configured to connect via Unix-Domain sockets to the given Unix-Domain path

- * - * @param path the Unix-Domain path to connect to - * @return a ClientConnector that connects to the given Unix-Domain path - * @deprecated replaced by {@link Transport.TCPUnix} - */ - @Deprecated(since = "12.0.7", forRemoval = true) - public static ClientConnector forUnixDomain(Path path) - { - return new ClientConnector(Configurator.forUnixDomain(path)); - } - - private final Configurator configurator; private Executor executor; private Scheduler scheduler; private ByteBufferPool byteBufferPool; @@ -109,36 +91,6 @@ public class ClientConnector extends ContainerLifeCycle private int receiveBufferSize = -1; private int sendBufferSize = -1; - public ClientConnector() - { - this(new Configurator()); - } - - /** - * @param configurator the {@link Configurator} - * @deprecated replaced by {@link Transport} - */ - @Deprecated(since = "12.0.7", forRemoval = true) - public ClientConnector(Configurator configurator) - { - this.configurator = Objects.requireNonNull(configurator); - installBean(configurator); - configurator.addBean(this, false); - } - - /** - * @param address the SocketAddress to connect to - * @return whether the connection to the given SocketAddress is intrinsically secure - * @see Configurator#isIntrinsicallySecure(ClientConnector, SocketAddress) - * - * @deprecated replaced by {@link Transport#isIntrinsicallySecure()} - */ - @Deprecated(since = "12.0.7", forRemoval = true) - public boolean isIntrinsicallySecure(SocketAddress address) - { - return configurator.isIntrinsicallySecure(this, address); - } - public SelectorManager getSelectorManager() { return selectorManager; @@ -149,21 +101,6 @@ public class ClientConnector extends ContainerLifeCycle return executor; } - /** - *

Returns the default {@link Transport} for this connector.

- *

This method only exists for backwards compatibility, when - * {@link Configurator} was used, and should be removed when - * {@link Configurator} is removed.

- * - * @return the default {@link Transport} for this connector - * @deprecated use {@link Transport} instead - */ - @Deprecated(since = "12.0.7", forRemoval = true) - public Transport newTransport() - { - return configurator.newTransport(); - } - public void setExecutor(Executor executor) { if (isStarted()) @@ -632,125 +569,4 @@ public class ClientConnector extends ContainerLifeCycle connectFailed(failure, context); } } - - /** - *

Configures a {@link ClientConnector}.

- * - * @deprecated replaced by {@link Transport} - */ - @Deprecated(since = "12.0.7", forRemoval = true) - public static class Configurator extends ContainerLifeCycle - { - /** - * @return the default {@link Transport} for this configurator - */ - public Transport newTransport() - { - return null; - } - - /** - *

Returns whether the connection to a given {@link SocketAddress} is intrinsically secure.

- *

A protocol such as HTTP/1.1 can be transported by TCP; however, TCP is not secure because - * it does not offer any encryption.

- *

Encryption is provided by using TLS to wrap the HTTP/1.1 bytes, and then transporting the - * TLS bytes over TCP.

- *

On the other hand, protocols such as QUIC are intrinsically secure, and therefore it is - * not necessary to wrap the HTTP/1.1 bytes with TLS: the HTTP/1.1 bytes are transported over - * QUIC in an intrinsically secure way.

- * - * @param clientConnector the ClientConnector - * @param address the SocketAddress to connect to - * @return whether the connection to the given SocketAddress is intrinsically secure - */ - public boolean isIntrinsicallySecure(ClientConnector clientConnector, SocketAddress address) - { - return false; - } - - /** - *

Creates a new {@link SocketChannel} to connect to a {@link SocketAddress} - * derived from the input socket address.

- *

The input socket address represents the destination socket address to - * connect to, as it is typically specified by a URI authority, for example - * {@code localhost:8080} if the URI is {@code http://localhost:8080/path}.

- *

However, the returned socket address may be different as the implementation - * may use a Unix-Domain socket address to physically connect to the virtual - * destination socket address given as input.

- *

The return type is a pair/record holding the socket channel and the - * socket address, with the socket channel not yet connected. - * The implementation of this methods must not call - * {@link SocketChannel#connect(SocketAddress)}, as this is done later, - * after configuring the socket, by the {@link ClientConnector} implementation.

- * - * @param clientConnector the client connector requesting channel with associated address - * @param address the destination socket address, typically specified in a URI - * @param context the context to create the new socket channel - * @return a new {@link SocketChannel} with an associated {@link SocketAddress} to connect to - * @throws IOException if the socket channel or the socket address cannot be created - */ - public ChannelWithAddress newChannelWithAddress(ClientConnector clientConnector, SocketAddress address, Map context) throws IOException - { - return new ChannelWithAddress(SocketChannel.open(), address); - } - - public EndPoint newEndPoint(ClientConnector clientConnector, SocketAddress address, SelectableChannel selectable, ManagedSelector selector, SelectionKey selectionKey) - { - return new SocketChannelEndPoint((SocketChannel)selectable, selector, selectionKey, clientConnector.getScheduler()); - } - - public Connection newConnection(ClientConnector clientConnector, SocketAddress address, EndPoint endPoint, Map context) throws IOException - { - ClientConnectionFactory factory = (ClientConnectionFactory)context.get(CLIENT_CONNECTION_FACTORY_CONTEXT_KEY); - return factory.newConnection(endPoint, context); - } - - /** - *

A pair/record holding a {@link SelectableChannel} and a {@link SocketAddress} to connect to.

- * - * @deprecated replaced by {@link Transport} - */ - @Deprecated(since = "12.0.7", forRemoval = true) - public static class ChannelWithAddress - { - private final SelectableChannel channel; - private final SocketAddress address; - - public ChannelWithAddress(SelectableChannel channel, SocketAddress address) - { - this.channel = channel; - this.address = address; - } - - public SelectableChannel getSelectableChannel() - { - return channel; - } - - public SocketAddress getSocketAddress() - { - return address; - } - } - - private static Configurator forUnixDomain(Path path) - { - return new Configurator() - { - @Override - public Transport newTransport() - { - return new Transport.TCPUnix(path); - } - - @Override - public ChannelWithAddress newChannelWithAddress(ClientConnector clientConnector, SocketAddress address, Map context) throws IOException - { - SocketChannel socketChannel = SocketChannel.open(StandardProtocolFamily.UNIX); - UnixDomainSocketAddress socketAddress = UnixDomainSocketAddress.of(path); - return new ChannelWithAddress(socketChannel, socketAddress); - } - }; - } - } } diff --git a/jetty-core/jetty-quic/jetty-quic-client/src/main/java/org/eclipse/jetty/quic/client/QuicClientConnectorConfigurator.java b/jetty-core/jetty-quic/jetty-quic-client/src/main/java/org/eclipse/jetty/quic/client/QuicClientConnectorConfigurator.java deleted file mode 100644 index bd9aa198689..00000000000 --- a/jetty-core/jetty-quic/jetty-quic-client/src/main/java/org/eclipse/jetty/quic/client/QuicClientConnectorConfigurator.java +++ /dev/null @@ -1,136 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.quic.client; - -import java.io.IOException; -import java.net.SocketAddress; -import java.nio.channels.DatagramChannel; -import java.nio.channels.SelectableChannel; -import java.nio.channels.SelectionKey; -import java.nio.channels.SocketChannel; -import java.util.Map; -import java.util.Objects; -import java.util.function.UnaryOperator; - -import org.eclipse.jetty.io.ClientConnector; -import org.eclipse.jetty.io.Connection; -import org.eclipse.jetty.io.DatagramChannelEndPoint; -import org.eclipse.jetty.io.EndPoint; -import org.eclipse.jetty.io.ManagedSelector; -import org.eclipse.jetty.io.SocketChannelEndPoint; -import org.eclipse.jetty.io.Transport; -import org.eclipse.jetty.quic.common.QuicConfiguration; -import org.eclipse.jetty.util.ssl.SslContextFactory; - -/** - *

A QUIC specific {@link ClientConnector.Configurator}.

- *

Since QUIC is based on UDP, this class creates {@link DatagramChannel}s instead of - * {@link SocketChannel}s, and {@link DatagramChannelEndPoint}s instead of - * {@link SocketChannelEndPoint}s.

- * - * @see QuicConfiguration - * @deprecated replaced by {@link Transport} - */ -@Deprecated(since = "12.0.7", forRemoval = true) -public class QuicClientConnectorConfigurator extends ClientConnector.Configurator -{ - private final QuicConfiguration initQuicConfig = new QuicConfiguration(); - private final UnaryOperator configurator; - private ClientQuicConfiguration quicConfig; - - public QuicClientConnectorConfigurator() - { - this(UnaryOperator.identity()); - } - - public QuicClientConnectorConfigurator(UnaryOperator configurator) - { - this.configurator = Objects.requireNonNull(configurator); - // Initialize to sane defaults for a client. - initQuicConfig.setSessionRecvWindow(16 * 1024 * 1024); - initQuicConfig.setBidirectionalStreamRecvWindow(8 * 1024 * 1024); - initQuicConfig.setDisableActiveMigration(true); - } - - public QuicConfiguration getQuicConfiguration() - { - if (!isStarted()) - return initQuicConfig; - else - return quicConfig; - } - - @Override - protected void doStart() throws Exception - { - ClientConnector clientConnector = getBean(ClientConnector.class); - SslContextFactory.Client sslContextFactory = clientConnector.getSslContextFactory(); - - quicConfig = new ClientQuicConfiguration(sslContextFactory, initQuicConfig.getPemWorkDirectory()); - addBean(quicConfig); - - quicConfig.setInputBufferSize(initQuicConfig.getInputBufferSize()); - quicConfig.setOutputBufferSize(initQuicConfig.getOutputBufferSize()); - quicConfig.setUseInputDirectByteBuffers(initQuicConfig.isUseInputDirectByteBuffers()); - quicConfig.setUseOutputDirectByteBuffers(initQuicConfig.isUseOutputDirectByteBuffers()); - quicConfig.setProtocols(initQuicConfig.getProtocols()); - quicConfig.setDisableActiveMigration(initQuicConfig.isDisableActiveMigration()); - quicConfig.setMaxBidirectionalRemoteStreams(initQuicConfig.getMaxBidirectionalRemoteStreams()); - quicConfig.setMaxUnidirectionalRemoteStreams(initQuicConfig.getMaxUnidirectionalRemoteStreams()); - quicConfig.setSessionRecvWindow(initQuicConfig.getSessionRecvWindow()); - quicConfig.setBidirectionalStreamRecvWindow(initQuicConfig.getBidirectionalStreamRecvWindow()); - quicConfig.setUnidirectionalStreamRecvWindow(initQuicConfig.getUnidirectionalStreamRecvWindow()); - quicConfig.getImplementationConfiguration().putAll(initQuicConfig.getImplementationConfiguration()); - - super.doStart(); - } - - @Override - public Transport newTransport() - { - return new QuicTransport(quicConfig); - } - - @Override - public boolean isIntrinsicallySecure(ClientConnector clientConnector, SocketAddress address) - { - return true; - } - - @Override - public ChannelWithAddress newChannelWithAddress(ClientConnector clientConnector, SocketAddress address, Map context) throws IOException - { - context.put(QuicConfiguration.CONTEXT_KEY, initQuicConfig); - - DatagramChannel channel = DatagramChannel.open(); - if (clientConnector.getBindAddress() == null) - { - // QUIC must know the local address for connection migration, so we must always bind early. - channel.bind(null); - } - return new ChannelWithAddress(channel, address); - } - - @Override - public EndPoint newEndPoint(ClientConnector clientConnector, SocketAddress address, SelectableChannel selectable, ManagedSelector selector, SelectionKey selectionKey) - { - return new DatagramChannelEndPoint((DatagramChannel)selectable, selector, selectionKey, clientConnector.getScheduler()); - } - - @Override - public Connection newConnection(ClientConnector clientConnector, SocketAddress address, EndPoint endPoint, Map context) - { - return configurator.apply(new ClientQuicConnection(clientConnector, endPoint, context)); - } -} diff --git a/jetty-core/jetty-quic/jetty-quic-client/src/test/java/org/eclipse/jetty/quic/client/End2EndClientTest.java b/jetty-core/jetty-quic/jetty-quic-client/src/test/java/org/eclipse/jetty/quic/client/End2EndClientTest.java index 526b7d2d335..6d852a1fa71 100644 --- a/jetty-core/jetty-quic/jetty-quic-client/src/test/java/org/eclipse/jetty/quic/client/End2EndClientTest.java +++ b/jetty-core/jetty-quic/jetty-quic-client/src/test/java/org/eclipse/jetty/quic/client/End2EndClientTest.java @@ -30,6 +30,7 @@ import org.eclipse.jetty.io.ClientConnectionFactory; import org.eclipse.jetty.io.ClientConnector; import org.eclipse.jetty.io.Content; import org.eclipse.jetty.quic.server.QuicServerConnector; +import org.eclipse.jetty.quic.server.ServerQuicConfiguration; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -65,6 +66,7 @@ public class End2EndClientTest """; + private QuicTransport transport; @BeforeEach public void setUp() throws Exception @@ -83,9 +85,8 @@ public class End2EndClientTest HttpConfiguration httpConfiguration = new HttpConfiguration(); HttpConnectionFactory http1 = new HttpConnectionFactory(httpConfiguration); HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory(httpConfiguration); - // Use the deprecated APIs for backwards compatibility testing. - connector = new QuicServerConnector(server, sslContextFactory, http1, http2); - connector.getQuicConfiguration().setPemWorkDirectory(workDir.getEmptyPathDir()); + ServerQuicConfiguration serverQuicConfiguration = new ServerQuicConfiguration(sslContextFactory, workDir.getEmptyPathDir()); + connector = new QuicServerConnector(server, serverQuicConfiguration, http1, http2); server.addConnector(connector); server.setHandler(new Handler.Abstract() @@ -100,9 +101,9 @@ public class End2EndClientTest server.start(); - // Use the deprecated APIs for backwards compatibility testing. - ClientConnector clientConnector = new ClientConnector(new QuicClientConnectorConfigurator()); SslContextFactory.Client clientSslContextFactory = new SslContextFactory.Client(true); + transport = new QuicTransport(new ClientQuicConfiguration(clientSslContextFactory, null)); + ClientConnector clientConnector = new ClientConnector(); clientConnector.setSslContextFactory(clientSslContextFactory); ClientConnectionFactory.Info http1Info = HttpClientConnectionFactory.HTTP11; ClientConnectionFactoryOverHTTP2.HTTP2 http2Info = new ClientConnectionFactoryOverHTTP2.HTTP2(new HTTP2Client(clientConnector)); @@ -123,6 +124,7 @@ public class End2EndClientTest public void testSimpleHTTP1() throws Exception { ContentResponse response = client.newRequest("https://localhost:" + connector.getLocalPort()) + .transport(transport) .timeout(5, TimeUnit.SECONDS) .send(); assertThat(response.getStatus(), is(200)); @@ -135,6 +137,7 @@ public class End2EndClientTest { ContentResponse response = client.newRequest("https://localhost:" + connector.getLocalPort()) .version(HttpVersion.HTTP_2) + .transport(transport) .timeout(5, TimeUnit.SECONDS) .send(); assertThat(response.getStatus(), is(200)); @@ -148,6 +151,7 @@ public class End2EndClientTest for (int i = 0; i < 1000; i++) { ContentResponse response = client.newRequest("https://localhost:" + connector.getLocalPort() + "/" + i) + .transport(transport) .timeout(5, TimeUnit.SECONDS) .send(); assertThat(response.getStatus(), is(200)); @@ -169,7 +173,9 @@ public class End2EndClientTest { try { - ContentResponse response = client.GET("https://localhost:" + connector.getLocalPort() + path); + ContentResponse response = client.newRequest("https://localhost:" + connector.getLocalPort() + path) + .transport(transport) + .send(); assertThat(response.getStatus(), is(200)); String contentAsString = response.getContentAsString(); assertThat(contentAsString, is(responseContent)); @@ -178,7 +184,7 @@ public class End2EndClientTest { throw new RuntimeException(e); } - }); + }, client.getExecutor()); } CompletableFuture.allOf(futures) .orTimeout(15, TimeUnit.SECONDS) diff --git a/jetty-core/jetty-quic/jetty-quic-client/src/test/java/org/eclipse/jetty/quic/client/End2EndClientWithClientCertAuthTest.java b/jetty-core/jetty-quic/jetty-quic-client/src/test/java/org/eclipse/jetty/quic/client/End2EndClientWithClientCertAuthTest.java index 7ff11ef82d9..03eae31e3d3 100644 --- a/jetty-core/jetty-quic/jetty-quic-client/src/test/java/org/eclipse/jetty/quic/client/End2EndClientWithClientCertAuthTest.java +++ b/jetty-core/jetty-quic/jetty-quic-client/src/test/java/org/eclipse/jetty/quic/client/End2EndClientWithClientCertAuthTest.java @@ -30,7 +30,9 @@ import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory; import org.eclipse.jetty.io.ClientConnectionFactory; import org.eclipse.jetty.io.ClientConnector; import org.eclipse.jetty.io.Content; +import org.eclipse.jetty.io.Transport; import org.eclipse.jetty.quic.server.QuicServerConnector; +import org.eclipse.jetty.quic.server.ServerQuicConfiguration; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -67,6 +69,7 @@ public class End2EndClientWithClientCertAuthTest \t """; private SslContextFactory.Server serverSslContextFactory; + private Transport transport; @BeforeEach public void setUp() throws Exception @@ -95,9 +98,8 @@ public class End2EndClientWithClientCertAuthTest httpConfiguration.addCustomizer(new SecureRequestCustomizer()); HttpConnectionFactory http1 = new HttpConnectionFactory(httpConfiguration); HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory(httpConfiguration); - // Use the deprecated APIs for backwards compatibility testing. - connector = new QuicServerConnector(server, serverSslContextFactory, http1, http2); - connector.getQuicConfiguration().setPemWorkDirectory(serverWorkPath); + ServerQuicConfiguration serverQuicConfiguration = new ServerQuicConfiguration(serverSslContextFactory, serverWorkPath); + connector = new QuicServerConnector(server, serverQuicConfiguration, http1, http2); server.addConnector(connector); server.setHandler(new Handler.Abstract() @@ -112,15 +114,16 @@ public class End2EndClientWithClientCertAuthTest server.start(); - // Use the deprecated APIs for backwards compatibility testing. - QuicClientConnectorConfigurator configurator = new QuicClientConnectorConfigurator(); - configurator.getQuicConfiguration().setPemWorkDirectory(clientWorkPath); - ClientConnector clientConnector = new ClientConnector(configurator); SslContextFactory.Client clientSslContextFactory = new SslContextFactory.Client(); clientSslContextFactory.setCertAlias("mykey"); clientSslContextFactory.setKeyStore(keyStore); clientSslContextFactory.setKeyStorePassword("storepwd"); clientSslContextFactory.setTrustStore(keyStore); + clientSslContextFactory.setTrustStorePassword("storepwd"); + ClientQuicConfiguration clientQuicConfiguration = new ClientQuicConfiguration(clientSslContextFactory, clientWorkPath); + clientQuicConfiguration.start(); + transport = new QuicTransport(clientQuicConfiguration); + ClientConnector clientConnector = new ClientConnector(); clientConnector.setSslContextFactory(clientSslContextFactory); ClientConnectionFactory.Info http1Info = HttpClientConnectionFactory.HTTP11; ClientConnectionFactoryOverHTTP2.HTTP2 http2Info = new ClientConnectionFactoryOverHTTP2.HTTP2(new HTTP2Client(clientConnector)); @@ -141,6 +144,7 @@ public class End2EndClientWithClientCertAuthTest { ContentResponse response = client.newRequest("https://localhost:" + connector.getLocalPort()) .timeout(5, TimeUnit.SECONDS) + .transport(transport) .send(); assertThat(response.getStatus(), is(200)); String contentAsString = response.getContentAsString(); @@ -150,12 +154,13 @@ public class End2EndClientWithClientCertAuthTest @Test public void testServerRejectsClientInvalidCert() throws Exception { - // remove the trust store config from the server + // Remove the trust store config from the server. server.stop(); serverSslContextFactory.setTrustStore(null); server.start(); assertThrows(TimeoutException.class, () -> client.newRequest("https://localhost:" + connector.getLocalPort()) + .transport(transport) .timeout(1, TimeUnit.SECONDS) .send()); } diff --git a/jetty-core/jetty-quic/jetty-quic-server/src/main/java/org/eclipse/jetty/quic/server/QuicServerConnector.java b/jetty-core/jetty-quic/jetty-quic-server/src/main/java/org/eclipse/jetty/quic/server/QuicServerConnector.java index ca91eb88c9e..cb340e95aac 100644 --- a/jetty-core/jetty-quic/jetty-quic-server/src/main/java/org/eclipse/jetty/quic/server/QuicServerConnector.java +++ b/jetty-core/jetty-quic/jetty-quic-server/src/main/java/org/eclipse/jetty/quic/server/QuicServerConnector.java @@ -37,7 +37,6 @@ import org.eclipse.jetty.server.AbstractNetworkConnector; import org.eclipse.jetty.server.ConnectionFactory; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.Scheduler; /** @@ -57,38 +56,11 @@ public class QuicServerConnector extends AbstractNetworkConnector private volatile DatagramChannel datagramChannel; private volatile int localPort = -1; - /** - * @param server the {@link Server} - * @param sslContextFactory the {@link SslContextFactory.Server} - * @param factories the {@link ConnectionFactory}s of the protocols transported by QUIC - * @deprecated use {@link #QuicServerConnector(Server, ServerQuicConfiguration, ConnectionFactory...)} instead - */ - @Deprecated(since = "12.0.7", forRemoval = true) - public QuicServerConnector(Server server, SslContextFactory.Server sslContextFactory, ConnectionFactory... factories) - { - this(server, new ServerQuicConfiguration(sslContextFactory, null), factories); - } - public QuicServerConnector(Server server, ServerQuicConfiguration quicConfiguration, ConnectionFactory... factories) { this(server, null, null, null, quicConfiguration, factories); } - /** - * @param server the {@link Server} - * @param executor the {@link Executor} - * @param scheduler the {@link Scheduler} - * @param bufferPool the {@link ByteBufferPool} - * @param sslContextFactory the {@link SslContextFactory.Server} - * @param factories the {@link ConnectionFactory}s of the protocols transported by QUIC - * @deprecated use {@link #QuicServerConnector(Server, Executor, Scheduler, ByteBufferPool, ServerQuicConfiguration, ConnectionFactory...)} instead - */ - @Deprecated(since = "12.0.7", forRemoval = true) - public QuicServerConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, SslContextFactory.Server sslContextFactory, ConnectionFactory... factories) - { - this(server, executor, scheduler, bufferPool, new ServerQuicConfiguration(sslContextFactory, null), factories); - } - public QuicServerConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, ServerQuicConfiguration quicConfiguration, ConnectionFactory... factories) { super(server, executor, scheduler, bufferPool, 0, factories); diff --git a/jetty-core/jetty-unixdomain-server/src/test/java/org/eclipse/jetty/unixdomain/server/UnixDomainTest.java b/jetty-core/jetty-unixdomain-server/src/test/java/org/eclipse/jetty/unixdomain/server/UnixDomainTest.java index 56485f5af07..7d30279883b 100644 --- a/jetty-core/jetty-unixdomain-server/src/test/java/org/eclipse/jetty/unixdomain/server/UnixDomainTest.java +++ b/jetty-core/jetty-unixdomain-server/src/test/java/org/eclipse/jetty/unixdomain/server/UnixDomainTest.java @@ -109,12 +109,12 @@ public class UnixDomainTest } }); - // Use the deprecated APIs for backwards compatibility testing. - ClientConnector clientConnector = ClientConnector.forUnixDomain(unixDomainPath); + ClientConnector clientConnector = new ClientConnector(); try (HttpClient httpClient = new HttpClient(new HttpClientTransportDynamic(clientConnector))) { httpClient.start(); ContentResponse response = httpClient.newRequest(uri) + .transport(new Transport.TCPUnix(unixDomainPath)) .timeout(5, TimeUnit.SECONDS) .send();