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

core,netty,okhttp,alts,inprocess: deprecate usePlaintext(boolean) #4117

Merged
merged 2 commits into from Feb 28, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -58,7 +58,7 @@ private static ManagedChannel createChannel() {
NettyChannelBuilder.forTarget(handshakerAddress)
.directExecutor()
.eventLoopGroup(new NioEventLoopGroup(1, clientThreadFactory))
.usePlaintext(true)
.usePlaintext()
.build();
return channel;
}
Expand Down
Expand Up @@ -57,7 +57,7 @@ public void setup() throws Exception {
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<Stats.ClientStats>();
}
Expand Down
13 changes: 12 additions & 1 deletion core/src/main/java/io/grpc/ForwardingChannelBuilder.java
Expand Up @@ -31,6 +31,7 @@
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/3363")
public abstract class ForwardingChannelBuilder<T extends ForwardingChannelBuilder<T>>
extends ManagedChannelBuilder<T> {

/**
* The default constructor.
*/
Expand Down Expand Up @@ -91,9 +92,19 @@ public T overrideAuthority(String authority) {
return thisT();
}

/**
* @deprecated use {@link #usePlaintext()} instead.
*/
@Override
@Deprecated
public T usePlaintext(boolean skipNegotiation) {
delegate().usePlaintext(skipNegotiation);
ManagedChannelBuilder<?> o = delegate().usePlaintext(skipNegotiation);
return thisT();
}

@Override
public T usePlaintext() {
delegate().usePlaintext();
return thisT();
}

Expand Down
27 changes: 26 additions & 1 deletion core/src/main/java/io/grpc/ManagedChannelBuilder.java
Expand Up @@ -152,13 +152,38 @@ public static ManagedChannelBuilder<?> forTarget(String target) {
*
* @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.
*
* <p>Should only be used for testing or for APIs where the use of such API or the data
* exchanged is not sensitive.
*
* <p>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.
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java
Expand Up @@ -91,12 +91,23 @@ public InProcessChannelBuilder useTransportSecurity() {

/**
* 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) {
Expand Down
Expand Up @@ -422,10 +422,5 @@ static class Builder extends AbstractManagedChannelImplBuilder<Builder> {
protected ClientTransportFactory buildTransportFactory() {
throw new UnsupportedOperationException();
}

@Override
public Builder usePlaintext(boolean value) {
throw new UnsupportedOperationException();
}
}
}
Expand Up @@ -128,7 +128,7 @@ class Builder extends AbstractManagedChannelImplBuilder<Builder> {
throw new UnsupportedOperationException();
}

@Override public Builder usePlaintext(boolean b) {
@Override public Builder usePlaintext() {
throw new UnsupportedOperationException();
}
}
Expand Down
Expand Up @@ -216,7 +216,7 @@ class Builder extends AbstractManagedChannelImplBuilder<Builder> {
return NAME_RESOLVER_PARAMS;
}

@Override public Builder usePlaintext(boolean b) {
@Override public Builder usePlaintext() {
throw new UnsupportedOperationException();
}
}
Expand Down
Expand Up @@ -358,7 +358,7 @@ protected ManagedChannel createChannel() {
throw new RuntimeException(e);
}
} else {
okBuilder.usePlaintext(true);
okBuilder.usePlaintext();
}
if (fullStreamDecompression) {
okBuilder.enableFullStreamDecompression();
Expand Down
Expand Up @@ -193,7 +193,7 @@ public void compression() throws Exception {
.decompressorRegistry(clientDecompressors)
.compressorRegistry(clientCompressors)
.intercept(new ClientCompressorInterceptor())
.usePlaintext(true)
.usePlaintext()
.build();
stub = TestServiceGrpc.newBlockingStub(channel);

Expand Down
Expand Up @@ -129,7 +129,7 @@ public void gaugesShouldBeExported() throws Exception {

// Connect to the metrics service
ManagedChannel ch = ManagedChannelBuilder.forAddress("localhost", client.getMetricServerPort())
.usePlaintext(true)
.usePlaintext()
.build();

MetricsServiceGrpc.MetricsServiceBlockingStub stub = MetricsServiceGrpc.newBlockingStub(ch);
Expand Down
Expand Up @@ -167,7 +167,7 @@ public void onHeaders(Metadata headers) {
};
}
})
.usePlaintext(true);
.usePlaintext();
io.grpc.internal.TestingAccessor.setStatsImplementation(
builder, createClientCensusStatsModule());
return builder.build();
Expand Down
Expand Up @@ -78,7 +78,7 @@ public void basic() throws Exception {
.build().start();
channel = ManagedChannelBuilder
.forAddress("localhost", server.getPort())
.usePlaintext(true)
.usePlaintext()
.build();
SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel);
assertThat(SimpleResponse.getDefaultInstance())
Expand Down
12 changes: 12 additions & 0 deletions netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java
Expand Up @@ -226,8 +226,11 @@ public NettyChannelBuilder maxHeaderListSize(int maxHeaderListSize) {
/**
* 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);
Expand All @@ -237,6 +240,15 @@ public NettyChannelBuilder usePlaintext(boolean skipNegotiation) {
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}.
*/
Expand Down
14 changes: 13 additions & 1 deletion okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java
Expand Up @@ -273,7 +273,7 @@ public final OkHttpChannelBuilder hostnameVerifier(@Nullable HostnameVerifier ho
* <p>By default {@link #DEFAULT_CONNECTION_SPEC} will be used.
*
* <p>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
Expand All @@ -286,8 +286,11 @@ public final OkHttpChannelBuilder connectionSpec(ConnectionSpec connectionSpec)

/**
* 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);
Expand All @@ -297,6 +300,15 @@ public final OkHttpChannelBuilder usePlaintext(boolean skipNegotiation) {
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}.
*/
Expand Down
Expand Up @@ -108,14 +108,14 @@ public void allowUsingTlsConnectionSpec() {

@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());
}
Expand All @@ -125,7 +125,7 @@ public void usePlaintextCreatesNullSocketFactory() {
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234);
assertNotNull(builder.createSocketFactory());

builder.usePlaintext(true);
builder.usePlaintext();
assertNull(builder.createSocketFactory());
}
}
Expand Down