diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpcrest/ServiceClientClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpcrest/ServiceClientClassComposer.java index 5eb48fa06a..e600ada5d2 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpcrest/ServiceClientClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpcrest/ServiceClientClassComposer.java @@ -59,7 +59,7 @@ protected List createClassHeaderComments( ServiceClientHeaderSampleComposer.composeSetEndpointSample(clientType, settingsType); Sample transportSampleCode = ServiceClientHeaderSampleComposer.composeTransportSample( - clientType, settingsType, "newHttpJsonBuilder"); + clientType, settingsType, "defaultHttpJsonTransportProviderBuilder"); samples.addAll( Arrays.asList( classMethodSampleCode, credentialsSampleCode, endpointSampleCode, transportSampleCode)); diff --git a/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposer.java b/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposer.java index 11f70bcb27..2c00498e4f 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposer.java @@ -285,7 +285,7 @@ public static Sample composeSetEndpointSample(TypeNode clientType, TypeNode sett } public static Sample composeTransportSample( - TypeNode clientType, TypeNode settingsType, String transportBuilderMethod) { + TypeNode clientType, TypeNode settingsType, String transportProviderMethod) { String settingsName = JavaStyle.toLowerCamelCase(settingsType.reference().name()); String clientName = JavaStyle.toLowerCamelCase(clientType.reference().name()); VariableExpr settingsVarExpr = @@ -294,11 +294,26 @@ public static Sample composeTransportSample( MethodInvocationExpr newBuilderMethodExpr = MethodInvocationExpr.builder() .setStaticReferenceType(settingsType) - .setMethodName(transportBuilderMethod) + .setMethodName("newBuilder") .build(); - MethodInvocationExpr buildMethodExpr = + MethodInvocationExpr transportChannelProviderArg = + MethodInvocationExpr.builder() + .setExprReferenceExpr( + MethodInvocationExpr.builder() + .setStaticReferenceType(settingsType) + .setMethodName(transportProviderMethod) + .build()) + .setMethodName("build") + .build(); + MethodInvocationExpr credentialsMethodExpr = MethodInvocationExpr.builder() .setExprReferenceExpr(newBuilderMethodExpr) + .setArguments(transportChannelProviderArg) + .setMethodName("setTransportChannelProvider") + .build(); + MethodInvocationExpr buildMethodExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(credentialsMethodExpr) .setReturnType(settingsType) .setMethodName("build") .build(); diff --git a/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoClient.golden b/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoClient.golden index 15d3a77a29..5e38c6d146 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoClient.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoClient.golden @@ -105,7 +105,11 @@ import javax.annotation.Generated; * // - It may require correct/in-range values for request initialization. * // - It may require specifying regional endpoints when creating the service client as shown in * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library - * EchoSettings echoSettings = EchoSettings.newHttpJsonBuilder().build(); + * EchoSettings echoSettings = + * EchoSettings.newBuilder() + * .setTransportChannelProvider( + * EchoSettings.defaultHttpJsonTransportProviderBuilder().build()) + * .build(); * EchoClient echoClient = EchoClient.create(echoSettings); * } * diff --git a/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoEmpty.golden b/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoEmpty.golden index d9708af4ae..0165872e80 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoEmpty.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoEmpty.golden @@ -85,7 +85,11 @@ import javax.annotation.Generated; * // - It may require correct/in-range values for request initialization. * // - It may require specifying regional endpoints when creating the service client as shown in * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library - * EchoEmpySettings echoEmpySettings = EchoEmpySettings.newHttpJsonBuilder().build(); + * EchoEmpySettings echoEmpySettings = + * EchoEmpySettings.newBuilder() + * .setTransportChannelProvider( + * EchoEmpySettings.defaultHttpJsonTransportProviderBuilder().build()) + * .build(); * EchoEmpyClient echoEmpyClient = EchoEmpyClient.create(echoEmpySettings); * } *