From 003b993f7ad7cae8ae8c101e0ff147e517dcd83e Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 6 Jun 2023 14:17:37 -0400 Subject: [PATCH] feat: Dynamic Routing Headers for HttpJson (#1667) * feat: Add RequestParamsExtractor to HttpJsonCallSettings * feat: Add RequestParamsCallable classes * feat: Update HttpJsonCallableFactory to use new RequestParamCallables * feat: Add RequestParam to CallOptions * feat: Add RequestParam header for HttpJson * feat: Add initial Dynamic Routing Header showcase test * feat: Ignore empty string for Request Param * feat: Regenerate test client code * feat: Do not generate HttpBinding logic for REST * feat: Add Dynamic Routing Header showcase test cases * feat: Move header key value to constant * feat: Add URLEncoding for header * feat: Update showcase interceptor name * feat: Generate HttpJson Dyanmic Routing Header Stub * feat: Fix Request Params Test * feat: Update variable names * feat: Add gRPC Dynamic Routing Header showcase test * feat: Clean up IT showcase test * chore: Add comments for RequestBuilderParams * feat: Generate test client code with Implict Routing Headers * feat: Regenerate test client code * fix: Generate httpjson golden test case * chore: Fix format issues * chore: Regenerate integration golden tests * chore: Add more tests for RequestParamsBuilder * chore: Update docs for showcase test * chore: Refactor TestClientInitializer to include interceptors * chore: Add null assertions for showcase test * chore: Remove String.valueOf check for routing params * chore: Remove String.valueOf check for routing params * chore: Regenerate the showcase clients * chore: Address pr comments * chore: Update Dynamic Routing Header test cases * chore: Use PercentEscaper for percent encoding * chore: Empty commit * chore: Migrate transport specific code to abstract class * chore: Address pr comments * chore: Address pr comments * chore: Use HttpJsonMetadata for headers * chore: Revert call options changes * chore: Set default request header map * chore: Move encoding logic to RequestUrlParamsEncoder * chore: Fix lint issues * chore: Add clirr ignore for RequestUrlParamsEncoder * chore: Address PR comments * chore: Address PR comments --- ...ractTransportServiceStubClassComposer.java | 318 ++++++++++++++- .../grpc/GrpcServiceStubClassComposer.java | 294 -------------- .../HttpJsonServiceStubClassComposer.java | 39 -- .../grpc/goldens/GrpcLoggingStub.golden | 14 +- .../grpc/goldens/GrpcPublisherStub.golden | 56 +-- .../goldens/GrpcRoutingHeadersStub.golden | 7 +- .../grpc/goldens/GrpcTestingStub.golden | 45 ++- .../grpcrest/goldens/GrpcEchoStub.golden | 14 +- .../grpcrest/goldens/HttpJsonEchoStub.golden | 13 + .../HttpJsonServiceStubClassComposerTest.java | 11 + .../goldens/HttpJsonComplianceStub.golden | 30 ++ .../goldens/HttpJsonRoutingHeadersStub.golden | 372 ++++++++++++++++++ .../google/api/gax/grpc/CallOptionsUtil.java | 3 +- ...pcServerStreamingRequestParamCallable.java | 15 +- .../grpc/GrpcUnaryRequestParamCallable.java | 15 +- .../gax/httpjson/HttpJsonCallSettings.java | 23 +- .../gax/httpjson/HttpJsonCallableFactory.java | 18 +- .../api/gax/httpjson/HttpJsonClientCalls.java | 12 +- .../gax/httpjson/HttpJsonDirectCallable.java | 2 +- ...HttpJsonDirectServerStreamingCallable.java | 2 +- .../HttpJsonDirectStreamController.java | 7 +- .../api/gax/httpjson/HttpJsonMetadata.java | 18 + ...onServerStreamingRequestParamCallable.java | 69 ++++ .../HttpJsonUnaryRequestParamCallable.java | 74 ++++ gax-java/gax/pom.xml | 10 + .../api/gax/rpc/RequestParamsBuilder.java | 22 +- .../api/gax/rpc/RequestUrlParamsEncoder.java | 62 +-- .../google/api/gax/rpc/internal/Headers.java | 2 + .../api/gax/rpc/RequestParamsBuilderTest.java | 67 ++++ .../gax/rpc/RequestUrlParamsEncoderTest.java | 92 ++--- .../v1beta1/stub/GrpcComplianceStub.java | 46 +-- .../showcase/v1beta1/stub/GrpcEchoStub.java | 13 +- .../v1beta1/stub/GrpcIdentityStub.java | 32 +- .../v1beta1/stub/GrpcMessagingStub.java | 80 ++-- .../v1beta1/stub/GrpcSequenceServiceStub.java | 38 +- .../v1beta1/stub/GrpcTestingStub.java | 50 +-- .../v1beta1/stub/HttpJsonComplianceStub.java | 42 ++ .../v1beta1/stub/HttpJsonEchoStub.java | 41 ++ .../v1beta1/stub/HttpJsonIdentityStub.java | 31 ++ .../v1beta1/stub/HttpJsonMessagingStub.java | 73 ++++ .../stub/HttpJsonSequenceServiceStub.java | 37 ++ .../v1beta1/stub/HttpJsonTestingStub.java | 49 +++ .../v1beta1/it/ITDynamicRoutingHeaders.java | 311 +++++++++++++++ .../it/util/TestClientInitializer.java | 16 + .../v1/stub/GrpcConnectionServiceStub.java | 8 +- .../stub/HttpJsonConnectionServiceStub.java | 7 + .../asset/v1/stub/GrpcAssetServiceStub.java | 123 +++--- .../v1/stub/HttpJsonAssetServiceStub.java | 126 ++++++ .../v1small/stub/HttpJsonAddressesStub.java | 29 ++ .../stub/HttpJsonRegionOperationsStub.java | 17 + .../v1/stub/GrpcIamCredentialsStub.java | 26 +- .../v1/stub/HttpJsonIamCredentialsStub.java | 25 ++ .../google/iam/v1/stub/GrpcIAMPolicyStub.java | 20 +- .../v1/stub/GrpcKeyManagementServiceStub.java | 166 ++++---- .../v1/stub/GrpcLibraryServiceStub.java | 56 +-- .../v1/stub/HttpJsonLibraryServiceStub.java | 55 +++ .../v2/stub/GrpcConfigServiceV2Stub.java | 152 +++---- .../v2/stub/GrpcLoggingServiceV2Stub.java | 14 +- .../v2/stub/GrpcMetricsServiceV2Stub.java | 32 +- .../pubsub/v1/stub/GrpcPublisherStub.java | 74 ++-- .../pubsub/v1/stub/GrpcSchemaServiceStub.java | 80 ++-- .../pubsub/v1/stub/GrpcSubscriberStub.java | 110 +++--- .../v1beta1/stub/GrpcCloudRedisStub.java | 68 ++-- .../v1beta1/stub/HttpJsonCloudRedisStub.java | 67 ++++ 64 files changed, 2704 insertions(+), 1136 deletions(-) create mode 100644 gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonRoutingHeadersStub.golden create mode 100644 gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonServerStreamingRequestParamCallable.java create mode 100644 gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonUnaryRequestParamCallable.java create mode 100644 showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java index b566ed5a18..a85ab0c92f 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java @@ -23,6 +23,7 @@ import com.google.api.gax.rpc.ClientStreamingCallable; import com.google.api.gax.rpc.LongRunningClient; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.RequestParamsExtractor; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -34,13 +35,18 @@ import com.google.api.generator.engine.ast.EmptyLineStatement; import com.google.api.generator.engine.ast.Expr; import com.google.api.generator.engine.ast.ExprStatement; +import com.google.api.generator.engine.ast.IfStatement; import com.google.api.generator.engine.ast.JavaDocComment; +import com.google.api.generator.engine.ast.LambdaExpr; +import com.google.api.generator.engine.ast.LogicalOperationExpr; import com.google.api.generator.engine.ast.MethodDefinition; import com.google.api.generator.engine.ast.MethodInvocationExpr; import com.google.api.generator.engine.ast.NewObjectExpr; import com.google.api.generator.engine.ast.ReferenceConstructorExpr; +import com.google.api.generator.engine.ast.RelationalOperationExpr; import com.google.api.generator.engine.ast.ScopeNode; import com.google.api.generator.engine.ast.Statement; +import com.google.api.generator.engine.ast.StringObjectValue; import com.google.api.generator.engine.ast.ThisObjectValue; import com.google.api.generator.engine.ast.ThrowExpr; import com.google.api.generator.engine.ast.TryCatchStatement; @@ -56,14 +62,20 @@ import com.google.api.generator.gapic.model.GapicClass.Kind; import com.google.api.generator.gapic.model.GapicContext; import com.google.api.generator.gapic.model.GapicServiceConfig; +import com.google.api.generator.gapic.model.HttpBindings; import com.google.api.generator.gapic.model.Message; import com.google.api.generator.gapic.model.Method; +import com.google.api.generator.gapic.model.RoutingHeaderRule; import com.google.api.generator.gapic.model.Service; +import com.google.api.generator.gapic.model.Transport; import com.google.api.generator.gapic.utils.JavaStyle; +import com.google.api.pathtemplate.PathTemplate; import com.google.common.base.Preconditions; +import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.longrunning.Operation; +import com.google.protobuf.TypeRegistry; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -126,6 +138,7 @@ private static TypeStore createStaticTypes() { RequestParamsExtractor.class, ServerStreamingCallable.class, TimeUnit.class, + TypeRegistry.class, UnaryCallable.class, UnsupportedOperationException.class); return new TypeStore(concreteClazzes); @@ -260,11 +273,62 @@ protected List createOperationsStubGetterMethod( .build()); } - protected abstract Expr createTransportSettingsInitExpr( + protected Expr createTransportSettingsInitExpr( Method method, VariableExpr transportSettingsVarExpr, VariableExpr methodDescriptorVarExpr, - List classStatements); + List classStatements) { + MethodInvocationExpr callSettingsBuilderExpr = + MethodInvocationExpr.builder() + .setStaticReferenceType(getTransportContext().transportCallSettingsType()) + .setGenerics(transportSettingsVarExpr.type().reference().generics()) + .setMethodName("newBuilder") + .build(); + callSettingsBuilderExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(callSettingsBuilderExpr) + .setMethodName("setMethodDescriptor") + .setArguments(Arrays.asList(methodDescriptorVarExpr)) + .build(); + + // Transport is set to be either REST or GRPC from the sub composers + if (getTransportContext().transport() == Transport.REST) { + callSettingsBuilderExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(callSettingsBuilderExpr) + .setMethodName("setTypeRegistry") + .setArguments( + Arrays.asList( + VariableExpr.builder() + .setVariable( + Variable.builder() + .setName("typeRegistry") + .setType(FIXED_TYPESTORE.get(TypeRegistry.class.getSimpleName())) + .build()) + .build())) + .build(); + } + + if (method.shouldSetParamsExtractor()) { + callSettingsBuilderExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(callSettingsBuilderExpr) + .setMethodName("setParamsExtractor") + .setArguments(createRequestParamsExtractorClassInstance(method, classStatements)) + .build(); + } + + callSettingsBuilderExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(callSettingsBuilderExpr) + .setMethodName("build") + .setReturnType(transportSettingsVarExpr.type()) + .build(); + return AssignmentExpr.builder() + .setVariableExpr(transportSettingsVarExpr.toBuilder().setIsDecl(true).build()) + .setValueExpr(callSettingsBuilderExpr) + .build(); + } protected List createGetMethodDescriptorsMethod( Service service, @@ -1168,4 +1232,254 @@ protected TypeNode getTransportOperationsStubType(Service service) { return transportOpeationsStubType; } + + protected LambdaExpr createRequestParamsExtractorClassInstance( + Method method, List classStatements) { + List bodyStatements = new ArrayList<>(); + VariableExpr requestVarExpr = + VariableExpr.withVariable( + Variable.builder().setType(method.inputType()).setName("request").build()); + TypeNode returnType = + TypeNode.withReference( + ConcreteReference.builder() + .setClazz(Map.class) + .setGenerics(TypeNode.STRING.reference(), TypeNode.STRING.reference()) + .build()); + MethodInvocationExpr.Builder returnExpr = + MethodInvocationExpr.builder().setReturnType(returnType); + // If the google.api.routing annotation is present(even with empty routing parameters), + // the implicit routing headers specified in the google.api.http annotation should not be sent + if (method.routingHeaderRule() == null) { + createRequestParamsExtractorBodyForHttpBindings( + method, requestVarExpr, bodyStatements, returnExpr); + } else { + createRequestParamsExtractorBodyForRoutingHeaders( + method, requestVarExpr, classStatements, bodyStatements, returnExpr); + } + + // Overrides extract(). + // https://github.com/googleapis/gax-java/blob/8d45d186e36ae97b789a6f89d80ae5213a773b65/gax/src/main/java/com/google/api/gax/rpc/RequestParamsExtractor.java#L55 + return LambdaExpr.builder() + .setArguments(requestVarExpr.toBuilder().setIsDecl(true).build()) + .setBody(bodyStatements) + .setReturnExpr(returnExpr.build()) + .build(); + } + + private void createRequestParamsExtractorBodyForHttpBindings( + Method method, + VariableExpr requestVarExpr, + List bodyStatements, + MethodInvocationExpr.Builder returnExprBuilder) { + TypeNode routingHeadersBuilderType = + TypeNode.withReference( + ConcreteReference.builder().setClazz(RequestParamsBuilder.class).build()); + VariableExpr routingHeadersBuilderVarExpr = + VariableExpr.builder() + .setVariable( + Variable.builder().setName("builder").setType(routingHeadersBuilderType).build()) + .setIsDecl(true) + .build(); + MethodInvocationExpr routingHeaderBuilderInvokeExpr = + MethodInvocationExpr.builder() + .setStaticReferenceType(routingHeadersBuilderType) + .setMethodName("create") + .setReturnType(routingHeadersBuilderType) + .build(); + Expr routingHeadersBuilderInitExpr = + AssignmentExpr.builder() + .setVariableExpr(routingHeadersBuilderVarExpr) + .setValueExpr(routingHeaderBuilderInvokeExpr) + .build(); + bodyStatements.add(ExprStatement.withExpr(routingHeadersBuilderInitExpr)); + VariableExpr routingHeadersBuilderVarNonDeclExpr = + VariableExpr.builder() + .setVariable( + Variable.builder().setName("builder").setType(routingHeadersBuilderType).build()) + .build(); + for (HttpBindings.HttpBinding httpBindingFieldBinding : + method.httpBindings().pathParameters()) { + MethodInvocationExpr requestBuilderExpr = + createRequestFieldGetterExpr(requestVarExpr, httpBindingFieldBinding.name()); + Expr valueOfExpr = + MethodInvocationExpr.builder() + .setStaticReferenceType(TypeNode.STRING) + .setMethodName("valueOf") + .setArguments(requestBuilderExpr) + .build(); + + Expr paramsAddExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(routingHeadersBuilderVarNonDeclExpr) + .setMethodName("add") + .setArguments( + ValueExpr.withValue(StringObjectValue.withValue(httpBindingFieldBinding.name())), + valueOfExpr) + .build(); + bodyStatements.add(ExprStatement.withExpr(paramsAddExpr)); + } + + returnExprBuilder + .setExprReferenceExpr(routingHeadersBuilderVarNonDeclExpr) + .setMethodName("build"); + } + + private void createRequestParamsExtractorBodyForRoutingHeaders( + Method method, + VariableExpr requestVarExpr, + List classStatements, + List bodyStatements, + MethodInvocationExpr.Builder returnExprBuilder) { + TypeNode routingHeadersBuilderType = + TypeNode.withReference( + ConcreteReference.builder().setClazz(RequestParamsBuilder.class).build()); + VariableExpr routingHeadersBuilderVarExpr = + VariableExpr.builder() + .setVariable( + Variable.builder().setName("builder").setType(routingHeadersBuilderType).build()) + .setIsDecl(true) + .build(); + MethodInvocationExpr routingHeaderBuilderInvokeExpr = + MethodInvocationExpr.builder() + .setStaticReferenceType(routingHeadersBuilderType) + .setMethodName("create") + .setReturnType(routingHeadersBuilderType) + .build(); + Expr routingHeadersBuilderInitExpr = + AssignmentExpr.builder() + .setVariableExpr(routingHeadersBuilderVarExpr) + .setValueExpr(routingHeaderBuilderInvokeExpr) + .build(); + bodyStatements.add(ExprStatement.withExpr(routingHeadersBuilderInitExpr)); + List routingHeaderParams = + method.routingHeaderRule().routingHeaderParams(); + VariableExpr routingHeadersBuilderVarNonDeclExpr = + VariableExpr.builder() + .setVariable( + Variable.builder().setName("builder").setType(routingHeadersBuilderType).build()) + .build(); + for (int i = 0; i < routingHeaderParams.size(); i++) { + RoutingHeaderRule.RoutingHeaderParam routingHeaderParam = routingHeaderParams.get(i); + MethodInvocationExpr requestFieldGetterExpr = + createRequestFieldGetterExpr(requestVarExpr, routingHeaderParam.fieldName()); + Expr routingHeaderKeyExpr = + ValueExpr.withValue(StringObjectValue.withValue(routingHeaderParam.key())); + String pathTemplateName = + String.format("%s_%s_PATH_TEMPLATE", JavaStyle.toUpperSnakeCase(method.name()), i); + TypeNode pathTemplateType = + TypeNode.withReference(ConcreteReference.withClazz(PathTemplate.class)); + Variable pathTemplateVar = + Variable.builder().setType(pathTemplateType).setName(pathTemplateName).build(); + Expr routingHeaderPatternExpr = VariableExpr.withVariable(pathTemplateVar); + Statement pathTemplateClassVar = + createPathTemplateClassStatement(routingHeaderParam, pathTemplateType, pathTemplateVar); + classStatements.add(pathTemplateClassVar); + MethodInvocationExpr addParamMethodExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(routingHeadersBuilderVarNonDeclExpr) + .setMethodName("add") + .setArguments(requestFieldGetterExpr, routingHeaderKeyExpr, routingHeaderPatternExpr) + .build(); + + ExprStatement addParamStatement = ExprStatement.withExpr(addParamMethodExpr); + // No need to add null check if there is no nested fields + if (routingHeaderParam.getDescendantFieldNames().size() == 1) { + bodyStatements.add(addParamStatement); + } else { + IfStatement ifStatement = + IfStatement.builder() + .setConditionExpr( + fieldValuesNotNullConditionExpr( + requestVarExpr, routingHeaderParam.getDescendantFieldNames())) + .setBody(ImmutableList.of(addParamStatement)) + .build(); + bodyStatements.add(ifStatement); + } + } + returnExprBuilder + .setExprReferenceExpr(routingHeadersBuilderVarNonDeclExpr) + .setMethodName("build"); + } + + private Statement createPathTemplateClassStatement( + RoutingHeaderRule.RoutingHeaderParam routingHeaderParam, + TypeNode pathTemplateType, + Variable pathTemplateVar) { + VariableExpr pathTemplateVarExpr = + VariableExpr.builder() + .setVariable(pathTemplateVar) + .setIsDecl(true) + .setIsStatic(true) + .setIsFinal(true) + .setScope(ScopeNode.PRIVATE) + .build(); + ValueExpr valueExpr = + ValueExpr.withValue(StringObjectValue.withValue(routingHeaderParam.pattern())); + Expr pathTemplateExpr = + AssignmentExpr.builder() + .setVariableExpr(pathTemplateVarExpr) + .setValueExpr( + MethodInvocationExpr.builder() + .setStaticReferenceType(pathTemplateType) + .setMethodName("create") + .setArguments(valueExpr) + .setReturnType(pathTemplateType) + .build()) + .build(); + return ExprStatement.withExpr(pathTemplateExpr); + } + + private Expr fieldValuesNotNullConditionExpr( + VariableExpr requestVarExpr, List fieldNames) { + MethodInvocationExpr.Builder requestFieldGetterExprBuilder = + MethodInvocationExpr.builder().setExprReferenceExpr(requestVarExpr); + Expr fieldValuesNotNullExpr = null; + for (int i = 0; i < fieldNames.size() - 1; i++) { + String currFieldName = fieldNames.get(i); + String bindingFieldMethodName = + String.format("get%s", JavaStyle.toUpperCamelCase(currFieldName)); + requestFieldGetterExprBuilder = + requestFieldGetterExprBuilder.setMethodName(bindingFieldMethodName); + // set return type of each method invocation to String just to pass the validation for + // RelationalOperationExpr that both side of relational operation needs to be a valid equality + // type + MethodInvocationExpr requestGetterExpr = + requestFieldGetterExprBuilder.setReturnType(TypeNode.STRING).build(); + Expr currentValueNotNullExpr = + RelationalOperationExpr.notEqualToWithExprs( + requestGetterExpr, ValueExpr.createNullExpr()); + if (fieldValuesNotNullExpr == null) { + fieldValuesNotNullExpr = currentValueNotNullExpr; + } else { + fieldValuesNotNullExpr = + LogicalOperationExpr.logicalAndWithExprs( + fieldValuesNotNullExpr, currentValueNotNullExpr); + } + requestFieldGetterExprBuilder = + MethodInvocationExpr.builder().setExprReferenceExpr(requestGetterExpr); + } + return fieldValuesNotNullExpr; + } + + private MethodInvocationExpr createRequestFieldGetterExpr( + VariableExpr requestVarExpr, String fieldName) { + MethodInvocationExpr.Builder requestFieldGetterExprBuilder = + MethodInvocationExpr.builder().setExprReferenceExpr(requestVarExpr); + List descendantFields = Splitter.on(".").splitToList(fieldName); + // Handle foo.bar cases by descending into the subfields. + // e.g. foo.bar -> request.getFoo().getBar() + for (int i = 0; i < descendantFields.size(); i++) { + String currFieldName = descendantFields.get(i); + String bindingFieldMethodName = + String.format("get%s", JavaStyle.toUpperCamelCase(currFieldName)); + requestFieldGetterExprBuilder = + requestFieldGetterExprBuilder.setMethodName(bindingFieldMethodName); + if (i < descendantFields.size() - 1) { + requestFieldGetterExprBuilder = + MethodInvocationExpr.builder() + .setExprReferenceExpr(requestFieldGetterExprBuilder.build()); + } + } + return requestFieldGetterExprBuilder.build(); + } } diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposer.java index d6eedb9987..c10e5290a1 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposer.java @@ -16,40 +16,26 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; -import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.generator.engine.ast.AssignmentExpr; import com.google.api.generator.engine.ast.ConcreteReference; import com.google.api.generator.engine.ast.EnumRefExpr; import com.google.api.generator.engine.ast.Expr; import com.google.api.generator.engine.ast.ExprStatement; -import com.google.api.generator.engine.ast.IfStatement; -import com.google.api.generator.engine.ast.LambdaExpr; -import com.google.api.generator.engine.ast.LogicalOperationExpr; import com.google.api.generator.engine.ast.MethodInvocationExpr; -import com.google.api.generator.engine.ast.RelationalOperationExpr; import com.google.api.generator.engine.ast.ScopeNode; import com.google.api.generator.engine.ast.Statement; import com.google.api.generator.engine.ast.StringObjectValue; import com.google.api.generator.engine.ast.TypeNode; import com.google.api.generator.engine.ast.ValueExpr; -import com.google.api.generator.engine.ast.Variable; import com.google.api.generator.engine.ast.VariableExpr; import com.google.api.generator.gapic.composer.common.AbstractTransportServiceStubClassComposer; import com.google.api.generator.gapic.composer.store.TypeStore; -import com.google.api.generator.gapic.model.HttpBindings.HttpBinding; import com.google.api.generator.gapic.model.Message; import com.google.api.generator.gapic.model.Method; -import com.google.api.generator.gapic.model.RoutingHeaderRule.RoutingHeaderParam; import com.google.api.generator.gapic.model.Service; -import com.google.api.generator.gapic.utils.JavaStyle; -import com.google.api.pathtemplate.PathTemplate; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.stub.GrpcOperationsStub; import io.grpc.MethodDescriptor; import io.grpc.protobuf.ProtoUtils; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -200,46 +186,6 @@ protected EnumRefExpr getMethodDescriptorMethodTypeExpr(Method protoMethod) { .build(); } - @Override - protected Expr createTransportSettingsInitExpr( - Method method, - VariableExpr transportSettingsVarExpr, - VariableExpr methodDescriptorVarExpr, - List classStatements) { - MethodInvocationExpr callSettingsBuilderExpr = - MethodInvocationExpr.builder() - .setStaticReferenceType(getTransportContext().transportCallSettingsType()) - .setGenerics(transportSettingsVarExpr.type().reference().generics()) - .setMethodName("newBuilder") - .build(); - callSettingsBuilderExpr = - MethodInvocationExpr.builder() - .setExprReferenceExpr(callSettingsBuilderExpr) - .setMethodName("setMethodDescriptor") - .setArguments(Arrays.asList(methodDescriptorVarExpr)) - .build(); - - if (method.shouldSetParamsExtractor()) { - callSettingsBuilderExpr = - MethodInvocationExpr.builder() - .setExprReferenceExpr(callSettingsBuilderExpr) - .setMethodName("setParamsExtractor") - .setArguments(createRequestParamsExtractorClassInstance(method, classStatements)) - .build(); - } - - callSettingsBuilderExpr = - MethodInvocationExpr.builder() - .setExprReferenceExpr(callSettingsBuilderExpr) - .setMethodName("build") - .setReturnType(transportSettingsVarExpr.type()) - .build(); - return AssignmentExpr.builder() - .setVariableExpr(transportSettingsVarExpr.toBuilder().setIsDecl(true).build()) - .setValueExpr(callSettingsBuilderExpr) - .build(); - } - @Override protected String getProtoRpcFullMethodName(Service protoService, Method protoMethod) { if (protoMethod.isMixin()) { @@ -255,244 +201,4 @@ protected String getProtoRpcFullMethodName(Service protoService, Method protoMet // long-term solution. return String.format("google.iam.v1.IAMPolicy/%s", protoMethod.name()); } - - private LambdaExpr createRequestParamsExtractorClassInstance( - Method method, List classStatements) { - List bodyStatements = new ArrayList<>(); - VariableExpr requestVarExpr = - VariableExpr.withVariable( - Variable.builder().setType(method.inputType()).setName("request").build()); - TypeNode returnType = - TypeNode.withReference( - ConcreteReference.builder() - .setClazz(Map.class) - .setGenerics(TypeNode.STRING.reference(), TypeNode.STRING.reference()) - .build()); - MethodInvocationExpr.Builder returnExpr = - MethodInvocationExpr.builder().setReturnType(returnType); - // If the google.api.routing annotation is present(even with empty routing parameters), - // the implicit routing headers specified in the google.api.http annotation should not be sent - if (method.routingHeaderRule() == null) { - createRequestParamsExtractorBodyForHttpBindings( - method, requestVarExpr, bodyStatements, returnExpr); - } else { - createRequestParamsExtractorBodyForRoutingHeaders( - method, requestVarExpr, classStatements, bodyStatements, returnExpr); - } - - // Overrides extract(). - // https://github.com/googleapis/gax-java/blob/8d45d186e36ae97b789a6f89d80ae5213a773b65/gax/src/main/java/com/google/api/gax/rpc/RequestParamsExtractor.java#L55 - return LambdaExpr.builder() - .setArguments(requestVarExpr.toBuilder().setIsDecl(true).build()) - .setBody(bodyStatements) - .setReturnExpr(returnExpr.build()) - .build(); - } - - private void createRequestParamsExtractorBodyForHttpBindings( - Method method, - VariableExpr requestVarExpr, - List bodyStatements, - MethodInvocationExpr.Builder returnExprBuilder) { - TypeNode paramsVarType = - TypeNode.withReference( - ConcreteReference.builder() - .setClazz(ImmutableMap.Builder.class) - .setGenerics(TypeNode.STRING.reference(), TypeNode.STRING.reference()) - .build()); - VariableExpr paramsVarExpr = - VariableExpr.withVariable( - Variable.builder().setName("params").setType(paramsVarType).build()); - - Expr paramsAssignExpr = - AssignmentExpr.builder() - .setVariableExpr(paramsVarExpr.toBuilder().setIsDecl(true).build()) - .setValueExpr( - MethodInvocationExpr.builder() - .setStaticReferenceType(FIXED_TYPESTORE.get("ImmutableMap")) - .setMethodName("builder") - .setReturnType(paramsVarType) - .build()) - .build(); - bodyStatements.add(ExprStatement.withExpr(paramsAssignExpr)); - - for (HttpBinding httpBindingFieldBinding : method.httpBindings().pathParameters()) { - MethodInvocationExpr requestBuilderExpr = - createRequestFieldGetterExpr(requestVarExpr, httpBindingFieldBinding.name()); - Expr valueOfExpr = - MethodInvocationExpr.builder() - .setStaticReferenceType(TypeNode.STRING) - .setMethodName("valueOf") - .setArguments(requestBuilderExpr) - .build(); - - Expr paramsPutExpr = - MethodInvocationExpr.builder() - .setExprReferenceExpr(paramsVarExpr) - .setMethodName("put") - .setArguments( - ValueExpr.withValue(StringObjectValue.withValue(httpBindingFieldBinding.name())), - valueOfExpr) - .build(); - bodyStatements.add(ExprStatement.withExpr(paramsPutExpr)); - } - - returnExprBuilder.setExprReferenceExpr(paramsVarExpr).setMethodName("build"); - } - - private void createRequestParamsExtractorBodyForRoutingHeaders( - Method method, - VariableExpr requestVarExpr, - List classStatements, - List bodyStatements, - MethodInvocationExpr.Builder returnExprBuilder) { - TypeNode routingHeadersBuilderType = - TypeNode.withReference( - ConcreteReference.builder().setClazz(RequestParamsBuilder.class).build()); - VariableExpr routingHeadersBuilderVarExpr = - VariableExpr.builder() - .setVariable( - Variable.builder().setName("builder").setType(routingHeadersBuilderType).build()) - .setIsDecl(true) - .build(); - MethodInvocationExpr routingHeaderBuilderInvokeExpr = - MethodInvocationExpr.builder() - .setStaticReferenceType(routingHeadersBuilderType) - .setMethodName("create") - .setReturnType(routingHeadersBuilderType) - .build(); - Expr routingHeadersBuilderInitExpr = - AssignmentExpr.builder() - .setVariableExpr(routingHeadersBuilderVarExpr) - .setValueExpr(routingHeaderBuilderInvokeExpr) - .build(); - bodyStatements.add(ExprStatement.withExpr(routingHeadersBuilderInitExpr)); - List routingHeaderParams = method.routingHeaderRule().routingHeaderParams(); - VariableExpr routingHeadersBuilderVarNonDeclExpr = - VariableExpr.builder() - .setVariable( - Variable.builder().setName("builder").setType(routingHeadersBuilderType).build()) - .build(); - for (int i = 0; i < routingHeaderParams.size(); i++) { - RoutingHeaderParam routingHeaderParam = routingHeaderParams.get(i); - MethodInvocationExpr requestFieldGetterExpr = - createRequestFieldGetterExpr(requestVarExpr, routingHeaderParam.fieldName()); - Expr routingHeaderKeyExpr = - ValueExpr.withValue(StringObjectValue.withValue(routingHeaderParam.key())); - String pathTemplateName = - String.format("%s_%s_PATH_TEMPLATE", JavaStyle.toUpperSnakeCase(method.name()), i); - TypeNode pathTemplateType = - TypeNode.withReference(ConcreteReference.withClazz(PathTemplate.class)); - Variable pathTemplateVar = - Variable.builder().setType(pathTemplateType).setName(pathTemplateName).build(); - Expr routingHeaderPatternExpr = VariableExpr.withVariable(pathTemplateVar); - Statement pathTemplateClassVar = - createPathTemplateClassStatement(routingHeaderParam, pathTemplateType, pathTemplateVar); - classStatements.add(pathTemplateClassVar); - MethodInvocationExpr addParamMethodExpr = - MethodInvocationExpr.builder() - .setExprReferenceExpr(routingHeadersBuilderVarNonDeclExpr) - .setMethodName("add") - .setArguments(requestFieldGetterExpr, routingHeaderKeyExpr, routingHeaderPatternExpr) - .build(); - - ExprStatement addParamStatement = ExprStatement.withExpr(addParamMethodExpr); - // No need to add null check if there is no nested fields - if (routingHeaderParam.getDescendantFieldNames().size() == 1) { - bodyStatements.add(addParamStatement); - } else { - IfStatement ifStatement = - IfStatement.builder() - .setConditionExpr( - fieldValuesNotNullConditionExpr( - requestVarExpr, routingHeaderParam.getDescendantFieldNames())) - .setBody(ImmutableList.of(addParamStatement)) - .build(); - bodyStatements.add(ifStatement); - } - } - returnExprBuilder - .setExprReferenceExpr(routingHeadersBuilderVarNonDeclExpr) - .setMethodName("build"); - } - - private Statement createPathTemplateClassStatement( - RoutingHeaderParam routingHeaderParam, TypeNode pathTemplateType, Variable pathTemplateVar) { - VariableExpr pathTemplateVarExpr = - VariableExpr.builder() - .setVariable(pathTemplateVar) - .setIsDecl(true) - .setIsStatic(true) - .setIsFinal(true) - .setScope(ScopeNode.PRIVATE) - .build(); - ValueExpr valueExpr = - ValueExpr.withValue(StringObjectValue.withValue(routingHeaderParam.pattern())); - Expr pathTemplateExpr = - AssignmentExpr.builder() - .setVariableExpr(pathTemplateVarExpr) - .setValueExpr( - MethodInvocationExpr.builder() - .setStaticReferenceType(pathTemplateType) - .setMethodName("create") - .setArguments(valueExpr) - .setReturnType(pathTemplateType) - .build()) - .build(); - return ExprStatement.withExpr(pathTemplateExpr); - } - - private Expr fieldValuesNotNullConditionExpr( - VariableExpr requestVarExpr, List fieldNames) { - MethodInvocationExpr.Builder requestFieldGetterExprBuilder = - MethodInvocationExpr.builder().setExprReferenceExpr(requestVarExpr); - Expr fieldValuesNotNullExpr = null; - for (int i = 0; i < fieldNames.size() - 1; i++) { - String currFieldName = fieldNames.get(i); - String bindingFieldMethodName = - String.format("get%s", JavaStyle.toUpperCamelCase(currFieldName)); - requestFieldGetterExprBuilder = - requestFieldGetterExprBuilder.setMethodName(bindingFieldMethodName); - // set return type of each method invocation to String just to pass the validation for - // RelationalOperationExpr that both side of relational operation needs to be a valid equality - // type - MethodInvocationExpr requestGetterExpr = - requestFieldGetterExprBuilder.setReturnType(TypeNode.STRING).build(); - Expr currentValueNotNullExpr = - RelationalOperationExpr.notEqualToWithExprs( - requestGetterExpr, ValueExpr.createNullExpr()); - if (fieldValuesNotNullExpr == null) { - fieldValuesNotNullExpr = currentValueNotNullExpr; - } else { - fieldValuesNotNullExpr = - LogicalOperationExpr.logicalAndWithExprs( - fieldValuesNotNullExpr, currentValueNotNullExpr); - } - requestFieldGetterExprBuilder = - MethodInvocationExpr.builder().setExprReferenceExpr(requestGetterExpr); - } - return fieldValuesNotNullExpr; - } - - private MethodInvocationExpr createRequestFieldGetterExpr( - VariableExpr requestVarExpr, String fieldName) { - MethodInvocationExpr.Builder requestFieldGetterExprBuilder = - MethodInvocationExpr.builder().setExprReferenceExpr(requestVarExpr); - List descendantFields = Splitter.on(".").splitToList(fieldName); - // Handle foo.bar cases by descending into the subfields. - // e.g. foo.bar -> request.getFoo().getBar() - for (int i = 0; i < descendantFields.size(); i++) { - String currFieldName = descendantFields.get(i); - String bindingFieldMethodName = - String.format("get%s", JavaStyle.toUpperCamelCase(currFieldName)); - requestFieldGetterExprBuilder = - requestFieldGetterExprBuilder.setMethodName(bindingFieldMethodName); - if (i < descendantFields.size() - 1) { - requestFieldGetterExprBuilder = - MethodInvocationExpr.builder() - .setExprReferenceExpr(requestFieldGetterExprBuilder.build()); - } - } - return requestFieldGetterExprBuilder.build(); - } } diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java index c1be8dc67b..19e7cfbcbb 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java @@ -210,45 +210,6 @@ protected List createOperationsStubGetterMethod( return super.createOperationsStubGetterMethod(service, operationsStubVarExpr); } - @Override - protected Expr createTransportSettingsInitExpr( - Method method, - VariableExpr transportSettingsVarExpr, - VariableExpr methodDescriptorVarExpr, - List classStatements) { - MethodInvocationExpr callSettingsBuilderExpr = - MethodInvocationExpr.builder() - .setStaticReferenceType( - FIXED_REST_TYPESTORE.get(HttpJsonCallSettings.class.getSimpleName())) - .setGenerics(transportSettingsVarExpr.type().reference().generics()) - .setMethodName("newBuilder") - .build(); - callSettingsBuilderExpr = - MethodInvocationExpr.builder() - .setExprReferenceExpr(callSettingsBuilderExpr) - .setMethodName("setMethodDescriptor") - .setArguments(Arrays.asList(methodDescriptorVarExpr)) - .build(); - - callSettingsBuilderExpr = - MethodInvocationExpr.builder() - .setExprReferenceExpr(callSettingsBuilderExpr) - .setMethodName("setTypeRegistry") - .setArguments(Arrays.asList(TYPE_REGISTRY_VAR_EXPR)) - .build(); - - callSettingsBuilderExpr = - MethodInvocationExpr.builder() - .setExprReferenceExpr(callSettingsBuilderExpr) - .setMethodName("build") - .setReturnType(transportSettingsVarExpr.type()) - .build(); - return AssignmentExpr.builder() - .setVariableExpr(transportSettingsVarExpr.toBuilder().setIsDecl(true).build()) - .setValueExpr(callSettingsBuilderExpr) - .build(); - } - @Override protected List createClassAnnotations(Service service) { List annotations = super.createClassAnnotations(service); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcLoggingStub.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcLoggingStub.golden index 09386582c9..00931520dc 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcLoggingStub.golden +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcLoggingStub.golden @@ -10,8 +10,8 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.logging.v2.DeleteLogRequest; import com.google.logging.v2.ListLogEntriesRequest; import com.google.logging.v2.ListLogEntriesResponse; @@ -173,9 +173,9 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub { .setMethodDescriptor(deleteLogMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("log_name", String.valueOf(request.getLogName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("log_name", String.valueOf(request.getLogName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -201,9 +201,9 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub { .setMethodDescriptor(listLogsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcPublisherStub.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcPublisherStub.golden index 1b61e70b05..ceef5178af 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcPublisherStub.golden +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcPublisherStub.golden @@ -9,8 +9,8 @@ import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import com.google.pubsub.v1.DeleteTopicRequest; @@ -190,9 +190,9 @@ public class GrpcPublisherStub extends PublisherStub { .setMethodDescriptor(createTopicMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings updateTopicTransportSettings = @@ -200,9 +200,9 @@ public class GrpcPublisherStub extends PublisherStub { .setMethodDescriptor(updateTopicMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic.name", String.valueOf(request.getTopic().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic.name", String.valueOf(request.getTopic().getName())); + return builder.build(); }) .build(); GrpcCallSettings publishTransportSettings = @@ -210,9 +210,9 @@ public class GrpcPublisherStub extends PublisherStub { .setMethodDescriptor(publishMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic", String.valueOf(request.getTopic())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic", String.valueOf(request.getTopic())); + return builder.build(); }) .build(); GrpcCallSettings getTopicTransportSettings = @@ -220,9 +220,9 @@ public class GrpcPublisherStub extends PublisherStub { .setMethodDescriptor(getTopicMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic", String.valueOf(request.getTopic())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic", String.valueOf(request.getTopic())); + return builder.build(); }) .build(); GrpcCallSettings listTopicsTransportSettings = @@ -230,9 +230,9 @@ public class GrpcPublisherStub extends PublisherStub { .setMethodDescriptor(listTopicsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("project", String.valueOf(request.getProject())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("project", String.valueOf(request.getProject())); + return builder.build(); }) .build(); GrpcCallSettings @@ -242,9 +242,9 @@ public class GrpcPublisherStub extends PublisherStub { .setMethodDescriptor(listTopicSubscriptionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic", String.valueOf(request.getTopic())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic", String.valueOf(request.getTopic())); + return builder.build(); }) .build(); GrpcCallSettings @@ -253,9 +253,9 @@ public class GrpcPublisherStub extends PublisherStub { .setMethodDescriptor(listTopicSnapshotsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic", String.valueOf(request.getTopic())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic", String.valueOf(request.getTopic())); + return builder.build(); }) .build(); GrpcCallSettings deleteTopicTransportSettings = @@ -263,9 +263,9 @@ public class GrpcPublisherStub extends PublisherStub { .setMethodDescriptor(deleteTopicMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic", String.valueOf(request.getTopic())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic", String.valueOf(request.getTopic())); + return builder.build(); }) .build(); GrpcCallSettings @@ -274,9 +274,9 @@ public class GrpcPublisherStub extends PublisherStub { .setMethodDescriptor(detachSubscriptionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("subscription", String.valueOf(request.getSubscription())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("subscription", String.valueOf(request.getSubscription())); + return builder.build(); }) .build(); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcRoutingHeadersStub.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcRoutingHeadersStub.golden index 84489dd164..3ab4142af4 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcRoutingHeadersStub.golden +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcRoutingHeadersStub.golden @@ -8,7 +8,6 @@ import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.api.pathtemplate.PathTemplate; -import com.google.common.collect.ImmutableMap; import com.google.explicit.dynamic.routing.header.Request; import com.google.explicit.dynamic.routing.header.RequestWithNestedField; import com.google.longrunning.stub.GrpcOperationsStub; @@ -407,9 +406,9 @@ public class GrpcExplicitDynamicRoutingHeaderTestingStub .setMethodDescriptor(backwardsCompatible3TestMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("table_name", String.valueOf(request.getTableName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("table_name", String.valueOf(request.getTableName())); + return builder.build(); }) .build(); GrpcCallSettings nestedFieldTestTransportSettings = diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcTestingStub.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcTestingStub.golden index 6c0a667291..1cfa747b03 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcTestingStub.golden +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcTestingStub.golden @@ -12,7 +12,6 @@ import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.api.pathtemplate.PathTemplate; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.CreateSessionRequest; @@ -193,9 +192,9 @@ public class GrpcTestingStub extends TestingStub { .setMethodDescriptor(getSessionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listSessionsTransportSettings = @@ -207,9 +206,9 @@ public class GrpcTestingStub extends TestingStub { .setMethodDescriptor(deleteSessionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings reportSessionTransportSettings = @@ -217,9 +216,9 @@ public class GrpcTestingStub extends TestingStub { .setMethodDescriptor(reportSessionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getTestTransportSettings = @@ -241,9 +240,9 @@ public class GrpcTestingStub extends TestingStub { .setMethodDescriptor(listTestsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings deleteTestTransportSettings = @@ -251,9 +250,9 @@ public class GrpcTestingStub extends TestingStub { .setMethodDescriptor(deleteTestMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings verifyTestTransportSettings = @@ -261,14 +260,14 @@ public class GrpcTestingStub extends TestingStub { .setMethodDescriptor(verifyTestMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("answer", String.valueOf(request.getAnswer())); - params.put("foo", String.valueOf(request.getFoo())); - params.put("name", String.valueOf(request.getName())); - params.put( + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("answer", String.valueOf(request.getAnswer())); + builder.add("foo", String.valueOf(request.getFoo())); + builder.add("name", String.valueOf(request.getName())); + builder.add( "test_to_verify.name", String.valueOf(request.getTestToVerify().getName())); - params.put("type", String.valueOf(request.getType())); - return params.build(); + builder.add("type", String.valueOf(request.getType())); + return builder.build(); }) .build(); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/GrpcEchoStub.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/GrpcEchoStub.golden index c500e10c31..c52c8d3f07 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/GrpcEchoStub.golden +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/GrpcEchoStub.golden @@ -11,9 +11,9 @@ import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.showcase.grpcrest.v1beta1.BlockRequest; @@ -225,9 +225,9 @@ public class GrpcEchoStub extends EchoStub { .setMethodDescriptor(nestedBindingMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("foo_bar.name", String.valueOf(request.getFooBar().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("foo_bar.name", String.valueOf(request.getFooBar().getName())); + return builder.build(); }) .build(); GrpcCallSettings chatTransportSettings = @@ -243,9 +243,9 @@ public class GrpcEchoStub extends EchoStub { .setMethodDescriptor(updateCaseMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("case.name", String.valueOf(request.getCase().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("case.name", String.valueOf(request.getCase().getName())); + return builder.build(); }) .build(); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/HttpJsonEchoStub.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/HttpJsonEchoStub.golden index 909b6cfdba..a679c9c10e 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/HttpJsonEchoStub.golden +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/HttpJsonEchoStub.golden @@ -20,6 +20,7 @@ import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.common.collect.ImmutableMap; @@ -514,11 +515,23 @@ public class HttpJsonEchoStub extends EchoStub { HttpJsonCallSettings.newBuilder() .setMethodDescriptor(nestedBindingMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("foo_bar.name", String.valueOf(request.getFooBar().getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings updateCaseTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(updateCaseMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("case.name", String.valueOf(request.getCase().getName())); + return builder.build(); + }) .build(); this.echoCallable = diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposerTest.java index a99d23a7c6..f96e67217f 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposerTest.java @@ -196,4 +196,15 @@ public void testGetOperationsURIValueFromHttpRule() { IllegalArgumentException.class, () -> composer.getOperationsURIValueFromHttpRule(customHttpRule)); } + + @Test + public void generateGrpcServiceStubClass_routingHeaders() { + GapicContext context = + RestTestProtoLoader.instance().parseExplicitDynamicRoutingHeaderTesting(); + Service service = context.services().get(0); + GapicClass clazz = HttpJsonServiceStubClassComposer.instance().generate(context, service); + + Assert.assertGoldenClass(this.getClass(), clazz, "HttpJsonRoutingHeadersStub.golden"); + Assert.assertEmptySamples(clazz.samples()); + } } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonComplianceStub.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonComplianceStub.golden index bf282ba988..8ec6f14061 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonComplianceStub.golden +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonComplianceStub.golden @@ -11,6 +11,7 @@ import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; import com.google.api.gax.httpjson.ProtoMessageResponseParser; import com.google.api.gax.httpjson.ProtoRestSerializer; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.protobuf.TypeRegistry; import com.google.showcase.v1beta1.EnumRequest; @@ -419,17 +420,46 @@ public class HttpJsonComplianceStub extends ComplianceStub { HttpJsonCallSettings.newBuilder() .setMethodDescriptor(repeatDataSimplePathMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("info.f_bool", String.valueOf(request.getInfo().getFBool())); + builder.add("info.f_double", String.valueOf(request.getInfo().getFDouble())); + builder.add("info.f_int32", String.valueOf(request.getInfo().getFInt32())); + builder.add("info.f_kingdom", String.valueOf(request.getInfo().getFKingdom())); + builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); + return builder.build(); + }) .build(); HttpJsonCallSettings repeatDataPathResourceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(repeatDataPathResourceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("info.f_bool", String.valueOf(request.getInfo().getFBool())); + builder.add( + "info.f_child.f_string", + String.valueOf(request.getInfo().getFChild().getFString())); + builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); + return builder.build(); + }) .build(); HttpJsonCallSettings repeatDataPathTrailingResourceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(repeatDataPathTrailingResourceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + "info.f_child.f_string", + String.valueOf(request.getInfo().getFChild().getFString())); + builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); + return builder.build(); + }) .build(); HttpJsonCallSettings getEnumTransportSettings = HttpJsonCallSettings.newBuilder() diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonRoutingHeadersStub.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonRoutingHeadersStub.golden new file mode 100644 index 0000000000..56b00d49ea --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonRoutingHeadersStub.golden @@ -0,0 +1,372 @@ +package com.google.explicit.dynamic.routing.header.stub; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.api.pathtemplate.PathTemplate; +import com.google.explicit.dynamic.routing.header.Request; +import com.google.explicit.dynamic.routing.header.RequestWithNestedField; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the ExplicitDynamicRoutingHeaderTesting service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonExplicitDynamicRoutingHeaderTestingStub + extends ExplicitDynamicRoutingHeaderTestingStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + backwardsCompatible1TestMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.explicit.dynamic.routing.header.ExplicitDynamicRoutingHeaderTesting/BackwardsCompatible1Test") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{tableName=tests/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putPathParam(fields, "tableName", request.getTableName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "appProfileId", request.getAppProfileId()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + backwardsCompatible2TestMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.explicit.dynamic.routing.header.ExplicitDynamicRoutingHeaderTesting/BackwardsCompatible2Test") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{tableName=tests/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putPathParam(fields, "tableName", request.getTableName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "appProfileId", request.getAppProfileId()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + backwardsCompatible3TestMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.explicit.dynamic.routing.header.ExplicitDynamicRoutingHeaderTesting/BackwardsCompatible3Test") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{tableName=tests/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putPathParam(fields, "tableName", request.getTableName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "appProfileId", request.getAppProfileId()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable backwardsCompatible1TestCallable; + private final UnaryCallable backwardsCompatible2TestCallable; + private final UnaryCallable backwardsCompatible3TestCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + private static final PathTemplate BACKWARDS_COMPATIBLE1_TEST_0_PATH_TEMPLATE = + PathTemplate.create("{routing_id=projects/*}/**"); + + public static final HttpJsonExplicitDynamicRoutingHeaderTestingStub create( + ExplicitDynamicRoutingHeaderTestingStubSettings settings) throws IOException { + return new HttpJsonExplicitDynamicRoutingHeaderTestingStub( + settings, ClientContext.create(settings)); + } + + public static final HttpJsonExplicitDynamicRoutingHeaderTestingStub create( + ClientContext clientContext) throws IOException { + return new HttpJsonExplicitDynamicRoutingHeaderTestingStub( + ExplicitDynamicRoutingHeaderTestingStubSettings.newBuilder().build(), clientContext); + } + + public static final HttpJsonExplicitDynamicRoutingHeaderTestingStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonExplicitDynamicRoutingHeaderTestingStub( + ExplicitDynamicRoutingHeaderTestingStubSettings.newBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonExplicitDynamicRoutingHeaderTestingStub, using the given + * settings. This is protected so that it is easy to make a subclass, but otherwise, the static + * factory methods should be preferred. + */ + protected HttpJsonExplicitDynamicRoutingHeaderTestingStub( + ExplicitDynamicRoutingHeaderTestingStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonExplicitDynamicRoutingHeaderTestingCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonExplicitDynamicRoutingHeaderTestingStub, using the given + * settings. This is protected so that it is easy to make a subclass, but otherwise, the static + * factory methods should be preferred. + */ + protected HttpJsonExplicitDynamicRoutingHeaderTestingStub( + ExplicitDynamicRoutingHeaderTestingStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings backwardsCompatible1TestTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(backwardsCompatible1TestMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + request.getTableName(), + "routing_id", + BACKWARDS_COMPATIBLE1_TEST_0_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + HttpJsonCallSettings backwardsCompatible2TestTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(backwardsCompatible2TestMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings backwardsCompatible3TestTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(backwardsCompatible3TestMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("table_name", String.valueOf(request.getTableName())); + return builder.build(); + }) + .build(); + + this.backwardsCompatible1TestCallable = + callableFactory.createUnaryCallable( + backwardsCompatible1TestTransportSettings, + settings.backwardsCompatible1TestSettings(), + clientContext); + this.backwardsCompatible2TestCallable = + callableFactory.createUnaryCallable( + backwardsCompatible2TestTransportSettings, + settings.backwardsCompatible2TestSettings(), + clientContext); + this.backwardsCompatible3TestCallable = + callableFactory.createUnaryCallable( + backwardsCompatible3TestTransportSettings, + settings.backwardsCompatible3TestSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(backwardsCompatible1TestMethodDescriptor); + methodDescriptors.add(backwardsCompatible2TestMethodDescriptor); + methodDescriptors.add(backwardsCompatible3TestMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable backwardsCompatible1TestCallable() { + return backwardsCompatible1TestCallable; + } + + @Override + public UnaryCallable backwardsCompatible2TestCallable() { + return backwardsCompatible2TestCallable; + } + + @Override + public UnaryCallable backwardsCompatible3TestCallable() { + return backwardsCompatible3TestCallable; + } + + @Override + public UnaryCallable example1TestCallable() { + throw new UnsupportedOperationException( + "Not implemented: example1TestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public UnaryCallable example2TestCallable() { + throw new UnsupportedOperationException( + "Not implemented: example2TestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public UnaryCallable example3TestCallable() { + throw new UnsupportedOperationException( + "Not implemented: example3TestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public UnaryCallable example3CTestCallable() { + throw new UnsupportedOperationException( + "Not implemented: example3CTestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public UnaryCallable example4TestCallable() { + throw new UnsupportedOperationException( + "Not implemented: example4TestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public UnaryCallable example5TestCallable() { + throw new UnsupportedOperationException( + "Not implemented: example5TestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public UnaryCallable example6TestCallable() { + throw new UnsupportedOperationException( + "Not implemented: example6TestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public UnaryCallable example7TestCallable() { + throw new UnsupportedOperationException( + "Not implemented: example7TestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public UnaryCallable example8TestCallable() { + throw new UnsupportedOperationException( + "Not implemented: example8TestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public UnaryCallable example9TestCallable() { + throw new UnsupportedOperationException( + "Not implemented: example9TestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public UnaryCallable nestedFieldTestCallable() { + throw new UnsupportedOperationException( + "Not implemented: nestedFieldTestCallable(). REST transport is not implemented for this method yet."); + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/CallOptionsUtil.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/CallOptionsUtil.java index f36da0d4d9..9d6e85bdaa 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/CallOptionsUtil.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/CallOptionsUtil.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.grpc; +import com.google.api.gax.rpc.internal.Headers; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import io.grpc.CallOptions; @@ -45,7 +46,7 @@ class CallOptionsUtil { "gax_dynamic_headers", Collections., String>emptyMap()); // this is the header name, it is transferred over the wire static Metadata.Key REQUEST_PARAMS_HEADER_KEY = - Metadata.Key.of("x-goog-request-params", Metadata.ASCII_STRING_MARSHALLER); + Metadata.Key.of(Headers.DYNAMIC_ROUTING_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER); private static final CallOptions.Key METADATA_HANDLER_CALL_OPTION_KEY = CallOptions.Key.createWithDefault("gax_metadata_handler", null); diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcServerStreamingRequestParamCallable.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcServerStreamingRequestParamCallable.java index 5e0a59851e..27b4c56454 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcServerStreamingRequestParamCallable.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcServerStreamingRequestParamCallable.java @@ -51,8 +51,7 @@ class GrpcServerStreamingRequestParamCallable ServerStreamingCallable callable, RequestParamsExtractor paramsExtractor) { this.callable = Preconditions.checkNotNull(callable); - this.paramsEncoder = - new RequestUrlParamsEncoder<>(Preconditions.checkNotNull(paramsExtractor), false); + this.paramsEncoder = new RequestUrlParamsEncoder<>(Preconditions.checkNotNull(paramsExtractor)); } @Override @@ -62,8 +61,14 @@ public void call( } private ApiCallContext contextWithParamsEncoder(RequestT request, ApiCallContext inputContext) { - return GrpcCallContext.createDefault() - .nullToSelf(inputContext) - .withRequestParamsDynamicHeaderOption(paramsEncoder.encode(request)); + ApiCallContext newCallContext = inputContext; + String encodedHeader = paramsEncoder.encode(request); + if (!encodedHeader.isEmpty()) { + newCallContext = + GrpcCallContext.createDefault() + .nullToSelf(inputContext) + .withRequestParamsDynamicHeaderOption(encodedHeader); + } + return newCallContext; } } diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcUnaryRequestParamCallable.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcUnaryRequestParamCallable.java index 9eb78aca0d..22bbd8409b 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcUnaryRequestParamCallable.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcUnaryRequestParamCallable.java @@ -51,16 +51,19 @@ class GrpcUnaryRequestParamCallable UnaryCallable callable, RequestParamsExtractor paramsExtractor) { this.callable = Preconditions.checkNotNull(callable); - this.paramsEncoder = - new RequestUrlParamsEncoder<>(Preconditions.checkNotNull(paramsExtractor), false); + this.paramsEncoder = new RequestUrlParamsEncoder<>(Preconditions.checkNotNull(paramsExtractor)); } @Override public ApiFuture futureCall(RequestT request, ApiCallContext inputContext) { - GrpcCallContext newCallContext = - GrpcCallContext.createDefault() - .nullToSelf(inputContext) - .withRequestParamsDynamicHeaderOption(paramsEncoder.encode(request)); + ApiCallContext newCallContext = inputContext; + String encodedHeader = paramsEncoder.encode(request); + if (!encodedHeader.isEmpty()) { + newCallContext = + GrpcCallContext.createDefault() + .nullToSelf(inputContext) + .withRequestParamsDynamicHeaderOption(encodedHeader); + } return callable.futureCall(request, newCallContext); } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallSettings.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallSettings.java index ac013ed74a..7dd7732175 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallSettings.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallSettings.java @@ -29,23 +29,29 @@ */ package com.google.api.gax.httpjson; +import com.google.api.gax.rpc.RequestParamsExtractor; import com.google.protobuf.TypeRegistry; /** HTTP-specific settings for creating callables. */ public class HttpJsonCallSettings { private final ApiMethodDescriptor methodDescriptor; + private final RequestParamsExtractor paramsExtractor; private final TypeRegistry typeRegistry; - private HttpJsonCallSettings( - ApiMethodDescriptor methodDescriptor, TypeRegistry typeRegistry) { - this.methodDescriptor = methodDescriptor; - this.typeRegistry = typeRegistry; + private HttpJsonCallSettings(Builder builder) { + this.methodDescriptor = builder.methodDescriptor; + this.paramsExtractor = builder.paramsExtractor; + this.typeRegistry = builder.typeRegistry; } public ApiMethodDescriptor getMethodDescriptor() { return methodDescriptor; } + public RequestParamsExtractor getParamsExtractor() { + return paramsExtractor; + } + public TypeRegistry getTypeRegistry() { return typeRegistry; } @@ -67,6 +73,7 @@ public Builder toBuilder() { public static class Builder { private ApiMethodDescriptor methodDescriptor; + private RequestParamsExtractor paramsExtractor; private TypeRegistry typeRegistry; private Builder() {} @@ -81,13 +88,19 @@ public Builder setMethodDescriptor( return this; } + public Builder setParamsExtractor( + RequestParamsExtractor paramsExtractor) { + this.paramsExtractor = paramsExtractor; + return this; + } + public Builder setTypeRegistry(TypeRegistry typeRegistry) { this.typeRegistry = typeRegistry; return this; } public HttpJsonCallSettings build() { - return new HttpJsonCallSettings<>(methodDescriptor, typeRegistry); + return new HttpJsonCallSettings<>(this); } } } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallableFactory.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallableFactory.java index 6131c911f8..d95751e3b0 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallableFactory.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallableFactory.java @@ -60,8 +60,16 @@ private HttpJsonCallableFactory() {} private static UnaryCallable createDirectUnaryCallable( HttpJsonCallSettings httpJsonCallSettings) { - return new HttpJsonDirectCallable( - httpJsonCallSettings.getMethodDescriptor(), httpJsonCallSettings.getTypeRegistry()); + UnaryCallable callable = + new HttpJsonDirectCallable<>( + httpJsonCallSettings.getMethodDescriptor(), httpJsonCallSettings.getTypeRegistry()); + + if (httpJsonCallSettings.getParamsExtractor() != null) { + callable = + new HttpJsonUnaryRequestParamCallable<>( + callable, httpJsonCallSettings.getParamsExtractor()); + } + return callable; } static UnaryCallable createUnaryCallable( @@ -180,6 +188,12 @@ ServerStreamingCallable createServerStreamingCallable( ServerStreamingCallable callable = new HttpJsonDirectServerStreamingCallable<>(httpJsoncallSettings.getMethodDescriptor()); + if (httpJsoncallSettings.getParamsExtractor() != null) { + callable = + new HttpJsonServerStreamingRequestParamCallable<>( + callable, httpJsoncallSettings.getParamsExtractor()); + } + callable = new HttpJsonExceptionServerStreamingCallable<>( callable, streamingCallSettings.getRetryableCodes()); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java index c0b9719574..ae1ae3ca84 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java @@ -37,7 +37,7 @@ import org.threeten.bp.Duration; /** - * {@code HttpJsonClientCalls} creates a new {@code HttpJsonClientCAll} from the given call context. + * {@code HttpJsonClientCalls} creates a new {@code HttpJsonClientCall} from the given call context. * *

Package-private for internal use. */ @@ -68,8 +68,8 @@ public static HttpJsonClientCall newC .toBuilder() .setTimeout(java.time.Duration.ofMillis(httpJsonContext.getTimeout().toMillis())) .build(); - httpJsonContext = httpJsonContext.withCallOptions(callOptions); } + httpJsonContext = httpJsonContext.withCallOptions(callOptions); } // TODO: add headers interceptor logic @@ -77,10 +77,14 @@ public static HttpJsonClientCall newC } static ApiFuture futureUnaryCall( - HttpJsonClientCall clientCall, RequestT request) { + HttpJsonClientCall clientCall, + RequestT request, + HttpJsonCallContext context) { // Start the call HttpJsonFuture future = new HttpJsonFuture<>(clientCall); - clientCall.start(new FutureListener<>(future), HttpJsonMetadata.newBuilder().build()); + clientCall.start( + new FutureListener<>(future), + HttpJsonMetadata.newBuilder().build().withHeaders(context.getExtraHeaders())); // Send the request try { diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectCallable.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectCallable.java index c631ca60c8..abf3290067 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectCallable.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectCallable.java @@ -65,7 +65,7 @@ public ApiFuture futureCall(RequestT request, ApiCallContext inputCon HttpJsonClientCall clientCall = HttpJsonClientCalls.newCall(descriptor, context); - return HttpJsonClientCalls.futureUnaryCall(clientCall, request); + return HttpJsonClientCalls.futureUnaryCall(clientCall, request, context); } @Override diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallable.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallable.java index ed3bebde31..2f98ac177e 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallable.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallable.java @@ -64,6 +64,6 @@ public void call( HttpJsonClientCall call = HttpJsonClientCalls.newCall(descriptor, context); HttpJsonDirectStreamController controller = new HttpJsonDirectStreamController<>(call, responseObserver); - controller.start(request); + controller.start(request, context); } } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectStreamController.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectStreamController.java index 5f56390f04..9e1b23b257 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectStreamController.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonDirectStreamController.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.httpjson; +import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ResponseObserver; import com.google.api.gax.rpc.StreamController; import com.google.common.base.Preconditions; @@ -80,10 +81,12 @@ public void request(int count) { } } - void start(RequestT request) { + void start(RequestT request, ApiCallContext context) { responseObserver.onStart(this); this.hasStarted = true; - clientCall.start(new ResponseObserverAdapter(), HttpJsonMetadata.newBuilder().build()); + clientCall.start( + new ResponseObserverAdapter(), + HttpJsonMetadata.newBuilder().build().withHeaders(context.getExtraHeaders())); if (autoflowControl) { clientCall.request(1); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonMetadata.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonMetadata.java index 9fef6db5c5..7985396075 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonMetadata.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonMetadata.java @@ -33,6 +33,8 @@ import com.google.api.core.InternalExtensionOnly; import com.google.auto.value.AutoValue; import java.util.Collections; +import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Nullable; @@ -54,6 +56,22 @@ public static HttpJsonMetadata.Builder newBuilder() { return new AutoValue_HttpJsonMetadata.Builder().setHeaders(Collections.emptyMap()); } + public HttpJsonMetadata withHeaders(Map> headers) { + Map extraHeaders = new HashMap<>(); + for (Map.Entry> entrySet : headers.entrySet()) { + // HeaderValueList is always non-null. Check that it contains at least one value. + // Should only ever contain one value, but take the first one if there are multiple. + // TODO(https://github.com/googleapis/sdk-platform-java/issues/1752): + // Investigate how to better support extraHeaders + List headerValueList = entrySet.getValue(); + if (headerValueList.isEmpty()) { + continue; + } + extraHeaders.put(entrySet.getKey(), headerValueList.get(0)); + } + return toBuilder().setHeaders(extraHeaders).build(); + } + @AutoValue.Builder abstract static class Builder { abstract Builder setHeaders(Map headers); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonServerStreamingRequestParamCallable.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonServerStreamingRequestParamCallable.java new file mode 100644 index 0000000000..7b1d615961 --- /dev/null +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonServerStreamingRequestParamCallable.java @@ -0,0 +1,69 @@ +/* + * Copyright 2023 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.google.api.gax.httpjson; + +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.RequestParamsExtractor; +import com.google.api.gax.rpc.RequestUrlParamsEncoder; +import com.google.api.gax.rpc.ResponseObserver; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.internal.Headers; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +public class HttpJsonServerStreamingRequestParamCallable + extends ServerStreamingCallable { + private final ServerStreamingCallable callable; + private final RequestUrlParamsEncoder paramsEncoder; + + HttpJsonServerStreamingRequestParamCallable( + ServerStreamingCallable callable, + RequestParamsExtractor paramsExtractor) { + this.callable = Preconditions.checkNotNull(callable); + this.paramsEncoder = new RequestUrlParamsEncoder<>(Preconditions.checkNotNull(paramsExtractor)); + } + + @Override + public void call( + RequestT request, ResponseObserver responseObserver, ApiCallContext context) { + ApiCallContext newCallContext = context; + String encodedHeader = paramsEncoder.encode(request); + if (!encodedHeader.isEmpty()) { + newCallContext = + HttpJsonCallContext.createDefault() + .nullToSelf(context) + .withExtraHeaders( + ImmutableMap.of( + Headers.DYNAMIC_ROUTING_HEADER_KEY, ImmutableList.of(encodedHeader))); + } + callable.call(request, responseObserver, newCallContext); + } +} diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonUnaryRequestParamCallable.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonUnaryRequestParamCallable.java new file mode 100644 index 0000000000..3770872e87 --- /dev/null +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonUnaryRequestParamCallable.java @@ -0,0 +1,74 @@ +/* + * Copyright 2023 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.google.api.gax.httpjson; + +import com.google.api.core.ApiFuture; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.RequestParamsExtractor; +import com.google.api.gax.rpc.RequestUrlParamsEncoder; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.api.gax.rpc.internal.Headers; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +/** + * A {@code UnaryCallable} that extracts values from the fields of the request and inserts them into + * headers. + * + *

