Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated HttpClient#from and HttpServer#from #2203

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions reactor-netty-http/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ task japicmp(type: JapicmpTask) {
onlyIf { "$compatibleVersion" != "SKIP" }
methodExcludes = [
// Deprecated method is removed
'reactor.netty.http.client.HttpClient#from(reactor.netty.tcp.TcpClient)',
'reactor.netty.http.client.HttpClient#tcpConfiguration(java.util.function.Function)',
'reactor.netty.http.server.HttpServer#from(reactor.netty.tcp.TcpServer)',
'reactor.netty.http.server.HttpServer#tcpConfiguration(java.util.function.Function)'
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import reactor.netty.internal.util.Metrics;
import reactor.netty.resources.ConnectionProvider;
import reactor.netty.tcp.SslProvider;
import reactor.netty.tcp.TcpClient;
import reactor.netty.transport.ClientTransport;
import reactor.util.annotation.Nullable;

Expand Down Expand Up @@ -405,75 +404,6 @@ public static HttpClient create(ConnectionProvider connectionProvider) {
return new HttpClientConnect(new HttpConnectionProvider(connectionProvider));
}

/**
* Prepare an {@link HttpClient}
* <p>
* <strong>Note:</strong>
* There isn't only one method that replaces this deprecated method.
* The configuration that can be done with this deprecated method,
* can also be done with the other methods exposed by {@link HttpClient}.
* </p>
* <p>Examples:</p>
* <p>Configuration via the deprecated '.from(...)' method</p>
* <pre>
* {@code
* HttpClient.from(
* TcpClient.attr(...) // configures the channel attributes
* .bindAddress(...) // configures the bind (local) address
* .channelGroup(...) // configures the channel group
* .doOnChannelInit(...) // configures the channel handler
* .doOnConnected(...) // configures the doOnConnected callback
* .doOnDisconnected(...) // configures the doOnDisconnected callback
* .metrics(...) // configures the metrics
* .observe() // configures the connection observer
* .option(...) // configures the channel options
* .proxy(...) // configures the proxy
* .remoteAddress(...) // configures the remote address
* .resolver(...) // configures the host names resolver
* .runOn(...) // configures the event loop group
* .secure() // configures the SSL
* .wiretap()) // configures the wire logging
* }
* </pre>
*
* <p>Configuration via the other methods exposed by {@link HttpClient}</p>
* <pre>
* {@code
* HttpClient.attr(...) // configures the channel attributes
* .bindAddress(...) // configures the bind (local) address
* .channelGroup(...) // configures the channel group
* .doOnChannelInit(...) // configures the channel handler
* .doOnConnected(...) // configures the doOnConnected callback
* .doOnDisconnected(...) // configures the doOnDisconnected callback
* .metrics(...) // configures the metrics
* .observe() // configures the connection observer
* .option(...) // configures the channel options
* .proxy(...) // configures the proxy
* .remoteAddress(...) // configures the remote address
* .resolver(...) // configures the host names resolver
* .runOn(...) // configures the event loop group
* .secure() // configures the SSL
* .wiretap() // configures the wire logging
* }
* </pre>
*
* <p>Wire logging in plain text</p>
* <pre>
* {@code
* HttpClient.wiretap("logger", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL)
* }
* </pre>
*
* @return a new {@link HttpClient}
* @deprecated Use the other methods exposed by {@link HttpClient} to achieve the same configurations.
* This method will be removed in version 1.1.0.
*/
@Deprecated
public static HttpClient from(TcpClient tcpClient) {
Objects.requireNonNull(tcpClient, "tcpClient");
return HttpClientConnect.applyTcpClientConfig(tcpClient.configuration());
}

/**
* Prepare an unpooled {@link HttpClient}. {@link UriConfiguration#uri(String)} or
* {@link #baseUrl(String)} should be invoked after a verb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import reactor.netty.http.server.logging.AccessLogFactory;
import reactor.netty.internal.util.Metrics;
import reactor.netty.tcp.SslProvider;
import reactor.netty.tcp.TcpServer;
import reactor.netty.transport.ServerTransport;
import reactor.util.Logger;
import reactor.util.Loggers;
Expand Down Expand Up @@ -82,77 +81,6 @@ public static HttpServer create() {
return HttpServerBind.INSTANCE;
}

/**
* Prepare an {@link HttpServer}
* <p>
* <strong>Note:</strong>
* There isn't only one method that replaces this deprecated method.
* The configuration that can be done with this deprecated method,
* can also be done with the other methods exposed by {@link HttpServer}.
* </p>
* <p>Examples:</p>
* <p>Configuration via the deprecated '.from(...)' method</p>
* <pre>
* {@code
* HttpServer.from(
* TcpServer.attr(...) // configures the channel attributes
* .bindAddress(...) // configures the bind (local) address
* .childAttr(...) // configures the child channel attributes
* .childObserve() // configures the child channel connection observer
* .childOption(...) // configures the child channel options
* .channelGroup(...) // configures the channel group
* .doOnBound(...) // configures the doOnBound callback
* .doOnChannelInit(...) // configures the channel handler
* .doOnConnection(...) // configures the doOnConnection callback
* .doOnUnbound(...) // configures the doOnUnbound callback
* .metrics(...) // configures the metrics
* .observe() // configures the connection observer
* .option(...) // configures the channel options
* .runOn(...) // configures the event loop group
* .secure() // configures the SSL
* .wiretap()) // configures the wire logging
* }
* </pre>
*
* <p>Configuration via the other methods exposed by {@link HttpServer}</p>
* <pre>
* {@code
* HttpServer.attr(...) // configures the channel attributes
* .bindAddress(...) // configures the bind (local) address
* .childAttr(...) // configures the child channel attributes
* .childObserve() // configures the child channel connection observer
* .childOption(...) // configures the child channel options
* .channelGroup(...) // configures the channel group
* .doOnBound(...) // configures the doOnBound callback
* .doOnChannelInit(...) // configures the channel handler
* .doOnConnection(...) // configures the doOnConnection callback
* .doOnUnbound(...) // configures the doOnUnbound callback
* .metrics(...) // configures the metrics
* .observe() // configures the connection observer
* .option(...) // configures the channel options
* .runOn(...) // configures the event loop group
* .secure() // configures the SSL
* .wiretap() // configures the wire logging
* }
* </pre>
*
* <p>Wire logging in plain text</p>
* <pre>
* {@code
* HttpServer.wiretap("logger", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL)
* }
* </pre>
*
* @return a new {@link HttpServer}
* @deprecated Use the other methods exposed by {@link HttpServer} to achieve the same configurations.
* This method will be removed in version 1.1.0.
*/
@Deprecated
public static HttpServer from(TcpServer tcpServer) {
Objects.requireNonNull(tcpServer, "tcpServer");
return HttpServerBind.applyTcpServerConfig(tcpServer.configuration());
}

/**
* Enable or disable the access log. If enabled, the default log system will be used.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.channel.unix.DomainSocketAddress;
Expand Down Expand Up @@ -84,11 +82,9 @@
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.util.AttributeKey;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.ReferenceCounted;
import io.netty.util.concurrent.DefaultEventExecutor;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand Down Expand Up @@ -119,7 +115,6 @@
import reactor.netty.resources.LoopResources;
import reactor.netty.tcp.SslProvider;
import reactor.netty.tcp.TcpClient;
import reactor.netty.tcp.TcpServer;
import reactor.test.StepVerifier;
import reactor.util.annotation.Nullable;
import reactor.util.context.Context;
Expand Down Expand Up @@ -1775,74 +1770,6 @@ private void doTestHttpServerWithDomainSockets(HttpServer server, HttpClient cli
assertThat(response).isEqualTo("123");
}

@Test
@SuppressWarnings("deprecation")
void testTcpConfiguration_2() throws Exception {
CountDownLatch latch = new CountDownLatch(10);
LoopResources loop = LoopResources.create("testTcpConfiguration");
ChannelGroup group = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
doTestTcpConfiguration(
HttpServer.from(configureTcpServer(TcpServer.create(), loop, group, latch)),
HttpClient.from(configureTcpClient(TcpClient.create(), loop, group, latch))
);

assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();

FutureMono.from(group.close())
.then(loop.disposeLater())
.block(Duration.ofSeconds(30));
}

private void doTestTcpConfiguration(HttpServer server, HttpClient client) {
disposableServer = server.bindNow();

String response =
client.post()
.uri("/")
.send(ByteBufFlux.fromString(Mono.just("testTcpConfiguration")))
.responseContent()
.aggregate()
.asString()
.block(Duration.ofSeconds(30));

assertThat(response).isEqualTo("testTcpConfiguration");
}

private TcpServer configureTcpServer(TcpServer tcp, LoopResources loop, ChannelGroup group, CountDownLatch latch) {
return tcp.wiretap(true)
.host("localhost")
.runOn(loop)
.channelGroup(group)
.doOnBound(s -> latch.countDown())
.doOnConnection(c -> latch.countDown())
.doOnUnbound(s -> latch.countDown())
.handle((req, res) -> res.send(req.receive().retain()))
.noSSL()
.port(0)
.attr(AttributeKey.valueOf("testTcpConfiguration"), "testTcpConfiguration")
.option(ChannelOption.valueOf("testTcpConfiguration"), "testTcpConfiguration")
.childAttr(AttributeKey.valueOf("testTcpConfiguration"), "testTcpConfiguration")
.childOption(ChannelOption.valueOf("testTcpConfiguration"), "testTcpConfiguration")
.observe((conn, state) -> latch.countDown())
.childObserve((conn, state) -> latch.countDown())
.doOnChannelInit((observer, channel, address) -> latch.countDown());
}

private TcpClient configureTcpClient(TcpClient tcp, LoopResources loop, ChannelGroup group, CountDownLatch latch) {
return tcp.wiretap(true)
.runOn(loop)
.channelGroup(group)
.doOnConnected(c -> latch.countDown())
.doOnDisconnected(c -> latch.countDown())
.noSSL()
.noProxy()
.remoteAddress(() -> disposableServer.address())
.attr(AttributeKey.valueOf("testTcpConfiguration"), "testTcpConfiguration")
.option(ChannelOption.valueOf("testTcpConfiguration"), "testTcpConfiguration")
.observe((conn, state) -> latch.countDown())
.doOnChannelInit((observer, channel, address) -> latch.countDown());
}

@Test
void testStatus() {
doTestStatus(HttpResponseStatus.OK);
Expand Down