Skip to content

Commit dfdd46c

Browse files
authored
docs(samples): Added Endpoint to Document AI Samples (GoogleCloudPlatform#7593)
* docs(samples): Added Endpoint to Document AI Samples * docs(samples): Add Imports for `DocumentProcessorServiceSettings` * Updated formatting for ProcessSplitterDocument * Updated Endpoint to use port 443
1 parent c0f2de2 commit dfdd46c

8 files changed

+90
-34
lines changed

document-ai/src/main/java/documentai/v1/BatchProcessDocument.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.cloud.documentai.v1.DocumentOutputConfig;
2929
import com.google.cloud.documentai.v1.DocumentOutputConfig.GcsOutputConfig;
3030
import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
31+
import com.google.cloud.documentai.v1.DocumentProcessorServiceSettings;
3132
import com.google.cloud.documentai.v1.GcsDocument;
3233
import com.google.cloud.documentai.v1.GcsDocuments;
3334
import com.google.cloud.storage.Blob;
@@ -66,10 +67,16 @@ public static void batchProcessDocument(
6667
String gcsOutputBucketName,
6768
String gcsOutputUriPrefix)
6869
throws IOException, InterruptedException, TimeoutException, ExecutionException {
69-
// Initialize client that will be used to send requests. This client only needs to be created
70-
// once, and can be reused for multiple requests. After completing all of your requests, call
71-
// the "close" method on the client to safely clean up any remaining background resources.
72-
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create()) {
70+
// Initialize client that will be used to send requests. This client only needs
71+
// to be created
72+
// once, and can be reused for multiple requests. After completing all of your
73+
// requests, call
74+
// the "close" method on the client to safely clean up any remaining background
75+
// resources.
76+
String endpoint = String.format("%s-documentai.googleapis.com:443", location);
77+
DocumentProcessorServiceSettings settings =
78+
DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();
79+
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
7380
// The full resource name of the processor, e.g.:
7481
// projects/project-id/locations/location/processor/processor-id
7582
// You must create new processors in the Cloud Console first
@@ -146,7 +153,7 @@ public static void batchProcessDocument(
146153
}
147154

148155
// Form parsing provides additional output about
149-
// form-formatted PDFs. You must create a form
156+
// form-formatted PDFs. You must create a form
150157
// processor in the Cloud Console to see full field details.
151158
System.out.println("The following form key/value pairs were detected:");
152159

document-ai/src/main/java/documentai/v1/ProcessDocument.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.cloud.documentai.v1.Document;
2222
import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
23+
import com.google.cloud.documentai.v1.DocumentProcessorServiceSettings;
2324
import com.google.cloud.documentai.v1.ProcessRequest;
2425
import com.google.cloud.documentai.v1.ProcessResponse;
2526
import com.google.cloud.documentai.v1.RawDocument;
@@ -45,10 +46,16 @@ public static void processDocument()
4546
public static void processDocument(
4647
String projectId, String location, String processorId, String filePath)
4748
throws IOException, InterruptedException, ExecutionException, TimeoutException {
48-
// Initialize client that will be used to send requests. This client only needs to be created
49-
// once, and can be reused for multiple requests. After completing all of your requests, call
50-
// the "close" method on the client to safely clean up any remaining background resources.
51-
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create()) {
49+
// Initialize client that will be used to send requests. This client only needs
50+
// to be created
51+
// once, and can be reused for multiple requests. After completing all of your
52+
// requests, call
53+
// the "close" method on the client to safely clean up any remaining background
54+
// resources.
55+
String endpoint = String.format("%s-documentai.googleapis.com:443", location);
56+
DocumentProcessorServiceSettings settings =
57+
DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();
58+
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
5259
// The full resource name of the processor, e.g.:
5360
// projects/project-id/locations/location/processor/processor-id
5461
// You must create new processors in the Cloud Console first
@@ -86,7 +93,7 @@ public static void processDocument(
8693
}
8794

8895
// Form parsing provides additional output about
89-
// form-formatted PDFs. You must create a form
96+
// form-formatted PDFs. You must create a form
9097
// processor in the Cloud Console to see full field details.
9198
System.out.println("The following form key/value pairs were detected:");
9299

document-ai/src/main/java/documentai/v1/QuickStart.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// [START documentai_quickstart]
2020
import com.google.cloud.documentai.v1.Document;
2121
import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
22+
import com.google.cloud.documentai.v1.DocumentProcessorServiceSettings;
2223
import com.google.cloud.documentai.v1.ProcessRequest;
2324
import com.google.cloud.documentai.v1.ProcessResponse;
2425
import com.google.cloud.documentai.v1.RawDocument;
@@ -44,10 +45,16 @@ public static void main(String[] args)
4445
public static void quickStart(
4546
String projectId, String location, String processorId, String filePath)
4647
throws IOException, InterruptedException, ExecutionException, TimeoutException {
47-
// Initialize client that will be used to send requests. This client only needs to be created
48-
// once, and can be reused for multiple requests. After completing all of your requests, call
49-
// the "close" method on the client to safely clean up any remaining background resources.
50-
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create()) {
48+
// Initialize client that will be used to send requests. This client only needs
49+
// to be created
50+
// once, and can be reused for multiple requests. After completing all of your
51+
// requests, call
52+
// the "close" method on the client to safely clean up any remaining background
53+
// resources.
54+
String endpoint = String.format("%s-documentai.googleapis.com:443", location);
55+
DocumentProcessorServiceSettings settings =
56+
DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();
57+
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
5158
// The full resource name of the processor, e.g.:
5259
// projects/project-id/locations/location/processor/processor-id
5360
// You must create new processors in the Cloud Console first

document-ai/src/main/java/documentai/v1beta3/ProcessFormDocument.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.cloud.documentai.v1beta3.Document;
2222
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceClient;
23+
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceSettings;
2324
import com.google.cloud.documentai.v1beta3.ProcessRequest;
2425
import com.google.cloud.documentai.v1beta3.ProcessResponse;
2526
import com.google.cloud.documentai.v1beta3.RawDocument;
@@ -45,10 +46,16 @@ public static void processFormDocument()
4546
public static void processFormDocument(
4647
String projectId, String location, String processorId, String filePath)
4748
throws IOException, InterruptedException, ExecutionException, TimeoutException {
48-
// Initialize client that will be used to send requests. This client only needs to be created
49-
// once, and can be reused for multiple requests. After completing all of your requests, call
50-
// the "close" method on the client to safely clean up any remaining background resources.
51-
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create()) {
49+
// Initialize client that will be used to send requests. This client only needs
50+
// to be created
51+
// once, and can be reused for multiple requests. After completing all of your
52+
// requests, call
53+
// the "close" method on the client to safely clean up any remaining background
54+
// resources.
55+
String endpoint = String.format("%s-documentai.googleapis.com:443", location);
56+
DocumentProcessorServiceSettings settings =
57+
DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();
58+
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
5259
// The full resource name of the processor, e.g.:
5360
// projects/project-id/locations/location/processor/processor-id
5461
// You must create new processors in the Cloud Console first

document-ai/src/main/java/documentai/v1beta3/ProcessOcrDocument.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.cloud.documentai.v1beta3.Document;
2222
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceClient;
23+
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceSettings;
2324
import com.google.cloud.documentai.v1beta3.ProcessRequest;
2425
import com.google.cloud.documentai.v1beta3.ProcessResponse;
2526
import com.google.cloud.documentai.v1beta3.RawDocument;
@@ -45,10 +46,16 @@ public static void processOcrDocument()
4546
public static void processOcrDocument(
4647
String projectId, String location, String processorId, String filePath)
4748
throws IOException, InterruptedException, ExecutionException, TimeoutException {
48-
// Initialize client that will be used to send requests. This client only needs to be created
49-
// once, and can be reused for multiple requests. After completing all of your requests, call
50-
// the "close" method on the client to safely clean up any remaining background resources.
51-
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create()) {
49+
// Initialize client that will be used to send requests. This client only needs
50+
// to be created
51+
// once, and can be reused for multiple requests. After completing all of your
52+
// requests, call
53+
// the "close" method on the client to safely clean up any remaining background
54+
// resources.
55+
String endpoint = String.format("%s-documentai.googleapis.com:443", location);
56+
DocumentProcessorServiceSettings settings =
57+
DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();
58+
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
5259
// The full resource name of the processor, e.g.:
5360
// projects/project-id/locations/location/processor/processor-id
5461
// You must create new processors in the Cloud Console first

document-ai/src/main/java/documentai/v1beta3/ProcessQualityDocument.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.cloud.documentai.v1beta3.Document;
2222
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceClient;
23+
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceSettings;
2324
import com.google.cloud.documentai.v1beta3.ProcessRequest;
2425
import com.google.cloud.documentai.v1beta3.ProcessResponse;
2526
import com.google.cloud.documentai.v1beta3.RawDocument;
@@ -45,10 +46,16 @@ public static void processQualityDocument()
4546
public static void processQualityDocument(
4647
String projectId, String location, String processorId, String filePath)
4748
throws IOException, InterruptedException, ExecutionException, TimeoutException {
48-
// Initialize client that will be used to send requests. This client only needs to be created
49-
// once, and can be reused for multiple requests. After completing all of your requests, call
50-
// the "close" method on the client to safely clean up any remaining background resources.
51-
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create()) {
49+
// Initialize client that will be used to send requests. This client only needs
50+
// to be created
51+
// once, and can be reused for multiple requests. After completing all of your
52+
// requests, call
53+
// the "close" method on the client to safely clean up any remaining background
54+
// resources.
55+
String endpoint = String.format("%s-documentai.googleapis.com:443", location);
56+
DocumentProcessorServiceSettings settings =
57+
DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();
58+
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
5259
// The full resource name of the processor, e.g.:
5360
// projects/project-id/locations/location/processor/processor-id
5461
// You must create new processors in the Cloud Console first

document-ai/src/main/java/documentai/v1beta3/ProcessSpecializedDocument.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.cloud.documentai.v1beta3.Document;
2222
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceClient;
23+
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceSettings;
2324
import com.google.cloud.documentai.v1beta3.ProcessRequest;
2425
import com.google.cloud.documentai.v1beta3.ProcessResponse;
2526
import com.google.cloud.documentai.v1beta3.RawDocument;
@@ -44,10 +45,16 @@ public static void processSpecializedDocument()
4445
public static void processSpecializedDocument(
4546
String projectId, String location, String processorId, String filePath)
4647
throws IOException, InterruptedException, ExecutionException, TimeoutException {
47-
// Initialize client that will be used to send requests. This client only needs to be created
48-
// once, and can be reused for multiple requests. After completing all of your requests, call
49-
// the "close" method on the client to safely clean up any remaining background resources.
50-
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create()) {
48+
// Initialize client that will be used to send requests. This client only needs
49+
// to be created
50+
// once, and can be reused for multiple requests. After completing all of your
51+
// requests, call
52+
// the "close" method on the client to safely clean up any remaining background
53+
// resources.
54+
String endpoint = String.format("%s-documentai.googleapis.com:443", location);
55+
DocumentProcessorServiceSettings settings =
56+
DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();
57+
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
5158
// The full resource name of the processor, e.g.:
5259
// projects/project-id/locations/location/processor/processor-id
5360
// You must create new processors in the Cloud Console first

document-ai/src/main/java/documentai/v1beta3/ProcessSplitterDocument.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.cloud.documentai.v1beta3.Document;
2222
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceClient;
23+
import com.google.cloud.documentai.v1beta3.DocumentProcessorServiceSettings;
2324
import com.google.cloud.documentai.v1beta3.ProcessRequest;
2425
import com.google.cloud.documentai.v1beta3.ProcessResponse;
2526
import com.google.cloud.documentai.v1beta3.RawDocument;
@@ -45,10 +46,16 @@ public static void processSplitterDocument()
4546
public static void processSplitterDocument(
4647
String projectId, String location, String processorId, String filePath)
4748
throws IOException, InterruptedException, ExecutionException, TimeoutException {
48-
// Initialize client that will be used to send requests. This client only needs to be created
49-
// once, and can be reused for multiple requests. After completing all of your requests, call
50-
// the "close" method on the client to safely clean up any remaining background resources.
51-
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create()) {
49+
// Initialize client that will be used to send requests. This client only needs
50+
// to be created
51+
// once, and can be reused for multiple requests. After completing all of your
52+
// requests, call
53+
// the "close" method on the client to safely clean up any remaining background
54+
// resources.
55+
String endpoint = String.format("%s-documentai.googleapis.com:443", location);
56+
DocumentProcessorServiceSettings settings =
57+
DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();
58+
try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
5259
// The full resource name of the processor, e.g.:
5360
// projects/project-id/locations/location/processor/processor-id
5461
// You must create new processors in the Cloud Console first

0 commit comments

Comments
 (0)