diff --git a/core/src/main/java/io/grpc/ForwardingChannelBuilder.java b/core/src/main/java/io/grpc/ForwardingChannelBuilder.java index c3afd7f5007..084c3737eae 100644 --- a/core/src/main/java/io/grpc/ForwardingChannelBuilder.java +++ b/core/src/main/java/io/grpc/ForwardingChannelBuilder.java @@ -97,6 +97,12 @@ public T usePlaintext(boolean skipNegotiation) { return thisT(); } + @Override + public T useTransportSecurity() { + delegate().useTransportSecurity(); + return thisT(); + } + @Override public T nameResolverFactory(NameResolver.Factory resolverFactory) { delegate().nameResolverFactory(resolverFactory); diff --git a/core/src/main/java/io/grpc/ManagedChannelBuilder.java b/core/src/main/java/io/grpc/ManagedChannelBuilder.java index 9f0df8c15d5..29976c0a376 100644 --- a/core/src/main/java/io/grpc/ManagedChannelBuilder.java +++ b/core/src/main/java/io/grpc/ManagedChannelBuilder.java @@ -160,6 +160,18 @@ public static ManagedChannelBuilder forTarget(String target) { @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1772") public abstract T usePlaintext(boolean skipNegotiation); + /** + * Makes the client use TLS. + * + * @return this + * @throws UnsupportedOperationException if transport security is not supported. + * @since 1.9.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3713") + public T useTransportSecurity() { + throw new UnsupportedOperationException(); + } + /** * Provides a custom {@link NameResolver.Factory} for the channel. If this method is not called, * the builder will try the providers listed by {@link NameResolverProvider#providers()} for the diff --git a/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java b/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java index e994304aef6..f51868232b7 100644 --- a/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java +++ b/core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java @@ -79,6 +79,14 @@ public final InProcessChannelBuilder maxInboundMessageSize(int max) { return super.maxInboundMessageSize(max); } + /** + * Does nothing. + */ + @Override + public InProcessChannelBuilder useTransportSecurity() { + return this; + } + /** * Does nothing. */ diff --git a/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java b/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java index 4563d5a1dfe..39aa1e57b4f 100644 --- a/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java +++ b/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java @@ -235,6 +235,15 @@ public NettyChannelBuilder usePlaintext(boolean skipNegotiation) { return this; } + /** + * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code TLS}. + */ + @Override + public NettyChannelBuilder useTransportSecurity() { + negotiationType(NegotiationType.TLS); + return this; + } + /** * Enable keepalive with default delay and timeout. * diff --git a/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java b/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java index 0f0ae2afdc7..aa186c8b401 100644 --- a/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java +++ b/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java @@ -301,6 +301,15 @@ public final OkHttpChannelBuilder usePlaintext(boolean skipNegotiation) { return this; } + /** + * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code TLS}. + */ + @Override + public final OkHttpChannelBuilder useTransportSecurity() { + negotiationType(NegotiationType.TLS); + return this; + } + @Override @Internal protected final ClientTransportFactory buildTransportFactory() {