Package-private for internal usage. + */ +class HttpJsonUnaryRequestParamCallable + extends UnaryCallable { + private final UnaryCallable callable; + private final RequestUrlParamsEncoder paramsEncoder; + + public HttpJsonUnaryRequestParamCallable( + UnaryCallable callable, + RequestParamsExtractor paramsExtractor) { + this.callable = Preconditions.checkNotNull(callable); + this.paramsEncoder = new RequestUrlParamsEncoder<>(Preconditions.checkNotNull(paramsExtractor)); + } + + @Override + public ApiFuture futureCall(RequestT request, ApiCallContext context) { + ApiCallContext newCallContext = context; + String encodedHeader = paramsEncoder.encode(request); + if (!encodedHeader.isEmpty()) { + newCallContext = + HttpJsonCallContext.createDefault() + .nullToSelf(context) + .withExtraHeaders( + ImmutableMap.of( + Headers.DYNAMIC_ROUTING_HEADER_KEY, ImmutableList.of(encodedHeader))); + } + return callable.futureCall(request, newCallContext); + } +} diff --git a/gax-java/gax/pom.xml b/gax-java/gax/pom.xml index 7d730ed191..ffef9496ad 100644 --- a/gax-java/gax/pom.xml +++ b/gax-java/gax/pom.xml @@ -81,6 +81,16 @@ + + org.codehaus.mojo + clirr-maven-plugin + + + + com/google/api/gax/rpc/RequestUrlParamsEncoder + + + \ No newline at end of file diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/RequestParamsBuilder.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/RequestParamsBuilder.java index 4f234f0ce3..9e3914309c 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/RequestParamsBuilder.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/RequestParamsBuilder.java @@ -40,7 +40,6 @@ */ @BetaApi public class RequestParamsBuilder { - private final ImmutableMap.Builder paramsBuilder; private RequestParamsBuilder() { @@ -63,7 +62,7 @@ public static RequestParamsBuilder create() { * @param pathTemplate {@link PathTemplate} the path template used for match-and-extract */ public void add(String fieldValue, String headerKey, PathTemplate pathTemplate) { - if (fieldValue == null) { + if (checkInvalidHeaderValues(headerKey, fieldValue)) { return; } Map matchedValues = pathTemplate.match(fieldValue); @@ -72,6 +71,25 @@ public void add(String fieldValue, String headerKey, PathTemplate pathTemplate) } } + /** + * Add an entry to paramsBuilder with key-value pairing of (headerKey, fieldValue). The only + * validation done is to ensure the headerKey and fieldValue are not null and non-empty. This + * method is used for implicit routing headers (backwards compatibility). + * + * @param headerKey the header key for the routing header param + * @param fieldValue the field value from a request + */ + public void add(String headerKey, String fieldValue) { + if (checkInvalidHeaderValues(headerKey, fieldValue)) { + return; + } + paramsBuilder.put(headerKey, fieldValue); + } + + private boolean checkInvalidHeaderValues(String headerKey, String fieldValue) { + return headerKey == null || headerKey.isEmpty() || fieldValue == null || fieldValue.isEmpty(); + } + public Map build() { return paramsBuilder.buildKeepingLast(); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/RequestUrlParamsEncoder.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/RequestUrlParamsEncoder.java index 6bb1da2509..a5b50086cf 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/RequestUrlParamsEncoder.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/RequestUrlParamsEncoder.java @@ -31,46 +31,40 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.api.client.util.escape.PercentEscaper; import com.google.api.core.InternalApi; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.net.URLEncoder; import java.util.Map; /** * The request params encoder, which encodes URL-encoded parameters in one URL parameters string. - * This class expects that name-value pairs, returned from parameters extractor are already - * URL-encoded and can perform optional validation of that, but does not encode the name-value pairs - * themselves. * * @param request message type */ @InternalApi("For use by transport-specific implementations") public class RequestUrlParamsEncoder implements RequestParamsEncoder { - private static final String STR_ENCODING = "UTF-8"; - + // Per RFC 3986 Section 2.3, these are the four unreserved characters that don't need to be + // encoded + private static final PercentEscaper PERCENT_ESCAPER = new PercentEscaper("._-~"); private final RequestParamsExtractor paramsExtractor; - private final boolean validateExtractedParameters; /** * Creates the encoder. * * @param paramsExtractor parameters extractor which returns already URL-encoded key-value pairs - * @param validateExtractedParameters {@code true} if this class should validate that the - * extracted parameters are URL-encoded, {@code false} otherwise */ - public RequestUrlParamsEncoder( - RequestParamsExtractor paramsExtractor, boolean validateExtractedParameters) { + public RequestUrlParamsEncoder(RequestParamsExtractor paramsExtractor) { this.paramsExtractor = checkNotNull(paramsExtractor); - this.validateExtractedParameters = validateExtractedParameters; } /** * Encodes the {@code request} in a form of a URL parameters string, for example {@code * "param1=value+1¶m2=value2%26"}. This method may optionally validate that the name-value - * paris are URL-encoded, but it will not perform the actual encoding of them (it will only - * concatenate the valid individual name-value pairs in a valid URL parameters string). This is - * so, because in most practical cases the name-value paris are already URL-encoded. + * paris are URL-encoded. It will URL encode the key and values if there are any non-allowed + * characters. It will then concatenate the valid individual name-value pairs in a valid URL + * parameters string. + * + *

Note: This will url-encode the key and values during concatenation. Double url-encoding may + * occur if the input has values that are already url-encoded. * * @param request request message * @throws IllegalArgumentException if is not @@ -86,37 +80,17 @@ public String encode(RequestT request) { if (sb.length() > 0) { sb.append("&"); } - String name = entry.getKey(); - String value = entry.getValue(); - if (name == null) { - throw new IllegalArgumentException("Request parameter name cannot be null"); - } - - // Let the server decide if the value is required. - // Empty value is allowed. - if (value != null) { - if (!isValid(name, value)) { - throw new IllegalArgumentException( - "Invalid url-encoded request parameter name-value pair: " + name + "=" + value); - } - sb.append(name).append("=").append(value); - } + // RequestParamsExtractor checks that the values are non-null and non-empty + String encodedKey = percentEncodeString(entry.getKey()); + String encodedValue = percentEncodeString(entry.getValue()); + sb.append(encodedKey).append("=").append(encodedValue); } return sb.toString(); } - // Not sure if we need this at all. - private boolean isValid(String name, String value) { - try { - // hoping that encode/decode do not lose information in the middle - // (at least for practical use cases) - return !validateExtractedParameters - || name.equals(URLEncoder.encode(URLDecoder.decode(name, STR_ENCODING), STR_ENCODING)) - && value.equals( - URLEncoder.encode(URLDecoder.decode(value, STR_ENCODING), STR_ENCODING)); - } catch (UnsupportedEncodingException e) { - return false; - } + // Percent encode the value passed in. + private String percentEncodeString(String value) { + return PERCENT_ESCAPER.escape(value); } } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/internal/Headers.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/internal/Headers.java index ddd6600362..49d4c049ab 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/internal/Headers.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/internal/Headers.java @@ -38,6 +38,8 @@ @InternalApi public class Headers { + public static final String DYNAMIC_ROUTING_HEADER_KEY = "x-goog-request-params"; + public static ImmutableMap> mergeHeaders( Map> oldHeaders, Map> newHeaders) { ImmutableMap.Builder> headersBuilder = ImmutableMap.builder(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RequestParamsBuilderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RequestParamsBuilderTest.java index 30f4d7e628..d3a16960fd 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RequestParamsBuilderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RequestParamsBuilderTest.java @@ -58,6 +58,29 @@ public void add_happyPath() { assertThat(actual).containsExactly("table_location", "instances/living_room"); } + @Test + public void add_twoParams_happyPath() { + requestParamsBuilder.add("table_location", "instances/living_room"); + Map actual = requestParamsBuilder.build(); + assertThat(actual).containsExactly("table_location", "instances/living_room"); + } + + @Test + public void add_containsNonEncodedHeaderAndValue() { + PathTemplate pathTemplate = PathTemplate.create("projects/**/{table$$_++location=instances/*}"); + requestParamsBuilder.add( + "projects/my_cozy_home/instances/living_room", "table$$_++location", pathTemplate); + Map actual = requestParamsBuilder.build(); + assertThat(actual).containsExactly("table$$_++location", "instances/living_room"); + } + + @Test + public void add_twoParams_containsNonEncodedHeaderAndValue() { + requestParamsBuilder.add("table$$_++location", "instances/living_room"); + Map actual = requestParamsBuilder.build(); + assertThat(actual).containsExactly("table$$_++location", "instances/living_room"); + } + @Test public void build_shouldKeepLastEntryIfMultipleEntriesHaveTheSameKeyRatherThanErrorOut() { requestParamsBuilder.add( @@ -103,6 +126,50 @@ public void add_nullFieldValue() { assertThat(actual).isEmpty(); } + @Test + public void addWithTwoParams_nullFieldValue() { + requestParamsBuilder.add("test", null); + Map actual = requestParamsBuilder.build(); + assertThat(actual).isEmpty(); + } + + @Test + public void add_emptyString_noMatches() { + // protobuf's default value for string is empty string. The `**` pathtemplate would match + // for empty string if it's not explicitly filtered out + Map actual = getRoutingHeaders("{table_location=**}", ""); + assertThat(actual).isEmpty(); + } + + @Test + public void addWithTwoParams_emptyString_noMatches() { + // protobuf's default value for string is empty string. The `**` pathtemplate would match + // for empty string if it's not explicitly filtered out + Map actual = getRoutingHeaders("{table_location=**}", ""); + assertThat(actual).isEmpty(); + } + + @Test + public void add_nullHeader_noMatches() { + requestParamsBuilder.add(null, "projects/does_not_matter"); + Map actual = requestParamsBuilder.build(); + assertThat(actual).isEmpty(); + } + + @Test + public void addWithTwoParams_nullHeader_noMatches() { + requestParamsBuilder.add(null, "hello"); + Map actual = requestParamsBuilder.build(); + assertThat(actual).isEmpty(); + } + + @Test + public void addWithTwoParams_emptyHeader_noMatches() { + requestParamsBuilder.add("", "hello"); + Map actual = requestParamsBuilder.build(); + assertThat(actual).isEmpty(); + } + private Map getRoutingHeaders(String patternString, String fieldValue) { PathTemplate pathTemplate = PathTemplate.create(patternString); requestParamsBuilder.add(fieldValue, "table_location", pathTemplate); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RequestUrlParamsEncoderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RequestUrlParamsEncoderTest.java index 3239bd148f..a4260305de 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RequestUrlParamsEncoderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RequestUrlParamsEncoderTest.java @@ -31,7 +31,6 @@ package com.google.api.gax.rpc; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; @@ -42,87 +41,50 @@ public class RequestUrlParamsEncoderTest { - @Test - public void testEncodeValidationSuccess() throws Exception { - @SuppressWarnings("unchecked") - RequestParamsExtractor extractor = - getMockExtractor(2, ImmutableMap.of("param1", "value+1", "param2", "value+2+%26")); - - RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor, true); - String encodedParams = encoder.encode(2); + private final String key = "key"; - assertEquals("param1=value+1¶m2=value+2+%26", encodedParams); - } + @Test + public void testEncode() { + RequestParamsExtractor extractor = getMockExtractor(ImmutableMap.of("param", "value")); + RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor); + String encodedParams = encoder.encode(key); - @Test(expected = IllegalArgumentException.class) - public void testEncodeValidationFail() throws Exception { - RequestParamsExtractor extractor = - getMockExtractor(1, ImmutableMap.of("param1", "value+1", "param2", "value+2+&")); - RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor, true); - encoder.encode(1); + assertEquals("param=value", encodedParams); } @Test - public void testEncodeNoValidationSuccess() throws Exception { - RequestParamsExtractor extractor = - getMockExtractor(1, ImmutableMap.of("param1", "value+1", "param2", "value+2+&")); - RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor, false); - String encodedParams = encoder.encode(1); + public void testEncode_multipleEntriesConcatenation() { + RequestParamsExtractor extractor = + getMockExtractor(ImmutableMap.of("param1", "value1", "param2", "value2")); + RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor); + String encodedParams = encoder.encode(key); - assertEquals("param1=value+1¶m2=value+2+&", encodedParams); - } - - @Test(expected = IllegalArgumentException.class) - public void testEncodeNullName() throws Exception { - RequestParamsExtractor extractor = - getMockExtractor(1, Collections.singletonMap((String) null, "value1")); - RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor, false); - encoder.encode(1); + assertEquals("param1=value1¶m2=value2", encodedParams); } @Test - public void testEncodeNullValue() throws Exception { - RequestParamsExtractor extractor = - getMockExtractor(1, Collections.singletonMap("param1", (String) null)); - RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor, false); - String encodedParams = encoder.encode(1); - assertEquals("", encodedParams); - } + public void testEncode_multipleEntriesConcatenation_encodedKeyAndValues() { + RequestParamsExtractor extractor = + getMockExtractor(ImmutableMap.of("param1!@#", "value+1", "param2()", "value+2+&")); + RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor); + String encodedParams = encoder.encode(key); - @Test - public void testEncodeEmptyValue() throws Exception { - RequestParamsExtractor extractor = - getMockExtractor(1, Collections.singletonMap("param1", "")); - RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor, false); - String encodedParams = encoder.encode(1); - assertEquals("param1=", encodedParams); + assertEquals("param1%21%40%23=value%2B1¶m2%28%29=value%2B2%2B%26", encodedParams); } @Test - public void testEncodeNullAndEmptyParams() throws Exception { - RequestParamsExtractor extractor = - getMockExtractor(1, Collections.emptyMap()); - RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor, false); - String encodedParams = encoder.encode(1); + public void testEncodeEmptyMap() { + RequestParamsExtractor extractor = getMockExtractor(Collections.emptyMap()); + RequestUrlParamsEncoder encoder = new RequestUrlParamsEncoder<>(extractor); + String encodedParams = encoder.encode(key); assertEquals("", encodedParams); - - extractor = getMockExtractor(1, null); - encoder = new RequestUrlParamsEncoder<>(extractor, false); - NullPointerException exception = null; - try { - encoder.encode(1); - } catch (NullPointerException e) { - exception = e; - } - assertNotNull(exception); } - private RequestParamsExtractor getMockExtractor( - Integer input, Map output) { + private RequestParamsExtractor getMockExtractor(Map output) { @SuppressWarnings("unchecked") - RequestParamsExtractor extractor = - (RequestParamsExtractor) Mockito.mock(RequestParamsExtractor.class); - when(extractor.extract(input)).thenReturn(output); + RequestParamsExtractor extractor = + (RequestParamsExtractor) Mockito.mock(RequestParamsExtractor.class); + when(extractor.extract(key)).thenReturn(output); return extractor; } } diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java index 4748fd99d6..c6dcf25bf3 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java @@ -24,12 +24,12 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.location.GetLocationRequest; import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.showcase.v1beta1.EnumRequest; import com.google.showcase.v1beta1.EnumResponse; @@ -233,13 +233,13 @@ protected GrpcComplianceStub( .setMethodDescriptor(repeatDataSimplePathMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("info.f_bool", String.valueOf(request.getInfo().getFBool())); - params.put("info.f_double", String.valueOf(request.getInfo().getFDouble())); - params.put("info.f_int32", String.valueOf(request.getInfo().getFInt32())); - params.put("info.f_kingdom", String.valueOf(request.getInfo().getFKingdom())); - params.put("info.f_string", String.valueOf(request.getInfo().getFString())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("info.f_bool", String.valueOf(request.getInfo().getFBool())); + builder.add("info.f_double", String.valueOf(request.getInfo().getFDouble())); + builder.add("info.f_int32", String.valueOf(request.getInfo().getFInt32())); + builder.add("info.f_kingdom", String.valueOf(request.getInfo().getFKingdom())); + builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); + return builder.build(); }) .build(); GrpcCallSettings repeatDataPathResourceTransportSettings = @@ -247,13 +247,13 @@ protected GrpcComplianceStub( .setMethodDescriptor(repeatDataPathResourceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("info.f_bool", String.valueOf(request.getInfo().getFBool())); - params.put( + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("info.f_bool", String.valueOf(request.getInfo().getFBool())); + builder.add( "info.f_child.f_string", String.valueOf(request.getInfo().getFChild().getFString())); - params.put("info.f_string", String.valueOf(request.getInfo().getFString())); - return params.build(); + builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); + return builder.build(); }) .build(); GrpcCallSettings @@ -262,12 +262,12 @@ protected GrpcComplianceStub( .setMethodDescriptor(repeatDataPathTrailingResourceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put( + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( "info.f_child.f_string", String.valueOf(request.getInfo().getFChild().getFString())); - params.put("info.f_string", String.valueOf(request.getInfo().getFString())); - return params.build(); + builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); + return builder.build(); }) .build(); GrpcCallSettings repeatDataBodyPutTransportSettings = @@ -291,9 +291,9 @@ protected GrpcComplianceStub( .setMethodDescriptor(listLocationsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getLocationTransportSettings = @@ -301,9 +301,9 @@ protected GrpcComplianceStub( .setMethodDescriptor(getLocationMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java index 0ead71ff7a..36c6e630d5 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java @@ -37,7 +37,6 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.showcase.v1beta1.BlockRequest; @@ -295,9 +294,9 @@ protected GrpcEchoStub( .setMethodDescriptor(listLocationsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getLocationTransportSettings = @@ -305,9 +304,9 @@ protected GrpcEchoStub( .setMethodDescriptor(getLocationMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java index 5e8e26e032..1e2c7c0b4c 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java @@ -25,12 +25,12 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.location.GetLocationRequest; import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.CreateUserRequest; @@ -175,9 +175,9 @@ protected GrpcIdentityStub( .setMethodDescriptor(getUserMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings updateUserTransportSettings = @@ -185,9 +185,9 @@ protected GrpcIdentityStub( .setMethodDescriptor(updateUserMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("user.name", String.valueOf(request.getUser().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("user.name", String.valueOf(request.getUser().getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteUserTransportSettings = @@ -195,9 +195,9 @@ protected GrpcIdentityStub( .setMethodDescriptor(deleteUserMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listUsersTransportSettings = @@ -209,9 +209,9 @@ protected GrpcIdentityStub( .setMethodDescriptor(listLocationsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getLocationTransportSettings = @@ -219,9 +219,9 @@ protected GrpcIdentityStub( .setMethodDescriptor(getLocationMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java index 30d08ad270..52bc2b8c36 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java @@ -29,13 +29,13 @@ import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientStreamingCallable; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.location.GetLocationRequest; import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; @@ -289,9 +289,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(getRoomMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings updateRoomTransportSettings = @@ -299,9 +299,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(updateRoomMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("room.name", String.valueOf(request.getRoom().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("room.name", String.valueOf(request.getRoom().getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteRoomTransportSettings = @@ -309,9 +309,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(deleteRoomMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listRoomsTransportSettings = @@ -323,9 +323,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(createBlurbMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getBlurbTransportSettings = @@ -333,9 +333,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(getBlurbMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings updateBlurbTransportSettings = @@ -343,9 +343,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(updateBlurbMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("blurb.name", String.valueOf(request.getBlurb().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("blurb.name", String.valueOf(request.getBlurb().getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteBlurbTransportSettings = @@ -353,9 +353,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(deleteBlurbMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listBlurbsTransportSettings = @@ -363,9 +363,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(listBlurbsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings searchBlurbsTransportSettings = @@ -373,9 +373,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(searchBlurbsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings streamBlurbsTransportSettings = @@ -383,9 +383,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(streamBlurbsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings sendBlurbsTransportSettings = @@ -393,9 +393,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(sendBlurbsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings connectTransportSettings = @@ -407,9 +407,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(listLocationsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getLocationTransportSettings = @@ -417,9 +417,9 @@ protected GrpcMessagingStub( .setMethodDescriptor(getLocationMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java index 23ce2c2ced..e2c47d1117 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java @@ -24,13 +24,13 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.location.GetLocationRequest; import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.AttemptSequenceRequest; @@ -217,9 +217,9 @@ protected GrpcSequenceServiceStub( .setMethodDescriptor(getSequenceReportMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -229,9 +229,9 @@ protected GrpcSequenceServiceStub( .setMethodDescriptor(getStreamingSequenceReportMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings attemptSequenceTransportSettings = @@ -239,9 +239,9 @@ protected GrpcSequenceServiceStub( .setMethodDescriptor(attemptSequenceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -251,9 +251,9 @@ protected GrpcSequenceServiceStub( .setMethodDescriptor(attemptStreamingSequenceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listLocationsTransportSettings = @@ -261,9 +261,9 @@ protected GrpcSequenceServiceStub( .setMethodDescriptor(listLocationsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getLocationTransportSettings = @@ -271,9 +271,9 @@ protected GrpcSequenceServiceStub( .setMethodDescriptor(getLocationMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcTestingStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcTestingStub.java index a1bcc07614..fb4f36ca08 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcTestingStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcTestingStub.java @@ -26,12 +26,12 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.location.GetLocationRequest; import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.CreateSessionRequest; @@ -219,9 +219,9 @@ protected GrpcTestingStub( .setMethodDescriptor(getSessionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listSessionsTransportSettings = @@ -233,9 +233,9 @@ protected GrpcTestingStub( .setMethodDescriptor(deleteSessionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings reportSessionTransportSettings = @@ -243,9 +243,9 @@ protected GrpcTestingStub( .setMethodDescriptor(reportSessionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listTestsTransportSettings = @@ -253,9 +253,9 @@ protected GrpcTestingStub( .setMethodDescriptor(listTestsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings deleteTestTransportSettings = @@ -263,9 +263,9 @@ protected GrpcTestingStub( .setMethodDescriptor(deleteTestMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings verifyTestTransportSettings = @@ -273,9 +273,9 @@ protected GrpcTestingStub( .setMethodDescriptor(verifyTestMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listLocationsTransportSettings = @@ -283,9 +283,9 @@ protected GrpcTestingStub( .setMethodDescriptor(listLocationsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getLocationTransportSettings = @@ -293,9 +293,9 @@ protected GrpcTestingStub( .setMethodDescriptor(getLocationMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java index b79796ba13..d03d9ee917 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java @@ -29,6 +29,7 @@ import com.google.api.gax.httpjson.ProtoMessageResponseParser; import com.google.api.gax.httpjson.ProtoRestSerializer; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.location.GetLocationRequest; import com.google.cloud.location.ListLocationsRequest; @@ -654,17 +655,46 @@ protected HttpJsonComplianceStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(repeatDataSimplePathMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("info.f_bool", String.valueOf(request.getInfo().getFBool())); + builder.add("info.f_double", String.valueOf(request.getInfo().getFDouble())); + builder.add("info.f_int32", String.valueOf(request.getInfo().getFInt32())); + builder.add("info.f_kingdom", String.valueOf(request.getInfo().getFKingdom())); + builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); + return builder.build(); + }) .build(); HttpJsonCallSettings repeatDataPathResourceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(repeatDataPathResourceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("info.f_bool", String.valueOf(request.getInfo().getFBool())); + builder.add( + "info.f_child.f_string", + String.valueOf(request.getInfo().getFChild().getFString())); + builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); + return builder.build(); + }) .build(); HttpJsonCallSettings repeatDataPathTrailingResourceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(repeatDataPathTrailingResourceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + "info.f_child.f_string", + String.valueOf(request.getInfo().getFChild().getFString())); + builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); + return builder.build(); + }) .build(); HttpJsonCallSettings repeatDataBodyPutTransportSettings = HttpJsonCallSettings.newBuilder() @@ -691,11 +721,23 @@ protected HttpJsonComplianceStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listLocationsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings getLocationTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getLocationMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); this.repeatDataBodyCallable = diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java index e6f5924ac1..494d6613c7 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java @@ -38,8 +38,10 @@ import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientStreamingCallable; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; +import com.google.api.pathtemplate.PathTemplate; import com.google.cloud.location.GetLocationRequest; import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; @@ -409,6 +411,20 @@ public class HttpJsonEchoStub extends EchoStub { private final HttpJsonOperationsStub httpJsonOperationsStub; private final HttpJsonStubCallableFactory callableFactory; + private static final PathTemplate ECHO_0_PATH_TEMPLATE = PathTemplate.create("{header=**}"); + private static final PathTemplate ECHO_1_PATH_TEMPLATE = PathTemplate.create("{routing_id=**}"); + private static final PathTemplate ECHO_2_PATH_TEMPLATE = + PathTemplate.create("{table_name=regions/*/zones/*/**}"); + private static final PathTemplate ECHO_3_PATH_TEMPLATE = + PathTemplate.create("{super_id=projects/*}/**"); + private static final PathTemplate ECHO_4_PATH_TEMPLATE = + PathTemplate.create("{table_name=projects/*/instances/*/**}"); + private static final PathTemplate ECHO_5_PATH_TEMPLATE = + PathTemplate.create("projects/*/{instance_id=instances/*}/**"); + private static final PathTemplate ECHO_6_PATH_TEMPLATE = PathTemplate.create("{baz=**}"); + private static final PathTemplate ECHO_7_PATH_TEMPLATE = + PathTemplate.create("{qux=projects/*}/**"); + public static final HttpJsonEchoStub create(EchoStubSettings settings) throws IOException { return new HttpJsonEchoStub(settings, ClientContext.create(settings)); } @@ -466,6 +482,19 @@ protected HttpJsonEchoStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(echoMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getHeader(), "header", ECHO_0_PATH_TEMPLATE); + builder.add(request.getHeader(), "routing_id", ECHO_1_PATH_TEMPLATE); + builder.add(request.getHeader(), "table_name", ECHO_2_PATH_TEMPLATE); + builder.add(request.getHeader(), "super_id", ECHO_3_PATH_TEMPLATE); + builder.add(request.getHeader(), "table_name", ECHO_4_PATH_TEMPLATE); + builder.add(request.getHeader(), "instance_id", ECHO_5_PATH_TEMPLATE); + builder.add(request.getOtherHeader(), "baz", ECHO_6_PATH_TEMPLATE); + builder.add(request.getOtherHeader(), "qux", ECHO_7_PATH_TEMPLATE); + return builder.build(); + }) .build(); HttpJsonCallSettings expandTransportSettings = HttpJsonCallSettings.newBuilder() @@ -504,11 +533,23 @@ protected HttpJsonEchoStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listLocationsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings getLocationTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getLocationMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); this.echoCallable = diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java index 2297ed9b67..264eb6c5bc 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java @@ -30,6 +30,7 @@ import com.google.api.gax.httpjson.ProtoMessageResponseParser; import com.google.api.gax.httpjson.ProtoRestSerializer; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.location.GetLocationRequest; import com.google.cloud.location.ListLocationsRequest; @@ -357,16 +358,34 @@ protected HttpJsonIdentityStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getUserMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings updateUserTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(updateUserMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("user.name", String.valueOf(request.getUser().getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings deleteUserTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteUserMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listUsersTransportSettings = HttpJsonCallSettings.newBuilder() @@ -378,11 +397,23 @@ protected HttpJsonIdentityStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listLocationsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings getLocationTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getLocationMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); this.createUserCallable = diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java index 956af82bc6..100623c169 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java @@ -38,6 +38,7 @@ import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientStreamingCallable; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.location.GetLocationRequest; @@ -668,16 +669,34 @@ protected HttpJsonMessagingStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getRoomMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings updateRoomTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(updateRoomMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("room.name", String.valueOf(request.getRoom().getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings deleteRoomTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteRoomMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listRoomsTransportSettings = HttpJsonCallSettings.newBuilder() @@ -688,47 +707,101 @@ protected HttpJsonMessagingStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(createBlurbMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings getBlurbTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getBlurbMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings updateBlurbTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(updateBlurbMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("blurb.name", String.valueOf(request.getBlurb().getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings deleteBlurbTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteBlurbMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listBlurbsTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listBlurbsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings searchBlurbsTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(searchBlurbsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings streamBlurbsTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(streamBlurbsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listLocationsTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listLocationsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings getLocationTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getLocationMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); this.createRoomCallable = diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java index 5582a569ed..4652aef4a4 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java @@ -29,6 +29,7 @@ import com.google.api.gax.httpjson.ProtoMessageResponseParser; import com.google.api.gax.httpjson.ProtoRestSerializer; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.location.GetLocationRequest; @@ -420,6 +421,12 @@ protected HttpJsonSequenceServiceStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getSequenceReportMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings getStreamingSequenceReportTransportSettings = @@ -427,11 +434,23 @@ protected HttpJsonSequenceServiceStub( .newBuilder() .setMethodDescriptor(getStreamingSequenceReportMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings attemptSequenceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(attemptSequenceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings attemptStreamingSequenceTransportSettings = @@ -439,17 +458,35 @@ protected HttpJsonSequenceServiceStub( .newBuilder() .setMethodDescriptor(attemptStreamingSequenceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listLocationsTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listLocationsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings getLocationTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getLocationMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); this.createSequenceCallable = diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java index 4e458eaaab..560f9a1fb6 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java @@ -31,6 +31,7 @@ import com.google.api.gax.httpjson.ProtoMessageResponseParser; import com.google.api.gax.httpjson.ProtoRestSerializer; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.location.GetLocationRequest; import com.google.cloud.location.ListLocationsRequest; @@ -469,6 +470,12 @@ protected HttpJsonTestingStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getSessionMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listSessionsTransportSettings = HttpJsonCallSettings.newBuilder() @@ -479,38 +486,80 @@ protected HttpJsonTestingStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteSessionMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings reportSessionTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(reportSessionMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listTestsTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listTestsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings deleteTestTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteTestMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings verifyTestTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(verifyTestMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listLocationsTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listLocationsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings getLocationTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getLocationMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); this.createSessionCallable = diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java new file mode 100644 index 0000000000..e542b70eb7 --- /dev/null +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java @@ -0,0 +1,311 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.showcase.v1beta1.it; + +import static com.google.api.gax.rpc.internal.Headers.DYNAMIC_ROUTING_HEADER_KEY; +import static com.google.common.truth.Truth.assertThat; + +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.ForwardingHttpJsonClientCall; +import com.google.api.gax.httpjson.ForwardingHttpJsonClientCallListener; +import com.google.api.gax.httpjson.HttpJsonCallOptions; +import com.google.api.gax.httpjson.HttpJsonChannel; +import com.google.api.gax.httpjson.HttpJsonClientCall; +import com.google.api.gax.httpjson.HttpJsonClientInterceptor; +import com.google.api.gax.httpjson.HttpJsonMetadata; +import com.google.common.collect.ImmutableList; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.it.util.TestClientInitializer; +import io.grpc.CallOptions; +import io.grpc.Channel; +import io.grpc.ClientCall; +import io.grpc.ClientInterceptor; +import io.grpc.ForwardingClientCall; +import io.grpc.Metadata; +import io.grpc.MethodDescriptor; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ITDynamicRoutingHeaders { + private static final String SPLIT_TOKEN = "&"; + private static final Metadata.Key REQUEST_PARAMS_HEADER_KEY = + Metadata.Key.of(DYNAMIC_ROUTING_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER); + + // Implement a request interceptor to retrieve the headers being sent on the request. + // The headers being set are part of the Metadata + private static class GrpcCapturingClientInterceptor implements ClientInterceptor { + private Metadata metadata; + + @Override + public ClientCall interceptCall( + MethodDescriptor method, final CallOptions callOptions, Channel next) { + ClientCall call = next.newCall(method, callOptions); + return new ForwardingClientCall.SimpleForwardingClientCall(call) { + @Override + public void start(ClientCall.Listener responseListener, Metadata headers) { + metadata = headers; + super.start(responseListener, headers); + } + }; + } + } + + // Implement a request interceptor to retrieve the headers being sent on the request + // The headers being set are part of the CallOptions + private static class HttpJsonCapturingClientInterceptor implements HttpJsonClientInterceptor { + private String requestParam; + + @Override + public HttpJsonClientCall interceptCall( + ApiMethodDescriptor method, + HttpJsonCallOptions callOptions, + HttpJsonChannel next) { + HttpJsonClientCall call = next.newCall(method, callOptions); + return new ForwardingHttpJsonClientCall.SimpleForwardingHttpJsonClientCall< + RequestT, ResponseT>(call) { + @Override + public void start(Listener responseListener, HttpJsonMetadata requestHeaders) { + Listener forwardingResponseListener = + new ForwardingHttpJsonClientCallListener.SimpleForwardingHttpJsonClientCallListener< + ResponseT>(responseListener) { + @Override + public void onHeaders(HttpJsonMetadata responseHeaders) { + super.onHeaders(responseHeaders); + } + + @Override + public void onMessage(ResponseT message) { + super.onMessage(message); + } + + @Override + public void onClose(int statusCode, HttpJsonMetadata trailers) { + super.onClose(statusCode, trailers); + } + }; + + super.start(forwardingResponseListener, requestHeaders); + if (requestHeaders.getHeaders().containsKey(DYNAMIC_ROUTING_HEADER_KEY)) { + requestParam = + String.valueOf(requestHeaders.getHeaders().get(DYNAMIC_ROUTING_HEADER_KEY)); + } + } + }; + } + } + + private HttpJsonCapturingClientInterceptor httpJsonInterceptor; + private GrpcCapturingClientInterceptor grpcInterceptor; + + private EchoClient grpcClient; + private EchoClient httpJsonClient; + + @Before + public void createClients() throws Exception { + // Create gRPC Interceptor and Client + grpcInterceptor = new GrpcCapturingClientInterceptor(); + grpcClient = TestClientInitializer.createGrpcEchoClient(ImmutableList.of(grpcInterceptor)); + + // Create HttpJson Interceptor and Client + httpJsonInterceptor = new HttpJsonCapturingClientInterceptor(); + httpJsonClient = + TestClientInitializer.createHttpJsonEchoClient(ImmutableList.of(httpJsonInterceptor)); + } + + @After + public void destroyClient() { + grpcClient.close(); + httpJsonClient.close(); + } + + @Test + public void testGrpc_noRoutingHeaderUsed() { + grpcClient.echo(EchoRequest.newBuilder().build()); + String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); + assertThat(headerValue).isNull(); + } + + @Test + public void testHttpJson_noRoutingHeaderUsed() { + httpJsonClient.echo(EchoRequest.newBuilder().build()); + String headerValue = httpJsonInterceptor.requestParam; + assertThat(headerValue).isNull(); + } + + @Test + public void testGrpc_emptyHeader() { + grpcClient.echo(EchoRequest.newBuilder().setHeader("").build()); + String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); + assertThat(headerValue).isNull(); + } + + @Test + public void testHttpJson_emptyHeader() { + httpJsonClient.echo(EchoRequest.newBuilder().setHeader("").build()); + String headerValue = httpJsonInterceptor.requestParam; + assertThat(headerValue).isNull(); + } + + @Test + public void testGrpc_matchesHeaderName() { + grpcClient.echo(EchoRequest.newBuilder().setHeader("potato").build()); + String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + List expectedHeaders = ImmutableList.of("header=potato", "routing_id=potato"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } + + @Test + public void testHttpJson_matchesHeaderName() { + httpJsonClient.echo(EchoRequest.newBuilder().setHeader("potato").build()); + String headerValue = httpJsonInterceptor.requestParam; + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + List expectedHeaders = ImmutableList.of("header=potato", "routing_id=potato"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } + + @Test + public void testGrpc_matchesOtherHeaderName() { + grpcClient.echo(EchoRequest.newBuilder().setOtherHeader("instances/456").build()); + String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + List expectedHeaders = ImmutableList.of("baz=instances%2F456"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } + + @Test + public void testHttpJson_matchesOtherHeaderName() { + httpJsonClient.echo(EchoRequest.newBuilder().setOtherHeader("instances/456").build()); + String headerValue = httpJsonInterceptor.requestParam; + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + List expectedHeaders = ImmutableList.of("baz=instances%2F456"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } + + @Test + public void testGrpc_matchesMultipleOfSameRoutingHeader_usesHeader() { + grpcClient.echo(EchoRequest.newBuilder().setHeader("projects/123/instances/456").build()); + String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + List expectedHeaders = + ImmutableList.of( + "header=projects%2F123%2Finstances%2F456", + "routing_id=projects%2F123%2Finstances%2F456", + "super_id=projects%2F123", + "table_name=projects%2F123%2Finstances%2F456", + "instance_id=instances%2F456"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } + + @Test + public void testHttpJson_matchesMultipleOfSameRoutingHeader_usesHeader() { + httpJsonClient.echo(EchoRequest.newBuilder().setHeader("projects/123/instances/456").build()); + String headerValue = httpJsonInterceptor.requestParam; + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + List expectedHeaders = + ImmutableList.of( + "header=projects%2F123%2Finstances%2F456", + "routing_id=projects%2F123%2Finstances%2F456", + "super_id=projects%2F123", + "table_name=projects%2F123%2Finstances%2F456", + "instance_id=instances%2F456"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders).inOrder(); + } + + @Test + public void testGrpc_matchesMultipleOfSameRoutingHeader_usesOtherHeader() { + grpcClient.echo(EchoRequest.newBuilder().setOtherHeader("projects/123/instances/456").build()); + String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + List expectedHeaders = + ImmutableList.of("baz=projects%2F123%2Finstances%2F456", "qux=projects%2F123"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } + + @Test + public void testHttpJson_matchesMultipleOfSameRoutingHeader_usesOtherHeader() { + httpJsonClient.echo( + EchoRequest.newBuilder().setOtherHeader("projects/123/instances/456").build()); + String headerValue = httpJsonInterceptor.requestParam; + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + List expectedHeaders = + ImmutableList.of("baz=projects%2F123%2Finstances%2F456", "qux=projects%2F123"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } + + @Test + public void testGrpc_matchesMultipleRoutingHeaders() { + grpcClient.echo( + EchoRequest.newBuilder() + .setHeader("regions/123/zones/456") + .setOtherHeader("projects/123/instances/456") + .build()); + String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + List expectedHeaders = + ImmutableList.of( + "baz=projects%2F123%2Finstances%2F456", + "qux=projects%2F123", + "table_name=regions%2F123%2Fzones%2F456", + "header=regions%2F123%2Fzones%2F456", + "routing_id=regions%2F123%2Fzones%2F456"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } + + @Test + public void testHttpJson_matchesMultipleRoutingHeaders() { + httpJsonClient.echo( + EchoRequest.newBuilder() + .setHeader("regions/123/zones/456") + .setOtherHeader("projects/123/instances/456") + .build()); + String headerValue = httpJsonInterceptor.requestParam; + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + List expectedHeaders = + ImmutableList.of( + "baz=projects%2F123%2Finstances%2F456", + "qux=projects%2F123", + "table_name=regions%2F123%2Fzones%2F456", + "header=regions%2F123%2Fzones%2F456", + "routing_id=regions%2F123%2Fzones%2F456"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } +} diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/util/TestClientInitializer.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/util/TestClientInitializer.java index e0d04472c8..fe8566bd2f 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/util/TestClientInitializer.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/util/TestClientInitializer.java @@ -18,18 +18,22 @@ import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.HttpJsonClientInterceptor; import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.StatusCode; import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.common.collect.ImmutableList; import com.google.showcase.v1beta1.EchoClient; import com.google.showcase.v1beta1.EchoSettings; import com.google.showcase.v1beta1.IdentityClient; import com.google.showcase.v1beta1.IdentitySettings; import com.google.showcase.v1beta1.WaitRequest; import com.google.showcase.v1beta1.stub.EchoStubSettings; +import io.grpc.ClientInterceptor; import io.grpc.ManagedChannelBuilder; +import java.util.List; import java.util.Set; public class TestClientInitializer { @@ -37,18 +41,29 @@ public class TestClientInitializer { public static final int AWAIT_TERMINATION_SECONDS = 10; public static EchoClient createGrpcEchoClient() throws Exception { + return createGrpcEchoClient(ImmutableList.of()); + } + + public static EchoClient createGrpcEchoClient(List interceptorList) + throws Exception { EchoSettings grpcEchoSettings = EchoSettings.newBuilder() .setCredentialsProvider(NoCredentialsProvider.create()) .setTransportChannelProvider( EchoSettings.defaultGrpcTransportProviderBuilder() .setChannelConfigurator(ManagedChannelBuilder::usePlaintext) + .setInterceptorProvider(() -> interceptorList) .build()) .build(); return EchoClient.create(grpcEchoSettings); } public static EchoClient createHttpJsonEchoClient() throws Exception { + return createHttpJsonEchoClient(ImmutableList.of()); + } + + public static EchoClient createHttpJsonEchoClient(List interceptorList) + throws Exception { EchoSettings httpJsonEchoSettings = EchoSettings.newHttpJsonBuilder() .setCredentialsProvider(NoCredentialsProvider.create()) @@ -57,6 +72,7 @@ public static EchoClient createHttpJsonEchoClient() throws Exception { .setHttpTransport( new NetHttpTransport.Builder().doNotValidateCertificate().build()) .setEndpoint("http://localhost:7469") + .setInterceptorProvider(() -> interceptorList) .build()) .build(); return EchoClient.create(httpJsonEchoSettings); diff --git a/test/integration/goldens/apigeeconnect/src/com/google/cloud/apigeeconnect/v1/stub/GrpcConnectionServiceStub.java b/test/integration/goldens/apigeeconnect/src/com/google/cloud/apigeeconnect/v1/stub/GrpcConnectionServiceStub.java index 74e56ea21a..772d87a816 100644 --- a/test/integration/goldens/apigeeconnect/src/com/google/cloud/apigeeconnect/v1/stub/GrpcConnectionServiceStub.java +++ b/test/integration/goldens/apigeeconnect/src/com/google/cloud/apigeeconnect/v1/stub/GrpcConnectionServiceStub.java @@ -23,10 +23,10 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.apigeeconnect.v1.ListConnectionsRequest; import com.google.cloud.apigeeconnect.v1.ListConnectionsResponse; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.stub.GrpcOperationsStub; import io.grpc.MethodDescriptor; import io.grpc.protobuf.ProtoUtils; @@ -109,9 +109,9 @@ protected GrpcConnectionServiceStub( .setMethodDescriptor(listConnectionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/apigeeconnect/src/com/google/cloud/apigeeconnect/v1/stub/HttpJsonConnectionServiceStub.java b/test/integration/goldens/apigeeconnect/src/com/google/cloud/apigeeconnect/v1/stub/HttpJsonConnectionServiceStub.java index 89f6e389c1..4bf5d6e94f 100644 --- a/test/integration/goldens/apigeeconnect/src/com/google/cloud/apigeeconnect/v1/stub/HttpJsonConnectionServiceStub.java +++ b/test/integration/goldens/apigeeconnect/src/com/google/cloud/apigeeconnect/v1/stub/HttpJsonConnectionServiceStub.java @@ -29,6 +29,7 @@ import com.google.api.gax.httpjson.ProtoMessageResponseParser; import com.google.api.gax.httpjson.ProtoRestSerializer; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.apigeeconnect.v1.ListConnectionsRequest; import com.google.cloud.apigeeconnect.v1.ListConnectionsResponse; @@ -140,6 +141,12 @@ protected HttpJsonConnectionServiceStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listConnectionsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); this.listConnectionsCallable = diff --git a/test/integration/goldens/asset/src/com/google/cloud/asset/v1/stub/GrpcAssetServiceStub.java b/test/integration/goldens/asset/src/com/google/cloud/asset/v1/stub/GrpcAssetServiceStub.java index c7fa0d9950..85b316e8a4 100644 --- a/test/integration/goldens/asset/src/com/google/cloud/asset/v1/stub/GrpcAssetServiceStub.java +++ b/test/integration/goldens/asset/src/com/google/cloud/asset/v1/stub/GrpcAssetServiceStub.java @@ -27,6 +27,7 @@ import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningMetadata; import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; @@ -63,7 +64,6 @@ import com.google.cloud.asset.v1.SearchAllResourcesResponse; import com.google.cloud.asset.v1.UpdateFeedRequest; import com.google.cloud.asset.v1.UpdateSavedQueryRequest; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; @@ -370,9 +370,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(exportAssetsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings listAssetsTransportSettings = @@ -380,9 +380,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(listAssetsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings @@ -392,9 +392,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(batchGetAssetsHistoryMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings createFeedTransportSettings = @@ -402,9 +402,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(createFeedMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getFeedTransportSettings = @@ -412,9 +412,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(getFeedMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listFeedsTransportSettings = @@ -422,9 +422,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(listFeedsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings updateFeedTransportSettings = @@ -432,9 +432,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(updateFeedMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("feed.name", String.valueOf(request.getFeed().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("feed.name", String.valueOf(request.getFeed().getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteFeedTransportSettings = @@ -442,9 +442,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(deleteFeedMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -453,9 +453,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(searchAllResourcesMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("scope", String.valueOf(request.getScope())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("scope", String.valueOf(request.getScope())); + return builder.build(); }) .build(); GrpcCallSettings @@ -464,9 +464,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(searchAllIamPoliciesMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("scope", String.valueOf(request.getScope())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("scope", String.valueOf(request.getScope())); + return builder.build(); }) .build(); GrpcCallSettings @@ -475,11 +475,11 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(analyzeIamPolicyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put( + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( "analysis_query.scope", String.valueOf(request.getAnalysisQuery().getScope())); - return params.build(); + return builder.build(); }) .build(); GrpcCallSettings @@ -488,11 +488,11 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(analyzeIamPolicyLongrunningMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put( + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( "analysis_query.scope", String.valueOf(request.getAnalysisQuery().getScope())); - return params.build(); + return builder.build(); }) .build(); GrpcCallSettings analyzeMoveTransportSettings = @@ -500,9 +500,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(analyzeMoveMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); GrpcCallSettings queryAssetsTransportSettings = @@ -510,9 +510,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(queryAssetsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings createSavedQueryTransportSettings = @@ -520,9 +520,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(createSavedQueryMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getSavedQueryTransportSettings = @@ -530,9 +530,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(getSavedQueryMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -541,9 +541,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(listSavedQueriesMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings updateSavedQueryTransportSettings = @@ -551,9 +551,10 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(updateSavedQueryMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("saved_query.name", String.valueOf(request.getSavedQuery().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + "saved_query.name", String.valueOf(request.getSavedQuery().getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteSavedQueryTransportSettings = @@ -561,9 +562,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(deleteSavedQueryMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -574,9 +575,9 @@ protected GrpcAssetServiceStub( .setMethodDescriptor(batchGetEffectiveIamPoliciesMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("scope", String.valueOf(request.getScope())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("scope", String.valueOf(request.getScope())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/asset/src/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceStub.java b/test/integration/goldens/asset/src/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceStub.java index d0f8637436..ef3b723171 100644 --- a/test/integration/goldens/asset/src/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceStub.java +++ b/test/integration/goldens/asset/src/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceStub.java @@ -36,6 +36,7 @@ import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningMetadata; import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; @@ -955,11 +956,23 @@ protected HttpJsonAssetServiceStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(exportAssetsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings listAssetsTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listAssetsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings batchGetAssetsHistoryTransportSettings = @@ -967,37 +980,79 @@ protected HttpJsonAssetServiceStub( .newBuilder() .setMethodDescriptor(batchGetAssetsHistoryMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings createFeedTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(createFeedMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings getFeedTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getFeedMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listFeedsTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listFeedsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings updateFeedTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(updateFeedMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("feed.name", String.valueOf(request.getFeed().getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings deleteFeedTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteFeedMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings searchAllResourcesTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(searchAllResourcesMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("scope", String.valueOf(request.getScope())); + return builder.build(); + }) .build(); HttpJsonCallSettings searchAllIamPoliciesTransportSettings = @@ -1005,54 +1060,119 @@ protected HttpJsonAssetServiceStub( .newBuilder() .setMethodDescriptor(searchAllIamPoliciesMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("scope", String.valueOf(request.getScope())); + return builder.build(); + }) .build(); HttpJsonCallSettings analyzeIamPolicyTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(analyzeIamPolicyMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + "analysis_query.scope", + String.valueOf(request.getAnalysisQuery().getScope())); + return builder.build(); + }) .build(); HttpJsonCallSettings analyzeIamPolicyLongrunningTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(analyzeIamPolicyLongrunningMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + "analysis_query.scope", + String.valueOf(request.getAnalysisQuery().getScope())); + return builder.build(); + }) .build(); HttpJsonCallSettings analyzeMoveTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(analyzeMoveMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) .build(); HttpJsonCallSettings queryAssetsTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(queryAssetsMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings createSavedQueryTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(createSavedQueryMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings getSavedQueryTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getSavedQueryMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listSavedQueriesTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listSavedQueriesMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings updateSavedQueryTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(updateSavedQueryMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + "saved_query.name", String.valueOf(request.getSavedQuery().getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings deleteSavedQueryTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteSavedQueryMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings batchGetEffectiveIamPoliciesTransportSettings = @@ -1061,6 +1181,12 @@ protected HttpJsonAssetServiceStub( newBuilder() .setMethodDescriptor(batchGetEffectiveIamPoliciesMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("scope", String.valueOf(request.getScope())); + return builder.build(); + }) .build(); this.exportAssetsCallable = diff --git a/test/integration/goldens/compute/src/com/google/cloud/compute/v1small/stub/HttpJsonAddressesStub.java b/test/integration/goldens/compute/src/com/google/cloud/compute/v1small/stub/HttpJsonAddressesStub.java index 8c15fda7f9..a6ee1e36b2 100644 --- a/test/integration/goldens/compute/src/com/google/cloud/compute/v1small/stub/HttpJsonAddressesStub.java +++ b/test/integration/goldens/compute/src/com/google/cloud/compute/v1small/stub/HttpJsonAddressesStub.java @@ -33,6 +33,7 @@ import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.compute.v1small.AddressAggregatedList; import com.google.cloud.compute.v1small.AddressList; @@ -319,21 +320,49 @@ protected HttpJsonAddressesStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(aggregatedListMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("project", String.valueOf(request.getProject())); + return builder.build(); + }) .build(); HttpJsonCallSettings deleteTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("address", String.valueOf(request.getAddress())); + builder.add("project", String.valueOf(request.getProject())); + builder.add("region", String.valueOf(request.getRegion())); + return builder.build(); + }) .build(); HttpJsonCallSettings insertTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(insertMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("project", String.valueOf(request.getProject())); + builder.add("region", String.valueOf(request.getRegion())); + return builder.build(); + }) .build(); HttpJsonCallSettings listTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("project", String.valueOf(request.getProject())); + builder.add("region", String.valueOf(request.getRegion())); + return builder.build(); + }) .build(); this.aggregatedListCallable = diff --git a/test/integration/goldens/compute/src/com/google/cloud/compute/v1small/stub/HttpJsonRegionOperationsStub.java b/test/integration/goldens/compute/src/com/google/cloud/compute/v1small/stub/HttpJsonRegionOperationsStub.java index 1716c4feea..6e7a7ed27d 100644 --- a/test/integration/goldens/compute/src/com/google/cloud/compute/v1small/stub/HttpJsonRegionOperationsStub.java +++ b/test/integration/goldens/compute/src/com/google/cloud/compute/v1small/stub/HttpJsonRegionOperationsStub.java @@ -31,6 +31,7 @@ import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.LongRunningClient; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.compute.v1small.GetRegionOperationRequest; import com.google.cloud.compute.v1small.Operation; @@ -197,11 +198,27 @@ protected HttpJsonRegionOperationsStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("operation", String.valueOf(request.getOperation())); + builder.add("project", String.valueOf(request.getProject())); + builder.add("region", String.valueOf(request.getRegion())); + return builder.build(); + }) .build(); HttpJsonCallSettings waitTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(waitMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("operation", String.valueOf(request.getOperation())); + builder.add("project", String.valueOf(request.getProject())); + builder.add("region", String.valueOf(request.getRegion())); + return builder.build(); + }) .build(); this.getCallable = diff --git a/test/integration/goldens/credentials/src/com/google/cloud/iam/credentials/v1/stub/GrpcIamCredentialsStub.java b/test/integration/goldens/credentials/src/com/google/cloud/iam/credentials/v1/stub/GrpcIamCredentialsStub.java index c9101c3d8c..3d51a4d38b 100644 --- a/test/integration/goldens/credentials/src/com/google/cloud/iam/credentials/v1/stub/GrpcIamCredentialsStub.java +++ b/test/integration/goldens/credentials/src/com/google/cloud/iam/credentials/v1/stub/GrpcIamCredentialsStub.java @@ -21,6 +21,7 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.iam.credentials.v1.GenerateAccessTokenRequest; import com.google.cloud.iam.credentials.v1.GenerateAccessTokenResponse; @@ -30,7 +31,6 @@ import com.google.cloud.iam.credentials.v1.SignBlobResponse; import com.google.cloud.iam.credentials.v1.SignJwtRequest; import com.google.cloud.iam.credentials.v1.SignJwtResponse; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.stub.GrpcOperationsStub; import io.grpc.MethodDescriptor; import io.grpc.protobuf.ProtoUtils; @@ -143,9 +143,9 @@ protected GrpcIamCredentialsStub( .setMethodDescriptor(generateAccessTokenMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -154,9 +154,9 @@ protected GrpcIamCredentialsStub( .setMethodDescriptor(generateIdTokenMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings signBlobTransportSettings = @@ -164,9 +164,9 @@ protected GrpcIamCredentialsStub( .setMethodDescriptor(signBlobMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings signJwtTransportSettings = @@ -174,9 +174,9 @@ protected GrpcIamCredentialsStub( .setMethodDescriptor(signJwtMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/credentials/src/com/google/cloud/iam/credentials/v1/stub/HttpJsonIamCredentialsStub.java b/test/integration/goldens/credentials/src/com/google/cloud/iam/credentials/v1/stub/HttpJsonIamCredentialsStub.java index ceb00e8a0a..c3254effa9 100644 --- a/test/integration/goldens/credentials/src/com/google/cloud/iam/credentials/v1/stub/HttpJsonIamCredentialsStub.java +++ b/test/integration/goldens/credentials/src/com/google/cloud/iam/credentials/v1/stub/HttpJsonIamCredentialsStub.java @@ -27,6 +27,7 @@ import com.google.api.gax.httpjson.ProtoMessageResponseParser; import com.google.api.gax.httpjson.ProtoRestSerializer; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.iam.credentials.v1.GenerateAccessTokenRequest; import com.google.cloud.iam.credentials.v1.GenerateAccessTokenResponse; @@ -259,22 +260,46 @@ protected HttpJsonIamCredentialsStub( .newBuilder() .setMethodDescriptor(generateAccessTokenMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings generateIdTokenTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(generateIdTokenMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings signBlobTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(signBlobMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings signJwtTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(signJwtMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); this.generateAccessTokenCallable = diff --git a/test/integration/goldens/iam/src/com/google/iam/v1/stub/GrpcIAMPolicyStub.java b/test/integration/goldens/iam/src/com/google/iam/v1/stub/GrpcIAMPolicyStub.java index 63d6c655f5..e734c54817 100644 --- a/test/integration/goldens/iam/src/com/google/iam/v1/stub/GrpcIAMPolicyStub.java +++ b/test/integration/goldens/iam/src/com/google/iam/v1/stub/GrpcIAMPolicyStub.java @@ -21,8 +21,8 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.iam.v1.GetIamPolicyRequest; import com.google.iam.v1.Policy; import com.google.iam.v1.SetIamPolicyRequest; @@ -122,9 +122,9 @@ protected GrpcIAMPolicyStub( .setMethodDescriptor(setIamPolicyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); GrpcCallSettings getIamPolicyTransportSettings = @@ -132,9 +132,9 @@ protected GrpcIAMPolicyStub( .setMethodDescriptor(getIamPolicyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); GrpcCallSettings @@ -143,9 +143,9 @@ protected GrpcIAMPolicyStub( .setMethodDescriptor(testIamPermissionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/kms/src/com/google/cloud/kms/v1/stub/GrpcKeyManagementServiceStub.java b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/stub/GrpcKeyManagementServiceStub.java index eb9616a51c..832a2ca2cc 100644 --- a/test/integration/goldens/kms/src/com/google/cloud/kms/v1/stub/GrpcKeyManagementServiceStub.java +++ b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/stub/GrpcKeyManagementServiceStub.java @@ -27,6 +27,7 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.kms.v1.AsymmetricDecryptRequest; import com.google.cloud.kms.v1.AsymmetricDecryptResponse; @@ -68,7 +69,6 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; -import com.google.common.collect.ImmutableMap; import com.google.iam.v1.GetIamPolicyRequest; import com.google.iam.v1.Policy; import com.google.iam.v1.TestIamPermissionsRequest; @@ -451,9 +451,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(listKeyRingsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings @@ -462,9 +462,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(listCryptoKeysMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings @@ -474,9 +474,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(listCryptoKeyVersionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings @@ -485,9 +485,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(listImportJobsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getKeyRingTransportSettings = @@ -495,9 +495,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(getKeyRingMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getCryptoKeyTransportSettings = @@ -505,9 +505,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(getCryptoKeyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -516,9 +516,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(getCryptoKeyVersionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getPublicKeyTransportSettings = @@ -526,9 +526,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(getPublicKeyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getImportJobTransportSettings = @@ -536,9 +536,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(getImportJobMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings createKeyRingTransportSettings = @@ -546,9 +546,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(createKeyRingMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings createCryptoKeyTransportSettings = @@ -556,9 +556,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(createCryptoKeyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings @@ -567,9 +567,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(createCryptoKeyVersionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings @@ -578,9 +578,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(importCryptoKeyVersionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings createImportJobTransportSettings = @@ -588,9 +588,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(createImportJobMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings updateCryptoKeyTransportSettings = @@ -598,9 +598,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(updateCryptoKeyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("crypto_key.name", String.valueOf(request.getCryptoKey().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("crypto_key.name", String.valueOf(request.getCryptoKey().getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -609,11 +609,11 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(updateCryptoKeyVersionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put( + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( "crypto_key_version.name", String.valueOf(request.getCryptoKeyVersion().getName())); - return params.build(); + return builder.build(); }) .build(); GrpcCallSettings encryptTransportSettings = @@ -621,9 +621,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(encryptMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings decryptTransportSettings = @@ -631,9 +631,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(decryptMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -642,9 +642,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(asymmetricSignMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -653,9 +653,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(asymmetricDecryptMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -664,9 +664,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(updateCryptoKeyPrimaryVersionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -675,9 +675,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(destroyCryptoKeyVersionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -686,9 +686,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(restoreCryptoKeyVersionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getIamPolicyTransportSettings = @@ -696,9 +696,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(getIamPolicyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); GrpcCallSettings listLocationsTransportSettings = @@ -706,10 +706,10 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(listLocationsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("filter", String.valueOf(request.getFilter())); - params.put("page_size", String.valueOf(request.getPageSize())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("filter", String.valueOf(request.getFilter())); + builder.add("page_size", String.valueOf(request.getPageSize())); + return builder.build(); }) .build(); GrpcCallSettings getLocationTransportSettings = @@ -717,9 +717,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(getLocationMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -728,9 +728,9 @@ protected GrpcKeyManagementServiceStub( .setMethodDescriptor(testIamPermissionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/library/src/com/google/cloud/example/library/v1/stub/GrpcLibraryServiceStub.java b/test/integration/goldens/library/src/com/google/cloud/example/library/v1/stub/GrpcLibraryServiceStub.java index 2a993a38d5..89d8bff088 100644 --- a/test/integration/goldens/library/src/com/google/cloud/example/library/v1/stub/GrpcLibraryServiceStub.java +++ b/test/integration/goldens/library/src/com/google/cloud/example/library/v1/stub/GrpcLibraryServiceStub.java @@ -24,8 +24,8 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.example.library.v1.Book; import com.google.example.library.v1.CreateBookRequest; import com.google.example.library.v1.CreateShelfRequest; @@ -217,9 +217,9 @@ protected GrpcLibraryServiceStub( .setMethodDescriptor(getShelfMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listShelvesTransportSettings = @@ -231,9 +231,9 @@ protected GrpcLibraryServiceStub( .setMethodDescriptor(deleteShelfMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings mergeShelvesTransportSettings = @@ -241,9 +241,9 @@ protected GrpcLibraryServiceStub( .setMethodDescriptor(mergeShelvesMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings createBookTransportSettings = @@ -251,9 +251,9 @@ protected GrpcLibraryServiceStub( .setMethodDescriptor(createBookMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getBookTransportSettings = @@ -261,9 +261,9 @@ protected GrpcLibraryServiceStub( .setMethodDescriptor(getBookMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listBooksTransportSettings = @@ -271,9 +271,9 @@ protected GrpcLibraryServiceStub( .setMethodDescriptor(listBooksMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings deleteBookTransportSettings = @@ -281,9 +281,9 @@ protected GrpcLibraryServiceStub( .setMethodDescriptor(deleteBookMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings updateBookTransportSettings = @@ -291,9 +291,9 @@ protected GrpcLibraryServiceStub( .setMethodDescriptor(updateBookMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("book.name", String.valueOf(request.getBook().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("book.name", String.valueOf(request.getBook().getName())); + return builder.build(); }) .build(); GrpcCallSettings moveBookTransportSettings = @@ -301,9 +301,9 @@ protected GrpcLibraryServiceStub( .setMethodDescriptor(moveBookMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/library/src/com/google/cloud/example/library/v1/stub/HttpJsonLibraryServiceStub.java b/test/integration/goldens/library/src/com/google/cloud/example/library/v1/stub/HttpJsonLibraryServiceStub.java index a027522eaf..565318ff8b 100644 --- a/test/integration/goldens/library/src/com/google/cloud/example/library/v1/stub/HttpJsonLibraryServiceStub.java +++ b/test/integration/goldens/library/src/com/google/cloud/example/library/v1/stub/HttpJsonLibraryServiceStub.java @@ -30,6 +30,7 @@ import com.google.api.gax.httpjson.ProtoMessageResponseParser; import com.google.api.gax.httpjson.ProtoRestSerializer; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.example.library.v1.Book; import com.google.example.library.v1.CreateBookRequest; @@ -514,6 +515,12 @@ protected HttpJsonLibraryServiceStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getShelfMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listShelvesTransportSettings = HttpJsonCallSettings.newBuilder() @@ -524,41 +531,89 @@ protected HttpJsonLibraryServiceStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteShelfMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings mergeShelvesTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(mergeShelvesMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings createBookTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(createBookMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings getBookTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getBookMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings listBooksTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listBooksMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings deleteBookTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteBookMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings updateBookTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(updateBookMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("book.name", String.valueOf(request.getBook().getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings moveBookTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(moveBookMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); this.createShelfCallable = diff --git a/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2Stub.java b/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2Stub.java index bef0cf84af..f586326410 100644 --- a/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2Stub.java +++ b/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2Stub.java @@ -27,8 +27,8 @@ import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.logging.v2.CmekSettings; import com.google.logging.v2.CopyLogEntriesMetadata; import com.google.logging.v2.CopyLogEntriesRequest; @@ -404,9 +404,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(listBucketsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getBucketTransportSettings = @@ -414,9 +414,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(getBucketMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings createBucketTransportSettings = @@ -424,9 +424,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(createBucketMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings updateBucketTransportSettings = @@ -434,9 +434,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(updateBucketMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteBucketTransportSettings = @@ -444,9 +444,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(deleteBucketMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings undeleteBucketTransportSettings = @@ -454,9 +454,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(undeleteBucketMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listViewsTransportSettings = @@ -464,9 +464,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(listViewsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getViewTransportSettings = @@ -474,9 +474,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(getViewMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings createViewTransportSettings = @@ -484,9 +484,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(createViewMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings updateViewTransportSettings = @@ -494,9 +494,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(updateViewMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteViewTransportSettings = @@ -504,9 +504,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(deleteViewMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listSinksTransportSettings = @@ -514,9 +514,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(listSinksMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getSinkTransportSettings = @@ -524,9 +524,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(getSinkMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("sink_name", String.valueOf(request.getSinkName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("sink_name", String.valueOf(request.getSinkName())); + return builder.build(); }) .build(); GrpcCallSettings createSinkTransportSettings = @@ -534,9 +534,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(createSinkMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings updateSinkTransportSettings = @@ -544,9 +544,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(updateSinkMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("sink_name", String.valueOf(request.getSinkName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("sink_name", String.valueOf(request.getSinkName())); + return builder.build(); }) .build(); GrpcCallSettings deleteSinkTransportSettings = @@ -554,9 +554,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(deleteSinkMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("sink_name", String.valueOf(request.getSinkName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("sink_name", String.valueOf(request.getSinkName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -565,9 +565,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(listExclusionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getExclusionTransportSettings = @@ -575,9 +575,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(getExclusionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings createExclusionTransportSettings = @@ -585,9 +585,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(createExclusionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings updateExclusionTransportSettings = @@ -595,9 +595,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(updateExclusionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteExclusionTransportSettings = @@ -605,9 +605,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(deleteExclusionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getCmekSettingsTransportSettings = @@ -615,9 +615,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(getCmekSettingsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings updateCmekSettingsTransportSettings = @@ -625,9 +625,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(updateCmekSettingsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getSettingsTransportSettings = @@ -635,9 +635,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(getSettingsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings updateSettingsTransportSettings = @@ -645,9 +645,9 @@ protected GrpcConfigServiceV2Stub( .setMethodDescriptor(updateSettingsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings copyLogEntriesTransportSettings = diff --git a/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2Stub.java b/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2Stub.java index fb52911d4e..e3d33f31d2 100644 --- a/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2Stub.java +++ b/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2Stub.java @@ -26,8 +26,8 @@ import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.logging.v2.DeleteLogRequest; import com.google.logging.v2.ListLogEntriesRequest; import com.google.logging.v2.ListLogEntriesResponse; @@ -189,9 +189,9 @@ protected GrpcLoggingServiceV2Stub( .setMethodDescriptor(deleteLogMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("log_name", String.valueOf(request.getLogName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("log_name", String.valueOf(request.getLogName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -217,9 +217,9 @@ protected GrpcLoggingServiceV2Stub( .setMethodDescriptor(listLogsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings diff --git a/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2Stub.java b/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2Stub.java index a06b273ace..19ac83ffd6 100644 --- a/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2Stub.java +++ b/test/integration/goldens/logging/src/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2Stub.java @@ -23,8 +23,8 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.logging.v2.CreateLogMetricRequest; import com.google.logging.v2.DeleteLogMetricRequest; import com.google.logging.v2.GetLogMetricRequest; @@ -157,9 +157,9 @@ protected GrpcMetricsServiceV2Stub( .setMethodDescriptor(listLogMetricsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getLogMetricTransportSettings = @@ -167,9 +167,9 @@ protected GrpcMetricsServiceV2Stub( .setMethodDescriptor(getLogMetricMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("metric_name", String.valueOf(request.getMetricName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("metric_name", String.valueOf(request.getMetricName())); + return builder.build(); }) .build(); GrpcCallSettings createLogMetricTransportSettings = @@ -177,9 +177,9 @@ protected GrpcMetricsServiceV2Stub( .setMethodDescriptor(createLogMetricMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings updateLogMetricTransportSettings = @@ -187,9 +187,9 @@ protected GrpcMetricsServiceV2Stub( .setMethodDescriptor(updateLogMetricMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("metric_name", String.valueOf(request.getMetricName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("metric_name", String.valueOf(request.getMetricName())); + return builder.build(); }) .build(); GrpcCallSettings deleteLogMetricTransportSettings = @@ -197,9 +197,9 @@ protected GrpcMetricsServiceV2Stub( .setMethodDescriptor(deleteLogMetricMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("metric_name", String.valueOf(request.getMetricName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("metric_name", String.valueOf(request.getMetricName())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java b/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java index 11f9e50c51..6a9446b178 100644 --- a/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java +++ b/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java @@ -25,8 +25,8 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.iam.v1.GetIamPolicyRequest; import com.google.iam.v1.Policy; import com.google.iam.v1.SetIamPolicyRequest; @@ -242,9 +242,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(createTopicMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings updateTopicTransportSettings = @@ -252,9 +252,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(updateTopicMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic.name", String.valueOf(request.getTopic().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic.name", String.valueOf(request.getTopic().getName())); + return builder.build(); }) .build(); GrpcCallSettings publishTransportSettings = @@ -262,9 +262,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(publishMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic", String.valueOf(request.getTopic())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic", String.valueOf(request.getTopic())); + return builder.build(); }) .build(); GrpcCallSettings getTopicTransportSettings = @@ -272,9 +272,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(getTopicMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic", String.valueOf(request.getTopic())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic", String.valueOf(request.getTopic())); + return builder.build(); }) .build(); GrpcCallSettings listTopicsTransportSettings = @@ -282,9 +282,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(listTopicsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("project", String.valueOf(request.getProject())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("project", String.valueOf(request.getProject())); + return builder.build(); }) .build(); GrpcCallSettings @@ -294,9 +294,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(listTopicSubscriptionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic", String.valueOf(request.getTopic())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic", String.valueOf(request.getTopic())); + return builder.build(); }) .build(); GrpcCallSettings @@ -305,9 +305,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(listTopicSnapshotsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic", String.valueOf(request.getTopic())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic", String.valueOf(request.getTopic())); + return builder.build(); }) .build(); GrpcCallSettings deleteTopicTransportSettings = @@ -315,9 +315,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(deleteTopicMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("topic", String.valueOf(request.getTopic())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("topic", String.valueOf(request.getTopic())); + return builder.build(); }) .build(); GrpcCallSettings @@ -326,9 +326,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(detachSubscriptionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("subscription", String.valueOf(request.getSubscription())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("subscription", String.valueOf(request.getSubscription())); + return builder.build(); }) .build(); GrpcCallSettings setIamPolicyTransportSettings = @@ -336,9 +336,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(setIamPolicyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); GrpcCallSettings getIamPolicyTransportSettings = @@ -346,9 +346,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(getIamPolicyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); GrpcCallSettings @@ -357,9 +357,9 @@ protected GrpcPublisherStub( .setMethodDescriptor(testIamPermissionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcSchemaServiceStub.java b/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcSchemaServiceStub.java index 956ceaebe4..35929c01f6 100644 --- a/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcSchemaServiceStub.java +++ b/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcSchemaServiceStub.java @@ -24,8 +24,8 @@ import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.iam.v1.GetIamPolicyRequest; import com.google.iam.v1.Policy; import com.google.iam.v1.SetIamPolicyRequest; @@ -253,9 +253,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(createSchemaMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getSchemaTransportSettings = @@ -263,9 +263,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(getSchemaMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings listSchemasTransportSettings = @@ -273,9 +273,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(listSchemasMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings @@ -284,9 +284,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(listSchemaRevisionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings commitSchemaTransportSettings = @@ -294,9 +294,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(commitSchemaMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings rollbackSchemaTransportSettings = @@ -304,9 +304,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(rollbackSchemaMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteSchemaRevisionTransportSettings = @@ -314,9 +314,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(deleteSchemaRevisionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteSchemaTransportSettings = @@ -324,9 +324,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(deleteSchemaMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -335,9 +335,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(validateSchemaMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings @@ -346,9 +346,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(validateMessageMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings setIamPolicyTransportSettings = @@ -356,9 +356,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(setIamPolicyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); GrpcCallSettings getIamPolicyTransportSettings = @@ -366,9 +366,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(getIamPolicyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); GrpcCallSettings @@ -377,9 +377,9 @@ protected GrpcSchemaServiceStub( .setMethodDescriptor(testIamPermissionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcSubscriberStub.java b/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcSubscriberStub.java index 81ec8fdbd2..ba79536cb1 100644 --- a/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcSubscriberStub.java +++ b/test/integration/goldens/pubsub/src/com/google/cloud/pubsub/v1/stub/GrpcSubscriberStub.java @@ -25,8 +25,8 @@ import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; -import com.google.common.collect.ImmutableMap; import com.google.iam.v1.GetIamPolicyRequest; import com.google.iam.v1.Policy; import com.google.iam.v1.SetIamPolicyRequest; @@ -326,9 +326,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(createSubscriptionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings getSubscriptionTransportSettings = @@ -336,9 +336,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(getSubscriptionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("subscription", String.valueOf(request.getSubscription())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("subscription", String.valueOf(request.getSubscription())); + return builder.build(); }) .build(); GrpcCallSettings updateSubscriptionTransportSettings = @@ -346,10 +346,10 @@ protected GrpcSubscriberStub( .setMethodDescriptor(updateSubscriptionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put( + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( "subscription.name", String.valueOf(request.getSubscription().getName())); - return params.build(); + return builder.build(); }) .build(); GrpcCallSettings @@ -358,9 +358,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(listSubscriptionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("project", String.valueOf(request.getProject())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("project", String.valueOf(request.getProject())); + return builder.build(); }) .build(); GrpcCallSettings deleteSubscriptionTransportSettings = @@ -368,9 +368,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(deleteSubscriptionMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("subscription", String.valueOf(request.getSubscription())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("subscription", String.valueOf(request.getSubscription())); + return builder.build(); }) .build(); GrpcCallSettings modifyAckDeadlineTransportSettings = @@ -378,9 +378,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(modifyAckDeadlineMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("subscription", String.valueOf(request.getSubscription())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("subscription", String.valueOf(request.getSubscription())); + return builder.build(); }) .build(); GrpcCallSettings acknowledgeTransportSettings = @@ -388,9 +388,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(acknowledgeMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("subscription", String.valueOf(request.getSubscription())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("subscription", String.valueOf(request.getSubscription())); + return builder.build(); }) .build(); GrpcCallSettings pullTransportSettings = @@ -398,9 +398,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(pullMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("subscription", String.valueOf(request.getSubscription())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("subscription", String.valueOf(request.getSubscription())); + return builder.build(); }) .build(); GrpcCallSettings streamingPullTransportSettings = @@ -412,9 +412,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(modifyPushConfigMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("subscription", String.valueOf(request.getSubscription())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("subscription", String.valueOf(request.getSubscription())); + return builder.build(); }) .build(); GrpcCallSettings getSnapshotTransportSettings = @@ -422,9 +422,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(getSnapshotMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("snapshot", String.valueOf(request.getSnapshot())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("snapshot", String.valueOf(request.getSnapshot())); + return builder.build(); }) .build(); GrpcCallSettings listSnapshotsTransportSettings = @@ -432,9 +432,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(listSnapshotsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("project", String.valueOf(request.getProject())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("project", String.valueOf(request.getProject())); + return builder.build(); }) .build(); GrpcCallSettings createSnapshotTransportSettings = @@ -442,9 +442,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(createSnapshotMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings updateSnapshotTransportSettings = @@ -452,9 +452,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(updateSnapshotMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("snapshot.name", String.valueOf(request.getSnapshot().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("snapshot.name", String.valueOf(request.getSnapshot().getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteSnapshotTransportSettings = @@ -462,9 +462,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(deleteSnapshotMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("snapshot", String.valueOf(request.getSnapshot())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("snapshot", String.valueOf(request.getSnapshot())); + return builder.build(); }) .build(); GrpcCallSettings seekTransportSettings = @@ -472,9 +472,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(seekMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("subscription", String.valueOf(request.getSubscription())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("subscription", String.valueOf(request.getSubscription())); + return builder.build(); }) .build(); GrpcCallSettings setIamPolicyTransportSettings = @@ -482,9 +482,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(setIamPolicyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); GrpcCallSettings getIamPolicyTransportSettings = @@ -492,9 +492,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(getIamPolicyMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); GrpcCallSettings @@ -503,9 +503,9 @@ protected GrpcSubscriberStub( .setMethodDescriptor(testIamPermissionsMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("resource", String.valueOf(request.getResource())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/redis/src/com/google/cloud/redis/v1beta1/stub/GrpcCloudRedisStub.java b/test/integration/goldens/redis/src/com/google/cloud/redis/v1beta1/stub/GrpcCloudRedisStub.java index dab6511359..fb6ae5f82d 100644 --- a/test/integration/goldens/redis/src/com/google/cloud/redis/v1beta1/stub/GrpcCloudRedisStub.java +++ b/test/integration/goldens/redis/src/com/google/cloud/redis/v1beta1/stub/GrpcCloudRedisStub.java @@ -25,6 +25,7 @@ import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.redis.v1beta1.CreateInstanceRequest; import com.google.cloud.redis.v1beta1.DeleteInstanceRequest; @@ -40,7 +41,6 @@ import com.google.cloud.redis.v1beta1.RescheduleMaintenanceRequest; import com.google.cloud.redis.v1beta1.UpdateInstanceRequest; import com.google.cloud.redis.v1beta1.UpgradeInstanceRequest; -import com.google.common.collect.ImmutableMap; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Any; @@ -249,9 +249,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(listInstancesMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings getInstanceTransportSettings = @@ -259,9 +259,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(getInstanceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -270,9 +270,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(getInstanceAuthStringMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings createInstanceTransportSettings = @@ -280,9 +280,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(createInstanceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("parent", String.valueOf(request.getParent())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); }) .build(); GrpcCallSettings updateInstanceTransportSettings = @@ -290,9 +290,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(updateInstanceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("instance.name", String.valueOf(request.getInstance().getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("instance.name", String.valueOf(request.getInstance().getName())); + return builder.build(); }) .build(); GrpcCallSettings upgradeInstanceTransportSettings = @@ -300,9 +300,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(upgradeInstanceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings importInstanceTransportSettings = @@ -310,9 +310,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(importInstanceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings exportInstanceTransportSettings = @@ -320,9 +320,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(exportInstanceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings failoverInstanceTransportSettings = @@ -330,9 +330,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(failoverInstanceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings deleteInstanceTransportSettings = @@ -340,9 +340,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(deleteInstanceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); GrpcCallSettings @@ -351,9 +351,9 @@ protected GrpcCloudRedisStub( .setMethodDescriptor(rescheduleMaintenanceMethodDescriptor) .setParamsExtractor( request -> { - ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); - return params.build(); + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); }) .build(); diff --git a/test/integration/goldens/redis/src/com/google/cloud/redis/v1beta1/stub/HttpJsonCloudRedisStub.java b/test/integration/goldens/redis/src/com/google/cloud/redis/v1beta1/stub/HttpJsonCloudRedisStub.java index 208336f01c..c000dd4523 100644 --- a/test/integration/goldens/redis/src/com/google/cloud/redis/v1beta1/stub/HttpJsonCloudRedisStub.java +++ b/test/integration/goldens/redis/src/com/google/cloud/redis/v1beta1/stub/HttpJsonCloudRedisStub.java @@ -34,6 +34,7 @@ import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.redis.v1beta1.CreateInstanceRequest; import com.google.cloud.redis.v1beta1.DeleteInstanceRequest; @@ -609,58 +610,124 @@ protected HttpJsonCloudRedisStub( HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listInstancesMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings getInstanceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getInstanceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings getInstanceAuthStringTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getInstanceAuthStringMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings createInstanceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(createInstanceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) .build(); HttpJsonCallSettings updateInstanceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(updateInstanceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("instance.name", String.valueOf(request.getInstance().getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings upgradeInstanceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(upgradeInstanceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings importInstanceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(importInstanceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings exportInstanceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(exportInstanceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings failoverInstanceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(failoverInstanceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings deleteInstanceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteInstanceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); HttpJsonCallSettings rescheduleMaintenanceTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(rescheduleMaintenanceMethodDescriptor) .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) .build(); this.listInstancesCallable =