diff --git a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/DocumentProcessorServiceClient.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/DocumentProcessorServiceClient.java
index 858c5b47..d0747349 100644
--- a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/DocumentProcessorServiceClient.java
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/DocumentProcessorServiceClient.java
@@ -16,14 +16,15 @@
package com.google.cloud.documentai.v1;
+import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
+import com.google.api.gax.httpjson.longrunning.OperationsClient;
import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.rpc.OperationCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.documentai.v1.stub.DocumentProcessorServiceStub;
import com.google.cloud.documentai.v1.stub.DocumentProcessorServiceStubSettings;
import com.google.longrunning.Operation;
-import com.google.longrunning.OperationsClient;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
@@ -99,13 +100,29 @@
* DocumentProcessorServiceClient.create(documentProcessorServiceSettings);
* }
*
+ * 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.
+ * DocumentProcessorServiceSettings documentProcessorServiceSettings =
+ * DocumentProcessorServiceSettings.newBuilder()
+ * .setTransportChannelProvider(
+ * DocumentProcessorServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ * .build();
+ * DocumentProcessorServiceClient documentProcessorServiceClient =
+ * DocumentProcessorServiceClient.create(documentProcessorServiceSettings);
+ * }
+ *
* Please refer to the GitHub repository's samples for more quickstart code snippets.
*/
@Generated("by gapic-generator-java")
public class DocumentProcessorServiceClient implements BackgroundResource {
private final DocumentProcessorServiceSettings settings;
private final DocumentProcessorServiceStub stub;
- private final OperationsClient operationsClient;
+ private final OperationsClient httpJsonOperationsClient;
+ private final com.google.longrunning.OperationsClient operationsClient;
/** Constructs an instance of DocumentProcessorServiceClient with default settings. */
public static final DocumentProcessorServiceClient create() throws IOException {
@@ -139,13 +156,17 @@ protected DocumentProcessorServiceClient(DocumentProcessorServiceSettings settin
throws IOException {
this.settings = settings;
this.stub = ((DocumentProcessorServiceStubSettings) settings.getStubSettings()).createStub();
- this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
+ this.operationsClient =
+ com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
+ this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
}
protected DocumentProcessorServiceClient(DocumentProcessorServiceStub stub) {
this.settings = null;
this.stub = stub;
- this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
+ this.operationsClient =
+ com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
+ this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
}
public final DocumentProcessorServiceSettings getSettings() {
@@ -160,10 +181,19 @@ public DocumentProcessorServiceStub getStub() {
* Returns the OperationsClient that can be used to query the status of a long-running operation
* returned by another API method call.
*/
- public final OperationsClient getOperationsClient() {
+ public final com.google.longrunning.OperationsClient getOperationsClient() {
return operationsClient;
}
+ /**
+ * Returns the OperationsClient that can be used to query the status of a long-running operation
+ * returned by another API method call.
+ */
+ @BetaApi
+ public final OperationsClient getHttpJsonOperationsClient() {
+ return httpJsonOperationsClient;
+ }
+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Processes a single document.
diff --git a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/DocumentProcessorServiceSettings.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/DocumentProcessorServiceSettings.java
index d483d039..6207218d 100644
--- a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/DocumentProcessorServiceSettings.java
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/DocumentProcessorServiceSettings.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;
@@ -128,11 +129,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
return DocumentProcessorServiceStubSettings.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 DocumentProcessorServiceStubSettings.defaultGrpcTransportProviderBuilder();
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return DocumentProcessorServiceStubSettings.defaultHttpJsonTransportProviderBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return DocumentProcessorServiceStubSettings.defaultTransportChannelProvider();
}
@@ -142,11 +150,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
return DocumentProcessorServiceStubSettings.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);
@@ -185,6 +199,11 @@ private static Builder createDefault() {
return new Builder(DocumentProcessorServiceStubSettings.newBuilder());
}
+ @BetaApi
+ private static Builder createHttpJsonDefault() {
+ return new Builder(DocumentProcessorServiceStubSettings.newHttpJsonBuilder());
+ }
+
public DocumentProcessorServiceStubSettings.Builder getStubSettingsBuilder() {
return ((DocumentProcessorServiceStubSettings.Builder) getStubSettings());
}
diff --git a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/DocumentProcessorServiceStub.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/DocumentProcessorServiceStub.java
index aea812f9..370b89a2 100644
--- a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/DocumentProcessorServiceStub.java
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/DocumentProcessorServiceStub.java
@@ -41,7 +41,11 @@
public abstract class DocumentProcessorServiceStub implements BackgroundResource {
public OperationsStub getOperationsStub() {
- throw new UnsupportedOperationException("Not implemented: getOperationsStub()");
+ return null;
+ }
+
+ public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() {
+ return null;
}
public UnaryCallable processDocumentCallable() {
diff --git a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/DocumentProcessorServiceStubSettings.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/DocumentProcessorServiceStubSettings.java
index abed65d9..7da61e8f 100644
--- a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/DocumentProcessorServiceStubSettings.java
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/DocumentProcessorServiceStubSettings.java
@@ -25,6 +25,9 @@
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.grpc.ProtoOperationTransformers;
+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.longrunning.OperationSnapshot;
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
@@ -139,6 +142,11 @@ public DocumentProcessorServiceStub createStub() throws IOException {
.equals(GrpcTransportChannel.getGrpcTransportName())) {
return GrpcDocumentProcessorServiceStub.create(this);
}
+ if (getTransportChannelProvider()
+ .getTransportName()
+ .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
+ return HttpJsonDocumentProcessorServiceStub.create(this);
+ }
throw new UnsupportedOperationException(
String.format(
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
@@ -171,18 +179,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", GaxProperties.getLibraryVersion(DocumentProcessorServiceStubSettings.class))
@@ -190,11 +205,30 @@ 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(DocumentProcessorServiceStubSettings.class))
+ .setTransportToken(
+ GaxHttpJsonProperties.getHttpJsonTokenName(),
+ GaxHttpJsonProperties.getHttpJsonVersion());
+ }
+
+ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ return DocumentProcessorServiceStubSettings.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);
@@ -312,6 +346,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
.processDocumentSettings()
diff --git a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/HttpJsonDocumentProcessorServiceCallableFactory.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/HttpJsonDocumentProcessorServiceCallableFactory.java
new file mode 100644
index 00000000..d1c4d2a5
--- /dev/null
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/HttpJsonDocumentProcessorServiceCallableFactory.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.documentai.v1.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 DocumentProcessorService service API.
+ *
+ * This class is for advanced usage.
+ */
+@Generated("by gapic-generator-java")
+@BetaApi
+public class HttpJsonDocumentProcessorServiceCallableFactory
+ 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-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/HttpJsonDocumentProcessorServiceStub.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/HttpJsonDocumentProcessorServiceStub.java
new file mode 100644
index 00000000..745b9ea5
--- /dev/null
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1/stub/HttpJsonDocumentProcessorServiceStub.java
@@ -0,0 +1,365 @@
+/*
+ * 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.documentai.v1.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.HttpJsonOperationSnapshot;
+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.httpjson.longrunning.stub.HttpJsonOperationsStub;
+import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.OperationCallable;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.cloud.documentai.v1.BatchProcessMetadata;
+import com.google.cloud.documentai.v1.BatchProcessRequest;
+import com.google.cloud.documentai.v1.BatchProcessResponse;
+import com.google.cloud.documentai.v1.ProcessRequest;
+import com.google.cloud.documentai.v1.ProcessResponse;
+import com.google.cloud.documentai.v1.ReviewDocumentOperationMetadata;
+import com.google.cloud.documentai.v1.ReviewDocumentRequest;
+import com.google.cloud.documentai.v1.ReviewDocumentResponse;
+import com.google.longrunning.Operation;
+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 DocumentProcessorService service API.
+ *
+ * This class is for advanced usage and reflects the underlying API directly.
+ */
+@Generated("by gapic-generator-java")
+@BetaApi
+public class HttpJsonDocumentProcessorServiceStub extends DocumentProcessorServiceStub {
+ private static final TypeRegistry typeRegistry =
+ TypeRegistry.newBuilder()
+ .add(BatchProcessResponse.getDescriptor())
+ .add(ReviewDocumentResponse.getDescriptor())
+ .add(ReviewDocumentOperationMetadata.getDescriptor())
+ .add(BatchProcessMetadata.getDescriptor())
+ .build();
+
+ private static final ApiMethodDescriptor
+ processDocumentMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1.DocumentProcessorService/ProcessDocument")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/locations/*/processors/*}:process",
+ 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(ProcessResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ batchProcessDocumentsMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1.DocumentProcessorService/BatchProcessDocuments")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/locations/*/processors/*}:batchProcess",
+ 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(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (BatchProcessRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private static final ApiMethodDescriptor
+ reviewDocumentMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1.DocumentProcessorService/ReviewDocument")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{humanReviewConfig=projects/*/locations/*/processors/*/humanReviewConfig}:reviewDocument",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(
+ fields, "humanReviewConfig", request.getHumanReviewConfig());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody(
+ "*", request.toBuilder().clearHumanReviewConfig().build()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (ReviewDocumentRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private final UnaryCallable processDocumentCallable;
+ private final UnaryCallable batchProcessDocumentsCallable;
+ private final OperationCallable
+ batchProcessDocumentsOperationCallable;
+ private final UnaryCallable reviewDocumentCallable;
+ private final OperationCallable<
+ ReviewDocumentRequest, ReviewDocumentResponse, ReviewDocumentOperationMetadata>
+ reviewDocumentOperationCallable;
+
+ private final BackgroundResource backgroundResources;
+ private final HttpJsonOperationsStub httpJsonOperationsStub;
+ private final HttpJsonStubCallableFactory callableFactory;
+
+ public static final HttpJsonDocumentProcessorServiceStub create(
+ DocumentProcessorServiceStubSettings settings) throws IOException {
+ return new HttpJsonDocumentProcessorServiceStub(settings, ClientContext.create(settings));
+ }
+
+ public static final HttpJsonDocumentProcessorServiceStub create(ClientContext clientContext)
+ throws IOException {
+ return new HttpJsonDocumentProcessorServiceStub(
+ DocumentProcessorServiceStubSettings.newHttpJsonBuilder().build(), clientContext);
+ }
+
+ public static final HttpJsonDocumentProcessorServiceStub create(
+ ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
+ return new HttpJsonDocumentProcessorServiceStub(
+ DocumentProcessorServiceStubSettings.newHttpJsonBuilder().build(),
+ clientContext,
+ callableFactory);
+ }
+
+ /**
+ * Constructs an instance of HttpJsonDocumentProcessorServiceStub, 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 HttpJsonDocumentProcessorServiceStub(
+ DocumentProcessorServiceStubSettings settings, ClientContext clientContext)
+ throws IOException {
+ this(settings, clientContext, new HttpJsonDocumentProcessorServiceCallableFactory());
+ }
+
+ /**
+ * Constructs an instance of HttpJsonDocumentProcessorServiceStub, 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 HttpJsonDocumentProcessorServiceStub(
+ DocumentProcessorServiceStubSettings settings,
+ ClientContext clientContext,
+ HttpJsonStubCallableFactory callableFactory)
+ throws IOException {
+ this.callableFactory = callableFactory;
+ this.httpJsonOperationsStub =
+ HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry);
+
+ HttpJsonCallSettings processDocumentTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(processDocumentMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings batchProcessDocumentsTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(batchProcessDocumentsMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings reviewDocumentTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(reviewDocumentMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+
+ this.processDocumentCallable =
+ callableFactory.createUnaryCallable(
+ processDocumentTransportSettings, settings.processDocumentSettings(), clientContext);
+ this.batchProcessDocumentsCallable =
+ callableFactory.createUnaryCallable(
+ batchProcessDocumentsTransportSettings,
+ settings.batchProcessDocumentsSettings(),
+ clientContext);
+ this.batchProcessDocumentsOperationCallable =
+ callableFactory.createOperationCallable(
+ batchProcessDocumentsTransportSettings,
+ settings.batchProcessDocumentsOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+ this.reviewDocumentCallable =
+ callableFactory.createUnaryCallable(
+ reviewDocumentTransportSettings, settings.reviewDocumentSettings(), clientContext);
+ this.reviewDocumentOperationCallable =
+ callableFactory.createOperationCallable(
+ reviewDocumentTransportSettings,
+ settings.reviewDocumentOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+
+ this.backgroundResources =
+ new BackgroundResourceAggregation(clientContext.getBackgroundResources());
+ }
+
+ @InternalApi
+ public static List getMethodDescriptors() {
+ List methodDescriptors = new ArrayList<>();
+ methodDescriptors.add(processDocumentMethodDescriptor);
+ methodDescriptors.add(batchProcessDocumentsMethodDescriptor);
+ methodDescriptors.add(reviewDocumentMethodDescriptor);
+ return methodDescriptors;
+ }
+
+ public HttpJsonOperationsStub getHttpJsonOperationsStub() {
+ return httpJsonOperationsStub;
+ }
+
+ @Override
+ public UnaryCallable processDocumentCallable() {
+ return processDocumentCallable;
+ }
+
+ @Override
+ public UnaryCallable batchProcessDocumentsCallable() {
+ return batchProcessDocumentsCallable;
+ }
+
+ @Override
+ public OperationCallable
+ batchProcessDocumentsOperationCallable() {
+ return batchProcessDocumentsOperationCallable;
+ }
+
+ @Override
+ public UnaryCallable reviewDocumentCallable() {
+ return reviewDocumentCallable;
+ }
+
+ @Override
+ public OperationCallable<
+ ReviewDocumentRequest, ReviewDocumentResponse, ReviewDocumentOperationMetadata>
+ reviewDocumentOperationCallable() {
+ return reviewDocumentOperationCallable;
+ }
+
+ @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-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceClient.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceClient.java
index 2f72c56c..58a12665 100644
--- a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceClient.java
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceClient.java
@@ -20,6 +20,7 @@
import com.google.api.core.ApiFutures;
import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
+import com.google.api.gax.httpjson.longrunning.OperationsClient;
import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.paging.AbstractFixedSizeCollection;
import com.google.api.gax.paging.AbstractPage;
@@ -31,7 +32,6 @@
import com.google.cloud.documentai.v1beta3.stub.DocumentProcessorServiceStubSettings;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.longrunning.Operation;
-import com.google.longrunning.OperationsClient;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.List;
@@ -109,6 +109,21 @@
* DocumentProcessorServiceClient.create(documentProcessorServiceSettings);
* }
*
+ * 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.
+ * DocumentProcessorServiceSettings documentProcessorServiceSettings =
+ * DocumentProcessorServiceSettings.newBuilder()
+ * .setTransportChannelProvider(
+ * DocumentProcessorServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ * .build();
+ * DocumentProcessorServiceClient documentProcessorServiceClient =
+ * DocumentProcessorServiceClient.create(documentProcessorServiceSettings);
+ * }
+ *
* Please refer to the GitHub repository's samples for more quickstart code snippets.
*/
@BetaApi
@@ -116,7 +131,8 @@
public class DocumentProcessorServiceClient implements BackgroundResource {
private final DocumentProcessorServiceSettings settings;
private final DocumentProcessorServiceStub stub;
- private final OperationsClient operationsClient;
+ private final OperationsClient httpJsonOperationsClient;
+ private final com.google.longrunning.OperationsClient operationsClient;
/** Constructs an instance of DocumentProcessorServiceClient with default settings. */
public static final DocumentProcessorServiceClient create() throws IOException {
@@ -150,13 +166,17 @@ protected DocumentProcessorServiceClient(DocumentProcessorServiceSettings settin
throws IOException {
this.settings = settings;
this.stub = ((DocumentProcessorServiceStubSettings) settings.getStubSettings()).createStub();
- this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
+ this.operationsClient =
+ com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
+ this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
}
protected DocumentProcessorServiceClient(DocumentProcessorServiceStub stub) {
this.settings = null;
this.stub = stub;
- this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
+ this.operationsClient =
+ com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
+ this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
}
public final DocumentProcessorServiceSettings getSettings() {
@@ -171,10 +191,19 @@ public DocumentProcessorServiceStub getStub() {
* Returns the OperationsClient that can be used to query the status of a long-running operation
* returned by another API method call.
*/
- public final OperationsClient getOperationsClient() {
+ public final com.google.longrunning.OperationsClient getOperationsClient() {
return operationsClient;
}
+ /**
+ * Returns the OperationsClient that can be used to query the status of a long-running operation
+ * returned by another API method call.
+ */
+ @BetaApi
+ public final OperationsClient getHttpJsonOperationsClient() {
+ return httpJsonOperationsClient;
+ }
+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Processes a single document.
diff --git a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceSettings.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceSettings.java
index 8bac2b6b..951a2264 100644
--- a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceSettings.java
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceSettings.java
@@ -23,6 +23,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;
@@ -189,11 +190,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
return DocumentProcessorServiceStubSettings.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 DocumentProcessorServiceStubSettings.defaultGrpcTransportProviderBuilder();
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return DocumentProcessorServiceStubSettings.defaultHttpJsonTransportProviderBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return DocumentProcessorServiceStubSettings.defaultTransportChannelProvider();
}
@@ -203,11 +211,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
return DocumentProcessorServiceStubSettings.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);
@@ -246,6 +260,11 @@ private static Builder createDefault() {
return new Builder(DocumentProcessorServiceStubSettings.newBuilder());
}
+ @BetaApi
+ private static Builder createHttpJsonDefault() {
+ return new Builder(DocumentProcessorServiceStubSettings.newHttpJsonBuilder());
+ }
+
public DocumentProcessorServiceStubSettings.Builder getStubSettingsBuilder() {
return ((DocumentProcessorServiceStubSettings.Builder) getStubSettings());
}
diff --git a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/DocumentProcessorServiceStub.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/DocumentProcessorServiceStub.java
index c301b665..c327462a 100644
--- a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/DocumentProcessorServiceStub.java
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/DocumentProcessorServiceStub.java
@@ -60,7 +60,11 @@
public abstract class DocumentProcessorServiceStub implements BackgroundResource {
public OperationsStub getOperationsStub() {
- throw new UnsupportedOperationException("Not implemented: getOperationsStub()");
+ return null;
+ }
+
+ public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() {
+ return null;
}
public UnaryCallable processDocumentCallable() {
diff --git a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/DocumentProcessorServiceStubSettings.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/DocumentProcessorServiceStubSettings.java
index 3d9a55f6..c6fa4888 100644
--- a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/DocumentProcessorServiceStubSettings.java
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/DocumentProcessorServiceStubSettings.java
@@ -28,6 +28,9 @@
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.grpc.ProtoOperationTransformers;
+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.longrunning.OperationSnapshot;
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
@@ -288,6 +291,11 @@ public DocumentProcessorServiceStub createStub() throws IOException {
.equals(GrpcTransportChannel.getGrpcTransportName())) {
return GrpcDocumentProcessorServiceStub.create(this);
}
+ if (getTransportChannelProvider()
+ .getTransportName()
+ .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
+ return HttpJsonDocumentProcessorServiceStub.create(this);
+ }
throw new UnsupportedOperationException(
String.format(
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
@@ -320,18 +328,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", GaxProperties.getLibraryVersion(DocumentProcessorServiceStubSettings.class))
@@ -339,11 +354,30 @@ 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(DocumentProcessorServiceStubSettings.class))
+ .setTransportToken(
+ GaxHttpJsonProperties.getHttpJsonTokenName(),
+ GaxHttpJsonProperties.getHttpJsonVersion());
+ }
+
+ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ return DocumentProcessorServiceStubSettings.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);
@@ -529,6 +563,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
.processDocumentSettings()
diff --git a/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/HttpJsonDocumentProcessorServiceCallableFactory.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/HttpJsonDocumentProcessorServiceCallableFactory.java
new file mode 100644
index 00000000..750c1df5
--- /dev/null
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/HttpJsonDocumentProcessorServiceCallableFactory.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.documentai.v1beta3.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 DocumentProcessorService service API.
+ *
+ * This class is for advanced usage.
+ */
+@BetaApi
+@Generated("by gapic-generator-java")
+public class HttpJsonDocumentProcessorServiceCallableFactory
+ 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-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/HttpJsonDocumentProcessorServiceStub.java b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/HttpJsonDocumentProcessorServiceStub.java
new file mode 100644
index 00000000..6bffd115
--- /dev/null
+++ b/google-cloud-document-ai/src/main/java/com/google/cloud/documentai/v1beta3/stub/HttpJsonDocumentProcessorServiceStub.java
@@ -0,0 +1,765 @@
+/*
+ * 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.documentai.v1beta3.stub;
+
+import static com.google.cloud.documentai.v1beta3.DocumentProcessorServiceClient.ListProcessorsPagedResponse;
+
+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.HttpJsonOperationSnapshot;
+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.httpjson.longrunning.stub.HttpJsonOperationsStub;
+import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.OperationCallable;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.cloud.documentai.v1beta3.BatchProcessMetadata;
+import com.google.cloud.documentai.v1beta3.BatchProcessRequest;
+import com.google.cloud.documentai.v1beta3.BatchProcessResponse;
+import com.google.cloud.documentai.v1beta3.CreateProcessorRequest;
+import com.google.cloud.documentai.v1beta3.DeleteProcessorMetadata;
+import com.google.cloud.documentai.v1beta3.DeleteProcessorRequest;
+import com.google.cloud.documentai.v1beta3.DisableProcessorMetadata;
+import com.google.cloud.documentai.v1beta3.DisableProcessorRequest;
+import com.google.cloud.documentai.v1beta3.DisableProcessorResponse;
+import com.google.cloud.documentai.v1beta3.EnableProcessorMetadata;
+import com.google.cloud.documentai.v1beta3.EnableProcessorRequest;
+import com.google.cloud.documentai.v1beta3.EnableProcessorResponse;
+import com.google.cloud.documentai.v1beta3.FetchProcessorTypesRequest;
+import com.google.cloud.documentai.v1beta3.FetchProcessorTypesResponse;
+import com.google.cloud.documentai.v1beta3.ListProcessorsRequest;
+import com.google.cloud.documentai.v1beta3.ListProcessorsResponse;
+import com.google.cloud.documentai.v1beta3.ProcessRequest;
+import com.google.cloud.documentai.v1beta3.ProcessResponse;
+import com.google.cloud.documentai.v1beta3.Processor;
+import com.google.cloud.documentai.v1beta3.ReviewDocumentOperationMetadata;
+import com.google.cloud.documentai.v1beta3.ReviewDocumentRequest;
+import com.google.cloud.documentai.v1beta3.ReviewDocumentResponse;
+import com.google.longrunning.Operation;
+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 DocumentProcessorService service API.
+ *
+ * This class is for advanced usage and reflects the underlying API directly.
+ */
+@BetaApi
+@Generated("by gapic-generator-java")
+public class HttpJsonDocumentProcessorServiceStub extends DocumentProcessorServiceStub {
+ private static final TypeRegistry typeRegistry =
+ TypeRegistry.newBuilder()
+ .add(BatchProcessMetadata.getDescriptor())
+ .add(Empty.getDescriptor())
+ .add(DisableProcessorMetadata.getDescriptor())
+ .add(EnableProcessorMetadata.getDescriptor())
+ .add(DeleteProcessorMetadata.getDescriptor())
+ .add(ReviewDocumentResponse.getDescriptor())
+ .add(EnableProcessorResponse.getDescriptor())
+ .add(BatchProcessResponse.getDescriptor())
+ .add(DisableProcessorResponse.getDescriptor())
+ .add(ReviewDocumentOperationMetadata.getDescriptor())
+ .build();
+
+ private static final ApiMethodDescriptor
+ processDocumentMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1beta3.DocumentProcessorService/ProcessDocument")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta3/{name=projects/*/locations/*/processors/*}:process",
+ 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(ProcessResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ batchProcessDocumentsMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1beta3.DocumentProcessorService/BatchProcessDocuments")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta3/{name=projects/*/locations/*/processors/*}:batchProcess",
+ 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(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (BatchProcessRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private static final ApiMethodDescriptor
+ fetchProcessorTypesMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1beta3.DocumentProcessorService/FetchProcessorTypes")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta3/{parent=projects/*/locations/*}:fetchProcessorTypes",
+ 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 -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(FetchProcessorTypesResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ listProcessorsMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1beta3.DocumentProcessorService/ListProcessors")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta3/{parent=projects/*/locations/*}/processors",
+ 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();
+ serializer.putQueryParam(fields, "pageSize", request.getPageSize());
+ serializer.putQueryParam(fields, "pageToken", request.getPageToken());
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(ListProcessorsResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ createProcessorMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1beta3.DocumentProcessorService/CreateProcessor")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta3/{parent=projects/*/locations/*}/processors",
+ 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("processor", request.getProcessor()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Processor.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ deleteProcessorMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1beta3.DocumentProcessorService/DeleteProcessor")
+ .setHttpMethod("DELETE")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta3/{name=projects/*/locations/*/processors/*}",
+ 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 -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (DeleteProcessorRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private static final ApiMethodDescriptor
+ enableProcessorMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1beta3.DocumentProcessorService/EnableProcessor")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta3/{name=projects/*/locations/*/processors/*}:enable",
+ 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(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (EnableProcessorRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private static final ApiMethodDescriptor
+ disableProcessorMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1beta3.DocumentProcessorService/DisableProcessor")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta3/{name=projects/*/locations/*/processors/*}:disable",
+ 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(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (DisableProcessorRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private static final ApiMethodDescriptor
+ reviewDocumentMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.documentai.v1beta3.DocumentProcessorService/ReviewDocument")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1beta3/{humanReviewConfig=projects/*/locations/*/processors/*/humanReviewConfig}:reviewDocument",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(
+ fields, "humanReviewConfig", request.getHumanReviewConfig());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody(
+ "*", request.toBuilder().clearHumanReviewConfig().build()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (ReviewDocumentRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private final UnaryCallable processDocumentCallable;
+ private final UnaryCallable batchProcessDocumentsCallable;
+ private final OperationCallable
+ batchProcessDocumentsOperationCallable;
+ private final UnaryCallable
+ fetchProcessorTypesCallable;
+ private final UnaryCallable listProcessorsCallable;
+ private final UnaryCallable
+ listProcessorsPagedCallable;
+ private final UnaryCallable createProcessorCallable;
+ private final UnaryCallable deleteProcessorCallable;
+ private final OperationCallable
+ deleteProcessorOperationCallable;
+ private final UnaryCallable enableProcessorCallable;
+ private final OperationCallable<
+ EnableProcessorRequest, EnableProcessorResponse, EnableProcessorMetadata>
+ enableProcessorOperationCallable;
+ private final UnaryCallable disableProcessorCallable;
+ private final OperationCallable<
+ DisableProcessorRequest, DisableProcessorResponse, DisableProcessorMetadata>
+ disableProcessorOperationCallable;
+ private final UnaryCallable reviewDocumentCallable;
+ private final OperationCallable<
+ ReviewDocumentRequest, ReviewDocumentResponse, ReviewDocumentOperationMetadata>
+ reviewDocumentOperationCallable;
+
+ private final BackgroundResource backgroundResources;
+ private final HttpJsonOperationsStub httpJsonOperationsStub;
+ private final HttpJsonStubCallableFactory callableFactory;
+
+ public static final HttpJsonDocumentProcessorServiceStub create(
+ DocumentProcessorServiceStubSettings settings) throws IOException {
+ return new HttpJsonDocumentProcessorServiceStub(settings, ClientContext.create(settings));
+ }
+
+ public static final HttpJsonDocumentProcessorServiceStub create(ClientContext clientContext)
+ throws IOException {
+ return new HttpJsonDocumentProcessorServiceStub(
+ DocumentProcessorServiceStubSettings.newHttpJsonBuilder().build(), clientContext);
+ }
+
+ public static final HttpJsonDocumentProcessorServiceStub create(
+ ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
+ return new HttpJsonDocumentProcessorServiceStub(
+ DocumentProcessorServiceStubSettings.newHttpJsonBuilder().build(),
+ clientContext,
+ callableFactory);
+ }
+
+ /**
+ * Constructs an instance of HttpJsonDocumentProcessorServiceStub, 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 HttpJsonDocumentProcessorServiceStub(
+ DocumentProcessorServiceStubSettings settings, ClientContext clientContext)
+ throws IOException {
+ this(settings, clientContext, new HttpJsonDocumentProcessorServiceCallableFactory());
+ }
+
+ /**
+ * Constructs an instance of HttpJsonDocumentProcessorServiceStub, 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 HttpJsonDocumentProcessorServiceStub(
+ DocumentProcessorServiceStubSettings settings,
+ ClientContext clientContext,
+ HttpJsonStubCallableFactory callableFactory)
+ throws IOException {
+ this.callableFactory = callableFactory;
+ this.httpJsonOperationsStub =
+ HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry);
+
+ HttpJsonCallSettings processDocumentTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(processDocumentMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings batchProcessDocumentsTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(batchProcessDocumentsMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ fetchProcessorTypesTransportSettings =
+ HttpJsonCallSettings
+ .newBuilder()
+ .setMethodDescriptor(fetchProcessorTypesMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ listProcessorsTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(listProcessorsMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings createProcessorTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(createProcessorMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings deleteProcessorTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(deleteProcessorMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings enableProcessorTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(enableProcessorMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings disableProcessorTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(disableProcessorMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings reviewDocumentTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(reviewDocumentMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+
+ this.processDocumentCallable =
+ callableFactory.createUnaryCallable(
+ processDocumentTransportSettings, settings.processDocumentSettings(), clientContext);
+ this.batchProcessDocumentsCallable =
+ callableFactory.createUnaryCallable(
+ batchProcessDocumentsTransportSettings,
+ settings.batchProcessDocumentsSettings(),
+ clientContext);
+ this.batchProcessDocumentsOperationCallable =
+ callableFactory.createOperationCallable(
+ batchProcessDocumentsTransportSettings,
+ settings.batchProcessDocumentsOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+ this.fetchProcessorTypesCallable =
+ callableFactory.createUnaryCallable(
+ fetchProcessorTypesTransportSettings,
+ settings.fetchProcessorTypesSettings(),
+ clientContext);
+ this.listProcessorsCallable =
+ callableFactory.createUnaryCallable(
+ listProcessorsTransportSettings, settings.listProcessorsSettings(), clientContext);
+ this.listProcessorsPagedCallable =
+ callableFactory.createPagedCallable(
+ listProcessorsTransportSettings, settings.listProcessorsSettings(), clientContext);
+ this.createProcessorCallable =
+ callableFactory.createUnaryCallable(
+ createProcessorTransportSettings, settings.createProcessorSettings(), clientContext);
+ this.deleteProcessorCallable =
+ callableFactory.createUnaryCallable(
+ deleteProcessorTransportSettings, settings.deleteProcessorSettings(), clientContext);
+ this.deleteProcessorOperationCallable =
+ callableFactory.createOperationCallable(
+ deleteProcessorTransportSettings,
+ settings.deleteProcessorOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+ this.enableProcessorCallable =
+ callableFactory.createUnaryCallable(
+ enableProcessorTransportSettings, settings.enableProcessorSettings(), clientContext);
+ this.enableProcessorOperationCallable =
+ callableFactory.createOperationCallable(
+ enableProcessorTransportSettings,
+ settings.enableProcessorOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+ this.disableProcessorCallable =
+ callableFactory.createUnaryCallable(
+ disableProcessorTransportSettings, settings.disableProcessorSettings(), clientContext);
+ this.disableProcessorOperationCallable =
+ callableFactory.createOperationCallable(
+ disableProcessorTransportSettings,
+ settings.disableProcessorOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+ this.reviewDocumentCallable =
+ callableFactory.createUnaryCallable(
+ reviewDocumentTransportSettings, settings.reviewDocumentSettings(), clientContext);
+ this.reviewDocumentOperationCallable =
+ callableFactory.createOperationCallable(
+ reviewDocumentTransportSettings,
+ settings.reviewDocumentOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+
+ this.backgroundResources =
+ new BackgroundResourceAggregation(clientContext.getBackgroundResources());
+ }
+
+ @InternalApi
+ public static List getMethodDescriptors() {
+ List methodDescriptors = new ArrayList<>();
+ methodDescriptors.add(processDocumentMethodDescriptor);
+ methodDescriptors.add(batchProcessDocumentsMethodDescriptor);
+ methodDescriptors.add(fetchProcessorTypesMethodDescriptor);
+ methodDescriptors.add(listProcessorsMethodDescriptor);
+ methodDescriptors.add(createProcessorMethodDescriptor);
+ methodDescriptors.add(deleteProcessorMethodDescriptor);
+ methodDescriptors.add(enableProcessorMethodDescriptor);
+ methodDescriptors.add(disableProcessorMethodDescriptor);
+ methodDescriptors.add(reviewDocumentMethodDescriptor);
+ return methodDescriptors;
+ }
+
+ public HttpJsonOperationsStub getHttpJsonOperationsStub() {
+ return httpJsonOperationsStub;
+ }
+
+ @Override
+ public UnaryCallable processDocumentCallable() {
+ return processDocumentCallable;
+ }
+
+ @Override
+ public UnaryCallable batchProcessDocumentsCallable() {
+ return batchProcessDocumentsCallable;
+ }
+
+ @Override
+ public OperationCallable
+ batchProcessDocumentsOperationCallable() {
+ return batchProcessDocumentsOperationCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ fetchProcessorTypesCallable() {
+ return fetchProcessorTypesCallable;
+ }
+
+ @Override
+ public UnaryCallable listProcessorsCallable() {
+ return listProcessorsCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ listProcessorsPagedCallable() {
+ return listProcessorsPagedCallable;
+ }
+
+ @Override
+ public UnaryCallable createProcessorCallable() {
+ return createProcessorCallable;
+ }
+
+ @Override
+ public UnaryCallable deleteProcessorCallable() {
+ return deleteProcessorCallable;
+ }
+
+ @Override
+ public OperationCallable
+ deleteProcessorOperationCallable() {
+ return deleteProcessorOperationCallable;
+ }
+
+ @Override
+ public UnaryCallable enableProcessorCallable() {
+ return enableProcessorCallable;
+ }
+
+ @Override
+ public OperationCallable
+ enableProcessorOperationCallable() {
+ return enableProcessorOperationCallable;
+ }
+
+ @Override
+ public UnaryCallable disableProcessorCallable() {
+ return disableProcessorCallable;
+ }
+
+ @Override
+ public OperationCallable<
+ DisableProcessorRequest, DisableProcessorResponse, DisableProcessorMetadata>
+ disableProcessorOperationCallable() {
+ return disableProcessorOperationCallable;
+ }
+
+ @Override
+ public UnaryCallable reviewDocumentCallable() {
+ return reviewDocumentCallable;
+ }
+
+ @Override
+ public OperationCallable<
+ ReviewDocumentRequest, ReviewDocumentResponse, ReviewDocumentOperationMetadata>
+ reviewDocumentOperationCallable() {
+ return reviewDocumentOperationCallable;
+ }
+
+ @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-document-ai/src/test/java/com/google/cloud/documentai/v1/DocumentProcessorServiceClientHttpJsonTest.java b/google-cloud-document-ai/src/test/java/com/google/cloud/documentai/v1/DocumentProcessorServiceClientHttpJsonTest.java
new file mode 100644
index 00000000..e1de51f9
--- /dev/null
+++ b/google-cloud-document-ai/src/test/java/com/google/cloud/documentai/v1/DocumentProcessorServiceClientHttpJsonTest.java
@@ -0,0 +1,356 @@
+/*
+ * 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.documentai.v1;
+
+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.documentai.v1.stub.HttpJsonDocumentProcessorServiceStub;
+import com.google.longrunning.Operation;
+import com.google.protobuf.Any;
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+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 DocumentProcessorServiceClientHttpJsonTest {
+ private static MockHttpService mockService;
+ private static DocumentProcessorServiceClient client;
+
+ @BeforeClass
+ public static void startStaticServer() throws IOException {
+ mockService =
+ new MockHttpService(
+ HttpJsonDocumentProcessorServiceStub.getMethodDescriptors(),
+ DocumentProcessorServiceSettings.getDefaultEndpoint());
+ DocumentProcessorServiceSettings settings =
+ DocumentProcessorServiceSettings.newHttpJsonBuilder()
+ .setTransportChannelProvider(
+ DocumentProcessorServiceSettings.defaultHttpJsonTransportProviderBuilder()
+ .setHttpTransport(mockService)
+ .build())
+ .setCredentialsProvider(NoCredentialsProvider.create())
+ .build();
+ client = DocumentProcessorServiceClient.create(settings);
+ }
+
+ @AfterClass
+ public static void stopServer() {
+ client.close();
+ }
+
+ @Before
+ public void setUp() {}
+
+ @After
+ public void tearDown() throws Exception {
+ mockService.reset();
+ }
+
+ @Test
+ public void processDocumentTest() throws Exception {
+ ProcessResponse expectedResponse =
+ ProcessResponse.newBuilder()
+ .setDocument(Document.newBuilder().build())
+ .setHumanReviewStatus(HumanReviewStatus.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+
+ ProcessResponse actualResponse = client.processDocument(name);
+ 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 processDocumentExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+ client.processDocument(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void processDocumentTest2() throws Exception {
+ ProcessResponse expectedResponse =
+ ProcessResponse.newBuilder()
+ .setDocument(Document.newBuilder().build())
+ .setHumanReviewStatus(HumanReviewStatus.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "projects/project-5167/locations/location-5167/processors/processor-5167";
+
+ ProcessResponse actualResponse = client.processDocument(name);
+ 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 processDocumentExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-5167/locations/location-5167/processors/processor-5167";
+ client.processDocument(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void batchProcessDocumentsTest() throws Exception {
+ BatchProcessResponse expectedResponse = BatchProcessResponse.newBuilder().build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("batchProcessDocumentsTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+
+ BatchProcessResponse actualResponse = client.batchProcessDocumentsAsync(name).get();
+ 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 batchProcessDocumentsExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+ client.batchProcessDocumentsAsync(name).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void batchProcessDocumentsTest2() throws Exception {
+ BatchProcessResponse expectedResponse = BatchProcessResponse.newBuilder().build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("batchProcessDocumentsTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ String name = "projects/project-5167/locations/location-5167/processors/processor-5167";
+
+ BatchProcessResponse actualResponse = client.batchProcessDocumentsAsync(name).get();
+ 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 batchProcessDocumentsExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-5167/locations/location-5167/processors/processor-5167";
+ client.batchProcessDocumentsAsync(name).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void reviewDocumentTest() throws Exception {
+ ReviewDocumentResponse expectedResponse =
+ ReviewDocumentResponse.newBuilder().setGcsDestination("gcsDestination-1612392329").build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("reviewDocumentTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ HumanReviewConfigName humanReviewConfig =
+ HumanReviewConfigName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+
+ ReviewDocumentResponse actualResponse = client.reviewDocumentAsync(humanReviewConfig).get();
+ 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 reviewDocumentExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ HumanReviewConfigName humanReviewConfig =
+ HumanReviewConfigName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+ client.reviewDocumentAsync(humanReviewConfig).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void reviewDocumentTest2() throws Exception {
+ ReviewDocumentResponse expectedResponse =
+ ReviewDocumentResponse.newBuilder().setGcsDestination("gcsDestination-1612392329").build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("reviewDocumentTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ String humanReviewConfig =
+ "projects/project-1917/locations/location-1917/processors/processor-1917/humanReviewConfig";
+
+ ReviewDocumentResponse actualResponse = client.reviewDocumentAsync(humanReviewConfig).get();
+ 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 reviewDocumentExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String humanReviewConfig =
+ "projects/project-1917/locations/location-1917/processors/processor-1917/humanReviewConfig";
+ client.reviewDocumentAsync(humanReviewConfig).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+}
diff --git a/google-cloud-document-ai/src/test/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceClientHttpJsonTest.java b/google-cloud-document-ai/src/test/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceClientHttpJsonTest.java
new file mode 100644
index 00000000..68ff6c34
--- /dev/null
+++ b/google-cloud-document-ai/src/test/java/com/google/cloud/documentai/v1beta3/DocumentProcessorServiceClientHttpJsonTest.java
@@ -0,0 +1,851 @@
+/*
+ * 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.documentai.v1beta3;
+
+import static com.google.cloud.documentai.v1beta3.DocumentProcessorServiceClient.ListProcessorsPagedResponse;
+
+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.documentai.v1beta3.stub.HttpJsonDocumentProcessorServiceStub;
+import com.google.common.collect.Lists;
+import com.google.longrunning.Operation;
+import com.google.protobuf.Any;
+import com.google.protobuf.Empty;
+import com.google.protobuf.Timestamp;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+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 DocumentProcessorServiceClientHttpJsonTest {
+ private static MockHttpService mockService;
+ private static DocumentProcessorServiceClient client;
+
+ @BeforeClass
+ public static void startStaticServer() throws IOException {
+ mockService =
+ new MockHttpService(
+ HttpJsonDocumentProcessorServiceStub.getMethodDescriptors(),
+ DocumentProcessorServiceSettings.getDefaultEndpoint());
+ DocumentProcessorServiceSettings settings =
+ DocumentProcessorServiceSettings.newHttpJsonBuilder()
+ .setTransportChannelProvider(
+ DocumentProcessorServiceSettings.defaultHttpJsonTransportProviderBuilder()
+ .setHttpTransport(mockService)
+ .build())
+ .setCredentialsProvider(NoCredentialsProvider.create())
+ .build();
+ client = DocumentProcessorServiceClient.create(settings);
+ }
+
+ @AfterClass
+ public static void stopServer() {
+ client.close();
+ }
+
+ @Before
+ public void setUp() {}
+
+ @After
+ public void tearDown() throws Exception {
+ mockService.reset();
+ }
+
+ @Test
+ public void processDocumentTest() throws Exception {
+ ProcessResponse expectedResponse =
+ ProcessResponse.newBuilder()
+ .setDocument(Document.newBuilder().build())
+ .setHumanReviewOperation("humanReviewOperation1807415298")
+ .setHumanReviewStatus(HumanReviewStatus.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+
+ ProcessResponse actualResponse = client.processDocument(name);
+ 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 processDocumentExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+ client.processDocument(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void processDocumentTest2() throws Exception {
+ ProcessResponse expectedResponse =
+ ProcessResponse.newBuilder()
+ .setDocument(Document.newBuilder().build())
+ .setHumanReviewOperation("humanReviewOperation1807415298")
+ .setHumanReviewStatus(HumanReviewStatus.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "projects/project-5167/locations/location-5167/processors/processor-5167";
+
+ ProcessResponse actualResponse = client.processDocument(name);
+ 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 processDocumentExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-5167/locations/location-5167/processors/processor-5167";
+ client.processDocument(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void batchProcessDocumentsTest() throws Exception {
+ BatchProcessResponse expectedResponse = BatchProcessResponse.newBuilder().build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("batchProcessDocumentsTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+
+ BatchProcessResponse actualResponse = client.batchProcessDocumentsAsync(name).get();
+ 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 batchProcessDocumentsExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+ client.batchProcessDocumentsAsync(name).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void batchProcessDocumentsTest2() throws Exception {
+ BatchProcessResponse expectedResponse = BatchProcessResponse.newBuilder().build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("batchProcessDocumentsTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ String name = "projects/project-5167/locations/location-5167/processors/processor-5167";
+
+ BatchProcessResponse actualResponse = client.batchProcessDocumentsAsync(name).get();
+ 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 batchProcessDocumentsExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-5167/locations/location-5167/processors/processor-5167";
+ client.batchProcessDocumentsAsync(name).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void fetchProcessorTypesTest() throws Exception {
+ FetchProcessorTypesResponse expectedResponse =
+ FetchProcessorTypesResponse.newBuilder()
+ .addAllProcessorTypes(new ArrayList())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+
+ FetchProcessorTypesResponse actualResponse = client.fetchProcessorTypes(parent);
+ 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 fetchProcessorTypesExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+ client.fetchProcessorTypes(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void fetchProcessorTypesTest2() throws Exception {
+ FetchProcessorTypesResponse expectedResponse =
+ FetchProcessorTypesResponse.newBuilder()
+ .addAllProcessorTypes(new ArrayList())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "projects/project-5833/locations/location-5833";
+
+ FetchProcessorTypesResponse actualResponse = client.fetchProcessorTypes(parent);
+ 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 fetchProcessorTypesExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "projects/project-5833/locations/location-5833";
+ client.fetchProcessorTypes(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void listProcessorsTest() throws Exception {
+ Processor responsesElement = Processor.newBuilder().build();
+ ListProcessorsResponse expectedResponse =
+ ListProcessorsResponse.newBuilder()
+ .setNextPageToken("")
+ .addAllProcessors(Arrays.asList(responsesElement))
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+
+ ListProcessorsPagedResponse pagedListResponse = client.listProcessors(parent);
+
+ List resources = Lists.newArrayList(pagedListResponse.iterateAll());
+
+ Assert.assertEquals(1, resources.size());
+ Assert.assertEquals(expectedResponse.getProcessorsList().get(0), resources.get(0));
+
+ 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 listProcessorsExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+ client.listProcessors(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void listProcessorsTest2() throws Exception {
+ Processor responsesElement = Processor.newBuilder().build();
+ ListProcessorsResponse expectedResponse =
+ ListProcessorsResponse.newBuilder()
+ .setNextPageToken("")
+ .addAllProcessors(Arrays.asList(responsesElement))
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "projects/project-5833/locations/location-5833";
+
+ ListProcessorsPagedResponse pagedListResponse = client.listProcessors(parent);
+
+ List resources = Lists.newArrayList(pagedListResponse.iterateAll());
+
+ Assert.assertEquals(1, resources.size());
+ Assert.assertEquals(expectedResponse.getProcessorsList().get(0), resources.get(0));
+
+ 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 listProcessorsExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "projects/project-5833/locations/location-5833";
+ client.listProcessors(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void createProcessorTest() throws Exception {
+ Processor expectedResponse =
+ Processor.newBuilder()
+ .setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
+ .setType("type3575610")
+ .setDisplayName("displayName1714148973")
+ .setDefaultProcessorVersion("defaultProcessorVersion-1428555705")
+ .setProcessEndpoint("processEndpoint-891502300")
+ .setCreateTime(Timestamp.newBuilder().build())
+ .setKmsKeyName("kmsKeyName412586233")
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+ Processor processor = Processor.newBuilder().build();
+
+ Processor actualResponse = client.createProcessor(parent, processor);
+ 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 createProcessorExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+ Processor processor = Processor.newBuilder().build();
+ client.createProcessor(parent, processor);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void createProcessorTest2() throws Exception {
+ Processor expectedResponse =
+ Processor.newBuilder()
+ .setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
+ .setType("type3575610")
+ .setDisplayName("displayName1714148973")
+ .setDefaultProcessorVersion("defaultProcessorVersion-1428555705")
+ .setProcessEndpoint("processEndpoint-891502300")
+ .setCreateTime(Timestamp.newBuilder().build())
+ .setKmsKeyName("kmsKeyName412586233")
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "projects/project-5833/locations/location-5833";
+ Processor processor = Processor.newBuilder().build();
+
+ Processor actualResponse = client.createProcessor(parent, processor);
+ 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 createProcessorExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "projects/project-5833/locations/location-5833";
+ Processor processor = Processor.newBuilder().build();
+ client.createProcessor(parent, processor);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void deleteProcessorTest() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("deleteProcessorTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+
+ client.deleteProcessorAsync(name).get();
+
+ 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 deleteProcessorExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+ client.deleteProcessorAsync(name).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void deleteProcessorTest2() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("deleteProcessorTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ String name = "projects/project-5167/locations/location-5167/processors/processor-5167";
+
+ client.deleteProcessorAsync(name).get();
+
+ 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 deleteProcessorExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-5167/locations/location-5167/processors/processor-5167";
+ client.deleteProcessorAsync(name).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void enableProcessorTest() throws Exception {
+ EnableProcessorResponse expectedResponse = EnableProcessorResponse.newBuilder().build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("enableProcessorTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ EnableProcessorRequest request =
+ EnableProcessorRequest.newBuilder()
+ .setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
+ .build();
+
+ EnableProcessorResponse actualResponse = client.enableProcessorAsync(request).get();
+ 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 enableProcessorExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ EnableProcessorRequest request =
+ EnableProcessorRequest.newBuilder()
+ .setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
+ .build();
+ client.enableProcessorAsync(request).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void disableProcessorTest() throws Exception {
+ DisableProcessorResponse expectedResponse = DisableProcessorResponse.newBuilder().build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("disableProcessorTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ DisableProcessorRequest request =
+ DisableProcessorRequest.newBuilder()
+ .setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
+ .build();
+
+ DisableProcessorResponse actualResponse = client.disableProcessorAsync(request).get();
+ 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 disableProcessorExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ DisableProcessorRequest request =
+ DisableProcessorRequest.newBuilder()
+ .setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
+ .build();
+ client.disableProcessorAsync(request).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void reviewDocumentTest() throws Exception {
+ ReviewDocumentResponse expectedResponse =
+ ReviewDocumentResponse.newBuilder().setGcsDestination("gcsDestination-1612392329").build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("reviewDocumentTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ HumanReviewConfigName humanReviewConfig =
+ HumanReviewConfigName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+
+ ReviewDocumentResponse actualResponse = client.reviewDocumentAsync(humanReviewConfig).get();
+ 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 reviewDocumentExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ HumanReviewConfigName humanReviewConfig =
+ HumanReviewConfigName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
+ client.reviewDocumentAsync(humanReviewConfig).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void reviewDocumentTest2() throws Exception {
+ ReviewDocumentResponse expectedResponse =
+ ReviewDocumentResponse.newBuilder().setGcsDestination("gcsDestination-1612392329").build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("reviewDocumentTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ String humanReviewConfig =
+ "projects/project-1917/locations/location-1917/processors/processor-1917/humanReviewConfig";
+
+ ReviewDocumentResponse actualResponse = client.reviewDocumentAsync(humanReviewConfig).get();
+ 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 reviewDocumentExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String humanReviewConfig =
+ "projects/project-1917/locations/location-1917/processors/processor-1917/humanReviewConfig";
+ client.reviewDocumentAsync(humanReviewConfig).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+}
diff --git a/grpc-google-cloud-document-ai-v1/pom.xml b/grpc-google-cloud-document-ai-v1/pom.xml
index 50743629..88685fc6 100644
--- a/grpc-google-cloud-document-ai-v1/pom.xml
+++ b/grpc-google-cloud-document-ai-v1/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
grpc-google-cloud-document-ai-v1
- 2.5.2
+ 2.6.0
grpc-google-cloud-document-ai-v1
GRPC library for google-cloud-document-ai
com.google.cloud
google-cloud-document-ai-parent
- 2.5.2
+ 2.6.0
diff --git a/grpc-google-cloud-document-ai-v1beta1/pom.xml b/grpc-google-cloud-document-ai-v1beta1/pom.xml
index 106fc5ce..6210af00 100644
--- a/grpc-google-cloud-document-ai-v1beta1/pom.xml
+++ b/grpc-google-cloud-document-ai-v1beta1/pom.xml
@@ -3,13 +3,13 @@
4.0.0
com.google.api.grpc
grpc-google-cloud-document-ai-v1beta1
- 0.17.2
+ 0.18.0
grpc-google-cloud-document-ai-v1beta1
GRPC library for grpc-google-cloud-document-ai-v1beta1
com.google.cloud
google-cloud-document-ai-parent
- 2.5.2
+ 2.6.0
diff --git a/grpc-google-cloud-document-ai-v1beta2/pom.xml b/grpc-google-cloud-document-ai-v1beta2/pom.xml
index 164b6a91..0e45dd6a 100644
--- a/grpc-google-cloud-document-ai-v1beta2/pom.xml
+++ b/grpc-google-cloud-document-ai-v1beta2/pom.xml
@@ -3,13 +3,13 @@
4.0.0
com.google.api.grpc
grpc-google-cloud-document-ai-v1beta2
- 0.17.2
+ 0.18.0
grpc-google-cloud-document-ai-v1beta2
GRPC library for grpc-google-cloud-document-ai-v1beta2
com.google.cloud
google-cloud-document-ai-parent
- 2.5.2
+ 2.6.0
diff --git a/grpc-google-cloud-document-ai-v1beta3/pom.xml b/grpc-google-cloud-document-ai-v1beta3/pom.xml
index 05f1862d..43066550 100644
--- a/grpc-google-cloud-document-ai-v1beta3/pom.xml
+++ b/grpc-google-cloud-document-ai-v1beta3/pom.xml
@@ -3,13 +3,13 @@
4.0.0
com.google.api.grpc
grpc-google-cloud-document-ai-v1beta3
- 0.17.2
+ 0.18.0
grpc-google-cloud-document-ai-v1beta3
GRPC library for grpc-google-cloud-document-ai-v1beta3
com.google.cloud
google-cloud-document-ai-parent
- 2.5.2
+ 2.6.0
diff --git a/pom.xml b/pom.xml
index ddb71238..09e718b0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.google.cloud
google-cloud-document-ai-parent
pom
- 2.5.2
+ 2.6.0
Google Cloud Document AI Parent
https://github.com/googleapis/java-document-ai
@@ -61,47 +61,47 @@
com.google.api.grpc
grpc-google-cloud-document-ai-v1beta1
- 0.17.2
+ 0.18.0
com.google.api.grpc
proto-google-cloud-document-ai-v1
- 2.5.2
+ 2.6.0
com.google.api.grpc
grpc-google-cloud-document-ai-v1
- 2.5.2
+ 2.6.0
com.google.cloud
google-cloud-document-ai
- 2.5.2
+ 2.6.0
com.google.api.grpc
grpc-google-cloud-document-ai-v1beta2
- 0.17.2
+ 0.18.0
com.google.api.grpc
grpc-google-cloud-document-ai-v1beta3
- 0.17.2
+ 0.18.0
com.google.api.grpc
proto-google-cloud-document-ai-v1beta1
- 0.17.2
+ 0.18.0
com.google.api.grpc
proto-google-cloud-document-ai-v1beta2
- 0.17.2
+ 0.18.0
com.google.api.grpc
proto-google-cloud-document-ai-v1beta3
- 0.17.2
+ 0.18.0
diff --git a/proto-google-cloud-document-ai-v1/pom.xml b/proto-google-cloud-document-ai-v1/pom.xml
index 683188ba..13940e68 100644
--- a/proto-google-cloud-document-ai-v1/pom.xml
+++ b/proto-google-cloud-document-ai-v1/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
proto-google-cloud-document-ai-v1
- 2.5.2
+ 2.6.0
proto-google-cloud-document-ai-v1
Proto library for google-cloud-document-ai
com.google.cloud
google-cloud-document-ai-parent
- 2.5.2
+ 2.6.0
diff --git a/proto-google-cloud-document-ai-v1beta1/pom.xml b/proto-google-cloud-document-ai-v1beta1/pom.xml
index 3b8ce444..8e557c42 100644
--- a/proto-google-cloud-document-ai-v1beta1/pom.xml
+++ b/proto-google-cloud-document-ai-v1beta1/pom.xml
@@ -3,13 +3,13 @@