diff --git a/alts/src/main/java/io/grpc/alts/HandshakerServiceChannel.java b/alts/src/main/java/io/grpc/alts/HandshakerServiceChannel.java index 708ae791db..fdfa972e9c 100644 --- a/alts/src/main/java/io/grpc/alts/HandshakerServiceChannel.java +++ b/alts/src/main/java/io/grpc/alts/HandshakerServiceChannel.java @@ -58,7 +58,7 @@ final class HandshakerServiceChannel { NettyChannelBuilder.forTarget(handshakerAddress) .directExecutor() .eventLoopGroup(new NioEventLoopGroup(1, clientThreadFactory)) - .usePlaintext(true) + .usePlaintext() .build(); return channel; } diff --git a/benchmarks/src/test/java/io/grpc/benchmarks/driver/LoadWorkerTest.java b/benchmarks/src/test/java/io/grpc/benchmarks/driver/LoadWorkerTest.java index 0c5b62efe2..236545c04f 100644 --- a/benchmarks/src/test/java/io/grpc/benchmarks/driver/LoadWorkerTest.java +++ b/benchmarks/src/test/java/io/grpc/benchmarks/driver/LoadWorkerTest.java @@ -57,7 +57,7 @@ public class LoadWorkerTest { int port = Utils.pickUnusedPort(); worker = new LoadWorker(port, 0); worker.start(); - channel = NettyChannelBuilder.forAddress("localhost", port).usePlaintext(true).build(); + channel = NettyChannelBuilder.forAddress("localhost", port).usePlaintext().build(); workerServiceStub = WorkerServiceGrpc.newStub(channel); marksQueue = new LinkedBlockingQueue(); } diff --git a/core/src/main/java/io/grpc/ForwardingChannelBuilder.java b/core/src/main/java/io/grpc/ForwardingChannelBuilder.java index c689cc5bfc..9c780698ce 100644 --- a/core/src/main/java/io/grpc/ForwardingChannelBuilder.java +++ b/core/src/main/java/io/grpc/ForwardingChannelBuilder.java @@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit; @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3363") public abstract class ForwardingChannelBuilder> extends ManagedChannelBuilder { + /** * The default constructor. */ @@ -91,9 +92,19 @@ public abstract class ForwardingChannelBuilder o = delegate().usePlaintext(skipNegotiation); + return thisT(); + } + + @Override + public T usePlaintext() { + delegate().usePlaintext(); return thisT(); } diff --git a/core/src/main/java/io/grpc/ManagedChannelBuilder.java b/core/src/main/java/io/grpc/ManagedChannelBuilder.java index b606b48631..af9c05705f 100644 --- a/core/src/main/java/io/grpc/ManagedChannelBuilder.java +++ b/core/src/main/java/io/grpc/ManagedChannelBuilder.java @@ -152,13 +152,38 @@ public abstract class ManagedChannelBuilder> * * @param skipNegotiation @{code true} if there is a priori knowledge that the endpoint supports * plaintext, {@code false} if plaintext use must be negotiated. + * @deprecated Use {@link #usePlaintext()} instead. * * @throws UnsupportedOperationException if plaintext mode is not supported. * @return this * @since 1.0.0 */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1772") - public abstract T usePlaintext(boolean skipNegotiation); + @Deprecated + public T usePlaintext(boolean skipNegotiation) { + throw new UnsupportedOperationException(); + } + + /** + * Use of a plaintext connection to the server. By default a secure connection mechanism + * such as TLS will be used. + * + *

Should only be used for testing or for APIs where the use of such API or the data + * exchanged is not sensitive. + * + *

This assumes prior knowledge that the target of this channel is using plaintext. It will + * not perform HTTP/1.1 upgrades. + * + * + * @throws UnsupportedOperationException if plaintext mode is not supported. + * @return this + * @since 1.11.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1772") + @SuppressWarnings("deprecation") + public T usePlaintext() { + return usePlaintext(true); + } /** * Makes the client use TLS. diff --git a/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java b/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java index 31456e7077..f840cad2fa 100644 --- a/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java +++ b/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java @@ -94,12 +94,23 @@ public final class InProcessChannelBuilder extends /** * Does nothing. + * + * @deprecated use {@link #usePlaintext()} instead. */ @Override + @Deprecated public InProcessChannelBuilder usePlaintext(boolean skipNegotiation) { return this; } + /** + * Does nothing. + */ + @Override + public InProcessChannelBuilder usePlaintext() { + return this; + } + /** Does nothing. */ @Override public InProcessChannelBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit) { diff --git a/core/src/test/java/io/grpc/internal/AbstractManagedChannelImplBuilderTest.java b/core/src/test/java/io/grpc/internal/AbstractManagedChannelImplBuilderTest.java index b9775de07b..79f25da1ee 100644 --- a/core/src/test/java/io/grpc/internal/AbstractManagedChannelImplBuilderTest.java +++ b/core/src/test/java/io/grpc/internal/AbstractManagedChannelImplBuilderTest.java @@ -422,10 +422,5 @@ public class AbstractManagedChannelImplBuilderTest { protected ClientTransportFactory buildTransportFactory() { throw new UnsupportedOperationException(); } - - @Override - public Builder usePlaintext(boolean value) { - throw new UnsupportedOperationException(); - } } } diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplIdlenessTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplIdlenessTest.java index 8f981f03b6..82e3f71677 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelImplIdlenessTest.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplIdlenessTest.java @@ -128,7 +128,7 @@ public class ManagedChannelImplIdlenessTest { throw new UnsupportedOperationException(); } - @Override public Builder usePlaintext(boolean b) { + @Override public Builder usePlaintext() { throw new UnsupportedOperationException(); } } diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java index 5551231a9c..ba3749f2b8 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java @@ -218,7 +218,7 @@ public class ManagedChannelImplTest { return NAME_RESOLVER_PARAMS; } - @Override public Builder usePlaintext(boolean b) { + @Override public Builder usePlaintext() { throw new UnsupportedOperationException(); } } diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java index 1a5d4ad797..2e4eee73f2 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java @@ -370,7 +370,7 @@ public class TestServiceClient { throw new RuntimeException(e); } } else { - okBuilder.usePlaintext(true); + okBuilder.usePlaintext(); } if (fullStreamDecompression) { okBuilder.enableFullStreamDecompression(); diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/CompressionTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/CompressionTest.java index 3ba6bacaa9..2109996299 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/CompressionTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/CompressionTest.java @@ -193,7 +193,7 @@ public class CompressionTest { .decompressorRegistry(clientDecompressors) .compressorRegistry(clientCompressors) .intercept(new ClientCompressorInterceptor()) - .usePlaintext(true) + .usePlaintext() .build(); stub = TestServiceGrpc.newBlockingStub(channel); diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java index 54abe97d83..322ba4f8ba 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java @@ -129,7 +129,7 @@ public class StressTestClientTest { // Connect to the metrics service ManagedChannel ch = ManagedChannelBuilder.forAddress("localhost", client.getMetricServerPort()) - .usePlaintext(true) + .usePlaintext() .build(); MetricsServiceGrpc.MetricsServiceBlockingStub stub = MetricsServiceGrpc.newBlockingStub(ch); diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java index feec49e977..0fd25d5738 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java @@ -167,7 +167,7 @@ public class TransportCompressionTest extends AbstractInteropTest { }; } }) - .usePlaintext(true); + .usePlaintext(); io.grpc.internal.TestingAccessor.setStatsImplementation( builder, createClientCensusStatsModule()); return builder.build(); diff --git a/netty/shaded/src/testShadow/java/io/grpc/netty/shaded/ShadingTest.java b/netty/shaded/src/testShadow/java/io/grpc/netty/shaded/ShadingTest.java index 10b84fd35e..98228b58fc 100644 --- a/netty/shaded/src/testShadow/java/io/grpc/netty/shaded/ShadingTest.java +++ b/netty/shaded/src/testShadow/java/io/grpc/netty/shaded/ShadingTest.java @@ -78,7 +78,7 @@ public final class ShadingTest { .build().start(); channel = ManagedChannelBuilder .forAddress("localhost", server.getPort()) - .usePlaintext(true) + .usePlaintext() .build(); SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel); assertThat(SimpleResponse.getDefaultInstance()) diff --git a/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java b/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java index 92ef0ca728..92b68ce596 100644 --- a/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java +++ b/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java @@ -226,8 +226,11 @@ public final class NettyChannelBuilder /** * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code PLAINTEXT} or * {@code PLAINTEXT_UPGRADE}. + * + * @deprecated use {@link #usePlaintext()} instead. */ @Override + @Deprecated public NettyChannelBuilder usePlaintext(boolean skipNegotiation) { if (skipNegotiation) { negotiationType(NegotiationType.PLAINTEXT); @@ -237,6 +240,15 @@ public final class NettyChannelBuilder return this; } + /** + * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code PLAINTEXT}. + */ + @Override + public NettyChannelBuilder usePlaintext() { + negotiationType(NegotiationType.PLAINTEXT); + return this; + } + /** * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code TLS}. */ diff --git a/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java b/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java index 068ab0e87b..24073b8e7b 100644 --- a/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java +++ b/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java @@ -273,7 +273,7 @@ public class OkHttpChannelBuilder extends *

By default {@link #DEFAULT_CONNECTION_SPEC} will be used. * *

This method is only used when building a secure connection. For plaintext - * connection, use {@link #usePlaintext} instead. + * connection, use {@link #usePlaintext()} instead. * * @throws IllegalArgumentException * If {@code connectionSpec} is not with TLS @@ -286,8 +286,11 @@ public class OkHttpChannelBuilder extends /** * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code PLAINTEXT}. + * + * @deprecated use {@link #usePlaintext()} instead. */ @Override + @Deprecated public final OkHttpChannelBuilder usePlaintext(boolean skipNegotiation) { if (skipNegotiation) { negotiationType(NegotiationType.PLAINTEXT); @@ -297,6 +300,15 @@ public class OkHttpChannelBuilder extends return this; } + /** + * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code PLAINTEXT}. + */ + @Override + public final OkHttpChannelBuilder usePlaintext() { + negotiationType(NegotiationType.PLAINTEXT); + return this; + } + /** * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code TLS}. */ diff --git a/okhttp/src/test/java/io/grpc/okhttp/OkHttpChannelBuilderTest.java b/okhttp/src/test/java/io/grpc/okhttp/OkHttpChannelBuilderTest.java index 1f362eb6cb..429e7f8022 100644 --- a/okhttp/src/test/java/io/grpc/okhttp/OkHttpChannelBuilderTest.java +++ b/okhttp/src/test/java/io/grpc/okhttp/OkHttpChannelBuilderTest.java @@ -108,14 +108,14 @@ public class OkHttpChannelBuilderTest { @Test public void usePlaintext_newClientTransportAllowed() { - OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234).usePlaintext(true); + OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234).usePlaintext(); builder.buildTransportFactory().newClientTransport(new InetSocketAddress(5678), "dummy_authority", "dummy_userAgent", null /* proxy */); } @Test public void usePlaintextDefaultPort() { - OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234).usePlaintext(true); + OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234).usePlaintext(); assertEquals(GrpcUtil.DEFAULT_PORT_PLAINTEXT, builder.getNameResolverParams().get(NameResolver.Factory.PARAMS_DEFAULT_PORT).intValue()); } @@ -125,7 +125,7 @@ public class OkHttpChannelBuilderTest { OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234); assertNotNull(builder.createSocketFactory()); - builder.usePlaintext(true); + builder.usePlaintext(); assertNull(builder.createSocketFactory()); } }