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 a85ab0c92f..191e834a40 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 @@ -1300,7 +1300,10 @@ private void createRequestParamsExtractorBodyForHttpBindings( for (HttpBindings.HttpBinding httpBindingFieldBinding : method.httpBindings().pathParameters()) { MethodInvocationExpr requestBuilderExpr = - createRequestFieldGetterExpr(requestVarExpr, httpBindingFieldBinding.name()); + createRequestFieldGetterExpr( + requestVarExpr, + httpBindingFieldBinding.name(), + httpBindingFieldBinding.field() != null && httpBindingFieldBinding.field().isEnum()); Expr valueOfExpr = MethodInvocationExpr.builder() .setStaticReferenceType(TypeNode.STRING) @@ -1360,8 +1363,10 @@ private void createRequestParamsExtractorBodyForRoutingHeaders( .build(); for (int i = 0; i < routingHeaderParams.size(); i++) { RoutingHeaderRule.RoutingHeaderParam routingHeaderParam = routingHeaderParams.get(i); + // Explicit routing headers are implemented as strings currently, hence sending "false" + // in isFieldEnum() for it. MethodInvocationExpr requestFieldGetterExpr = - createRequestFieldGetterExpr(requestVarExpr, routingHeaderParam.fieldName()); + createRequestFieldGetterExpr(requestVarExpr, routingHeaderParam.fieldName(), false); Expr routingHeaderKeyExpr = ValueExpr.withValue(StringObjectValue.withValue(routingHeaderParam.key())); String pathTemplateName = @@ -1462,7 +1467,7 @@ private Expr fieldValuesNotNullConditionExpr( } private MethodInvocationExpr createRequestFieldGetterExpr( - VariableExpr requestVarExpr, String fieldName) { + VariableExpr requestVarExpr, String fieldName, boolean isFieldEnum) { MethodInvocationExpr.Builder requestFieldGetterExprBuilder = MethodInvocationExpr.builder().setExprReferenceExpr(requestVarExpr); List descendantFields = Splitter.on(".").splitToList(fieldName); @@ -1472,6 +1477,18 @@ private MethodInvocationExpr createRequestFieldGetterExpr( String currFieldName = descendantFields.get(i); String bindingFieldMethodName = String.format("get%s", JavaStyle.toUpperCamelCase(currFieldName)); + + // Only at the last descendant field, if enum, we want to extract the value. + // For example, consider the chain request.getFoo().getBar(). + // If you added "Value" to both fields (getFooValue().getBarValue()), + // it would not work correctly, as getFooValue() may return an int or some other type, + // and calling getBarValue() on it wouldn't make sense + // By adding "Value" only at the last descendant field, + // you ensure that the modification aligns with the expected method + // chaining behavior and correctly retrieves the underlying value of the enum field." + if (i == descendantFields.size() - 1 && isFieldEnum) { + bindingFieldMethodName = bindingFieldMethodName + "Value"; + } requestFieldGetterExprBuilder = requestFieldGetterExprBuilder.setMethodName(bindingFieldMethodName); if (i < descendantFields.size() - 1) { 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 3ab4142af4..2979cd27f3 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,6 +8,8 @@ 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.EnumRequest; +import com.google.explicit.dynamic.routing.header.EnumResponse; import com.google.explicit.dynamic.routing.header.Request; import com.google.explicit.dynamic.routing.header.RequestWithNestedField; import com.google.longrunning.stub.GrpcOperationsStub; @@ -156,6 +158,16 @@ public class GrpcExplicitDynamicRoutingHeaderTestingStub .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) .build(); + private static final MethodDescriptor + implicitRoutingHeaderWithEnumTestMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName( + "google.explicit.dynamic.routing.header.ExplicitDynamicRoutingHeaderTesting/ImplicitRoutingHeaderWithEnumTest") + .setRequestMarshaller(ProtoUtils.marshaller(EnumRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(EnumResponse.getDefaultInstance())) + .build(); + private final UnaryCallable example1TestCallable; private final UnaryCallable example2TestCallable; private final UnaryCallable example3TestCallable; @@ -170,6 +182,7 @@ public class GrpcExplicitDynamicRoutingHeaderTestingStub private final UnaryCallable backwardsCompatible2TestCallable; private final UnaryCallable backwardsCompatible3TestCallable; private final UnaryCallable nestedFieldTestCallable; + private final UnaryCallable implicitRoutingHeaderWithEnumTestCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; @@ -427,6 +440,17 @@ public class GrpcExplicitDynamicRoutingHeaderTestingStub return builder.build(); }) .build(); + GrpcCallSettings implicitRoutingHeaderWithEnumTestTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(implicitRoutingHeaderWithEnumTestMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + "info.enum_test", String.valueOf(request.getInfo().getEnumTestValue())); + return builder.build(); + }) + .build(); this.example1TestCallable = callableFactory.createUnaryCallable( @@ -476,6 +500,11 @@ public class GrpcExplicitDynamicRoutingHeaderTestingStub this.nestedFieldTestCallable = callableFactory.createUnaryCallable( nestedFieldTestTransportSettings, settings.nestedFieldTestSettings(), clientContext); + this.implicitRoutingHeaderWithEnumTestCallable = + callableFactory.createUnaryCallable( + implicitRoutingHeaderWithEnumTestTransportSettings, + settings.implicitRoutingHeaderWithEnumTestSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -555,6 +584,11 @@ public class GrpcExplicitDynamicRoutingHeaderTestingStub return nestedFieldTestCallable; } + @Override + public UnaryCallable implicitRoutingHeaderWithEnumTestCallable() { + return implicitRoutingHeaderWithEnumTestCallable; + } + @Override public final void close() { try { 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 1cfa747b03..b3c92a772e 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 @@ -266,7 +266,7 @@ public class GrpcTestingStub extends TestingStub { builder.add("name", String.valueOf(request.getName())); builder.add( "test_to_verify.name", String.valueOf(request.getTestToVerify().getName())); - builder.add("type", String.valueOf(request.getType())); + builder.add("type", String.valueOf(request.getTypeValue())); return builder.build(); }) .build(); 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 8ec6f14061..c808b9404e 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 @@ -426,7 +426,8 @@ public class HttpJsonComplianceStub extends ComplianceStub { 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_kingdom", String.valueOf(request.getInfo().getFKingdomValue())); builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); return builder.build(); }) 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 index 56b00d49ea..1987cbc592 100644 --- 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 @@ -14,6 +14,8 @@ 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.EnumRequest; +import com.google.explicit.dynamic.routing.header.EnumResponse; import com.google.explicit.dynamic.routing.header.Request; import com.google.explicit.dynamic.routing.header.RequestWithNestedField; import com.google.protobuf.Empty; @@ -140,9 +142,48 @@ public class HttpJsonExplicitDynamicRoutingHeaderTestingStub .build()) .build(); + private static final ApiMethodDescriptor + implicitRoutingHeaderWithEnumTestMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.explicit.dynamic.routing.header.ExplicitDynamicRoutingHeaderTesting/ImplicitRoutingHeaderWithEnumTest") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{info.enumTest}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "info.enumTest", request.getInfo().getEnumTestValue()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(EnumResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + private final UnaryCallable backwardsCompatible1TestCallable; private final UnaryCallable backwardsCompatible2TestCallable; private final UnaryCallable backwardsCompatible3TestCallable; + private final UnaryCallable implicitRoutingHeaderWithEnumTestCallable; private final BackgroundResource backgroundResources; private final HttpJsonStubCallableFactory callableFactory; @@ -223,6 +264,19 @@ public class HttpJsonExplicitDynamicRoutingHeaderTestingStub return builder.build(); }) .build(); + HttpJsonCallSettings + implicitRoutingHeaderWithEnumTestTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(implicitRoutingHeaderWithEnumTestMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + "info.enum_test", String.valueOf(request.getInfo().getEnumTestValue())); + return builder.build(); + }) + .build(); this.backwardsCompatible1TestCallable = callableFactory.createUnaryCallable( @@ -239,6 +293,11 @@ public class HttpJsonExplicitDynamicRoutingHeaderTestingStub backwardsCompatible3TestTransportSettings, settings.backwardsCompatible3TestSettings(), clientContext); + this.implicitRoutingHeaderWithEnumTestCallable = + callableFactory.createUnaryCallable( + implicitRoutingHeaderWithEnumTestTransportSettings, + settings.implicitRoutingHeaderWithEnumTestSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -250,6 +309,7 @@ public class HttpJsonExplicitDynamicRoutingHeaderTestingStub methodDescriptors.add(backwardsCompatible1TestMethodDescriptor); methodDescriptors.add(backwardsCompatible2TestMethodDescriptor); methodDescriptors.add(backwardsCompatible3TestMethodDescriptor); + methodDescriptors.add(implicitRoutingHeaderWithEnumTestMethodDescriptor); return methodDescriptors; } @@ -268,6 +328,11 @@ public class HttpJsonExplicitDynamicRoutingHeaderTestingStub return backwardsCompatible3TestCallable; } + @Override + public UnaryCallable implicitRoutingHeaderWithEnumTestCallable() { + return implicitRoutingHeaderWithEnumTestCallable; + } + @Override public UnaryCallable example1TestCallable() { throw new UnsupportedOperationException( diff --git a/gapic-generator-java/src/test/proto/explicit_dynamic_routing_header_testing.proto b/gapic-generator-java/src/test/proto/explicit_dynamic_routing_header_testing.proto index cbe9526a7b..8ac8873243 100644 --- a/gapic-generator-java/src/test/proto/explicit_dynamic_routing_header_testing.proto +++ b/gapic-generator-java/src/test/proto/explicit_dynamic_routing_header_testing.proto @@ -265,9 +265,37 @@ service ExplicitDynamicRoutingHeaderTesting { } }; } + + // This method echoes the request. This method exercises + // including a non-proto3-optional enum field in the URL path while sending the + // entire request object in the REST body. + rpc ImplicitRoutingHeaderWithEnumTest(EnumRequest) returns (EnumResponse) { + option (google.api.http) = { + post: "/v1beta1/{info.enum_test}" + body: "*" + }; + } +} + +message EnumRequest { + string name = 1; + EnumMessage info = 2; } +message EnumResponse { + EnumRequest request = 1; +} +message EnumMessage { + enum EnumValues { + ENUM_VALUE_1 = 0; + ENUM_VALUE_2 = 1; + ENUM_VALUE_3 = 2; + ENUM_VALUE_4 = 3; + } + // scalar types + EnumValues enum_test = 22; +} // Example message: // 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 876e5f3eef..dfd4b5870a 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 @@ -273,7 +273,8 @@ protected GrpcComplianceStub( 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_kingdom", String.valueOf(request.getInfo().getFKingdomValue())); builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); return builder.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 9fe85b496f..bc890f7fc9 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 @@ -787,7 +787,8 @@ protected HttpJsonComplianceStub( 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_kingdom", String.valueOf(request.getInfo().getFKingdomValue())); builder.add("info.f_string", String.valueOf(request.getInfo().getFString())); return builder.build(); }) 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 index e542b70eb7..46ac29f2f2 100644 --- 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 @@ -27,8 +27,12 @@ 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.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; import com.google.showcase.v1beta1.EchoClient; import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; import com.google.showcase.v1beta1.it.util.TestClientInitializer; import io.grpc.CallOptions; import io.grpc.Channel; @@ -113,10 +117,14 @@ public void onClose(int statusCode, HttpJsonMetadata trailers) { } private HttpJsonCapturingClientInterceptor httpJsonInterceptor; + private HttpJsonCapturingClientInterceptor httpJsonComplianceInterceptor; private GrpcCapturingClientInterceptor grpcInterceptor; + private GrpcCapturingClientInterceptor grpcComplianceInterceptor; private EchoClient grpcClient; private EchoClient httpJsonClient; + private ComplianceClient grpcComplianceClient; + private ComplianceClient httpJsonComplianceClient; @Before public void createClients() throws Exception { @@ -124,6 +132,20 @@ public void createClients() throws Exception { grpcInterceptor = new GrpcCapturingClientInterceptor(); grpcClient = TestClientInitializer.createGrpcEchoClient(ImmutableList.of(grpcInterceptor)); + // Create gRPC ComplianceClient and Interceptor + // Creating a compliance client because echo client doesn't have an implicit enum routing test + // case + grpcComplianceInterceptor = new GrpcCapturingClientInterceptor(); + grpcComplianceClient = + TestClientInitializer.createGrpcComplianceClient( + ImmutableList.of(grpcComplianceInterceptor)); + + // Create HttpJson ComplianceClient and Interceptor + httpJsonComplianceInterceptor = new HttpJsonCapturingClientInterceptor(); + httpJsonComplianceClient = + TestClientInitializer.createHttpJsonComplianceClient( + ImmutableList.of(httpJsonComplianceInterceptor)); + // Create HttpJson Interceptor and Client httpJsonInterceptor = new HttpJsonCapturingClientInterceptor(); httpJsonClient = @@ -134,6 +156,7 @@ public void createClients() throws Exception { public void destroyClient() { grpcClient.close(); httpJsonClient.close(); + grpcComplianceClient.close(); } @Test @@ -175,6 +198,51 @@ public void testGrpc_matchesHeaderName() { assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); } + @Test + public void testGrpc_implicitHeaders_enumsEncodedasInt() { + RepeatRequest request = + RepeatRequest.newBuilder().setInfo(ComplianceData.newBuilder().setFKingdomValue(5)).build(); + RepeatResponse actualResponse = grpcComplianceClient.repeatDataSimplePath(request); + String headerValue = grpcComplianceInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + // fields beside "info.f_kingdom" are default values (false, 0.0, 0) since we are not setting + // them in the request message. + List expectedHeaders = + ImmutableList.of( + "info.f_bool=false", "info.f_double=0.0", "info.f_int32=0", "info.f_kingdom=5"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } + + @Test + public void testHttpJson_implicitHeaders_enumsEncodedasInt() { + RepeatRequest request = + RepeatRequest.newBuilder() + .setInfo( + ComplianceData.newBuilder() + .setFString("test") + .setFInt32(1) + .setFDouble(2) + .setFBool(true) + .setFKingdomValue(3)) + .build(); + RepeatResponse actualResponse = httpJsonComplianceClient.repeatDataSimplePath(request); + String headerValue = httpJsonComplianceInterceptor.requestParam; + assertThat(headerValue).isNotNull(); + List requestHeaders = + Arrays.stream(headerValue.split(SPLIT_TOKEN)).collect(Collectors.toList()); + // In this case, we are setting the values explicitly. + List expectedHeaders = + ImmutableList.of( + "info.f_bool=true", + "info.f_double=2.0", + "info.f_int32=1", + "info.f_kingdom=3", + "info.f_string=test"); + assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders); + } + @Test public void testHttpJson_matchesHeaderName() { httpJsonClient.echo(EchoRequest.newBuilder().setHeader("potato").build()); 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 fe8566bd2f..f215f5bbf4 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 @@ -25,6 +25,8 @@ 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.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceSettings; import com.google.showcase.v1beta1.EchoClient; import com.google.showcase.v1beta1.EchoSettings; import com.google.showcase.v1beta1.IdentityClient; @@ -195,4 +197,35 @@ public static IdentityClient createHttpJsonIdentityClient() throws Exception { .build(); return IdentityClient.create(httpjsonIdentitySettings); } + + // Create grpcComplianceClient with Interceptor + public static ComplianceClient createGrpcComplianceClient(List interceptorList) + throws Exception { + ComplianceSettings grpcComplianceSettings = + ComplianceSettings.newBuilder() + .setCredentialsProvider(NoCredentialsProvider.create()) + .setTransportChannelProvider( + ComplianceSettings.defaultGrpcTransportProviderBuilder() + .setChannelConfigurator(ManagedChannelBuilder::usePlaintext) + .setInterceptorProvider(() -> interceptorList) + .build()) + .build(); + return ComplianceClient.create(grpcComplianceSettings); + } + + public static ComplianceClient createHttpJsonComplianceClient( + List interceptorList) throws Exception { + ComplianceSettings httpJsonComplianceSettings = + ComplianceSettings.newHttpJsonBuilder() + .setCredentialsProvider(NoCredentialsProvider.create()) + .setTransportChannelProvider( + EchoSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport( + new NetHttpTransport.Builder().doNotValidateCertificate().build()) + .setEndpoint("http://localhost:7469") + .setInterceptorProvider(() -> interceptorList) + .build()) + .build(); + return ComplianceClient.create(httpJsonComplianceSettings); + } }