diff --git a/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1Client.java b/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1Client.java
index eaa852ea..dd71b1e5 100644
--- a/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1Client.java
+++ b/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1Client.java
@@ -101,6 +101,22 @@
* RecaptchaEnterpriseServiceV1Beta1Client.create(recaptchaEnterpriseServiceV1Beta1Settings);
* }
*
+ * To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
+ * the wire:
+ *
+ *
{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * RecaptchaEnterpriseServiceV1Beta1Settings recaptchaEnterpriseServiceV1Beta1Settings =
+ * RecaptchaEnterpriseServiceV1Beta1Settings.newBuilder()
+ * .setTransportChannelProvider(
+ * RecaptchaEnterpriseServiceV1Beta1Settings.defaultHttpJsonTransportProviderBuilder()
+ * .build())
+ * .build();
+ * RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client =
+ * RecaptchaEnterpriseServiceV1Beta1Client.create(recaptchaEnterpriseServiceV1Beta1Settings);
+ * }
+ *
* Please refer to the GitHub repository's samples for more quickstart code snippets.
*/
@BetaApi
diff --git a/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1Settings.java b/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1Settings.java
index ea8ff356..c7402c06 100644
--- a/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1Settings.java
+++ b/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1Settings.java
@@ -21,6 +21,7 @@
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
+import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
@@ -115,11 +116,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
return RecaptchaEnterpriseServiceV1Beta1StubSettings.defaultCredentialsProviderBuilder();
}
- /** Returns a builder for the default ChannelProvider for this service. */
+ /** Returns a builder for the default gRPC ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return RecaptchaEnterpriseServiceV1Beta1StubSettings.defaultGrpcTransportProviderBuilder();
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return RecaptchaEnterpriseServiceV1Beta1StubSettings.defaultHttpJsonTransportProviderBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return RecaptchaEnterpriseServiceV1Beta1StubSettings.defaultTransportChannelProvider();
}
@@ -129,11 +137,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
return RecaptchaEnterpriseServiceV1Beta1StubSettings.defaultApiClientHeaderProviderBuilder();
}
- /** Returns a new builder for this class. */
+ /** Returns a new gRPC builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}
+ /** Returns a new REST builder for this class. */
+ @BetaApi
+ public static Builder newHttpJsonBuilder() {
+ return Builder.createHttpJsonDefault();
+ }
+
/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
@@ -172,6 +186,11 @@ private static Builder createDefault() {
return new Builder(RecaptchaEnterpriseServiceV1Beta1StubSettings.newBuilder());
}
+ @BetaApi
+ private static Builder createHttpJsonDefault() {
+ return new Builder(RecaptchaEnterpriseServiceV1Beta1StubSettings.newHttpJsonBuilder());
+ }
+
public RecaptchaEnterpriseServiceV1Beta1StubSettings.Builder getStubSettingsBuilder() {
return ((RecaptchaEnterpriseServiceV1Beta1StubSettings.Builder) getStubSettings());
}
diff --git a/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/HttpJsonRecaptchaEnterpriseServiceV1Beta1CallableFactory.java b/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/HttpJsonRecaptchaEnterpriseServiceV1Beta1CallableFactory.java
new file mode 100644
index 00000000..c6a71e2c
--- /dev/null
+++ b/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/HttpJsonRecaptchaEnterpriseServiceV1Beta1CallableFactory.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2022 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.cloud.recaptchaenterprise.v1beta1.stub;
+
+import com.google.api.core.BetaApi;
+import com.google.api.gax.httpjson.HttpJsonCallSettings;
+import com.google.api.gax.httpjson.HttpJsonCallableFactory;
+import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable;
+import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
+import com.google.api.gax.httpjson.longrunning.stub.OperationsStub;
+import com.google.api.gax.rpc.BatchingCallSettings;
+import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.OperationCallSettings;
+import com.google.api.gax.rpc.OperationCallable;
+import com.google.api.gax.rpc.PagedCallSettings;
+import com.google.api.gax.rpc.ServerStreamingCallSettings;
+import com.google.api.gax.rpc.ServerStreamingCallable;
+import com.google.api.gax.rpc.UnaryCallSettings;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.longrunning.Operation;
+import javax.annotation.Generated;
+
+// AUTO-GENERATED DOCUMENTATION AND CLASS.
+/**
+ * REST callable factory implementation for the RecaptchaEnterpriseServiceV1Beta1 service API.
+ *
+ *
This class is for advanced usage.
+ */
+@BetaApi
+@Generated("by gapic-generator-java")
+public class HttpJsonRecaptchaEnterpriseServiceV1Beta1CallableFactory
+ implements HttpJsonStubCallableFactory {
+
+ @Override
+ public UnaryCallable createUnaryCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ UnaryCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createUnaryCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @Override
+ public
+ UnaryCallable createPagedCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ PagedCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createPagedCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @Override
+ public UnaryCallable createBatchingCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ BatchingCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createBatchingCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @BetaApi(
+ "The surface for long-running operations is not stable yet and may change in the future.")
+ @Override
+ public
+ OperationCallable createOperationCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ OperationCallSettings callSettings,
+ ClientContext clientContext,
+ OperationsStub operationsStub) {
+ UnaryCallable innerCallable =
+ HttpJsonCallableFactory.createBaseUnaryCallable(
+ httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext);
+ HttpJsonOperationSnapshotCallable initialCallable =
+ new HttpJsonOperationSnapshotCallable(
+ innerCallable,
+ httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory());
+ return HttpJsonCallableFactory.createOperationCallable(
+ callSettings, clientContext, operationsStub.longRunningClient(), initialCallable);
+ }
+
+ @Override
+ public
+ ServerStreamingCallable createServerStreamingCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ ServerStreamingCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createServerStreamingCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+}
diff --git a/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub.java b/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub.java
new file mode 100644
index 00000000..07038952
--- /dev/null
+++ b/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub.java
@@ -0,0 +1,259 @@
+/*
+ * Copyright 2022 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.cloud.recaptchaenterprise.v1beta1.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.UnaryCallable;
+import com.google.protobuf.TypeRegistry;
+import com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest;
+import com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentResponse;
+import com.google.recaptchaenterprise.v1beta1.Assessment;
+import com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest;
+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 RecaptchaEnterpriseServiceV1Beta1 service API.
+ *
+ * This class is for advanced usage and reflects the underlying API directly.
+ */
+@BetaApi
+@Generated("by gapic-generator-java")
+public class HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub
+ extends RecaptchaEnterpriseServiceV1Beta1Stub {
+ private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();
+
+ private static final ApiMethodDescriptor
+ createAssessmentMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1/CreateAssessment")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta1/{parent=projects/*}/assessments",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "parent", request.getParent());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody("assessment", request.getAssessment()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Assessment.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ annotateAssessmentMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1/AnnotateAssessment")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta1/{name=projects/*/assessments/*}:annotate",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "name", request.getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody("*", request.toBuilder().clearName().build()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(AnnotateAssessmentResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private final UnaryCallable createAssessmentCallable;
+ private final UnaryCallable
+ annotateAssessmentCallable;
+
+ private final BackgroundResource backgroundResources;
+ private final HttpJsonStubCallableFactory callableFactory;
+
+ public static final HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub create(
+ RecaptchaEnterpriseServiceV1Beta1StubSettings settings) throws IOException {
+ return new HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub(
+ settings, ClientContext.create(settings));
+ }
+
+ public static final HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub create(
+ ClientContext clientContext) throws IOException {
+ return new HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub(
+ RecaptchaEnterpriseServiceV1Beta1StubSettings.newHttpJsonBuilder().build(), clientContext);
+ }
+
+ public static final HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub create(
+ ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
+ return new HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub(
+ RecaptchaEnterpriseServiceV1Beta1StubSettings.newHttpJsonBuilder().build(),
+ clientContext,
+ callableFactory);
+ }
+
+ /**
+ * Constructs an instance of HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub, 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 HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub(
+ RecaptchaEnterpriseServiceV1Beta1StubSettings settings, ClientContext clientContext)
+ throws IOException {
+ this(settings, clientContext, new HttpJsonRecaptchaEnterpriseServiceV1Beta1CallableFactory());
+ }
+
+ /**
+ * Constructs an instance of HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub, 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 HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub(
+ RecaptchaEnterpriseServiceV1Beta1StubSettings settings,
+ ClientContext clientContext,
+ HttpJsonStubCallableFactory callableFactory)
+ throws IOException {
+ this.callableFactory = callableFactory;
+
+ HttpJsonCallSettings createAssessmentTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(createAssessmentMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ annotateAssessmentTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(annotateAssessmentMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+
+ this.createAssessmentCallable =
+ callableFactory.createUnaryCallable(
+ createAssessmentTransportSettings, settings.createAssessmentSettings(), clientContext);
+ this.annotateAssessmentCallable =
+ callableFactory.createUnaryCallable(
+ annotateAssessmentTransportSettings,
+ settings.annotateAssessmentSettings(),
+ clientContext);
+
+ this.backgroundResources =
+ new BackgroundResourceAggregation(clientContext.getBackgroundResources());
+ }
+
+ @InternalApi
+ public static List getMethodDescriptors() {
+ List methodDescriptors = new ArrayList<>();
+ methodDescriptors.add(createAssessmentMethodDescriptor);
+ methodDescriptors.add(annotateAssessmentMethodDescriptor);
+ return methodDescriptors;
+ }
+
+ @Override
+ public UnaryCallable createAssessmentCallable() {
+ return createAssessmentCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ annotateAssessmentCallable() {
+ return annotateAssessmentCallable;
+ }
+
+ @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/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/RecaptchaEnterpriseServiceV1Beta1StubSettings.java b/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/RecaptchaEnterpriseServiceV1Beta1StubSettings.java
index a08977fa..cd9bc3b1 100644
--- a/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/RecaptchaEnterpriseServiceV1Beta1StubSettings.java
+++ b/google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/RecaptchaEnterpriseServiceV1Beta1StubSettings.java
@@ -24,6 +24,9 @@
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
+import com.google.api.gax.httpjson.GaxHttpJsonProperties;
+import com.google.api.gax.httpjson.HttpJsonTransportChannel;
+import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
@@ -110,6 +113,11 @@ public RecaptchaEnterpriseServiceV1Beta1Stub createStub() throws IOException {
.equals(GrpcTransportChannel.getGrpcTransportName())) {
return GrpcRecaptchaEnterpriseServiceV1Beta1Stub.create(this);
}
+ if (getTransportChannelProvider()
+ .getTransportName()
+ .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
+ return HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub.create(this);
+ }
throw new UnsupportedOperationException(
String.format(
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
@@ -142,18 +150,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
.setUseJwtAccessWithScope(true);
}
- /** Returns a builder for the default ChannelProvider for this service. */
+ /** Returns a builder for the default gRPC ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return InstantiatingGrpcChannelProvider.newBuilder()
.setMaxInboundMessageSize(Integer.MAX_VALUE);
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return InstantiatingHttpJsonChannelProvider.newBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return defaultGrpcTransportProviderBuilder().build();
}
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
- public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() {
return ApiClientHeaderProvider.newBuilder()
.setGeneratedLibToken(
"gapic",
@@ -162,11 +177,32 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
}
- /** Returns a new builder for this class. */
+ @BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
+ public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() {
+ return ApiClientHeaderProvider.newBuilder()
+ .setGeneratedLibToken(
+ "gapic",
+ GaxProperties.getLibraryVersion(RecaptchaEnterpriseServiceV1Beta1StubSettings.class))
+ .setTransportToken(
+ GaxHttpJsonProperties.getHttpJsonTokenName(),
+ GaxHttpJsonProperties.getHttpJsonVersion());
+ }
+
+ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ return RecaptchaEnterpriseServiceV1Beta1StubSettings
+ .defaultGrpcApiClientHeaderProviderBuilder();
+ }
+
+ /** Returns a new gRPC builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}
+ /** Returns a new REST builder for this class. */
+ public static Builder newHttpJsonBuilder() {
+ return Builder.createHttpJsonDefault();
+ }
+
/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
@@ -260,6 +296,19 @@ private static Builder createDefault() {
return initDefaults(builder);
}
+ private static Builder createHttpJsonDefault() {
+ Builder builder = new Builder(((ClientContext) null));
+
+ builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build());
+ builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
+ builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build());
+ builder.setEndpoint(getDefaultEndpoint());
+ builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
+ builder.setSwitchToMtlsEndpointAllowed(true);
+
+ return initDefaults(builder);
+ }
+
private static Builder initDefaults(Builder builder) {
builder
.createAssessmentSettings()
diff --git a/google-cloud-recaptchaenterprise/src/test/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1ClientHttpJsonTest.java b/google-cloud-recaptchaenterprise/src/test/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1ClientHttpJsonTest.java
new file mode 100644
index 00000000..4244a479
--- /dev/null
+++ b/google-cloud-recaptchaenterprise/src/test/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1ClientHttpJsonTest.java
@@ -0,0 +1,277 @@
+/*
+ * Copyright 2022 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.cloud.recaptchaenterprise.v1beta1;
+
+import com.google.api.gax.core.NoCredentialsProvider;
+import com.google.api.gax.httpjson.GaxHttpJsonProperties;
+import com.google.api.gax.httpjson.testing.MockHttpService;
+import com.google.api.gax.rpc.ApiClientHeaderProvider;
+import com.google.api.gax.rpc.ApiException;
+import com.google.api.gax.rpc.ApiExceptionFactory;
+import com.google.api.gax.rpc.InvalidArgumentException;
+import com.google.api.gax.rpc.StatusCode;
+import com.google.api.gax.rpc.testing.FakeStatusCode;
+import com.google.cloud.recaptchaenterprise.v1beta1.stub.HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub;
+import com.google.recaptchaenterprise.v1beta1.AccountDefenderAssessment;
+import com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest;
+import com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentResponse;
+import com.google.recaptchaenterprise.v1beta1.Assessment;
+import com.google.recaptchaenterprise.v1beta1.AssessmentName;
+import com.google.recaptchaenterprise.v1beta1.Event;
+import com.google.recaptchaenterprise.v1beta1.PasswordLeakVerification;
+import com.google.recaptchaenterprise.v1beta1.ProjectName;
+import com.google.recaptchaenterprise.v1beta1.TokenProperties;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Generated;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+@Generated("by gapic-generator-java")
+public class RecaptchaEnterpriseServiceV1Beta1ClientHttpJsonTest {
+ private static MockHttpService mockService;
+ private static RecaptchaEnterpriseServiceV1Beta1Client client;
+
+ @BeforeClass
+ public static void startStaticServer() throws IOException {
+ mockService =
+ new MockHttpService(
+ HttpJsonRecaptchaEnterpriseServiceV1Beta1Stub.getMethodDescriptors(),
+ RecaptchaEnterpriseServiceV1Beta1Settings.getDefaultEndpoint());
+ RecaptchaEnterpriseServiceV1Beta1Settings settings =
+ RecaptchaEnterpriseServiceV1Beta1Settings.newHttpJsonBuilder()
+ .setTransportChannelProvider(
+ RecaptchaEnterpriseServiceV1Beta1Settings.defaultHttpJsonTransportProviderBuilder()
+ .setHttpTransport(mockService)
+ .build())
+ .setCredentialsProvider(NoCredentialsProvider.create())
+ .build();
+ client = RecaptchaEnterpriseServiceV1Beta1Client.create(settings);
+ }
+
+ @AfterClass
+ public static void stopServer() {
+ client.close();
+ }
+
+ @Before
+ public void setUp() {}
+
+ @After
+ public void tearDown() throws Exception {
+ mockService.reset();
+ }
+
+ @Test
+ public void createAssessmentTest() throws Exception {
+ Assessment expectedResponse =
+ Assessment.newBuilder()
+ .setName(AssessmentName.of("[PROJECT]", "[ASSESSMENT]").toString())
+ .setEvent(Event.newBuilder().build())
+ .setScore(109264530)
+ .setTokenProperties(TokenProperties.newBuilder().build())
+ .addAllReasons(new ArrayList())
+ .setPasswordLeakVerification(PasswordLeakVerification.newBuilder().build())
+ .setAccountDefenderAssessment(AccountDefenderAssessment.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ ProjectName parent = ProjectName.of("[PROJECT]");
+ Assessment assessment = Assessment.newBuilder().build();
+
+ Assessment actualResponse = client.createAssessment(parent, assessment);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void createAssessmentExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ ProjectName parent = ProjectName.of("[PROJECT]");
+ Assessment assessment = Assessment.newBuilder().build();
+ client.createAssessment(parent, assessment);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void createAssessmentTest2() throws Exception {
+ Assessment expectedResponse =
+ Assessment.newBuilder()
+ .setName(AssessmentName.of("[PROJECT]", "[ASSESSMENT]").toString())
+ .setEvent(Event.newBuilder().build())
+ .setScore(109264530)
+ .setTokenProperties(TokenProperties.newBuilder().build())
+ .addAllReasons(new ArrayList())
+ .setPasswordLeakVerification(PasswordLeakVerification.newBuilder().build())
+ .setAccountDefenderAssessment(AccountDefenderAssessment.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "projects/project-2353";
+ Assessment assessment = Assessment.newBuilder().build();
+
+ Assessment actualResponse = client.createAssessment(parent, assessment);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void createAssessmentExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "projects/project-2353";
+ Assessment assessment = Assessment.newBuilder().build();
+ client.createAssessment(parent, assessment);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void annotateAssessmentTest() throws Exception {
+ AnnotateAssessmentResponse expectedResponse = AnnotateAssessmentResponse.newBuilder().build();
+ mockService.addResponse(expectedResponse);
+
+ AssessmentName name = AssessmentName.of("[PROJECT]", "[ASSESSMENT]");
+ AnnotateAssessmentRequest.Annotation annotation =
+ AnnotateAssessmentRequest.Annotation.forNumber(0);
+
+ AnnotateAssessmentResponse actualResponse = client.annotateAssessment(name, annotation);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void annotateAssessmentExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ AssessmentName name = AssessmentName.of("[PROJECT]", "[ASSESSMENT]");
+ AnnotateAssessmentRequest.Annotation annotation =
+ AnnotateAssessmentRequest.Annotation.forNumber(0);
+ client.annotateAssessment(name, annotation);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void annotateAssessmentTest2() throws Exception {
+ AnnotateAssessmentResponse expectedResponse = AnnotateAssessmentResponse.newBuilder().build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "projects/project-8909/assessments/assessment-8909";
+ AnnotateAssessmentRequest.Annotation annotation =
+ AnnotateAssessmentRequest.Annotation.forNumber(0);
+
+ AnnotateAssessmentResponse actualResponse = client.annotateAssessment(name, annotation);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void annotateAssessmentExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-8909/assessments/assessment-8909";
+ AnnotateAssessmentRequest.Annotation annotation =
+ AnnotateAssessmentRequest.Annotation.forNumber(0);
+ client.annotateAssessment(name, annotation);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+}
diff --git a/samples/snippets/generated/com/google/cloud/recaptchaenterprise/v1beta1/recaptchaenterpriseservicev1beta1client/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/recaptchaenterprise/v1beta1/recaptchaenterpriseservicev1beta1client/create/SyncCreateSetCredentialsProvider1.java
new file mode 100644
index 00000000..fc8dee29
--- /dev/null
+++ b/samples/snippets/generated/com/google/cloud/recaptchaenterprise/v1beta1/recaptchaenterpriseservicev1beta1client/create/SyncCreateSetCredentialsProvider1.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2022 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.cloud.recaptchaenterprise.v1beta1.samples;
+
+// [START
+// recaptchaenterprise_v1beta1_generated_recaptchaenterpriseservicev1beta1client_create_setcredentialsprovider1_sync]
+import com.google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client;
+import com.google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1Settings;
+
+public class SyncCreateSetCredentialsProvider1 {
+
+ public static void main(String[] args) throws Exception {
+ syncCreateSetCredentialsProvider1();
+ }
+
+ public static void syncCreateSetCredentialsProvider1() throws Exception {
+ // This snippet has been automatically generated for illustrative purposes only.
+ // It may require modifications to work in your environment.
+ RecaptchaEnterpriseServiceV1Beta1Settings recaptchaEnterpriseServiceV1Beta1Settings =
+ RecaptchaEnterpriseServiceV1Beta1Settings.newBuilder()
+ .setTransportChannelProvider(
+ RecaptchaEnterpriseServiceV1Beta1Settings.defaultHttpJsonTransportProviderBuilder()
+ .build())
+ .build();
+ RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client =
+ RecaptchaEnterpriseServiceV1Beta1Client.create(recaptchaEnterpriseServiceV1Beta1Settings);
+ }
+}
+// [END
+// recaptchaenterprise_v1beta1_generated_recaptchaenterpriseservicev1beta1client_create_setcredentialsprovider1_sync]