@@ -63,19 +63,19 @@
org.apache.maven.plugins
maven-war-plugin
- 3.2.3
+ 3.3.0
com.google.cloud.tools
appengine-maven-plugin
- 2.2.0
+ 2.3.0
org.eclipse.jetty
jetty-maven-plugin
- 9.4.29.v20200521
+ 9.4.30.v20200611
diff --git a/endpoints/getting-started/src/main/java/com/example/endpoints/AuthInfoServlet.java b/endpoints/getting-started/src/main/java/com/example/endpoints/AuthInfoServlet.java
index 5ec58b038e1..1e6b573b583 100644
--- a/endpoints/getting-started/src/main/java/com/example/endpoints/AuthInfoServlet.java
+++ b/endpoints/getting-started/src/main/java/com/example/endpoints/AuthInfoServlet.java
@@ -1,6 +1,6 @@
/*
* Copyright 2017 Google Inc.
- *
+ *
* 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
@@ -12,17 +12,14 @@
* 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.example.endpoints;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
-
import java.io.IOException;
import java.util.Base64;
-
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -30,8 +27,8 @@
// [START endpoints_auth_info_backend]
/**
- * A servlet that returns authentication information.
- * See openapi.yaml for authentication mechanisms (e.g. JWT tokens, Google ID token).
+ * A servlet that returns authentication information. See openapi.yaml for authentication mechanisms
+ * (e.g. JWT tokens, Google ID token).
*/
@WebServlet("/auth/info/*")
public class AuthInfoServlet extends HttpServlet {
diff --git a/endpoints/getting-started/src/main/java/com/example/endpoints/EchoServlet.java b/endpoints/getting-started/src/main/java/com/example/endpoints/EchoServlet.java
index 84e3152f404..288ae769b62 100644
--- a/endpoints/getting-started/src/main/java/com/example/endpoints/EchoServlet.java
+++ b/endpoints/getting-started/src/main/java/com/example/endpoints/EchoServlet.java
@@ -20,18 +20,14 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.stream.JsonReader;
-
import java.io.IOException;
import java.util.Map;
-
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-/**
- * A servlet that echoes JSON message bodies.
- */
+/** A servlet that echoes JSON message bodies. */
@WebServlet("/echo")
public class EchoServlet extends HttpServlet {
diff --git a/endpoints/multiple-versions/pom.xml b/endpoints/multiple-versions/pom.xml
index a40dff9fed2..e54fbd6d8d6 100644
--- a/endpoints/multiple-versions/pom.xml
+++ b/endpoints/multiple-versions/pom.xml
@@ -29,7 +29,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -38,8 +38,8 @@
2.6
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
false
diff --git a/errorreporting/README.md b/errorreporting/README.md
deleted file mode 100644
index 176e6256456..00000000000
--- a/errorreporting/README.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# Stackdriver Error Reporting sample
-
-
-
-
-[Stackdriver Error Reporting][error-reporting] Stackdriver Error Reporting counts, analyzes and aggregates the crashes in your running cloud services.
-A [centralized error management interface](https://console.cloud.google.com/errors) displays the results with sorting and filtering capabilities.
-
-This sample Java application demonstrates how to send custom error events using the [Error Reporting API][api-ref-docs].
-Note: Runtime exceptions and stack traces are automatically sent to Error reporting in applications running in [App Engine Flex environment][ae-flex].
-
-[ae-flex]: https://cloud.google.com/appengine/docs/flexible/java
-[error-reporting]: https://cloud.google.com/error-reporting/
-[api-ref-docs]: https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/errorreporting/v1beta1/package-summary.html
-
-## Setup
-
-1. Install [Maven](http://maven.apache.org/).
-1. [Enable](https://console.cloud.google.com/apis/api/clouderrorreporting.googleapis.com/overview) Stack Driver Error Reporting API.
-
-## Build
-
-Build your project with:
-```
- mvn clean package
-```
-
-## Local testing
-
-1. [Create a service account](https://cloud.google.com/docs/authentication/getting-started#creating_the_service_account)
-and set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.
-2. Run
-```
- mvn clean verify
-```
-Check the [error reporting console](https://console.cloud.google.com/errors).
-
-Confirm that you see the custom errors reported using the Error Reporting API.
diff --git a/errorreporting/pom.xml b/errorreporting/pom.xml
deleted file mode 100644
index bf30e94a354..00000000000
--- a/errorreporting/pom.xml
+++ /dev/null
@@ -1,51 +0,0 @@
-
-
- 4.0.0
- com.google.cloud.errorreporting.samples
- cloud-errorreporting-samples
- pom
-
-
-
- com.google.cloud.samples
- shared-configuration
- 1.0.17
-
-
- 1.8
- 1.8
-
-
-
-
- com.google.cloud
- google-cloud-errorreporting
- 0.117.0-beta
-
-
-
- junit
- junit
- 4.13
- test
-
-
-
diff --git a/errorreporting/src/main/java/com/example/errorreporting/QuickStart.java b/errorreporting/src/main/java/com/example/errorreporting/QuickStart.java
deleted file mode 100644
index 28d99b41d8e..00000000000
--- a/errorreporting/src/main/java/com/example/errorreporting/QuickStart.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * 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
- *
- * http://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.example.errorreporting;
-
-// [START errorreporting_quickstart]
-// [START error_reporting_quickstart]
-// [START error_reporting_setup_java]
-
-import com.google.cloud.ServiceOptions;
-import com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient;
-import com.google.devtools.clouderrorreporting.v1beta1.ErrorContext;
-import com.google.devtools.clouderrorreporting.v1beta1.ProjectName;
-import com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent;
-import com.google.devtools.clouderrorreporting.v1beta1.SourceLocation;
-
-/**
- * Snippet demonstrates using the Stackdriver Error Reporting API to report a custom error event.
- *
- * This library is not required on App Engine, errors written to stderr are automatically written
- * to Stackdriver Error Reporting.
- * It is also not required if you are writing logs to Stackdriver Logging.
- * Errors written to Stackdriver Logging that contain an exception or stack trace
- * are automatically written out to Stackdriver Error Reporting.
- */
-public class QuickStart {
- public static void main(String[] args) throws Exception {
-
- // Google Cloud Platform Project ID
- String projectId = (args.length > 0) ? args[0] : ServiceOptions.getDefaultProjectId();
- ProjectName projectName = ProjectName.of(projectId);
-
- // Instantiate an Error Reporting Client
- try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
-
- // Custom error events require an error reporting location as well.
- ErrorContext errorContext = ErrorContext.newBuilder()
- .setReportLocation(SourceLocation.newBuilder()
- .setFilePath("Test.java")
- .setLineNumber(10)
- .setFunctionName("myMethod")
- .build())
- .build();
-
- //Report a custom error event
- ReportedErrorEvent customErrorEvent = ReportedErrorEvent.getDefaultInstance()
- .toBuilder()
- .setMessage("custom error event")
- .setContext(errorContext)
- .build();
- // Report an event synchronously, use .reportErrorEventCallable for asynchronous reporting.
- reportErrorsServiceClient.reportErrorEvent(projectName, customErrorEvent);
- }
- }
-}
-// [END error_reporting_setup_java]
-// [END error_reporting_quickstart]
-// [END errorreporting_quickstart]
diff --git a/firestore/README.md b/firestore/README.md
index 918210a81d7..27723c999d3 100644
--- a/firestore/README.md
+++ b/firestore/README.md
@@ -15,7 +15,7 @@ project.
## Setup
- Install [Maven](http://maven.apache.org/).
-- Open the [Firebase Console](https://console.firebase.com) and click **Add project**.
+- Open the [Firebase Console](https://console.firebase.google.com) and click **Add project**.
- Select the option to **Enable Cloud Firestore Beta** for this project.
- Click **Create Project**.
When you create a Cloud Firestore project, it also enables the API in the
diff --git a/firestore/pom.xml b/firestore/pom.xml
index 594e9aa520a..f7c4403a90e 100644
--- a/firestore/pom.xml
+++ b/firestore/pom.xml
@@ -32,7 +32,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
1.8
@@ -50,7 +50,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -79,7 +79,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/firestore/src/main/java/com/example/firestore/Quickstart.java b/firestore/src/main/java/com/example/firestore/Quickstart.java
index dd7091b0b68..ffbc1f355a4 100644
--- a/firestore/src/main/java/com/example/firestore/Quickstart.java
+++ b/firestore/src/main/java/com/example/firestore/Quickstart.java
@@ -17,6 +17,7 @@
package com.example.firestore;
import com.google.api.core.ApiFuture;
+import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.DocumentReference;
// [START fs_include_dependencies]
import com.google.cloud.firestore.Firestore;
@@ -48,11 +49,12 @@ public Quickstart() {
this.db = db;
}
- public Quickstart(String projectId) {
+ public Quickstart(String projectId) throws Exception {
// [START fs_initialize_project_id]
FirestoreOptions firestoreOptions =
FirestoreOptions.getDefaultInstance().toBuilder()
.setProjectId(projectId)
+ .setCredentials(GoogleCredentials.getApplicationDefault())
.build();
Firestore db = firestoreOptions.getService();
// [END fs_initialize_project_id]
diff --git a/firestore/src/test/java/com/example/firestore/BaseIntegrationTest.java b/firestore/src/test/java/com/example/firestore/BaseIntegrationTest.java
index e2c7f666b99..53939494122 100644
--- a/firestore/src/test/java/com/example/firestore/BaseIntegrationTest.java
+++ b/firestore/src/test/java/com/example/firestore/BaseIntegrationTest.java
@@ -21,6 +21,7 @@
import com.example.firestore.snippets.ManageDataSnippetsIT;
import com.example.firestore.snippets.model.City;
import com.google.api.core.ApiFuture;
+import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.DocumentReference;
import com.google.cloud.firestore.DocumentSnapshot;
import com.google.cloud.firestore.Firestore;
@@ -49,6 +50,7 @@ private static String getEnvVar(String varName) {
public static void baseSetup() throws Exception {
projectId = getEnvVar("FIRESTORE_PROJECT_ID");
FirestoreOptions firestoreOptions = FirestoreOptions.getDefaultInstance().toBuilder()
+ .setCredentials(GoogleCredentials.getApplicationDefault())
.setProjectId(projectId)
.build();
db = firestoreOptions.getService();
diff --git a/flexible/analytics/pom.xml b/flexible/analytics/pom.xml
index 2d11c3037a4..4db0ba24f97 100644
--- a/flexible/analytics/pom.xml
+++ b/flexible/analytics/pom.xml
@@ -27,15 +27,15 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
1.8
1.8
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
false
diff --git a/flexible/async-rest/pom.xml b/flexible/async-rest/pom.xml
index a07a0f79239..2e29b912abb 100644
--- a/flexible/async-rest/pom.xml
+++ b/flexible/async-rest/pom.xml
@@ -28,7 +28,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
1.8
1.8
diff --git a/flexible/cloudsql/pom.xml b/flexible/cloudsql/pom.xml
index adffbfd1fa1..f2e11973fa6 100644
--- a/flexible/cloudsql/pom.xml
+++ b/flexible/cloudsql/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -46,7 +46,7 @@
false
- 9.4.29.v20200521
+ 9.4.30.v20200611
jdbc:mysql://google/${database}?cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=${user}&password=${password}&useSSL=false
@@ -103,7 +103,7 @@
com.google.cloud.tools
appengine-maven-plugin
- 2.2.0
+ 2.3.0
GCLOUD_CONFIG
GCLOUD_CONFIG
diff --git a/flexible/cloudstorage/pom.xml b/flexible/cloudstorage/pom.xml
index 5665219f68f..890bfef209f 100644
--- a/flexible/cloudstorage/pom.xml
+++ b/flexible/cloudstorage/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
@@ -48,7 +48,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
diff --git a/flexible/cron/pom.xml b/flexible/cron/pom.xml
index f2bb1bcd16f..9aa9614f1f5 100644
--- a/flexible/cron/pom.xml
+++ b/flexible/cron/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
diff --git a/flexible/datastore/pom.xml b/flexible/datastore/pom.xml
index 5c30da5e0c2..42186507256 100644
--- a/flexible/datastore/pom.xml
+++ b/flexible/datastore/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
@@ -48,7 +48,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
diff --git a/flexible/disk/pom.xml b/flexible/disk/pom.xml
index 13252ca4ca0..09b32fb6db2 100644
--- a/flexible/disk/pom.xml
+++ b/flexible/disk/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
diff --git a/flexible/errorreporting/pom.xml b/flexible/errorreporting/pom.xml
index 3fc82490526..73499bc6d32 100644
--- a/flexible/errorreporting/pom.xml
+++ b/flexible/errorreporting/pom.xml
@@ -27,15 +27,15 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
- 2.2.0
+ 2.3.0
1.8
1.8
false
- 9.4.29.v20200521
+ 9.4.30.v20200611
diff --git a/flexible/extending-runtime/pom.xml b/flexible/extending-runtime/pom.xml
index b38a2c372b4..eb64b2fb51b 100644
--- a/flexible/extending-runtime/pom.xml
+++ b/flexible/extending-runtime/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
diff --git a/flexible/gaeinfo/pom.xml b/flexible/gaeinfo/pom.xml
index 1d046fe0abf..94561c32a7a 100644
--- a/flexible/gaeinfo/pom.xml
+++ b/flexible/gaeinfo/pom.xml
@@ -27,7 +27,7 @@ Copyright 2017 Google Inc.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -78,7 +78,7 @@ Copyright 2017 Google Inc.
org.apache.maven.plugins
maven-war-plugin
- 3.2.3
+ 3.3.0
@@ -94,7 +94,7 @@ Copyright 2017 Google Inc.
com.google.cloud.tools
appengine-maven-plugin
- 2.2.0
+ 2.3.0
GCLOUD_CONFIG
GCLOUD_CONFIG
diff --git a/flexible/helloworld-springboot/pom.xml b/flexible/helloworld-springboot/pom.xml
index 48cea7cb329..314e00253df 100644
--- a/flexible/helloworld-springboot/pom.xml
+++ b/flexible/helloworld-springboot/pom.xml
@@ -28,7 +28,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -40,17 +40,17 @@
org.springframework.boot
spring-boot-starter-web
- 2.3.0.RELEASE
+ 2.3.1.RELEASE
org.springframework.boot
spring-boot-starter-actuator
- 2.3.0.RELEASE
+ 2.3.1.RELEASE
org.springframework.boot
spring-boot-starter-test
- 2.3.0.RELEASE
+ 2.3.1.RELEASE
test
@@ -66,7 +66,7 @@
org.springframework.boot
spring-boot-maven-plugin
- 2.3.0.RELEASE
+ 2.3.1.RELEASE
@@ -78,7 +78,7 @@
com.google.cloud.tools
appengine-maven-plugin
- 2.2.0
+ 2.3.0
GCLOUD_CONFIG
diff --git a/flexible/helloworld/gradle/wrapper/gradle-wrapper.properties b/flexible/helloworld/gradle/wrapper/gradle-wrapper.properties
index 3c5a6cbe1f4..25dddea0715 100644
--- a/flexible/helloworld/gradle/wrapper/gradle-wrapper.properties
+++ b/flexible/helloworld/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
diff --git a/flexible/helloworld/pom.xml b/flexible/helloworld/pom.xml
index c313c259e55..4bb2a6ce524 100644
--- a/flexible/helloworld/pom.xml
+++ b/flexible/helloworld/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
diff --git a/flexible/mailgun/pom.xml b/flexible/mailgun/pom.xml
index 034b0ff1336..dbf4645e58e 100644
--- a/flexible/mailgun/pom.xml
+++ b/flexible/mailgun/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
diff --git a/flexible/mailjet/pom.xml b/flexible/mailjet/pom.xml
index 5568697dfaf..b7e3158caf0 100644
--- a/flexible/mailjet/pom.xml
+++ b/flexible/mailjet/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
4.5.0
diff --git a/flexible/memcache/pom.xml b/flexible/memcache/pom.xml
index f849f0d1338..2f2d3fcd570 100644
--- a/flexible/memcache/pom.xml
+++ b/flexible/memcache/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -37,8 +37,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
diff --git a/flexible/postgres/pom.xml b/flexible/postgres/pom.xml
index ea929c61d56..ba085040f9a 100644
--- a/flexible/postgres/pom.xml
+++ b/flexible/postgres/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -46,7 +46,7 @@
false
- 9.4.29.v20200521
+ 9.4.30.v20200611
jdbc:postgresql://google/${database}?useSSL=false&socketFactoryArg=${INSTANCE_CONNECTION_NAME}&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=${user}&password=${password}
@@ -79,7 +79,7 @@
org.postgresql
postgresql
- 42.2.12
+ 42.2.14
@@ -105,7 +105,7 @@
com.google.cloud.tools
appengine-maven-plugin
- 2.2.0
+ 2.3.0
GCLOUD_CONFIG
GCLOUD_CONFIG
diff --git a/flexible/pubsub/pom.xml b/flexible/pubsub/pom.xml
index f0b4d0e6138..5a6aaad5a74 100644
--- a/flexible/pubsub/pom.xml
+++ b/flexible/pubsub/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
@@ -64,12 +64,12 @@
com.google.cloud
google-cloud-pubsub
- 1.105.1
+ 1.107.0
com.google.cloud
google-cloud-datastore
- 1.102.4
+ 1.104.0
diff --git a/flexible/sendgrid/pom.xml b/flexible/sendgrid/pom.xml
index 36fa3fe5668..163444804cd 100644
--- a/flexible/sendgrid/pom.xml
+++ b/flexible/sendgrid/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
@@ -52,7 +52,7 @@
com.sendgrid
sendgrid-java
- 4.5.0
+ 4.6.0
diff --git a/flexible/sparkjava/pom.xml b/flexible/sparkjava/pom.xml
index f0bd48ef61d..209fd5605ea 100644
--- a/flexible/sparkjava/pom.xml
+++ b/flexible/sparkjava/pom.xml
@@ -29,14 +29,14 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
1.8
1.8
- 2.2.0
+ 2.3.0
${project.build.directory}/spark-1.0-jar-with-dependencies.jar
@@ -64,7 +64,7 @@ limitations under the License.
com.google.cloud
google-cloud-datastore
- 1.102.4
+ 1.104.0
@@ -94,7 +94,7 @@ limitations under the License.
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
com.google.appengine.sparkdemo.Main
diff --git a/flexible/static-files/pom.xml b/flexible/static-files/pom.xml
index 4af19bb88d5..ac149448963 100644
--- a/flexible/static-files/pom.xml
+++ b/flexible/static-files/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
diff --git a/flexible/twilio/pom.xml b/flexible/twilio/pom.xml
index d6c9364d7d7..8b37743ae96 100644
--- a/flexible/twilio/pom.xml
+++ b/flexible/twilio/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,8 +36,8 @@
false
- 2.2.0
- 9.4.29.v20200521
+ 2.3.0
+ 9.4.30.v20200611
diff --git a/flexible/websocket-jetty/pom.xml b/flexible/websocket-jetty/pom.xml
index 7a55a2f3236..029e815d2d4 100644
--- a/flexible/websocket-jetty/pom.xml
+++ b/flexible/websocket-jetty/pom.xml
@@ -30,14 +30,14 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
1.8
1.8
false
- 9.4.29.v20200521
+ 9.4.30.v20200611
@@ -76,7 +76,7 @@
com.google.cloud.tools
appengine-maven-plugin
- 2.2.0
+ 2.3.0
GCLOUD_CONFIG
GCLOUD_CONFIG
diff --git a/flexible/websocket-jsr356/pom.xml b/flexible/websocket-jsr356/pom.xml
index 61eaba3d2ac..7056c294371 100644
--- a/flexible/websocket-jsr356/pom.xml
+++ b/flexible/websocket-jsr356/pom.xml
@@ -27,14 +27,14 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
1.8
1.8
false
- 9.4.29.v20200521
+ 9.4.30.v20200611
@@ -73,7 +73,7 @@ limitations under the License.
com.google.cloud.tools
appengine-maven-plugin
- 2.2.0
+ 2.3.0
GCLOUD_CONFIG
GCLOUD_CONFIG
diff --git a/functions/concepts/env-vars/pom.xml b/functions/concepts/env-vars/pom.xml
index 31844538af6..91caf87d79c 100644
--- a/functions/concepts/env-vars/pom.xml
+++ b/functions/concepts/env-vars/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -107,12 +107,12 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/concepts/execution-count/pom.xml b/functions/concepts/execution-count/pom.xml
index 7c38b72b814..42806b5c157 100644
--- a/functions/concepts/execution-count/pom.xml
+++ b/functions/concepts/execution-count/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -105,7 +105,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.EnvVars
@@ -113,7 +113,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/concepts/file-system/pom.xml b/functions/concepts/file-system/pom.xml
index af2ec97744d..fc010d52fe6 100644
--- a/functions/concepts/file-system/pom.xml
+++ b/functions/concepts/file-system/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -99,7 +99,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.FileSystem
@@ -107,7 +107,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/concepts/lazy-fields/pom.xml b/functions/concepts/lazy-fields/pom.xml
index e41b59bd3cb..d7ffefd8f14 100644
--- a/functions/concepts/lazy-fields/pom.xml
+++ b/functions/concepts/lazy-fields/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -99,7 +99,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.EnvVars
@@ -107,7 +107,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/concepts/retry-pubsub/pom.xml b/functions/concepts/retry-pubsub/pom.xml
index c80b7361249..4f6c6d38a36 100644
--- a/functions/concepts/retry-pubsub/pom.xml
+++ b/functions/concepts/retry-pubsub/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -110,7 +110,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.RetryPubSub
@@ -118,7 +118,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/concepts/retry-pubsub/src/test/java/functions/RetryPubSubTest.java b/functions/concepts/retry-pubsub/src/test/java/functions/RetryPubSubTest.java
index 8113fd8bc54..fbb77a38382 100644
--- a/functions/concepts/retry-pubsub/src/test/java/functions/RetryPubSubTest.java
+++ b/functions/concepts/retry-pubsub/src/test/java/functions/RetryPubSubTest.java
@@ -19,10 +19,12 @@
import static com.google.common.truth.Truth.assertThat;
import com.google.common.testing.TestLogHandler;
+import com.google.gson.Gson;
import functions.eventpojos.PubSubMessage;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
+import java.util.Map;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.BeforeClass;
@@ -38,6 +40,8 @@ public class RetryPubSubTest {
private static final TestLogHandler LOG_HANDLER = new TestLogHandler();
+ private static final Gson gson = new Gson();
+
@BeforeClass
public static void beforeClass() {
logger.addHandler(LOG_HANDLER);
@@ -50,7 +54,7 @@ public void afterTest() {
@Test(expected = RuntimeException.class)
public void retryPubsub_handlesRetryMsg() throws IOException {
- String data = "{\"retry\": true}";
+ String data = gson.toJson(Map.of("retry", true));
String encodedData = new String(
Base64.getEncoder().encode(data.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
@@ -62,7 +66,7 @@ public void retryPubsub_handlesRetryMsg() throws IOException {
@Test
public void retryPubsub_handlesStopMsg() throws IOException {
- String data = "{\"retry\": false}";
+ String data = gson.toJson(Map.of("retry", false));
String encodedData = new String(
Base64.getEncoder().encode(data.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
diff --git a/functions/concepts/retry-timeout/pom.xml b/functions/concepts/retry-timeout/pom.xml
index ca68161a68b..0f5bd48288b 100644
--- a/functions/concepts/retry-timeout/pom.xml
+++ b/functions/concepts/retry-timeout/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -111,7 +111,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.RetryTimeout
@@ -119,7 +119,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/concepts/retry-timeout/src/main/java/functions/RetryTimeout.java b/functions/concepts/retry-timeout/src/main/java/functions/RetryTimeout.java
index b89181f19d9..a5fcd42a409 100644
--- a/functions/concepts/retry-timeout/src/main/java/functions/RetryTimeout.java
+++ b/functions/concepts/retry-timeout/src/main/java/functions/RetryTimeout.java
@@ -59,6 +59,7 @@ public void accept(PubSubMessage message, Context context) {
}
// Process events that are recent enough
+ // To retry this invocation, throw an exception here
logger.info(String.format("Processing event %s.", data));
}
}
diff --git a/functions/concepts/retry-timeout/src/test/java/functions/RetryTimeoutTest.java b/functions/concepts/retry-timeout/src/test/java/functions/RetryTimeoutTest.java
index dd85a5ef16a..05e115b1014 100644
--- a/functions/concepts/retry-timeout/src/test/java/functions/RetryTimeoutTest.java
+++ b/functions/concepts/retry-timeout/src/test/java/functions/RetryTimeoutTest.java
@@ -19,10 +19,12 @@
import static com.google.common.truth.Truth.assertThat;
import com.google.common.testing.TestLogHandler;
+import com.google.gson.Gson;
import functions.eventpojos.PubSubMessage;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
+import java.util.Map;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.Before;
@@ -41,6 +43,8 @@ public class RetryTimeoutTest {
private static final TestLogHandler LOG_HANDLER = new TestLogHandler();
+ private static final Gson gson = new Gson();
+
@BeforeClass
public static void beforeClass() {
logger.addHandler(LOG_HANDLER);
@@ -61,8 +65,8 @@ public void afterTest() {
@Test
public void retryTimeout_handlesRetryMsg() {
- String timestampData = String.format(
- "{\"timestamp\":\"%s\"}", ZonedDateTime.now(ZoneOffset.UTC).toString());
+ String timestampData = gson.toJson(Map.of(
+ "timestamp", ZonedDateTime.now(ZoneOffset.UTC).toString()));
PubSubMessage pubsubMessage = new PubSubMessage();
pubsubMessage.setData(timestampData);
@@ -76,7 +80,7 @@ public void retryTimeout_handlesRetryMsg() {
@Test
public void retryTimeout_handlesStopMsg() {
String timestamp = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0), ZoneOffset.UTC).toString();
- String timestampData = String.format("{\"timestamp\":\"%s\"}", timestamp);
+ String timestampData = gson.toJson(Map.of("timestamp", timestamp));
PubSubMessage pubsubMessage = new PubSubMessage();
diff --git a/functions/concepts/scopes/pom.xml b/functions/concepts/scopes/pom.xml
index f3630036123..7b4227c6bf5 100644
--- a/functions/concepts/scopes/pom.xml
+++ b/functions/concepts/scopes/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -99,7 +99,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.Scopes
@@ -107,7 +107,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/firebase/auth/pom.xml b/functions/firebase/auth/pom.xml
index 3f3e2413414..d85b60e9d5b 100644
--- a/functions/firebase/auth/pom.xml
+++ b/functions/firebase/auth/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -104,7 +104,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.FirebaseAuth
@@ -114,7 +114,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/firebase/auth/src/test/java/functions/FirebaseAuthTest.java b/functions/firebase/auth/src/test/java/functions/FirebaseAuthTest.java
index 5d3c2cfe0fe..2fac9a6fca3 100644
--- a/functions/firebase/auth/src/test/java/functions/FirebaseAuthTest.java
+++ b/functions/firebase/auth/src/test/java/functions/FirebaseAuthTest.java
@@ -18,7 +18,9 @@
import com.google.common.testing.TestLogHandler;
import com.google.common.truth.Truth;
+import com.google.gson.Gson;
import java.io.IOException;
+import java.util.Map;
import java.util.logging.Logger;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -35,6 +37,8 @@ public class FirebaseAuthTest {
private static final TestLogHandler LOG_HANDLER = new TestLogHandler();
+ private static final Gson gson = new Gson();
+
@BeforeClass
public static void beforeClass() {
logger.addHandler(LOG_HANDLER);
@@ -47,7 +51,8 @@ public void beforeTest() throws IOException {
@Test
public void functionsFirebaseAuth_shouldShowUserId() {
- new FirebaseAuth().accept("{\"uid\": \"foo\"}", null);
+ String jsonStr = gson.toJson(Map.of("uid", "foo"));
+ new FirebaseAuth().accept(jsonStr, null);
Truth.assertThat(LOG_HANDLER.getStoredLogRecords().get(0).getMessage()).isEqualTo(
"Function triggered by change to user: foo");
@@ -55,7 +60,8 @@ public void functionsFirebaseAuth_shouldShowUserId() {
@Test
public void functionsFirebaseAuth_shouldShowOrigin() {
- new FirebaseAuth().accept("{\"metadata\": {\"createdAt\": \"123\"}}", null);
+ String jsonStr = gson.toJson(Map.of("metadata", Map.of("createdAt", "123")));
+ new FirebaseAuth().accept(jsonStr, null);
Truth.assertThat(LOG_HANDLER.getStoredLogRecords().get(0).getMessage()).isEqualTo(
"Created at: 123");
@@ -63,7 +69,8 @@ public void functionsFirebaseAuth_shouldShowOrigin() {
@Test
public void functionsFirebaseAuth_shouldShowVersion() {
- new FirebaseAuth().accept("{\"email\": \"foo@google.com\"}", null);
+ String jsonStr = gson.toJson(Map.of("email", "foo@google.com"));
+ new FirebaseAuth().accept(jsonStr, null);
Truth.assertThat(LOG_HANDLER.getStoredLogRecords().get(0).getMessage()).isEqualTo(
"Email: foo@google.com");
diff --git a/functions/firebase/firestore-reactive/pom.xml b/functions/firebase/firestore-reactive/pom.xml
index 8dc9eca8cd3..ae0fd033f8b 100644
--- a/functions/firebase/firestore-reactive/pom.xml
+++ b/functions/firebase/firestore-reactive/pom.xml
@@ -30,7 +30,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -44,7 +44,7 @@
com.google.cloud
google-cloud-firestore
- 1.33.0
+ 1.35.0
@@ -117,7 +117,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.FirebaseFirestoreReactive
@@ -127,7 +127,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
diff --git a/functions/firebase/firestore-reactive/src/main/java/functions/FirebaseFirestoreReactive.java b/functions/firebase/firestore-reactive/src/main/java/functions/FirebaseFirestoreReactive.java
index 9d980f69d83..912de8ae0f9 100644
--- a/functions/firebase/firestore-reactive/src/main/java/functions/FirebaseFirestoreReactive.java
+++ b/functions/firebase/firestore-reactive/src/main/java/functions/FirebaseFirestoreReactive.java
@@ -75,8 +75,7 @@ public void accept(String json, Context context) {
String newValue = currentValue.toUpperCase(Locale.getDefault());
// Update Firestore DB with ALL CAPS value
- Map newFields = new HashMap<>();
- newFields.put("original", newValue);
+ Map newFields = Map.of("original", newValue);
String affectedDoc = context.resource().split("/documents/")[1].replace("\"", "");
diff --git a/functions/firebase/firestore-reactive/src/test/java/functions/FirebaseFirestoreReactiveTest.java b/functions/firebase/firestore-reactive/src/test/java/functions/FirebaseFirestoreReactiveTest.java
index 15073ba3816..f5e79a5814a 100644
--- a/functions/firebase/firestore-reactive/src/test/java/functions/FirebaseFirestoreReactiveTest.java
+++ b/functions/firebase/firestore-reactive/src/test/java/functions/FirebaseFirestoreReactiveTest.java
@@ -23,7 +23,9 @@
import com.google.cloud.firestore.Firestore;
import com.google.common.testing.TestLogHandler;
import com.google.common.truth.Truth;
+import com.google.gson.Gson;
import functions.eventpojos.MockContext;
+import java.util.Map;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.Before;
@@ -47,6 +49,8 @@ public class FirebaseFirestoreReactiveTest {
private static final TestLogHandler LOG_HANDLER = new TestLogHandler();
+ private static final Gson gson = new Gson();
+
@BeforeClass
public static void beforeClass() {
logger.addHandler(LOG_HANDLER);
@@ -71,7 +75,11 @@ public void afterTest() {
@Test
public void functionsFirebaseReactive_shouldCapitalizeOriginalValue() {
- String jsonStr = "{\"value\":{\"fields\":{\"original\":{\"stringValue\":\"foo\"}}}}";
+
+ String jsonStr = gson.toJson(Map.of("value",
+ Map.of("fields",
+ Map.of("original",
+ Map.of("stringValue", "foo")))));
MockContext context = new MockContext();
context.resource = "projects/_/databases/(default)/documents/messages/ABCDE12345";
@@ -86,7 +94,10 @@ public void functionsFirebaseReactive_shouldCapitalizeOriginalValue() {
@Test
public void functionsFirebaseReactive_shouldReportBadJson() {
- String jsonStr = "{\"value\":{\"fields\":{\"original\":{\"missingValue\":\"foo\"}}}}";
+ String jsonStr = gson.toJson(Map.of("value",
+ Map.of("fields",
+ Map.of("original",
+ Map.of("missingValue", "foo")))));
MockContext context = new MockContext();
context.resource = "projects/_/databases/(default)/documents/messages/ABCDE12345";
diff --git a/functions/firebase/firestore/pom.xml b/functions/firebase/firestore/pom.xml
index 80bbe75516d..cb8d2f90c8b 100644
--- a/functions/firebase/firestore/pom.xml
+++ b/functions/firebase/firestore/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -40,7 +40,7 @@
com.google.cloud
google-cloud-firestore
- 1.33.0
+ 1.35.0
@@ -104,7 +104,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.FirebaseFirestore
@@ -114,7 +114,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/firebase/firestore/src/test/java/functions/FirebaseFirestoreTest.java b/functions/firebase/firestore/src/test/java/functions/FirebaseFirestoreTest.java
index d6035dd98bf..7e147ec3b50 100644
--- a/functions/firebase/firestore/src/test/java/functions/FirebaseFirestoreTest.java
+++ b/functions/firebase/firestore/src/test/java/functions/FirebaseFirestoreTest.java
@@ -18,8 +18,10 @@
import com.google.common.testing.TestLogHandler;
import com.google.common.truth.Truth;
+import com.google.gson.Gson;
import functions.eventpojos.MockContext;
import java.util.List;
+import java.util.Map;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import org.junit.After;
@@ -37,6 +39,8 @@ public class FirebaseFirestoreTest {
private static final TestLogHandler LOG_HANDLER = new TestLogHandler();
+ private static final Gson gson = new Gson();
+
@BeforeClass
public static void beforeClass() {
logger.addHandler(LOG_HANDLER);
@@ -64,7 +68,7 @@ public void functionsFirebaseFirestore_shouldIgnoreMissingValuesTest() {
@Test
public void functionsFirebaseFirestore_shouldProcessPresentValues() {
- String jsonStr = "{\"oldValue\": 999, \"value\": 777 }";
+ String jsonStr = gson.toJson(Map.of("oldValue", 999, "value", 777));
MockContext context = new MockContext();
context.resource = "resource_1";
diff --git a/functions/firebase/remote-config/pom.xml b/functions/firebase/remote-config/pom.xml
index 68ad716953f..65674057101 100644
--- a/functions/firebase/remote-config/pom.xml
+++ b/functions/firebase/remote-config/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -104,7 +104,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.FirebaseRemoteConfig
@@ -114,7 +114,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/firebase/remote-config/src/test/java/functions/FirebaseRemoteConfigTest.java b/functions/firebase/remote-config/src/test/java/functions/FirebaseRemoteConfigTest.java
index f0786248eae..b6a41824bf5 100644
--- a/functions/firebase/remote-config/src/test/java/functions/FirebaseRemoteConfigTest.java
+++ b/functions/firebase/remote-config/src/test/java/functions/FirebaseRemoteConfigTest.java
@@ -18,6 +18,8 @@
import com.google.common.testing.TestLogHandler;
import com.google.common.truth.Truth;
+import com.google.gson.Gson;
+import java.util.Map;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.BeforeClass;
@@ -33,6 +35,8 @@ public class FirebaseRemoteConfigTest {
private static final TestLogHandler LOG_HANDLER = new TestLogHandler();
+ private static final Gson gson = new Gson();
+
@BeforeClass
public static void beforeClass() {
logger.addHandler(LOG_HANDLER);
@@ -45,7 +49,8 @@ public void afterTest() {
@Test
public void functionsFirebaseRemoteConfig_shouldShowUpdateType() {
- new FirebaseRemoteConfig().accept("{\"updateType\": \"foo\"}", null);
+ String jsonStr = gson.toJson(Map.of("updateType", "foo"));
+ new FirebaseRemoteConfig().accept(jsonStr, null);
Truth.assertThat(LOG_HANDLER.getStoredLogRecords().get(0).getMessage()).isEqualTo(
"Update type: foo");
@@ -53,7 +58,8 @@ public void functionsFirebaseRemoteConfig_shouldShowUpdateType() {
@Test
public void functionsFirebaseRemoteConfig_shouldShowOrigin() {
- new FirebaseRemoteConfig().accept("{\"updateOrigin\": \"foo\"}", null);
+ String jsonStr = gson.toJson(Map.of("updateOrigin", "foo"));
+ new FirebaseRemoteConfig().accept(jsonStr, null);
Truth.assertThat(LOG_HANDLER.getStoredLogRecords().get(0).getMessage()).isEqualTo(
"Origin: foo");
@@ -61,7 +67,8 @@ public void functionsFirebaseRemoteConfig_shouldShowOrigin() {
@Test
public void functionsFirebaseRemoteConfig_shouldShowVersion() {
- new FirebaseRemoteConfig().accept("{\"versionNumber\": 2}", null);
+ String jsonStr = gson.toJson(Map.of("versionNumber", 2));
+ new FirebaseRemoteConfig().accept(jsonStr, null);
Truth.assertThat(LOG_HANDLER.getStoredLogRecords().get(0).getMessage()).isEqualTo("Version: 2");
}
diff --git a/functions/firebase/rtdb/pom.xml b/functions/firebase/rtdb/pom.xml
index a4226dfcf87..cf1dec65225 100644
--- a/functions/firebase/rtdb/pom.xml
+++ b/functions/firebase/rtdb/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -103,7 +103,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.FirebaseRtdb
@@ -113,7 +113,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/firebase/rtdb/src/test/java/functions/FirebaseRtdbTest.java b/functions/firebase/rtdb/src/test/java/functions/FirebaseRtdbTest.java
index 34ca16e80d3..a35eec7de68 100644
--- a/functions/firebase/rtdb/src/test/java/functions/FirebaseRtdbTest.java
+++ b/functions/firebase/rtdb/src/test/java/functions/FirebaseRtdbTest.java
@@ -18,9 +18,11 @@
import com.google.common.testing.TestLogHandler;
import com.google.common.truth.Truth;
+import com.google.gson.Gson;
import functions.eventpojos.MockContext;
import java.io.IOException;
import java.util.List;
+import java.util.Map;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import org.junit.Before;
@@ -37,6 +39,8 @@ public class FirebaseRtdbTest {
private static final TestLogHandler LOG_HANDLER = new TestLogHandler();
+ private static final Gson gson = new Gson();
+
@BeforeClass
public static void beforeClass() {
logger.addHandler(LOG_HANDLER);
@@ -62,7 +66,7 @@ public void functionsFirebaseRtdb_shouldDefaultAdminToZero() {
@Test
public void functionsFirebaseRtdb_shouldDisplayAdminStatus() {
- String jsonStr = "{\"auth\": { \"admin\": true }}";
+ String jsonStr = gson.toJson(Map.of("auth", Map.of("admin", true)));
MockContext context = new MockContext();
context.resource = "resource_1";
@@ -78,7 +82,7 @@ public void functionsFirebaseRtdb_shouldDisplayAdminStatus() {
@Test
public void functionsFirebaseRtdb_shouldShowDelta() {
- String jsonStr = "{\"delta\": { \"value\": 2 }}";
+ String jsonStr = gson.toJson(Map.of("delta", Map.of("value", 2)));
MockContext context = new MockContext();
context.resource = "resource_1";
@@ -91,7 +95,9 @@ public void functionsFirebaseRtdb_shouldShowDelta() {
Truth.assertThat(logs.get(0).getMessage()).isEqualTo(
"Function triggered by change to: resource_1");
Truth.assertThat(logs.get(2).getMessage()).isEqualTo("Delta:");
- Truth.assertThat(logs.get(3).getMessage()).isEqualTo("{\"value\":2}");
+
+ String expectedJsonStr = gson.toJson(Map.of("value", 2));
+ Truth.assertThat(logs.get(3).getMessage()).isEqualTo(expectedJsonStr);
}
}
diff --git a/functions/helloworld/groovy-hello-pubsub/pom.xml b/functions/helloworld/groovy-hello-pubsub/pom.xml
index 82faea265e1..3feca19497a 100644
--- a/functions/helloworld/groovy-hello-pubsub/pom.xml
+++ b/functions/helloworld/groovy-hello-pubsub/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -107,7 +107,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.GroovyHelloPubSub
@@ -140,7 +140,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/helloworld/groovy-helloworld/pom.xml b/functions/helloworld/groovy-helloworld/pom.xml
index 7b9fef4f950..cb06a76eabd 100644
--- a/functions/helloworld/groovy-helloworld/pom.xml
+++ b/functions/helloworld/groovy-helloworld/pom.xml
@@ -29,7 +29,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -121,7 +121,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.GroovyHelloWorld
@@ -155,7 +155,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/helloworld/hello-error/pom.xml b/functions/helloworld/hello-error/pom.xml
index e406ea139a6..cb58d80e5a6 100644
--- a/functions/helloworld/hello-error/pom.xml
+++ b/functions/helloworld/hello-error/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -78,7 +78,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.HelloError
@@ -88,7 +88,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/helloworld/hello-gcs-generic/pom.xml b/functions/helloworld/hello-gcs-generic/pom.xml
index a7105c0682f..b139d2ad69b 100644
--- a/functions/helloworld/hello-gcs-generic/pom.xml
+++ b/functions/helloworld/hello-gcs-generic/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -92,7 +92,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.HelloGcsGeneric
@@ -102,7 +102,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/helloworld/hello-gcs/pom.xml b/functions/helloworld/hello-gcs/pom.xml
index 0cee6336141..9f38e60c0a3 100644
--- a/functions/helloworld/hello-gcs/pom.xml
+++ b/functions/helloworld/hello-gcs/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -42,7 +42,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -101,13 +101,13 @@
io.github.resilience4j
resilience4j-core
- 1.4.0
+ 1.5.0
test
io.github.resilience4j
resilience4j-retry
- 1.4.0
+ 1.5.0
test
@@ -115,7 +115,7 @@
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
test
@@ -152,7 +152,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.HelloGcs
@@ -160,7 +160,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/helloworld/hello-http/pom.xml b/functions/helloworld/hello-http/pom.xml
index 8fa821cda52..38db06d86a3 100644
--- a/functions/helloworld/hello-http/pom.xml
+++ b/functions/helloworld/hello-http/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -69,13 +69,13 @@
io.github.resilience4j
resilience4j-core
- 1.4.0
+ 1.5.0
test
io.github.resilience4j
resilience4j-retry
- 1.4.0
+ 1.5.0
test
@@ -83,7 +83,7 @@
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
test
@@ -127,7 +127,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.HelloHttp
@@ -137,7 +137,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/helloworld/hello-http/src/test/java/functions/ExampleSystemTest.java b/functions/helloworld/hello-http/src/test/java/functions/ExampleSystemTest.java
index 1fb8f4584da..e274af87d7e 100644
--- a/functions/helloworld/hello-http/src/test/java/functions/ExampleSystemTest.java
+++ b/functions/helloworld/hello-http/src/test/java/functions/ExampleSystemTest.java
@@ -38,7 +38,7 @@ public class ExampleSystemTest {
@Test
public void helloHttp_shouldRunWithFunctionsFramework() throws IOException, InterruptedException {
- String functionUrl = BASE_URL + "/helloHttp";
+ String functionUrl = BASE_URL + "/HelloHttp";
java.net.http.HttpRequest getRequest =
java.net.http.HttpRequest.newBuilder().uri(URI.create(functionUrl)).GET().build();
diff --git a/functions/helloworld/hello-http/src/test/java/functions/HelloHttpTest.java b/functions/helloworld/hello-http/src/test/java/functions/HelloHttpTest.java
index e626bdadd8c..3c429d10f37 100644
--- a/functions/helloworld/hello-http/src/test/java/functions/HelloHttpTest.java
+++ b/functions/helloworld/hello-http/src/test/java/functions/HelloHttpTest.java
@@ -23,11 +23,13 @@
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;
+import com.google.gson.Gson;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
+import java.util.Map;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
@@ -43,6 +45,7 @@ public class HelloHttpTest {
private BufferedWriter writerOut;
private StringWriter responseOut;
+ private static final Gson gson = new Gson();
@Before
public void beforeTest() throws IOException {
@@ -78,6 +81,7 @@ public void helloHttp_urlParamsGet() throws IOException {
@Test
public void helloHttp_bodyParamsPost() throws IOException {
+ String requestJson = gson.toJson(Map.of("name", "Jane"));
BufferedReader jsonReader = new BufferedReader(new StringReader("{'name': 'Jane'}"));
when(request.getReader()).thenReturn(jsonReader);
diff --git a/functions/helloworld/hello-pubsub/pom.xml b/functions/helloworld/hello-pubsub/pom.xml
index 408c465ed46..b877d244ca3 100644
--- a/functions/helloworld/hello-pubsub/pom.xml
+++ b/functions/helloworld/hello-pubsub/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -42,7 +42,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -102,13 +102,13 @@
io.github.resilience4j
resilience4j-core
- 1.4.0
+ 1.5.0
test
io.github.resilience4j
resilience4j-retry
- 1.4.0
+ 1.5.0
test
@@ -116,7 +116,7 @@
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
test
@@ -153,7 +153,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.HelloPubSub
@@ -163,7 +163,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/helloworld/helloworld/pom.xml b/functions/helloworld/helloworld/pom.xml
index c1d901042c9..3e151a00173 100644
--- a/functions/helloworld/helloworld/pom.xml
+++ b/functions/helloworld/helloworld/pom.xml
@@ -32,7 +32,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -111,7 +111,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.HelloWorld
@@ -122,7 +122,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/helloworld/kotlin-hello-pubsub/pom.xml b/functions/helloworld/kotlin-hello-pubsub/pom.xml
index 267bab99ebc..2e0af3998bc 100644
--- a/functions/helloworld/kotlin-hello-pubsub/pom.xml
+++ b/functions/helloworld/kotlin-hello-pubsub/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -111,7 +111,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.KotlinHelloBackground
@@ -149,7 +149,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/helloworld/kotlin-helloworld/pom.xml b/functions/helloworld/kotlin-helloworld/pom.xml
index b8b58a9febb..e3dcedc1365 100644
--- a/functions/helloworld/kotlin-helloworld/pom.xml
+++ b/functions/helloworld/kotlin-helloworld/pom.xml
@@ -29,7 +29,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -124,7 +124,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.KotlinHelloWorld
@@ -162,7 +162,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/helloworld/scala-hello-pubsub/pom.xml b/functions/helloworld/scala-hello-pubsub/pom.xml
index 8d10265746b..42add4724a9 100644
--- a/functions/helloworld/scala-hello-pubsub/pom.xml
+++ b/functions/helloworld/scala-hello-pubsub/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -41,7 +41,7 @@
org.scala-lang
scala-library
- 2.13.2
+ 2.13.3
@@ -106,7 +106,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.ScalaHelloBackground
@@ -129,7 +129,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/helloworld/scala-helloworld/pom.xml b/functions/helloworld/scala-helloworld/pom.xml
index 2b7458d8119..9e82d234f14 100644
--- a/functions/helloworld/scala-helloworld/pom.xml
+++ b/functions/helloworld/scala-helloworld/pom.xml
@@ -29,7 +29,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -44,7 +44,7 @@
org.scala-lang
scala-library
- 2.13.2
+ 2.13.3
@@ -118,7 +118,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.ScalaHelloWorld
@@ -142,7 +142,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/http/bearer-token-http/pom.xml b/functions/http/bearer-token-http/pom.xml
index 39eda7354bd..1995774b275 100644
--- a/functions/http/bearer-token-http/pom.xml
+++ b/functions/http/bearer-token-http/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -77,7 +77,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.BearerTokenHttp
@@ -85,7 +85,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/http/cors-enabled-auth/pom.xml b/functions/http/cors-enabled-auth/pom.xml
index 434e22b2847..a06dd1adba3 100644
--- a/functions/http/cors-enabled-auth/pom.xml
+++ b/functions/http/cors-enabled-auth/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -98,7 +98,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.CorsEnabledAuth
@@ -106,7 +106,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/http/cors-enabled/pom.xml b/functions/http/cors-enabled/pom.xml
index 6bdfed96f05..796e850615b 100644
--- a/functions/http/cors-enabled/pom.xml
+++ b/functions/http/cors-enabled/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -98,7 +98,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.CorsEnabled
@@ -106,7 +106,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/http/http-form-data/pom.xml b/functions/http/http-form-data/pom.xml
index 2f6ad7e29e3..a0687885058 100644
--- a/functions/http/http-form-data/pom.xml
+++ b/functions/http/http-form-data/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -104,7 +104,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.HttpFormData
@@ -112,7 +112,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/http/http-method/pom.xml b/functions/http/http-method/pom.xml
index d038775f17e..e1defdc79d2 100644
--- a/functions/http/http-method/pom.xml
+++ b/functions/http/http-method/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -97,7 +97,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.HttpMethod
@@ -105,7 +105,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/http/parse-content-type/pom.xml b/functions/http/parse-content-type/pom.xml
index 884f28aa8e0..cbbfe04887e 100644
--- a/functions/http/parse-content-type/pom.xml
+++ b/functions/http/parse-content-type/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -103,7 +103,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.ParseContentType
@@ -111,7 +111,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/http/parse-content-type/src/test/java/functions/ParseContentTypeTest.java b/functions/http/parse-content-type/src/test/java/functions/ParseContentTypeTest.java
index 36022d2ce15..6a3f09aa7f1 100644
--- a/functions/http/parse-content-type/src/test/java/functions/ParseContentTypeTest.java
+++ b/functions/http/parse-content-type/src/test/java/functions/ParseContentTypeTest.java
@@ -21,6 +21,7 @@
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;
+import com.google.gson.Gson;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
@@ -30,6 +31,7 @@
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
+import java.util.Map;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
@@ -45,6 +47,7 @@ public class ParseContentTypeTest {
private BufferedWriter writerOut;
private StringWriter responseOut;
+ private static Gson gson = new Gson();
@Before
public void beforeTest() throws IOException {
@@ -58,7 +61,8 @@ public void beforeTest() throws IOException {
@Test
public void parseContentTypeTest_json() throws IOException {
// Send a request with JSON data
- BufferedReader bodyReader = new BufferedReader(new StringReader("{\"name\":\"John\"}"));
+ String requestJson = gson.toJson(Map.of("name", "John"));
+ BufferedReader bodyReader = new BufferedReader(new StringReader(requestJson));
when(request.getContentType()).thenReturn(Optional.of("application/json"));
when(request.getReader()).thenReturn(bodyReader);
diff --git a/functions/http/send-http-request/pom.xml b/functions/http/send-http-request/pom.xml
index 3137f24f313..3b65eaef356 100644
--- a/functions/http/send-http-request/pom.xml
+++ b/functions/http/send-http-request/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -98,7 +98,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.SendHttpRequest
@@ -106,7 +106,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/imagemagick/pom.xml b/functions/imagemagick/pom.xml
index 8e673ddaf16..399c8930746 100644
--- a/functions/imagemagick/pom.xml
+++ b/functions/imagemagick/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -41,7 +41,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -117,7 +117,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.ImageMagick
@@ -125,7 +125,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/imagemagick/src/main/java/functions/ImageMagick.java b/functions/imagemagick/src/main/java/functions/ImageMagick.java
index 0955b1cb406..c2b6f3bcaa0 100644
--- a/functions/imagemagick/src/main/java/functions/ImageMagick.java
+++ b/functions/imagemagick/src/main/java/functions/ImageMagick.java
@@ -68,13 +68,12 @@ public void accept(GcsEvent gcsEvent, Context context) {
logger.info(String.format("Analyzing %s", gcsEvent.getName()));
// Construct request.
- List requests = new ArrayList<>();
ImageSource imgSource = ImageSource.newBuilder().setImageUri(gcsPath).build();
Image img = Image.newBuilder().setSource(imgSource).build();
Feature feature = Feature.newBuilder().setType(Type.SAFE_SEARCH_DETECTION).build();
AnnotateImageRequest request =
AnnotateImageRequest.newBuilder().addFeatures(feature).setImage(img).build();
- requests.add(request);
+ List requests = List.of(request);
// Send request to the Vision API.
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
@@ -113,13 +112,8 @@ private static void blur(BlobInfo blobInfo) throws IOException {
blob.downloadTo(download);
// Construct the command.
- List args = new ArrayList();
- args.add("convert");
- args.add(download.toString());
- args.add("-blur");
- args.add("0x8");
Path upload = Paths.get("/tmp/", "blurred-" + fileName);
- args.add(upload.toString());
+ List args = List.of("convert", download.toString(), "-blur", "0x8", upload.toString());
try {
ProcessBuilder pb = new ProcessBuilder(args);
Process process = pb.start();
diff --git a/functions/logging/log-helloworld/pom.xml b/functions/logging/log-helloworld/pom.xml
index 8c9654021cc..d4dca437ac6 100644
--- a/functions/logging/log-helloworld/pom.xml
+++ b/functions/logging/log-helloworld/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -78,7 +78,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.LogHelloWorld
@@ -88,7 +88,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/logging/retrieve-logs/pom.xml b/functions/logging/retrieve-logs/pom.xml
index db502d4bc07..5391d5370a0 100644
--- a/functions/logging/retrieve-logs/pom.xml
+++ b/functions/logging/retrieve-logs/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -41,7 +41,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -121,7 +121,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.RetrieveLogs
@@ -131,7 +131,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/logging/stackdriver-logging/pom.xml b/functions/logging/stackdriver-logging/pom.xml
index 1bac826122a..148d36f905a 100644
--- a/functions/logging/stackdriver-logging/pom.xml
+++ b/functions/logging/stackdriver-logging/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -104,7 +104,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.StackdriverLogging
@@ -114,7 +114,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/logging/stackdriver-logging/src/test/java/functions/StackdriverLoggingTest.java b/functions/logging/stackdriver-logging/src/test/java/functions/StackdriverLoggingTest.java
index 49b12c2d4e9..1478b454428 100644
--- a/functions/logging/stackdriver-logging/src/test/java/functions/StackdriverLoggingTest.java
+++ b/functions/logging/stackdriver-logging/src/test/java/functions/StackdriverLoggingTest.java
@@ -22,6 +22,7 @@
import com.google.gson.Gson;
import functions.eventpojos.PubSubMessage;
import java.io.IOException;
+import java.util.Map;
import java.util.logging.Logger;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -46,8 +47,11 @@ public static void beforeClass() {
@Test
public void stackdriverLogging() throws IOException {
- PubSubMessage pubsubMessage = gson.fromJson(
- "{\"data\":\"ZGF0YQ==\",\"messageId\":\"id\"}", PubSubMessage.class);
+ String messageJson = gson.toJson(Map.of(
+ "data", "ZGF0YQ==",
+ "messageId", "id"
+ ));
+ PubSubMessage pubsubMessage = gson.fromJson(messageJson, PubSubMessage.class);
new StackdriverLogging().accept(pubsubMessage, null);
String logMessage = LOG_HANDLER.getStoredLogRecords().get(0).getMessage();
diff --git a/functions/ocr/ocr-process-image/pom.xml b/functions/ocr/ocr-process-image/pom.xml
index 115c661b12d..a158ca33690 100644
--- a/functions/ocr/ocr-process-image/pom.xml
+++ b/functions/ocr/ocr-process-image/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -41,7 +41,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -121,7 +121,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.OcrProcessImage
@@ -131,7 +131,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/ocr/ocr-save-result/pom.xml b/functions/ocr/ocr-save-result/pom.xml
index 46520b0d2ef..4ce006b4d52 100644
--- a/functions/ocr/ocr-save-result/pom.xml
+++ b/functions/ocr/ocr-save-result/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -41,7 +41,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -121,7 +121,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.OcrSaveResult
@@ -131,7 +131,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/ocr/ocr-translate-text/pom.xml b/functions/ocr/ocr-translate-text/pom.xml
index 91fb643fb6d..634ef9ab801 100644
--- a/functions/ocr/ocr-translate-text/pom.xml
+++ b/functions/ocr/ocr-translate-text/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -41,7 +41,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -117,7 +117,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.OcrTranslateText
@@ -127,7 +127,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/ocr/ocr-translate-text/src/main/java/functions/OcrTranslateText.java b/functions/ocr/ocr-translate-text/src/main/java/functions/OcrTranslateText.java
index 5c4b575d8d0..e955e7887cc 100644
--- a/functions/ocr/ocr-translate-text/src/main/java/functions/OcrTranslateText.java
+++ b/functions/ocr/ocr-translate-text/src/main/java/functions/OcrTranslateText.java
@@ -36,10 +36,11 @@
import java.util.logging.Logger;
public class OcrTranslateText implements BackgroundFunction {
- // TODO set these environment variables
- private static final String PROJECT_ID = System.getenv("GCP_PROJECT");
- private static final String RESULTS_TOPIC_NAME = System.getenv("RESULT_TOPIC");
private static final Logger logger = Logger.getLogger(OcrTranslateText.class.getName());
+
+ // TODO set these environment variables
+ private static final String PROJECT_ID = getenv("GCP_PROJECT");
+ private static final String RESULTS_TOPIC_NAME = getenv("RESULT_TOPIC");
private static final String LOCATION_NAME = LocationName.of(PROJECT_ID, "global").toString();
private Publisher publisher;
@@ -97,5 +98,16 @@ public void accept(PubSubMessage pubSubMessage, Context context) {
logger.log(Level.SEVERE, "Error publishing translation save request: " + e.getMessage(), e);
}
}
+
+ // Avoid ungraceful deployment failures due to unset environment variables.
+ // If you get this warning you should redeploy with the variable set.
+ private static String getenv(String name) {
+ String value = System.getenv(name);
+ if (value == null) {
+ logger.warning("Environment variable " + name + " was not set");
+ value = "MISSING";
+ }
+ return value;
+ }
}
// [END functions_ocr_translate]
diff --git a/functions/pubsub/publish-message/pom.xml b/functions/pubsub/publish-message/pom.xml
index c1d50b2677a..4567fc936a4 100644
--- a/functions/pubsub/publish-message/pom.xml
+++ b/functions/pubsub/publish-message/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -41,7 +41,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -120,7 +120,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.PublishMessage
@@ -130,7 +130,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/pubsub/subscribe-to-topic/pom.xml b/functions/pubsub/subscribe-to-topic/pom.xml
index 44fc91d71a6..915b4862e9e 100644
--- a/functions/pubsub/subscribe-to-topic/pom.xml
+++ b/functions/pubsub/subscribe-to-topic/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -92,7 +92,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.SubscribeToTopic
@@ -102,7 +102,7 @@
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/functions/slack/pom.xml b/functions/slack/pom.xml
index e1b3613adf3..6148dd80c5e 100644
--- a/functions/slack/pom.xml
+++ b/functions/slack/pom.xml
@@ -27,11 +27,10 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
- 2.0.7
11
11
UTF-8
@@ -42,7 +41,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -101,24 +100,6 @@
29.0-jre
test
-
- org.powermock
- powermock-core
- ${powermock.version}
- test
-
-
- org.powermock
- powermock-module-junit4
- ${powermock.version}
- test
-
-
- org.powermock
- powermock-api-mockito2
- ${powermock.version}
- test
-
@@ -153,7 +134,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.SlackSlashCommand
@@ -161,7 +142,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
${skipTests}
sponge_log
diff --git a/functions/slack/src/main/java/functions/SlackSlashCommand.java b/functions/slack/src/main/java/functions/SlackSlashCommand.java
index 640000c7a24..eb101f73268 100644
--- a/functions/slack/src/main/java/functions/SlackSlashCommand.java
+++ b/functions/slack/src/main/java/functions/SlackSlashCommand.java
@@ -30,25 +30,47 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.security.GeneralSecurityException;
-import java.util.HashMap;
-import java.util.List;
+import java.util.Optional;
+import java.util.logging.Logger;
import java.util.stream.Collectors;
public class SlackSlashCommand implements HttpFunction {
// [START functions_slack_setup]
- private static final String API_KEY = System.getenv("KG_API_KEY");
- private static final String SLACK_SECRET = System.getenv("SLACK_SECRET");
+ private static final Logger logger = Logger.getLogger(SlackSlashCommand.class.getName());
+ private static final String API_KEY = getenv("KG_API_KEY");
+ private static final String SLACK_SECRET = getenv("SLACK_SECRET");
private static final Gson gson = new Gson();
- private Kgsearch kgClient;
- private SlackSignature.Verifier verifier;
+ private final String apiKey;
+ private final Kgsearch kgClient;
+ private final SlackSignature.Verifier verifier;
public SlackSlashCommand() throws IOException, GeneralSecurityException {
- kgClient = new Kgsearch.Builder(
+ this(new SlackSignature.Verifier(new SlackSignature.Generator(SLACK_SECRET)));
+ }
+
+ SlackSlashCommand(SlackSignature.Verifier verifier) throws IOException, GeneralSecurityException {
+ this(verifier, API_KEY);
+ }
+
+ SlackSlashCommand(SlackSignature.Verifier verifier, String apiKey)
+ throws IOException, GeneralSecurityException {
+ this.verifier = verifier;
+ this.apiKey = apiKey;
+ this.kgClient = new Kgsearch.Builder(
GoogleNetHttpTransport.newTrustedTransport(), new JacksonFactory(), null).build();
+ }
- verifier = new SlackSignature.Verifier(new SlackSignature.Generator(SLACK_SECRET));
+ // Avoid ungraceful deployment failures due to unset environment variables.
+ // If you get this warning you should redeploy with the variable set.
+ private static String getenv(String name) {
+ String value = System.getenv(name);
+ if (value == null) {
+ logger.warning("Environment variable " + name + " was not set");
+ value = "MISSING";
+ }
+ return value;
}
// [END functions_slack_setup]
@@ -60,18 +82,13 @@ public SlackSlashCommand() throws IOException, GeneralSecurityException {
* @return true if the provided request came from Slack, false otherwise
*/
boolean isValidSlackWebhook(HttpRequest request, String requestBody) {
-
// Check for headers
- HashMap> headers = new HashMap(request.getHeaders());
- if (!headers.containsKey("X-Slack-Request-Timestamp")
- || !headers.containsKey("X-Slack-Signature")) {
+ Optional maybeTimestamp = request.getFirstHeader("X-Slack-Request-Timestamp");
+ Optional maybeSignature = request.getFirstHeader("X-Slack-Signature");
+ if (!maybeTimestamp.isPresent() || !maybeSignature.isPresent()) {
return false;
}
- return verifier.isValid(
- headers.get("X-Slack-Request-Timestamp").get(0),
- requestBody,
- headers.get("X-Slack-Signature").get(0),
- 1L);
+ return verifier.isValid(maybeTimestamp.get(), requestBody, maybeSignature.get(), 1L);
}
// [END functions_verify_webhook]
@@ -145,7 +162,7 @@ String formatSlackMessage(JsonObject kgResponse, String query) {
JsonObject searchKnowledgeGraph(String query) throws IOException {
Kgsearch.Entities.Search kgRequest = kgClient.entities().search();
kgRequest.setQuery(query);
- kgRequest.setKey(API_KEY);
+ kgRequest.setKey(apiKey);
return gson.fromJson(kgRequest.execute().toString(), JsonObject.class);
}
diff --git a/functions/slack/src/test/java/functions/SlackSlashCommandTest.java b/functions/slack/src/test/java/functions/SlackSlashCommandTest.java
index 3f2d01da5f5..7ce6e619c13 100644
--- a/functions/slack/src/test/java/functions/SlackSlashCommandTest.java
+++ b/functions/slack/src/test/java/functions/SlackSlashCommandTest.java
@@ -17,15 +17,18 @@
package functions;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.powermock.api.mockito.PowerMockito.mock;
-import static org.powermock.api.mockito.PowerMockito.when;
+import static org.mockito.Mockito.when;
import com.github.seratch.jslack.app_backend.SlackSignature;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;
+import com.google.gson.Gson;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
@@ -33,20 +36,20 @@
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.security.GeneralSecurityException;
-import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
-import org.powermock.reflect.Whitebox;
+import org.mockito.MockitoAnnotations;
public class SlackSlashCommandTest {
private BufferedWriter writerOut;
private StringWriter responseOut;
+ private static final Gson gson = new Gson();
+
@Mock private HttpRequest request;
@Mock private HttpResponse response;
@@ -54,36 +57,27 @@ public class SlackSlashCommandTest {
@Before
public void beforeTest() throws IOException {
- request = mock(HttpRequest.class);
- when(request.getReader()).thenReturn(new BufferedReader(new StringReader("")));
+ MockitoAnnotations.initMocks(this);
- response = mock(HttpResponse.class);
+ when(request.getReader()).thenReturn(new BufferedReader(new StringReader("")));
responseOut = new StringWriter();
writerOut = new BufferedWriter(responseOut);
when(response.getWriter()).thenReturn(writerOut);
- alwaysValidVerifier = mock(SlackSignature.Verifier.class);
- when(alwaysValidVerifier.isValid(
- ArgumentMatchers.any(),
- ArgumentMatchers.any(),
- ArgumentMatchers.any(),
- ArgumentMatchers.anyLong())
- ).thenReturn(true);
+ when(alwaysValidVerifier.isValid(any(), any(), any(), anyLong())).thenReturn(true);
// Construct valid header list
- HashMap> validHeaders = new HashMap>();
String validSlackSignature = System.getenv("SLACK_TEST_SIGNATURE");
String timestamp = "0"; // start of Unix epoch
- validHeaders.put("X-Slack-Signature", Arrays.asList(validSlackSignature));
- validHeaders.put("X-Slack-Request-Timestamp", Arrays.asList(timestamp));
+ Map> validHeaders = Map.of(
+ "X-Slack-Signature", List.of(validSlackSignature),
+ "X-Slack-Request-Timestamp", List.of(timestamp));
when(request.getHeaders()).thenReturn(validHeaders);
-
- // Reset knowledge graph API key
- Whitebox.setInternalState(SlackSlashCommand.class, "API_KEY", System.getenv("KG_API_KEY"));
+ when(request.getFirstHeader(any())).thenCallRealMethod();
}
@Test
@@ -97,7 +91,8 @@ public void onlyAcceptsPostRequestsTest() throws IOException, GeneralSecurityExc
@Test
public void requiresSlackAuthHeadersTest() throws IOException, GeneralSecurityException {
- StringReader requestReadable = new StringReader("{ \"text\": \"foo\" }\n");
+ String jsonStr = gson.toJson(Map.of("text", "foo"));
+ StringReader requestReadable = new StringReader(jsonStr);
when(request.getMethod()).thenReturn("POST");
when(request.getReader()).thenReturn(new BufferedReader(requestReadable));
@@ -120,31 +115,30 @@ public void recognizesValidSlackTokenTest() throws IOException, GeneralSecurityE
verify(response, times(1)).setStatusCode(HttpURLConnection.HTTP_BAD_REQUEST);
}
- @Test(expected = GoogleJsonResponseException.class)
+ @Test
public void handlesSearchErrorTest() throws IOException, GeneralSecurityException {
- StringReader requestReadable = new StringReader("{ \"text\": \"foo\" }\n");
+ String jsonStr = gson.toJson(Map.of("text", "foo"));
+ StringReader requestReadable = new StringReader(jsonStr);
when(request.getReader()).thenReturn(new BufferedReader(requestReadable));
when(request.getMethod()).thenReturn("POST");
- SlackSlashCommand functionInstance = new SlackSlashCommand();
- Whitebox.setInternalState(functionInstance, "verifier", alwaysValidVerifier);
- Whitebox.setInternalState(SlackSlashCommand.class, "API_KEY", "gibberish");
+ SlackSlashCommand functionInstance = new SlackSlashCommand(alwaysValidVerifier, "gibberish");
// Should throw a GoogleJsonResponseException (due to invalid API key)
- functionInstance.service(request, response);
+ assertThrows(
+ GoogleJsonResponseException.class, () -> functionInstance.service(request, response));
}
@Test
public void handlesEmptyKgResultsTest() throws IOException, GeneralSecurityException {
- StringReader requestReadable = new StringReader("{ \"text\": \"asdfjkl13579\" }\n");
+ String jsonStr = gson.toJson(Map.of("text", "asdfjkl13579"));
+ StringReader requestReadable = new StringReader(jsonStr);
when(request.getReader()).thenReturn(new BufferedReader(requestReadable));
when(request.getMethod()).thenReturn("POST");
- SlackSlashCommand functionInstance = new SlackSlashCommand();
- Whitebox.setInternalState(functionInstance, "verifier", alwaysValidVerifier);
-
+ SlackSlashCommand functionInstance = new SlackSlashCommand(alwaysValidVerifier);
functionInstance.service(request, response);
@@ -154,14 +148,13 @@ public void handlesEmptyKgResultsTest() throws IOException, GeneralSecurityExcep
@Test
public void handlesPopulatedKgResultsTest() throws IOException, GeneralSecurityException {
- StringReader requestReadable = new StringReader("{ \"text\": \"lion\" }\n");
+ String jsonStr = gson.toJson(Map.of("text", "lion"));
+ StringReader requestReadable = new StringReader(jsonStr);
when(request.getReader()).thenReturn(new BufferedReader(requestReadable));
when(request.getMethod()).thenReturn("POST");
- SlackSlashCommand functionInstance = new SlackSlashCommand();
- Whitebox.setInternalState(functionInstance, "verifier", alwaysValidVerifier);
-
+ SlackSlashCommand functionInstance = new SlackSlashCommand(alwaysValidVerifier);
functionInstance.service(request, response);
diff --git a/functions/spanner/pom.xml b/functions/spanner/pom.xml
index ba644099d71..1a8627642b7 100644
--- a/functions/spanner/pom.xml
+++ b/functions/spanner/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -41,7 +41,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -114,7 +114,7 @@
-->
com.google.cloud.functions
function-maven-plugin
- 0.9.2
+ 0.9.3
functions.HelloSpanner
@@ -122,7 +122,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
**/*Test.java
diff --git a/healthcare/v1/pom.xml b/healthcare/v1/pom.xml
index 5355dbc6c2b..dedc223ff60 100644
--- a/healthcare/v1/pom.xml
+++ b/healthcare/v1/pom.xml
@@ -42,7 +42,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -64,7 +64,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 7.0.2
pom
import
@@ -75,13 +75,18 @@
com.google.apis
google-api-services-healthcare
- v1-rev20200501-1.30.9
+ v1-rev20200605-1.30.9
com.google.api-client
google-api-client
1.30.9
+
+ com.google.auth
+ google-auth-library-oauth2-http
+ 0.21.0
+
com.google.cloud
google-cloud-core
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetCreate.java b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetCreate.java
index 26c69e75fcd..f8226352f31 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetCreate.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetCreate.java
@@ -17,8 +17,6 @@
package snippets.healthcare.datasets;
// [START healthcare_create_dataset]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -28,6 +26,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Dataset;
import com.google.api.services.healthcare.v1.model.Operation;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -80,14 +80,14 @@ public static void datasetCreate(String projectId, String regionId, String datas
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetDeIdentify.java b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetDeIdentify.java
index d76cc8044b2..1f244c5097c 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetDeIdentify.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetDeIdentify.java
@@ -17,8 +17,6 @@
package snippets.healthcare.datasets;
// [START healthcare_dicom_keeplist_deidentify_dataset]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -31,6 +29,8 @@
import com.google.api.services.healthcare.v1.model.DicomConfig;
import com.google.api.services.healthcare.v1.model.Operation;
import com.google.api.services.healthcare.v1.model.TagFilterList;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@@ -89,14 +89,14 @@ public static void datasetDeIdentify(String srcDatasetName, String destDatasetNa
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetDelete.java b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetDelete.java
index d64675c4d98..0b75cc9aceb 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetDelete.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetDelete.java
@@ -17,8 +17,6 @@
package snippets.healthcare.datasets;
// [START healthcare_delete_dataset]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -26,6 +24,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -52,14 +52,14 @@ public static void datasetDelete(String datasetName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetGet.java b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetGet.java
index b8e6edf72df..e124f232b7f 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetGet.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetGet.java
@@ -17,8 +17,6 @@
package snippets.healthcare.datasets;
// [START healthcare_get_dataset]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Dataset;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -53,14 +53,14 @@ public static void datasetGet(String datasetName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetGetIamPolicy.java b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetGetIamPolicy.java
index c0f1e534cee..0159be977a6 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetGetIamPolicy.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetGetIamPolicy.java
@@ -17,8 +17,6 @@
package snippets.healthcare.datasets;
// [START healthcare_dataset_get_iam_policy]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Policy;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -54,14 +54,14 @@ public static void datasetGetIamPolicy(String datasetName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetList.java b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetList.java
index 1e633971117..782cce407f2 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetList.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetList.java
@@ -17,8 +17,6 @@
package snippets.healthcare.datasets;
// [START healthcare_list_datasets]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -28,6 +26,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Dataset;
import com.google.api.services.healthcare.v1.model.ListDatasetsResponse;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -77,14 +77,14 @@ public static void datasetList(String projectId, String regionId) throws IOExcep
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetPatch.java b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetPatch.java
index eb6ae45b5ed..c399532dd2d 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetPatch.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetPatch.java
@@ -17,8 +17,6 @@
package snippets.healthcare.datasets;
// [START healthcare_patch_dataset]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Dataset;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -67,14 +67,14 @@ public static void datasetPatch(String datasetName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetSetIamPolicy.java b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetSetIamPolicy.java
index abccc78a551..0a7e966866f 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetSetIamPolicy.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/datasets/DatasetSetIamPolicy.java
@@ -17,8 +17,6 @@
package snippets.healthcare.datasets;
// [START healthcare_dataset_set_iam_policy]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -29,6 +27,8 @@
import com.google.api.services.healthcare.v1.model.Binding;
import com.google.api.services.healthcare.v1.model.Policy;
import com.google.api.services.healthcare.v1.model.SetIamPolicyRequest;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@@ -67,14 +67,14 @@ public static void datasetSetIamPolicy(String datasetName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreCreate.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreCreate.java
index e9f06f62aa1..a5d0d365f1f 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreCreate.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreCreate.java
@@ -17,8 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_create_dicom_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.DicomStore;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
@@ -68,14 +68,14 @@ public static void dicomStoreCreate(String datasetName, String dicomStoreId) thr
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreDelete.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreDelete.java
index 6f0431ee01c..fc937c985b9 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreDelete.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreDelete.java
@@ -17,8 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_delete_dicom_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -26,6 +24,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -54,14 +54,14 @@ public static void deleteDicomStore(String dicomStoreName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreExport.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreExport.java
index 69071f721aa..ed1a63f984b 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreExport.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreExport.java
@@ -17,8 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_export_dicom_instance_gcs]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -29,6 +27,8 @@
import com.google.api.services.healthcare.v1.model.ExportDicomDataRequest;
import com.google.api.services.healthcare.v1.model.GoogleCloudHealthcareV1DicomGcsDestination;
import com.google.api.services.healthcare.v1.model.Operation;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -86,14 +86,14 @@ public static void dicomStoreExport(String dicomStoreName, String gcsUri) throws
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreGet.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreGet.java
index 74a39e898fe..6f0bda847e4 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreGet.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreGet.java
@@ -17,8 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_get_dicom_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.DicomStore;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -55,14 +55,14 @@ public static void dicomeStoreGet(String dicomStoreName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreGetIamPolicy.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreGetIamPolicy.java
index 9b363f58f3b..566a86d5fce 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreGetIamPolicy.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreGetIamPolicy.java
@@ -17,8 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_dicom_store_get_iam_policy]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Policy;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -55,14 +55,14 @@ public static void dicomStoreGetIamPolicy(String dicomStoreName) throws IOExcept
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreImport.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreImport.java
index 84de170fe96..3458e431ff9 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreImport.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreImport.java
@@ -17,8 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_import_dicom_instance]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -29,6 +27,8 @@
import com.google.api.services.healthcare.v1.model.GoogleCloudHealthcareV1DicomGcsSource;
import com.google.api.services.healthcare.v1.model.ImportDicomDataRequest;
import com.google.api.services.healthcare.v1.model.Operation;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -85,14 +85,14 @@ public static void dicomStoreImport(String dicomStoreName, String gcsUri) throws
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreList.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreList.java
index 468a03c46c1..c0e17f548e2 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreList.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreList.java
@@ -17,8 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_list_dicom_stores]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -28,6 +26,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.DicomStore;
import com.google.api.services.healthcare.v1.model.ListDicomStoresResponse;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -78,14 +78,14 @@ public static void dicomStoreList(String datasetName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStorePatch.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStorePatch.java
index 9a3ed372a9c..38fd8856421 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStorePatch.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStorePatch.java
@@ -17,8 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_patch_dicom_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -28,6 +26,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.DicomStore;
import com.google.api.services.healthcare.v1.model.NotificationConfig;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -72,14 +72,14 @@ public static void patchDicomStore(String dicomStoreName, String pubsubTopic) th
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreSetIamPolicy.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreSetIamPolicy.java
index c014b606661..5fb1f84e8a8 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreSetIamPolicy.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomStoreSetIamPolicy.java
@@ -17,8 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_dicom_store_set_iam_policy]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -29,6 +27,8 @@
import com.google.api.services.healthcare.v1.model.Binding;
import com.google.api.services.healthcare.v1.model.Policy;
import com.google.api.services.healthcare.v1.model.SetIamPolicyRequest;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@@ -73,14 +73,14 @@ public static void dicomStoreSetIamPolicy(String dicomStoreName) throws IOExcept
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebDeleteStudy.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebDeleteStudy.java
index 3f65e951b92..7491242d0dc 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebDeleteStudy.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebDeleteStudy.java
@@ -17,8 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_dicomweb_delete_study]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -26,6 +24,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores.Studies;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -61,14 +61,14 @@ public static void dicomWebDeleteStudy(String dicomStoreName, String studyId) th
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveInstance.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveInstance.java
index a924fae55f3..3edbab2a42c 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveInstance.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveInstance.java
@@ -17,7 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_dicomweb_retrieve_instance]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpResponse;
@@ -27,14 +26,13 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores.Studies.Series.Instances;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
-import java.io.BufferedReader;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Collections;
-import java.util.stream.Collectors;
public class DicomWebRetrieveInstance {
private static final String DICOM_NAME = "projects/%s/locations/%s/datasets/%s/dicomStores/%s";
@@ -79,18 +77,16 @@ public static void dicomWebRetrieveInstance(String dicomStoreName, String dicomW
if (!response.isSuccessStatusCode()) {
System.err.print(
- String.format(
- "Exception retrieving DICOM instance: %s\n", response.getStatusMessage()));
+ String.format("Exception retrieving DICOM instance: %s\n", response.getStatusMessage()));
throw new RuntimeException();
}
-
}
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
HttpHeaders headers = new HttpHeaders();
@@ -102,8 +98,7 @@ private static CloudHealthcare createClient() throws IOException {
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
- request.setHeaders(headers);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -115,4 +110,3 @@ private static CloudHealthcare createClient() throws IOException {
}
}
// [END healthcare_dicomweb_retrieve_instance]
-
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveRendered.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveRendered.java
index 71df54edf2a..ea802325be5 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveRendered.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveRendered.java
@@ -17,7 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_dicomweb_retrieve_rendered]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpResponse;
@@ -27,14 +26,13 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores.Studies.Series.Instances;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
-import java.io.BufferedReader;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Collections;
-import java.util.stream.Collectors;
public class DicomWebRetrieveRendered {
private static final String DICOM_NAME = "projects/%s/locations/%s/datasets/%s/dicomStores/%s";
@@ -83,14 +81,13 @@ public static void dicomWebRetrieveRendered(String dicomStoreName, String dicomW
"Exception retrieving DICOM rendered image: %s\n", response.getStatusMessage()));
throw new RuntimeException();
}
-
}
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
HttpHeaders headers = new HttpHeaders();
@@ -100,8 +97,7 @@ private static CloudHealthcare createClient() throws IOException {
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
- request.setHeaders(headers);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -113,4 +109,3 @@ private static CloudHealthcare createClient() throws IOException {
}
}
// [END healthcare_dicomweb_retrieve_rendered]
-
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveStudy.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveStudy.java
index 39d6d9931b3..006359b9804 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveStudy.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebRetrieveStudy.java
@@ -17,7 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_dicomweb_retrieve_study]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpResponse;
@@ -27,14 +26,13 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores.Studies;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
-import java.io.BufferedReader;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Collections;
-import java.util.stream.Collectors;
public class DicomWebRetrieveStudy {
private static final String DICOM_NAME = "projects/%s/locations/%s/datasets/%s/dicomStores/%s";
@@ -78,18 +76,16 @@ public static void dicomWebRetrieveStudy(String dicomStoreName, String studyId)
if (!response.isSuccessStatusCode()) {
System.err.print(
- String.format(
- "Exception retrieving DICOM study: %s\n", response.getStatusMessage()));
+ String.format("Exception retrieving DICOM study: %s\n", response.getStatusMessage()));
throw new RuntimeException();
}
-
}
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
HttpHeaders headers = new HttpHeaders();
@@ -104,8 +100,7 @@ private static CloudHealthcare createClient() throws IOException {
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
- request.setHeaders(headers);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -117,4 +112,3 @@ private static CloudHealthcare createClient() throws IOException {
}
}
// [END healthcare_dicomweb_retrieve_study]
-
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebSearchForInstances.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebSearchForInstances.java
index e050a0e41e8..3dbc89b4d3e 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebSearchForInstances.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebSearchForInstances.java
@@ -17,7 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_dicomweb_search_instances]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.javanet.NetHttpTransport;
@@ -26,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -59,14 +60,14 @@ public static void dicomWebSearchForInstances(String dicomStoreName) throws IOEx
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebSearchStudies.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebSearchStudies.java
index f4839e0cf4f..e63d172416e 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebSearchStudies.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebSearchStudies.java
@@ -17,7 +17,6 @@
package snippets.healthcare.dicom;
// [START healthcare_dicomweb_search_studies]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.javanet.NetHttpTransport;
@@ -26,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -62,14 +63,14 @@ public static void dicomWebSearchStudies(String dicomStoreName) throws IOExcepti
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebStoreInstance.java b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebStoreInstance.java
index aef52d4ed54..8cb6d63a685 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebStoreInstance.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/dicom/DicomWebStoreInstance.java
@@ -17,13 +17,14 @@
package snippets.healthcare.dicom;
// [START healthcare_dicomweb_store_instance]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
@@ -56,27 +57,26 @@ public static void dicomWebStoreInstance(String dicomStoreName, String filePath)
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s/dicomWeb/studies", client.getRootUrl(), dicomStoreName);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
+ String uri = String.format("%sv1/%s/dicomWeb/studies", client.getRootUrl(), dicomStoreName);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
// Load the data from file representing the study.
File f = new File(filePath);
byte[] dicomBytes = Files.readAllBytes(Paths.get(filePath));
ByteArrayEntity requestEntity = new ByteArrayEntity(dicomBytes);
- HttpUriRequest request = RequestBuilder
- .post(uriBuilder.build())
- .setEntity(requestEntity)
- .addHeader("Content-Type","application/dicom")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.post(uriBuilder.build())
+ .setEntity(requestEntity)
+ .addHeader("Content-Type", "application/dicom")
+ .build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- System.err.print(String.format(
- "Exception storing DICOM instance: %s\n", response.getStatusLine().toString()));
+ System.err.print(
+ String.format(
+ "Exception storing DICOM instance: %s\n", response.getStatusLine().toString()));
responseEntity.writeTo(System.err);
throw new RuntimeException();
}
@@ -87,14 +87,14 @@ public static void dicomWebStoreInstance(String dicomStoreName, String filePath)
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -106,11 +106,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_dicomweb_store_instance]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreCreate.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreCreate.java
index bdd9b29ef20..a32b4e6db4d 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreCreate.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreCreate.java
@@ -17,8 +17,6 @@
package snippets.healthcare.fhir;
// [START healthcare_create_fhir_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.FhirStore;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
@@ -70,14 +70,14 @@ public static void fhirStoreCreate(String datasetName, String fhirStoreId) throw
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreDelete.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreDelete.java
index 54f60b3bb86..45a50a40c02 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreDelete.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreDelete.java
@@ -17,8 +17,6 @@
package snippets.healthcare.fhir;
// [START healthcare_delete_fhir_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -26,6 +24,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -54,14 +54,14 @@ public static void fhirStoreDelete(String fhirStoreName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreExecuteBundle.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreExecuteBundle.java
index 53ef44f9e39..0201af252d6 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreExecuteBundle.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreExecuteBundle.java
@@ -17,13 +17,14 @@
package snippets.healthcare.fhir;
// [START healthcare_fhir_execute_bundle]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -53,25 +54,25 @@ public static void fhirStoreExecuteBundle(String fhirStoreName, String data)
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
String baseUri = String.format("%sv1/%s/fhir", client.getRootUrl(), fhirStoreName);
- URIBuilder uriBuilder = new URIBuilder(baseUri)
- .setParameter("access_token", getAccessToken());
+ URIBuilder uriBuilder = new URIBuilder(baseUri).setParameter("access_token", getAccessToken());
StringEntity requestEntity = new StringEntity(data);
- HttpUriRequest request = RequestBuilder
- .post()
- .setUri(uriBuilder.build())
- .setEntity(requestEntity)
- .addHeader("Content-Type", "application/fhir+json")
- .addHeader("Accept-Charset", "utf-8")
- .addHeader("Accept", "application/fhir+json; charset=utf-8")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.post()
+ .setUri(uriBuilder.build())
+ .setEntity(requestEntity)
+ .addHeader("Content-Type", "application/fhir+json")
+ .addHeader("Accept-Charset", "utf-8")
+ .addHeader("Accept", "application/fhir+json; charset=utf-8")
+ .build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- System.err.print(String.format(
- "Exception executing FHIR bundle: %s\n", response.getStatusLine().toString()));
+ System.err.print(
+ String.format(
+ "Exception executing FHIR bundle: %s\n", response.getStatusLine().toString()));
responseEntity.writeTo(System.err);
throw new RuntimeException();
}
@@ -82,14 +83,14 @@ public static void fhirStoreExecuteBundle(String fhirStoreName, String data)
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -101,11 +102,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_fhir_execute_bundle]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreExport.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreExport.java
index eaf1faffae2..97492d654f7 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreExport.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreExport.java
@@ -17,8 +17,6 @@
package snippets.healthcare.fhir;
// [START healthcare_export_fhir_resources_gcs]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -29,6 +27,8 @@
import com.google.api.services.healthcare.v1.model.ExportResourcesRequest;
import com.google.api.services.healthcare.v1.model.GoogleCloudHealthcareV1FhirGcsDestination;
import com.google.api.services.healthcare.v1.model.Operation;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -81,14 +81,14 @@ public static void fhirStoreExport(String fhirStoreName, String gcsUri) throws I
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGet.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGet.java
index 45d5e59254e..d8286ae6ddc 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGet.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGet.java
@@ -17,8 +17,6 @@
package snippets.healthcare.fhir;
// [START healthcare_get_fhir_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.FhirStore;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -55,14 +55,14 @@ public static void fhirStoreGet(String fhirStoreName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGetIamPolicy.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGetIamPolicy.java
index ff4ab3fa569..efa97dcd8d5 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGetIamPolicy.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGetIamPolicy.java
@@ -17,8 +17,6 @@
package snippets.healthcare.fhir;
// [START healthcare_fhir_store_get_iam_policy]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Policy;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -55,14 +55,14 @@ public static void fhirStoreGetIamPolicy(String fhirStoreName) throws IOExceptio
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGetMetadata.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGetMetadata.java
index cba58f8abb3..b6c7707c93e 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGetMetadata.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreGetMetadata.java
@@ -17,7 +17,6 @@
package snippets.healthcare.fhir;
// [START healthcare_get_metadata]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -26,12 +25,13 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores.Fhir.Capabilities;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.HttpBody;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
public class FhirStoreGetMetadata {
- private static final String FHIR_NAME =
- "projects/%s/locations/%s/datasets/%s/fhirStores/%s";
+ private static final String FHIR_NAME = "projects/%s/locations/%s/datasets/%s/fhirStores/%s";
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();
@@ -55,14 +55,14 @@ public static void fhirStoreGetMetadata(String fhirStoreName) throws IOException
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreImport.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreImport.java
index 9bb3575d26e..d4e812137c1 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreImport.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreImport.java
@@ -17,8 +17,6 @@
package snippets.healthcare.fhir;
// [START healthcare_import_fhir_resources]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -29,6 +27,8 @@
import com.google.api.services.healthcare.v1.model.GoogleCloudHealthcareV1FhirGcsSource;
import com.google.api.services.healthcare.v1.model.ImportResourcesRequest;
import com.google.api.services.healthcare.v1.model.Operation;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -85,14 +85,14 @@ public static void fhirStoreImport(String fhirStoreName, String gcsUri) throws I
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreList.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreList.java
index ec70ef42fde..62f21dfa553 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreList.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreList.java
@@ -17,8 +17,6 @@
package snippets.healthcare.fhir;
// [START healthcare_list_fhir_stores]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -28,6 +26,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.FhirStore;
import com.google.api.services.healthcare.v1.model.ListFhirStoresResponse;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -78,14 +78,14 @@ public static void fhirStoreList(String datasetName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStorePatch.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStorePatch.java
index ff379400558..3ef8f6d1e49 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStorePatch.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStorePatch.java
@@ -17,8 +17,6 @@
package snippets.healthcare.fhir;
// [START healthcare_patch_fhir_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -28,6 +26,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.FhirStore;
import com.google.api.services.healthcare.v1.model.NotificationConfig;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -72,14 +72,14 @@ public static void fhirStorePatch(String fhirStoreName, String pubsubTopic) thro
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreSetIamPolicy.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreSetIamPolicy.java
index 2ab09db85f6..4ec2b8d9211 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreSetIamPolicy.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStoreSetIamPolicy.java
@@ -17,8 +17,6 @@
package snippets.healthcare.fhir;
// [START healthcare_fhir_store_set_iam_policy]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -29,6 +27,8 @@
import com.google.api.services.healthcare.v1.model.Binding;
import com.google.api.services.healthcare.v1.model.Policy;
import com.google.api.services.healthcare.v1.model.SetIamPolicyRequest;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@@ -73,14 +73,14 @@ public static void fhirStoreSetIamPolicy(String fhirStoreName) throws IOExceptio
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceCreate.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceCreate.java
index acc1bad37b0..615eeb2b34e 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceCreate.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceCreate.java
@@ -17,13 +17,14 @@
package snippets.healthcare.fhir.resources;
// [START healthcare_create_resource]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -52,28 +53,27 @@ public static void fhirResourceCreate(String fhirStoreName, String resourceType)
// Initialize the client, which will be used to interact with the service.
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s/fhir/%s", client.getRootUrl(), fhirStoreName, resourceType);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
- StringEntity requestEntity = new StringEntity(
- "{\"resourceType\": \"" + resourceType + "\", \"language\": \"en\"}");
+ String uri = String.format("%sv1/%s/fhir/%s", client.getRootUrl(), fhirStoreName, resourceType);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
+ StringEntity requestEntity =
+ new StringEntity("{\"resourceType\": \"" + resourceType + "\", \"language\": \"en\"}");
- HttpUriRequest request = RequestBuilder
- .post()
- .setUri(uriBuilder.build())
- .setEntity(requestEntity)
- .addHeader("Content-Type", "application/fhir+json")
- .addHeader("Accept-Charset", "utf-8")
- .addHeader("Accept", "application/fhir+json; charset=utf-8")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.post()
+ .setUri(uriBuilder.build())
+ .setEntity(requestEntity)
+ .addHeader("Content-Type", "application/fhir+json")
+ .addHeader("Accept-Charset", "utf-8")
+ .addHeader("Accept", "application/fhir+json; charset=utf-8")
+ .build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
- System.err.print(String.format(
- "Exception creating FHIR resource: %s\n", response.getStatusLine().toString()));
+ System.err.print(
+ String.format(
+ "Exception creating FHIR resource: %s\n", response.getStatusLine().toString()));
responseEntity.writeTo(System.err);
throw new RuntimeException();
}
@@ -84,14 +84,14 @@ public static void fhirResourceCreate(String fhirStoreName, String resourceType)
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -103,11 +103,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_create_resource]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceDelete.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceDelete.java
index 64c7949ac7e..55cb20f21c1 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceDelete.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceDelete.java
@@ -17,13 +17,14 @@
package snippets.healthcare.fhir.resources;
// [START healthcare_delete_resource]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -53,25 +54,28 @@ public static void fhirResourceDelete(String resourceName)
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s", client.getRootUrl(), resourceName);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
+ String uri = String.format("%sv1/%s", client.getRootUrl(), resourceName);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
- HttpUriRequest request = RequestBuilder
- .delete()
- .setUri(uriBuilder.build())
- .addHeader("Content-Type", "application/fhir+json")
- .addHeader("Accept-Charset", "utf-8")
- .addHeader("Accept", "application/fhir+json; charset=utf-8")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.delete()
+ .setUri(uriBuilder.build())
+ .addHeader("Content-Type", "application/fhir+json")
+ .addHeader("Accept-Charset", "utf-8")
+ .addHeader("Accept", "application/fhir+json; charset=utf-8")
+ .build();
// Execute the request and process the results.
+ // Regardless of whether the operation succeeds or
+ // fails, the server returns a 200 OK HTTP status code. To check that the
+ // resource was successfully deleted, search for or get the resource and
+ // see if it exists.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- String errorMessage = String.format(
- "Exception deleting FHIR resource: %s\n", response.getStatusLine().toString());
+ String errorMessage =
+ String.format(
+ "Exception deleting FHIR resource: %s\n", response.getStatusLine().toString());
System.err.print(errorMessage);
responseEntity.writeTo(System.err);
throw new RuntimeException(errorMessage);
@@ -83,14 +87,14 @@ public static void fhirResourceDelete(String resourceName)
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -102,11 +106,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_delete_resource]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceDeletePurge.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceDeletePurge.java
index b0739ca505a..88fb4b95a04 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceDeletePurge.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceDeletePurge.java
@@ -17,13 +17,14 @@
package snippets.healthcare.fhir.resources;
// [START healthcare_delete_resource_purge]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -52,25 +53,24 @@ public static void fhirResourceDeletePurge(String resourceName)
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s/$purge", client.getRootUrl(), resourceName);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
+ String uri = String.format("%sv1/%s/$purge", client.getRootUrl(), resourceName);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
- HttpUriRequest request = RequestBuilder
- .delete()
- .setUri(uriBuilder.build())
- .addHeader("Content-Type", "application/fhir+json")
- .addHeader("Accept-Charset", "utf-8")
- .addHeader("Accept", "application/fhir+json; charset=utf-8")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.delete()
+ .setUri(uriBuilder.build())
+ .addHeader("Content-Type", "application/fhir+json")
+ .addHeader("Accept-Charset", "utf-8")
+ .addHeader("Accept", "application/fhir+json; charset=utf-8")
+ .build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- String errorMessage = String.format(
- "Exception purging FHIR resource: %s\n", response.getStatusLine().toString());
+ String errorMessage =
+ String.format(
+ "Exception purging FHIR resource: %s\n", response.getStatusLine().toString());
System.err.print(errorMessage);
responseEntity.writeTo(System.err);
throw new RuntimeException(errorMessage);
@@ -82,14 +82,14 @@ public static void fhirResourceDeletePurge(String resourceName)
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -101,11 +101,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_delete_resource_purge]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGet.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGet.java
index ff4c2a465f9..3e3da1b03d1 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGet.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGet.java
@@ -17,13 +17,14 @@
package snippets.healthcare.fhir.resources;
// [START healthcare_get_resource]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -51,22 +52,18 @@ public static void fhirResourceGet(String resourceName) throws IOException, URIS
// Initialize the client, which will be used to interact with the service.
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s", client.getRootUrl(), resourceName);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
+ String uri = String.format("%sv1/%s", client.getRootUrl(), resourceName);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
- HttpUriRequest request = RequestBuilder
- .get()
- .setUri(uriBuilder.build())
- .build();
+ HttpUriRequest request = RequestBuilder.get().setUri(uriBuilder.build()).build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- String errorMessage = String.format(
- "Exception retrieving FHIR resource: %s\n", response.getStatusLine().toString());
+ String errorMessage =
+ String.format(
+ "Exception retrieving FHIR resource: %s\n", response.getStatusLine().toString());
System.err.print(errorMessage);
responseEntity.writeTo(System.err);
throw new RuntimeException(errorMessage);
@@ -78,14 +75,14 @@ public static void fhirResourceGet(String resourceName) throws IOException, URIS
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -97,11 +94,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_get_resource]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGetHistory.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGetHistory.java
index 251c619220c..7778f263071 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGetHistory.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGetHistory.java
@@ -17,13 +17,14 @@
package snippets.healthcare.fhir.resources;
// [START healthcare_get_resource_history]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -54,25 +55,24 @@ public static void fhirResourceGetHistory(String resourceName, String versionId)
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s/_history/%s", client.getRootUrl(), resourceName, versionId);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
+ String uri = String.format("%sv1/%s/_history/%s", client.getRootUrl(), resourceName, versionId);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
- HttpUriRequest request = RequestBuilder
- .get()
- .setUri(uriBuilder.build())
- .addHeader("Content-Type", "application/fhir+json")
- .addHeader("Accept-Charset", "utf-8")
- .addHeader("Accept", "application/fhir+json; charset=utf-8")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.get()
+ .setUri(uriBuilder.build())
+ .addHeader("Content-Type", "application/fhir+json")
+ .addHeader("Accept-Charset", "utf-8")
+ .addHeader("Accept", "application/fhir+json; charset=utf-8")
+ .build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- System.err.print(String.format(
- "Exception retrieving FHIR history: %s\n", response.getStatusLine().toString()));
+ System.err.print(
+ String.format(
+ "Exception retrieving FHIR history: %s\n", response.getStatusLine().toString()));
responseEntity.writeTo(System.err);
throw new RuntimeException();
}
@@ -83,16 +83,16 @@ public static void fhirResourceGetHistory(String resourceName, String versionId)
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
- request.setConnectTimeout(1 * 60 * 1000); // 1 minute connect timeout
- request.setReadTimeout(1 * 60 * 1000); // 1 minute read timeout
+ new HttpCredentialsAdapter(credential).initialize(request);
+ request.setConnectTimeout(60000); // 1 minute connect timeout
+ request.setReadTimeout(60000); // 1 minute read timeout
};
// Build the client for interacting with the service.
@@ -102,11 +102,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_get_resource_history]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGetPatientEverything.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGetPatientEverything.java
index 79d0bcc7565..e686ffbd519 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGetPatientEverything.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceGetPatientEverything.java
@@ -17,13 +17,14 @@
package snippets.healthcare.fhir.resources;
// [START healthcare_get_patient_everything]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -52,25 +53,24 @@ public static void fhirResourceGetPatientEverything(String resourceName)
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s/$everything", client.getRootUrl(), resourceName);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
+ String uri = String.format("%sv1/%s/$everything", client.getRootUrl(), resourceName);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
- HttpUriRequest request = RequestBuilder
- .get(uriBuilder.build())
- .addHeader("Content-Type", "application/json-patch+json")
- .addHeader("Accept-Charset", "utf-8")
- .addHeader("Accept", "application/fhir+json; charset=utf-8")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.get(uriBuilder.build())
+ .addHeader("Content-Type", "application/json-patch+json")
+ .addHeader("Accept-Charset", "utf-8")
+ .addHeader("Accept", "application/fhir+json; charset=utf-8")
+ .build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- System.err.print(String.format(
- "Exception getting patient everythingresource: %s\n",
- response.getStatusLine().toString()));
+ System.err.print(
+ String.format(
+ "Exception getting patient everythingresource: %s\n",
+ response.getStatusLine().toString()));
responseEntity.writeTo(System.err);
throw new RuntimeException();
}
@@ -81,14 +81,14 @@ public static void fhirResourceGetPatientEverything(String resourceName)
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -100,11 +100,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_get_patient_everything]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceListHistory.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceListHistory.java
index 45b315aceba..d28c8d3d970 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceListHistory.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceListHistory.java
@@ -18,13 +18,14 @@
// [START healthcare_list_resource_history]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -54,25 +55,24 @@ public static void fhirResourceListHistory(String resourceName)
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s/_history", client.getRootUrl(), resourceName);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
+ String uri = String.format("%sv1/%s/_history", client.getRootUrl(), resourceName);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
- HttpUriRequest request = RequestBuilder
- .get()
- .setUri(uriBuilder.build())
- .addHeader("Content-Type", "application/fhir+json")
- .addHeader("Accept-Charset", "utf-8")
- .addHeader("Accept", "application/fhir+json; charset=utf-8")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.get()
+ .setUri(uriBuilder.build())
+ .addHeader("Content-Type", "application/fhir+json")
+ .addHeader("Accept-Charset", "utf-8")
+ .addHeader("Accept", "application/fhir+json; charset=utf-8")
+ .build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- System.err.print(String.format(
- "Exception retrieving FHIR history: %s\n", response.getStatusLine().toString()));
+ System.err.print(
+ String.format(
+ "Exception retrieving FHIR history: %s\n", response.getStatusLine().toString()));
responseEntity.writeTo(System.err);
throw new RuntimeException();
}
@@ -83,16 +83,16 @@ public static void fhirResourceListHistory(String resourceName)
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
- request.setConnectTimeout(1 * 60 * 1000); // 1 minute connect timeout
- request.setReadTimeout(1 * 60 * 1000); // 1 minute read timeout
+ new HttpCredentialsAdapter(credential).initialize(request);
+ request.setConnectTimeout(60000); // 1 minute connect timeout
+ request.setReadTimeout(60000); // 1 minute read timeout
};
// Build the client for interacting with the service.
@@ -102,11 +102,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_list_resource_history]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourcePatch.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourcePatch.java
index 73f4330701d..02b12d9e671 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourcePatch.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourcePatch.java
@@ -17,13 +17,14 @@
package snippets.healthcare.fhir.resources;
// [START healthcare_patch_resource]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -55,26 +56,25 @@ public static void fhirResourcePatch(String resourceName, String data)
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s", client.getRootUrl(), resourceName);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
+ String uri = String.format("%sv1/%s", client.getRootUrl(), resourceName);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
StringEntity requestEntity = new StringEntity(data);
- HttpUriRequest request = RequestBuilder
- .patch(uriBuilder.build())
- .setEntity(requestEntity)
- .addHeader("Content-Type", "application/json-patch+json")
- .addHeader("Accept-Charset", "utf-8")
- .addHeader("Accept", "application/fhir+json; charset=utf-8")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.patch(uriBuilder.build())
+ .setEntity(requestEntity)
+ .addHeader("Content-Type", "application/json-patch+json")
+ .addHeader("Accept-Charset", "utf-8")
+ .addHeader("Accept", "application/fhir+json; charset=utf-8")
+ .build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- System.err.print(String.format(
- "Exception patching FHIR resource: %s\n", response.getStatusLine().toString()));
+ System.err.print(
+ String.format(
+ "Exception patching FHIR resource: %s\n", response.getStatusLine().toString()));
responseEntity.writeTo(System.err);
throw new RuntimeException();
}
@@ -85,14 +85,14 @@ public static void fhirResourcePatch(String resourceName, String data)
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -104,11 +104,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_patch_resource]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceSearchGet.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceSearchGet.java
index 18d0ad81950..cd323464351 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceSearchGet.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceSearchGet.java
@@ -17,13 +17,14 @@
package snippets.healthcare.fhir.resources;
// [START healthcare_search_resources_get]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -52,25 +53,24 @@ public static void fhirResourceSearchGet(String resourceName)
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s", client.getRootUrl(), resourceName);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
+ String uri = String.format("%sv1/%s", client.getRootUrl(), resourceName);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
- HttpUriRequest request = RequestBuilder
- .get()
- .setUri(uriBuilder.build())
- .addHeader("Content-Type", "application/fhir+json")
- .addHeader("Accept-Charset", "utf-8")
- .addHeader("Accept", "application/fhir+json; charset=utf-8")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.get()
+ .setUri(uriBuilder.build())
+ .addHeader("Content-Type", "application/fhir+json")
+ .addHeader("Accept-Charset", "utf-8")
+ .addHeader("Accept", "application/fhir+json; charset=utf-8")
+ .build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- System.err.print(String.format(
- "Exception searching GET FHIR resources: %s\n", response.getStatusLine().toString()));
+ System.err.print(
+ String.format(
+ "Exception searching GET FHIR resources: %s\n", response.getStatusLine().toString()));
responseEntity.writeTo(System.err);
throw new RuntimeException();
}
@@ -81,14 +81,14 @@ public static void fhirResourceSearchGet(String resourceName)
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -100,11 +100,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_search_resources_get]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceSearchPost.java b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceSearchPost.java
index fa0dabb8f49..6a3dff2797f 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceSearchPost.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/fhir/resources/FhirResourceSearchPost.java
@@ -17,13 +17,14 @@
package snippets.healthcare.fhir.resources;
// [START healthcare_search_resources_post]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -53,46 +54,45 @@ public static void fhirResourceSearchPost(String resourceName)
CloudHealthcare client = createClient();
HttpClient httpClient = HttpClients.createDefault();
- String uri = String.format(
- "%sv1/%s/_search", client.getRootUrl(), resourceName);
- URIBuilder uriBuilder = new URIBuilder(uri)
- .setParameter("access_token", getAccessToken());
+ String uri = String.format("%sv1/%s/_search", client.getRootUrl(), resourceName);
+ URIBuilder uriBuilder = new URIBuilder(uri).setParameter("access_token", getAccessToken());
StringEntity requestEntity = new StringEntity("");
- HttpUriRequest request = RequestBuilder
- .post()
- .setUri(uriBuilder.build())
- .setEntity(requestEntity)
- .addHeader("Content-Type", "application/fhir+json")
- .addHeader("Accept-Charset", "utf-8")
- .addHeader("Accept", "application/fhir+json; charset=utf-8")
- .build();
+ HttpUriRequest request =
+ RequestBuilder.post()
+ .setUri(uriBuilder.build())
+ .setEntity(requestEntity)
+ .addHeader("Content-Type", "application/fhir+json")
+ .addHeader("Accept-Charset", "utf-8")
+ .addHeader("Accept", "application/fhir+json; charset=utf-8")
+ .build();
// Execute the request and process the results.
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- System.err.print(String.format(
- "Exception searching POST FHIR resources: %s\n", response.getStatusLine().toString()));
+ System.err.print(
+ String.format(
+ "Exception searching POST FHIR resources: %s\n",
+ response.getStatusLine().toString()));
responseEntity.writeTo(System.err);
throw new RuntimeException();
}
System.out.println("FHIR resource search results: ");
responseEntity.writeTo(System.out);
-
}
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
@@ -104,11 +104,11 @@ private static CloudHealthcare createClient() throws IOException {
}
private static String getAccessToken() throws IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
- credential.refreshToken();
- return credential.getAccessToken();
+
+ return credential.refreshAccessToken().getTokenValue();
}
}
// [END healthcare_search_resources_post]
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreCreate.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreCreate.java
index f9ce662214e..b852e560226 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreCreate.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreCreate.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2;
// [START healthcare_create_hl7v2_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Hl7V2Store;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
@@ -69,14 +69,14 @@ public static void hl7v2StoreCreate(String datasetName, String hl7v2StoreId) thr
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreDelete.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreDelete.java
index 82d7472b844..47637bb1ddf 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreDelete.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreDelete.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2;
// [START healthcare_delete_hl7v2_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -26,6 +24,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -54,14 +54,14 @@ public static void hl7v2StoreDelete(String hl7v2StoreName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreGet.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreGet.java
index a0d81512c86..0f05c5599b1 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreGet.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreGet.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2;
// [START healthcare_get_hl7v2_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Hl7V2Store;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -55,14 +55,14 @@ public static void hl7v2eStoreGet(String hl7v2StoreName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreGetIamPolicy.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreGetIamPolicy.java
index 9b9eed70669..501bf7572bd 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreGetIamPolicy.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreGetIamPolicy.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2;
// [START healthcare_hl7v2_store_get_iam_policy]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Policy;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -55,14 +55,14 @@ public static void hl7v2StoreGetIamPolicy(String hl7v2StoreName) throws IOExcept
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreList.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreList.java
index 1a7e98cd0a8..39e1bfa8629 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreList.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreList.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2;
// [START healthcare_list_hl7v2_stores]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -28,6 +26,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Hl7V2Store;
import com.google.api.services.healthcare.v1.model.ListHl7V2StoresResponse;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -78,14 +78,14 @@ public static void hl7v2StoreList(String datasetName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StorePatch.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StorePatch.java
index 7b9941d6806..35e0a4ec5e0 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StorePatch.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StorePatch.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2;
// [START healthcare_patch_hl7v2_store]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -28,6 +26,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Hl7V2NotificationConfig;
import com.google.api.services.healthcare.v1.model.Hl7V2Store;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -78,14 +78,14 @@ public static void patchHl7v2Store(String hl7v2StoreName, String pubsubTopic) th
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreSetIamPolicy.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreSetIamPolicy.java
index fcde538a107..05d62e36307 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreSetIamPolicy.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/Hl7v2StoreSetIamPolicy.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2;
// [START healthcare_hl7v2_store_set_iam_policy]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -29,6 +27,8 @@
import com.google.api.services.healthcare.v1.model.Binding;
import com.google.api.services.healthcare.v1.model.Policy;
import com.google.api.services.healthcare.v1.model.SetIamPolicyRequest;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@@ -73,14 +73,14 @@ public static void hl7v2StoreSetIamPolicy(String hl7v2StoreName) throws IOExcept
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageCreate.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageCreate.java
index 1b6f69ce175..c4852f5ecf3 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageCreate.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageCreate.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2.messages;
// [START healthcare_create_hl7v2_message]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -28,6 +26,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.CreateMessageRequest;
import com.google.api.services.healthcare.v1.model.Message;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
@@ -75,14 +75,14 @@ public static void hl7v2MessageCreate(String hl7v2StoreName, String messageId, S
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageDelete.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageDelete.java
index 6438a74f00f..edbec86a8d1 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageDelete.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageDelete.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2.messages;
// [START healthcare_delete_hl7v2_message]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -26,6 +24,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -55,14 +55,14 @@ public static void hl7v2MessageDelete(String hl7v2MessageName) throws IOExceptio
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageGet.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageGet.java
index b26120383e2..e87b185f299 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageGet.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageGet.java
@@ -17,7 +17,6 @@
package snippets.healthcare.hl7v2.messages;
// [START healthcare_get_hl7v2_message]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -26,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Message;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -55,14 +56,14 @@ public static void hl7v2MessageGet(String hl7v2MessageName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageIngest.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageIngest.java
index 187361f11e3..8f0548d108e 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageIngest.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageIngest.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2.messages;
// [START healthcare_ingest_hl7v2_message]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -29,6 +27,8 @@
import com.google.api.services.healthcare.v1.model.IngestMessageRequest;
import com.google.api.services.healthcare.v1.model.IngestMessageResponse;
import com.google.api.services.healthcare.v1.model.Message;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
@@ -75,14 +75,14 @@ public static void hl7v2MessageIngest(String hl7v2StoreName, String filePath) th
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageList.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageList.java
index a04dd3dc69f..6bbfdac5c58 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageList.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageList.java
@@ -17,7 +17,6 @@
package snippets.healthcare.hl7v2.messages;
// [START healthcare_list_hl7v2_messages]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +26,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.ListMessagesResponse;
import com.google.api.services.healthcare.v1.model.Message;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
@@ -80,14 +81,14 @@ public static void hl7v2MessageList(String hl7v2StoreName) throws IOException {
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessagePatch.java b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessagePatch.java
index ee6e788104f..78e34511c2b 100644
--- a/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessagePatch.java
+++ b/healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessagePatch.java
@@ -17,8 +17,6 @@
package snippets.healthcare.hl7v2.messages;
// [START healthcare_patch_hl7v2_message]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
@@ -27,6 +25,8 @@
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Message;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
@@ -77,14 +77,14 @@ public static void hl7v2MessagePatch(String hl7v2MessageName) throws IOException
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
- credential.initialize(request);
+ new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
diff --git a/healthcare/v1/src/test/java/snippets/healthcare/FhirResourceTests.java b/healthcare/v1/src/test/java/snippets/healthcare/FhirResourceTests.java
index 5977fc977c2..d9c241bd8ac 100644
--- a/healthcare/v1/src/test/java/snippets/healthcare/FhirResourceTests.java
+++ b/healthcare/v1/src/test/java/snippets/healthcare/FhirResourceTests.java
@@ -20,7 +20,6 @@
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
@@ -37,7 +36,6 @@
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
diff --git a/healthcare/v1/src/test/java/snippets/healthcare/Hl7v2MessageTests.java b/healthcare/v1/src/test/java/snippets/healthcare/Hl7v2MessageTests.java
index f98efb49934..4ee160f0bc2 100644
--- a/healthcare/v1/src/test/java/snippets/healthcare/Hl7v2MessageTests.java
+++ b/healthcare/v1/src/test/java/snippets/healthcare/Hl7v2MessageTests.java
@@ -136,8 +136,6 @@ public void test_GetHL7v2Message() throws Exception {
@Test
public void test_Hl7v2MessageList() throws Exception {
- HL7v2MessageCreate.hl7v2MessageCreate(
- hl7v2StoreName, "new-hl7v2-message", "src/test/resources/hl7v2-sample-ingest.txt");
HL7v2MessageList.hl7v2MessageList(hl7v2StoreName);
String output = bout.toString();
diff --git a/iam/api-client/pom.xml b/iam/api-client/pom.xml
index 88e2146ec66..4584f1e5bdc 100644
--- a/iam/api-client/pom.xml
+++ b/iam/api-client/pom.xml
@@ -27,26 +27,31 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
1.8
1.8
-
+
com.google.apis
google-api-services-iam
- v1-rev20200221-1.30.9
+ v1-rev20200611-1.30.9
+
+ com.google.auth
+ google-auth-library-oauth2-http
+ 0.21.0
+
com.google.apis
google-api-services-cloudresourcemanager
- v1-rev20200504-1.30.9
+ v1-rev20200617-1.30.9
commons-cli
@@ -74,12 +79,12 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
com.google.iam.snippets.GrantableRoles
-
+
diff --git a/iam/api-client/src/main/java/iam/snippets/CreateServiceAccount.java b/iam/api-client/src/main/java/iam/snippets/CreateServiceAccount.java
index af434f3263f..ba45eed90fe 100644
--- a/iam/api-client/src/main/java/iam/snippets/CreateServiceAccount.java
+++ b/iam/api-client/src/main/java/iam/snippets/CreateServiceAccount.java
@@ -16,13 +16,14 @@
package iam.snippets;
// [START iam_create_service_account]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.IamScopes;
import com.google.api.services.iam.v1.model.CreateServiceAccountRequest;
import com.google.api.services.iam.v1.model.ServiceAccount;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -60,15 +61,15 @@ public static void createServiceAccount(String projectId) {
private static Iam initService() throws GeneralSecurityException, IOException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Initialize the IAM service, which can be used to send requests to the IAM API.
Iam service =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/CreateServiceAccountKey.java b/iam/api-client/src/main/java/iam/snippets/CreateServiceAccountKey.java
index 06db467d1e7..19a00119716 100644
--- a/iam/api-client/src/main/java/iam/snippets/CreateServiceAccountKey.java
+++ b/iam/api-client/src/main/java/iam/snippets/CreateServiceAccountKey.java
@@ -16,13 +16,14 @@
package iam.snippets;
// [START iam_create_key]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.IamScopes;
import com.google.api.services.iam.v1.model.CreateServiceAccountKeyRequest;
import com.google.api.services.iam.v1.model.ServiceAccountKey;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -32,7 +33,7 @@ public class CreateServiceAccountKey {
// Creates a key for a service account.
public static void createKey(String projectId) {
// String projectId = "my-project-id";
-
+
Iam service = null;
try {
service = initService();
@@ -63,15 +64,15 @@ public static void createKey(String projectId) {
private static Iam initService() throws GeneralSecurityException, IOException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Initialize the IAM service, which can be used to send requests to the IAM API.
Iam service =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-account-keys")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/DeleteServiceAccount.java b/iam/api-client/src/main/java/iam/snippets/DeleteServiceAccount.java
index bd3b94bee11..b7bf077fcce 100644
--- a/iam/api-client/src/main/java/iam/snippets/DeleteServiceAccount.java
+++ b/iam/api-client/src/main/java/iam/snippets/DeleteServiceAccount.java
@@ -16,11 +16,12 @@
package iam.snippets;
// [START iam_delete_service_account]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.IamScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -30,8 +31,8 @@ public class DeleteServiceAccount {
// Deletes a service account.
public static void deleteServiceAccount(String projectId) {
// String projectId = "my-project-id";
-
- Iam service = null;
+
+ Iam service = null;
try {
service = initService();
} catch (IOException | GeneralSecurityException e) {
@@ -63,15 +64,15 @@ public static void deleteServiceAccount(String projectId) {
private static Iam initService() throws GeneralSecurityException, IOException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Initialize the IAM service, which can be used to send requests to the IAM API.
Iam service =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/DeleteServiceAccountKey.java b/iam/api-client/src/main/java/iam/snippets/DeleteServiceAccountKey.java
index a20d99299d7..38cae094bea 100644
--- a/iam/api-client/src/main/java/iam/snippets/DeleteServiceAccountKey.java
+++ b/iam/api-client/src/main/java/iam/snippets/DeleteServiceAccountKey.java
@@ -16,12 +16,13 @@
package iam.snippets;
// [START iam_delete_key]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.IamScopes;
import com.google.api.services.iam.v1.model.ServiceAccountKey;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -32,7 +33,7 @@ public class DeleteServiceAccountKey {
// Deletes a service account key.
public static void deleteKey(String projectId) {
// String projectId = "my-project-id";
-
+
Iam service = null;
try {
service = initService();
@@ -69,15 +70,15 @@ public static void deleteKey(String projectId) {
private static Iam initService() throws GeneralSecurityException, IOException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Initialize the IAM service, which can be used to send requests to the IAM API.
Iam service =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-account-keys")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/DisableServiceAccount.java b/iam/api-client/src/main/java/iam/snippets/DisableServiceAccount.java
index c8e28a42949..ff8e949ced0 100644
--- a/iam/api-client/src/main/java/iam/snippets/DisableServiceAccount.java
+++ b/iam/api-client/src/main/java/iam/snippets/DisableServiceAccount.java
@@ -16,12 +16,13 @@
package iam.snippets;
// [START iam_disable_service_account]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.IamScopes;
import com.google.api.services.iam.v1.model.DisableServiceAccountRequest;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -66,15 +67,15 @@ public static void disableServiceAccount(String projectId) {
private static Iam initService() throws GeneralSecurityException, IOException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Initialize the IAM service, which can be used to send requests to the IAM API.
Iam service =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/EnableServiceAccount.java b/iam/api-client/src/main/java/iam/snippets/EnableServiceAccount.java
index 57778adb14d..bdccaab0ba1 100644
--- a/iam/api-client/src/main/java/iam/snippets/EnableServiceAccount.java
+++ b/iam/api-client/src/main/java/iam/snippets/EnableServiceAccount.java
@@ -16,12 +16,13 @@
package iam.snippets;
// [START iam_enable_service_account]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.IamScopes;
import com.google.api.services.iam.v1.model.EnableServiceAccountRequest;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -66,15 +67,15 @@ public static void enableServiceAccount(String projectId) {
private static Iam initService() throws GeneralSecurityException, IOException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Initialize the IAM service, which can be used to send requests to the IAM API.
Iam service =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/GetPolicy.java b/iam/api-client/src/main/java/iam/snippets/GetPolicy.java
index f3ecbc07759..d007fe48123 100644
--- a/iam/api-client/src/main/java/iam/snippets/GetPolicy.java
+++ b/iam/api-client/src/main/java/iam/snippets/GetPolicy.java
@@ -16,13 +16,14 @@
package iam.snippets;
// [START iam_get_policy]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.cloudresourcemanager.CloudResourceManager;
import com.google.api.services.cloudresourcemanager.model.GetIamPolicyRequest;
import com.google.api.services.cloudresourcemanager.model.Policy;
import com.google.api.services.iam.v1.IamScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -58,15 +59,15 @@ public static CloudResourceManager createCloudResourceManagerService()
throws IOException, GeneralSecurityException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
CloudResourceManager service =
new CloudResourceManager.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/GrantableRoles.java b/iam/api-client/src/main/java/iam/snippets/GrantableRoles.java
index f55f7ab274b..76528c070e0 100644
--- a/iam/api-client/src/main/java/iam/snippets/GrantableRoles.java
+++ b/iam/api-client/src/main/java/iam/snippets/GrantableRoles.java
@@ -15,7 +15,6 @@
package iam.snippets;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
@@ -23,21 +22,23 @@
import com.google.api.services.iam.v1.model.QueryGrantableRolesRequest;
import com.google.api.services.iam.v1.model.QueryGrantableRolesResponse;
import com.google.api.services.iam.v1.model.Role;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.util.Collections;
public class GrantableRoles {
public static void main(String[] args) throws Exception {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
Iam service =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("grantable-roles")
.build();
diff --git a/iam/api-client/src/main/java/iam/snippets/ListServiceAccountKeys.java b/iam/api-client/src/main/java/iam/snippets/ListServiceAccountKeys.java
index 62b14b57f99..42debf70c57 100644
--- a/iam/api-client/src/main/java/iam/snippets/ListServiceAccountKeys.java
+++ b/iam/api-client/src/main/java/iam/snippets/ListServiceAccountKeys.java
@@ -16,12 +16,13 @@
package iam.snippets;
// [START iam_list_keys]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.IamScopes;
import com.google.api.services.iam.v1.model.ServiceAccountKey;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -32,7 +33,7 @@ public class ListServiceAccountKeys {
// Lists all keys for a service account.
public static void listKeys(String projectId) {
// String projectId = "my-project-id";
-
+
Iam service = null;
try {
service = initService();
@@ -66,15 +67,15 @@ public static void listKeys(String projectId) {
private static Iam initService() throws GeneralSecurityException, IOException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Initialize the IAM service, which can be used to send requests to the IAM API.
Iam service =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-account-keys")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/ListServiceAccounts.java b/iam/api-client/src/main/java/iam/snippets/ListServiceAccounts.java
index 1f8b4314f05..2aa36612824 100644
--- a/iam/api-client/src/main/java/iam/snippets/ListServiceAccounts.java
+++ b/iam/api-client/src/main/java/iam/snippets/ListServiceAccounts.java
@@ -16,13 +16,14 @@
package iam.snippets;
// [START iam_list_service_accounts]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.IamScopes;
import com.google.api.services.iam.v1.model.ListServiceAccountsResponse;
import com.google.api.services.iam.v1.model.ServiceAccount;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -33,7 +34,7 @@ public class ListServiceAccounts {
// Lists all service accounts for the current project.
public static void listServiceAccounts(String projectId) {
// String projectId = "my-project-id"
-
+
Iam service = null;
try {
service = initService();
@@ -61,15 +62,15 @@ public static void listServiceAccounts(String projectId) {
private static Iam initService() throws GeneralSecurityException, IOException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Initialize the IAM service, which can be used to send requests to the IAM API.
Iam service =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/Quickstart.java b/iam/api-client/src/main/java/iam/snippets/Quickstart.java
index 9accc981da6..5167b07ea56 100644
--- a/iam/api-client/src/main/java/iam/snippets/Quickstart.java
+++ b/iam/api-client/src/main/java/iam/snippets/Quickstart.java
@@ -17,13 +17,14 @@
package iam.snippets;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.IamScopes;
import com.google.api.services.iam.v1.model.ListRolesResponse;
import com.google.api.services.iam.v1.model.Role;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.util.Collections;
import java.util.List;
@@ -31,8 +32,8 @@ public class Quickstart {
public static void main(String[] args) throws Exception {
// Get credentials
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Create the Cloud IAM service object
@@ -40,7 +41,7 @@ public static void main(String[] args) throws Exception {
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("quickstart")
.build();
diff --git a/iam/api-client/src/main/java/iam/snippets/QuickstartV2.java b/iam/api-client/src/main/java/iam/snippets/QuickstartV2.java
index 519356b56b3..b16379aaea2 100644
--- a/iam/api-client/src/main/java/iam/snippets/QuickstartV2.java
+++ b/iam/api-client/src/main/java/iam/snippets/QuickstartV2.java
@@ -14,9 +14,8 @@
*/
package iam.snippets;
-// [START iam_quickstart_v2]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
+// [START iam_quickstart_v2]
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.cloudresourcemanager.CloudResourceManager;
@@ -25,6 +24,8 @@
import com.google.api.services.cloudresourcemanager.model.Policy;
import com.google.api.services.cloudresourcemanager.model.SetIamPolicyRequest;
import com.google.api.services.iam.v1.IamScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -76,8 +77,8 @@ public static CloudResourceManager initializeService()
throws IOException, GeneralSecurityException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Creates the Cloud Resource Manager service object.
@@ -85,7 +86,7 @@ public static CloudResourceManager initializeService()
new CloudResourceManager.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/RenameServiceAccount.java b/iam/api-client/src/main/java/iam/snippets/RenameServiceAccount.java
index 05a047ff4ab..780780a8fc2 100644
--- a/iam/api-client/src/main/java/iam/snippets/RenameServiceAccount.java
+++ b/iam/api-client/src/main/java/iam/snippets/RenameServiceAccount.java
@@ -16,12 +16,13 @@
package iam.snippets;
// [START iam_rename_service_account]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.IamScopes;
import com.google.api.services.iam.v1.model.ServiceAccount;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -31,7 +32,7 @@ public class RenameServiceAccount {
// Changes a service account's display name.
public static void renameServiceAccount(String projectId) {
// String projectId = "my-project-id";
-
+
Iam service = null;
try {
service = initService();
@@ -75,15 +76,15 @@ public static void renameServiceAccount(String projectId) {
private static Iam initService() throws GeneralSecurityException, IOException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Initialize the IAM service, which can be used to send requests to the IAM API.
Iam service =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/SetPolicy.java b/iam/api-client/src/main/java/iam/snippets/SetPolicy.java
index 9ca0567e501..08119a2d9cc 100644
--- a/iam/api-client/src/main/java/iam/snippets/SetPolicy.java
+++ b/iam/api-client/src/main/java/iam/snippets/SetPolicy.java
@@ -16,13 +16,14 @@
package iam.snippets;
// [START iam_set_policy]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.cloudresourcemanager.CloudResourceManager;
import com.google.api.services.cloudresourcemanager.model.Policy;
import com.google.api.services.cloudresourcemanager.model.SetIamPolicyRequest;
import com.google.api.services.iam.v1.IamScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -56,15 +57,15 @@ public static CloudResourceManager createCloudResourceManagerService()
throws IOException, GeneralSecurityException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
CloudResourceManager service =
new CloudResourceManager.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
return service;
diff --git a/iam/api-client/src/main/java/iam/snippets/TestPermissions.java b/iam/api-client/src/main/java/iam/snippets/TestPermissions.java
index 70c9b420912..9bde6b2e10c 100644
--- a/iam/api-client/src/main/java/iam/snippets/TestPermissions.java
+++ b/iam/api-client/src/main/java/iam/snippets/TestPermissions.java
@@ -16,13 +16,14 @@
package iam.snippets;
// [START iam_test_permissions]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.cloudresourcemanager.CloudResourceManager;
import com.google.api.services.cloudresourcemanager.model.TestIamPermissionsRequest;
import com.google.api.services.cloudresourcemanager.model.TestIamPermissionsResponse;
import com.google.api.services.iam.v1.IamScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
@@ -64,15 +65,15 @@ public static CloudResourceManager createCloudResourceManagerService()
throws IOException, GeneralSecurityException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
CloudResourceManager service =
new CloudResourceManager.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
return service;
diff --git a/iam/api-client/src/test/java/iam/snippets/QuickstartV2Tests.java b/iam/api-client/src/test/java/iam/snippets/QuickstartV2Tests.java
index 1567d82121e..2566ad84ee4 100644
--- a/iam/api-client/src/test/java/iam/snippets/QuickstartV2Tests.java
+++ b/iam/api-client/src/test/java/iam/snippets/QuickstartV2Tests.java
@@ -19,7 +19,6 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.cloudresourcemanager.CloudResourceManager;
@@ -29,6 +28,8 @@
import com.google.api.services.iam.v1.IamScopes;
import com.google.api.services.iam.v1.model.CreateServiceAccountRequest;
import com.google.api.services.iam.v1.model.ServiceAccount;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
@@ -65,15 +66,15 @@ public static void checkRequirements() {
@Before
public void setUp() {
try {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault()
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
iamService =
new Iam.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
- credential)
+ new HttpCredentialsAdapter(credential))
.setApplicationName("service-accounts")
.build();
} catch (IOException | GeneralSecurityException e) {
diff --git a/iam/api-client/src/test/java/iam/snippets/ServiceAccountTests.java b/iam/api-client/src/test/java/iam/snippets/ServiceAccountTests.java
index 88179f94625..dbb6a2917e4 100644
--- a/iam/api-client/src/test/java/iam/snippets/ServiceAccountTests.java
+++ b/iam/api-client/src/test/java/iam/snippets/ServiceAccountTests.java
@@ -37,7 +37,8 @@ public class ServiceAccountTests {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static void requireEnvVar(String varName) {
- assertNotNull(System.getenv(varName),
+ assertNotNull(
+ System.getenv(varName),
String.format("Environment variable '%s' is required to perform these tests.", varName));
}
diff --git a/iap/pom.xml b/iap/pom.xml
index 23dcae4671f..e1015b54393 100644
--- a/iap/pom.xml
+++ b/iap/pom.xml
@@ -29,7 +29,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -43,7 +43,7 @@
com.fasterxml.jackson.core
jackson-core
- 2.11.0
+ 2.11.1
@@ -58,12 +58,7 @@
com.google.auth
google-auth-library-oauth2-http
- 0.20.0
-
-
- com.nimbusds
- nimbus-jose-jwt
- 8.17
+ 0.21.0
diff --git a/iap/src/main/java/com/example/iap/BuildIapRequest.java b/iap/src/main/java/com/example/iap/BuildIapRequest.java
index 2fae86f320c..b3d76ab10d0 100644
--- a/iap/src/main/java/com/example/iap/BuildIapRequest.java
+++ b/iap/src/main/java/com/example/iap/BuildIapRequest.java
@@ -25,29 +25,28 @@
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.IdTokenCredentials;
import com.google.auth.oauth2.IdTokenProvider;
-import java.time.Clock;
+import com.google.common.base.Preconditions;
+import java.io.IOException;
import java.util.Collections;
public class BuildIapRequest {
private static final String IAM_SCOPE = "https://www.googleapis.com/auth/iam";
- private static final String OAUTH_TOKEN_URI = "https://www.googleapis.com/oauth2/v4/token";
- private static final String JWT_BEARER_TOKEN_GRANT_TYPE =
- "urn:ietf:params:oauth:grant-type:jwt-bearer";
- private static final long EXPIRATION_TIME_IN_SECONDS = 3600L;
private static final HttpTransport httpTransport = new NetHttpTransport();
- private static Clock clock = Clock.systemUTC();
-
private BuildIapRequest() {}
- private static IdTokenProvider getIdTokenProvider() throws Exception {
+ private static IdTokenProvider getIdTokenProvider() throws IOException {
GoogleCredentials credentials =
GoogleCredentials.getApplicationDefault().createScoped(Collections.singleton(IAM_SCOPE));
- // service account credentials are required to sign the jwt token
- if (credentials == null || !(credentials instanceof IdTokenProvider)) {
- throw new Exception("Google credentials : credentials that can provide id tokens expected");
- }
+
+ Preconditions.checkNotNull(credentials, "Expected to load credentials");
+ Preconditions.checkState(
+ credentials instanceof IdTokenProvider,
+ String.format(
+ "Expected credentials that can provide id tokens, got %s instead",
+ credentials.getClass().getName()));
+
return (IdTokenProvider) credentials;
}
@@ -57,16 +56,17 @@ private static IdTokenProvider getIdTokenProvider() throws Exception {
* @param request Request to add authorization header
* @param iapClientId OAuth 2.0 client ID for IAP protected resource
* @return Clone of request with Bearer style authorization header with signed jwt token.
- * @throws Exception exception creating signed JWT
+ * @throws IOException exception creating signed JWT
*/
public static HttpRequest buildIapRequest(HttpRequest request, String iapClientId)
- throws Exception {
+ throws IOException {
IdTokenProvider idTokenProvider = getIdTokenProvider();
- IdTokenCredentials credentials = IdTokenCredentials.newBuilder()
- .setIdTokenProvider(idTokenProvider)
- .setTargetAudience(iapClientId)
- .build();
+ IdTokenCredentials credentials =
+ IdTokenCredentials.newBuilder()
+ .setIdTokenProvider(idTokenProvider)
+ .setTargetAudience(iapClientId)
+ .build();
HttpRequestInitializer httpRequestInitializer = new HttpCredentialsAdapter(credentials);
diff --git a/iap/src/main/java/com/example/iap/VerifyIapRequestHeader.java b/iap/src/main/java/com/example/iap/VerifyIapRequestHeader.java
index 61503264456..5f894187cd9 100644
--- a/iap/src/main/java/com/example/iap/VerifyIapRequestHeader.java
+++ b/iap/src/main/java/com/example/iap/VerifyIapRequestHeader.java
@@ -18,53 +18,14 @@
// [START iap_validate_jwt]
import com.google.api.client.http.HttpRequest;
-import com.google.common.base.Preconditions;
-import com.nimbusds.jose.JWSHeader;
-import com.nimbusds.jose.JWSVerifier;
-import com.nimbusds.jose.crypto.ECDSAVerifier;
-import com.nimbusds.jose.jwk.ECKey;
-import com.nimbusds.jose.jwk.JWK;
-import com.nimbusds.jose.jwk.JWKSet;
-import com.nimbusds.jwt.JWTClaimsSet;
-import com.nimbusds.jwt.SignedJWT;
-import java.net.URL;
-import java.security.interfaces.ECPublicKey;
-import java.time.Clock;
-import java.time.Instant;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+import com.google.api.client.json.webtoken.JsonWebToken;
+import com.google.auth.oauth2.TokenVerifier;
/** Verify IAP authorization JWT token in incoming request. */
public class VerifyIapRequestHeader {
- private static final String PUBLIC_KEY_VERIFICATION_URL =
- "https://www.gstatic.com/iap/verify/public_key-jwk";
-
private static final String IAP_ISSUER_URL = "https://cloud.google.com/iap";
- // using a simple cache with no eviction for this sample
- private final Map keyCache = new HashMap<>();
-
- private static Clock clock = Clock.systemUTC();
-
- private ECPublicKey getKey(String kid, String alg) throws Exception {
- JWK jwk = keyCache.get(kid);
- if (jwk == null) {
- // update cache loading jwk public key data from url
- JWKSet jwkSet = JWKSet.load(new URL(PUBLIC_KEY_VERIFICATION_URL));
- for (JWK key : jwkSet.getKeys()) {
- keyCache.put(key.getKeyID(), key);
- }
- jwk = keyCache.get(kid);
- }
- // confirm that algorithm matches
- if (jwk != null && jwk.getAlgorithm().getName().equals(alg)) {
- return ECKey.parse(jwk.toJSONString()).toECPublicKey();
- }
- return null;
- }
-
// Verify jwt tokens addressed to IAP protected resources on App Engine.
// The project *number* for your Google Cloud project via 'gcloud projects describe $PROJECT_ID'
// The project *number* can also be retrieved from the Project Info card in Cloud Console.
@@ -96,38 +57,21 @@ boolean verifyJwtForComputeEngine(
Long.toUnsignedString(projectNumber), Long.toUnsignedString(backendServiceId)));
}
- private boolean verifyJwt(String jwtToken, String expectedAudience) throws Exception {
-
- // parse signed token into header / claims
- SignedJWT signedJwt = SignedJWT.parse(jwtToken);
- JWSHeader jwsHeader = signedJwt.getHeader();
-
- // header must have algorithm("alg") and "kid"
- Preconditions.checkNotNull(jwsHeader.getAlgorithm());
- Preconditions.checkNotNull(jwsHeader.getKeyID());
-
- JWTClaimsSet claims = signedJwt.getJWTClaimsSet();
-
- // claims must have audience, issuer
- Preconditions.checkArgument(claims.getAudience().contains(expectedAudience));
- Preconditions.checkArgument(claims.getIssuer().equals(IAP_ISSUER_URL));
-
- // claim must have issued at time in the past
- Date currentTime = Date.from(Instant.now(clock));
- Preconditions.checkArgument(claims.getIssueTime().before(currentTime));
- // claim must have expiration time in the future
- Preconditions.checkArgument(claims.getExpirationTime().after(currentTime));
-
- // must have subject, email
- Preconditions.checkNotNull(claims.getSubject());
- Preconditions.checkNotNull(claims.getClaim("email"));
-
- // verify using public key : lookup with key id, algorithm name provided
- ECPublicKey publicKey = getKey(jwsHeader.getKeyID(), jwsHeader.getAlgorithm().getName());
-
- Preconditions.checkNotNull(publicKey);
- JWSVerifier jwsVerifier = new ECDSAVerifier(publicKey);
- return signedJwt.verify(jwsVerifier);
+ private boolean verifyJwt(String jwtToken, String expectedAudience) {
+ TokenVerifier tokenVerifier = TokenVerifier.newBuilder()
+ .setAudience(expectedAudience)
+ .setIssuer(IAP_ISSUER_URL)
+ .build();
+ try {
+ JsonWebToken jsonWebToken = tokenVerifier.verify(jwtToken);
+
+ // Verify that the token contain subject and email claims
+ JsonWebToken.Payload payload = jsonWebToken.getPayload();
+ return payload.getSubject() != null && payload.get("email") != null;
+ } catch (TokenVerifier.VerificationException e) {
+ System.out.println(e.getMessage());
+ return false;
+ }
}
}
// [END iap_validate_jwt]
diff --git a/iap/src/test/java/com/example/iap/BuildAndVerifyIapRequestIT.java b/iap/src/test/java/com/example/iap/BuildAndVerifyIapRequestIT.java
index e5f52e86e67..3bef9a2824e 100644
--- a/iap/src/test/java/com/example/iap/BuildAndVerifyIapRequestIT.java
+++ b/iap/src/test/java/com/example/iap/BuildAndVerifyIapRequestIT.java
@@ -33,9 +33,9 @@
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
-//CHECKSTYLE OFF: AbbreviationAsWordInName
+// CHECKSTYLE OFF: AbbreviationAsWordInName
public class BuildAndVerifyIapRequestIT {
- //CHECKSTYLE ON: AbbreviationAsWordInName
+ // CHECKSTYLE ON: AbbreviationAsWordInName
// Update these fields to reflect your IAP protected App Engine credentials
private static Long IAP_PROJECT_NUMBER = 320431926067L;
diff --git a/iot/api-client/codelab/manager/pom.xml b/iot/api-client/codelab/manager/pom.xml
index 36eb8376ad9..4e10e54c07e 100644
--- a/iot/api-client/codelab/manager/pom.xml
+++ b/iot/api-client/codelab/manager/pom.xml
@@ -30,11 +30,11 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
- 8
- 8
+ 1.8
+ 1.8
@@ -52,7 +52,7 @@
org.json
json
- 20190722
+ 20200518
io.jsonwebtoken
@@ -67,23 +67,17 @@
com.google.apis
google-api-services-cloudiot
- v1-rev20200414-1.30.9
+ v1-rev20200519-1.30.9
com.google.cloud
google-cloud-pubsub
- 1.105.1
+ 1.107.0
- com.google.oauth-client
com.google.cloud
google-cloud-core
- 1.93.0
-
-
- com.google.oauth-client
- google-oauth-client
- 1.30.6
+ 1.93.6
com.google.guava
diff --git a/iot/api-client/codelab/manager/src/main/java/com/example/cloud/iot/examples/MqttCommandsDemo.java b/iot/api-client/codelab/manager/src/main/java/com/example/cloud/iot/examples/MqttCommandsDemo.java
index 9fb00613f3b..30abca8937d 100644
--- a/iot/api-client/codelab/manager/src/main/java/com/example/cloud/iot/examples/MqttCommandsDemo.java
+++ b/iot/api-client/codelab/manager/src/main/java/com/example/cloud/iot/examples/MqttCommandsDemo.java
@@ -16,19 +16,6 @@
package com.example.cloud.iot.examples;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
-import com.google.api.client.http.HttpRequestInitializer;
-import com.google.api.client.json.JsonFactory;
-import com.google.api.client.json.jackson2.JacksonFactory;
-import com.google.api.services.cloudiot.v1.CloudIot;
-import com.google.api.services.cloudiot.v1.CloudIotScopes;
-import com.google.api.services.cloudiot.v1.model.Device;
-import com.google.api.services.cloudiot.v1.model.DeviceCredential;
-import com.google.api.services.cloudiot.v1.model.DeviceRegistry;
-import com.google.api.services.cloudiot.v1.model.EventNotificationConfig;
-import com.google.api.services.cloudiot.v1.model.PublicKeyCredential;
-import com.google.common.base.Charsets;
import com.googlecode.lanterna.Symbols;
import com.googlecode.lanterna.TerminalPosition;
import com.googlecode.lanterna.TerminalSize;
@@ -38,28 +25,20 @@
import com.googlecode.lanterna.input.KeyStroke;
import com.googlecode.lanterna.input.KeyType;
import com.googlecode.lanterna.screen.Screen;
-import com.googlecode.lanterna.screen.TabBehaviour;
import com.googlecode.lanterna.screen.TerminalScreen;
import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
import com.googlecode.lanterna.terminal.Terminal;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
-
-import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
import java.util.Properties;
-
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
@@ -72,14 +51,12 @@
import org.json.JSONException;
import org.json.JSONObject;
-
public class MqttCommandsDemo {
static MqttCallback mCallback;
static Thread mGUIthread;
static final String APP_NAME = "MqttCommandsDemo";
-
/** Create a Cloud IoT Core JWT for the given project id, signed with the given RSA key. */
private static String createJwtRsa(String projectId, String privateKeyFile)
throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
@@ -121,7 +98,6 @@ private static String createJwtEs(String projectId, String privateKeyFile)
return jwtBuilder.signWith(SignatureAlgorithm.ES256, kf.generatePrivate(spec)).compact();
}
-
/** Attaches the callback used when configuration changes occur. */
public static void attachCallback(MqttClient client, String deviceId, Screen mainScreen)
throws MqttException {
@@ -153,7 +129,6 @@ public void messageArrived(String topic, MqttMessage message) throws Exception {
// [end command respond code]
}
-
}
@Override
@@ -202,7 +177,7 @@ TextColor getColor(String col) {
public boolean isValidColor(JSONObject data, TextColor mainBgColor) throws JSONException {
return data.get("color") instanceof String
- && !mainBgColor.toColor().equals(getColor((String) data.get("color")));
+ && !mainBgColor.toColor().equals(getColor((String) data.get("color")));
}
};
@@ -217,10 +192,17 @@ public boolean isValidColor(JSONObject data, TextColor mainBgColor) throws JSONE
client.setCallback(mCallback);
}
- public static void mqttDeviceDemo(String projectId, String cloudRegion, String registryId,
- String deviceId, String privateKeyFile, String algorithm,
- String mqttBridgeHostname, short mqttBridgePort,
- String messageType, int waitTime)
+ public static void mqttDeviceDemo(
+ String projectId,
+ String cloudRegion,
+ String registryId,
+ String deviceId,
+ String privateKeyFile,
+ String algorithm,
+ String mqttBridgeHostname,
+ short mqttBridgePort,
+ String messageType,
+ int waitTime)
throws NoSuchAlgorithmException, IOException, InvalidKeySpecException, MqttException,
InterruptedException {
@@ -254,11 +236,9 @@ public static void mqttDeviceDemo(String projectId, String cloudRegion, String r
DateTime iat = new DateTime();
if (algorithm.equals("RS256")) {
- connectOptions.setPassword(
- createJwtRsa(projectId, privateKeyFile).toCharArray());
+ connectOptions.setPassword(createJwtRsa(projectId, privateKeyFile).toCharArray());
} else if (algorithm.equals("ES256")) {
- connectOptions.setPassword(
- createJwtEs(projectId, privateKeyFile).toCharArray());
+ connectOptions.setPassword(createJwtEs(projectId, privateKeyFile).toCharArray());
} else {
throw new IllegalArgumentException(
"Invalid algorithm " + algorithm + ". Should be one of 'RS256' or 'ES256'.");
@@ -482,7 +462,6 @@ was done in the call to startScreen()
screen.stopScreen();
}
-
public static boolean isJsonValid(String data) {
try {
new JSONObject(data);
@@ -505,9 +484,16 @@ public static void main(String[] args) throws Exception {
System.exit(1);
}
System.out.println("Starting mqtt demo:");
- mqttDeviceDemo(options.projectId, options.cloudRegion, options.registryId, options.deviceId,
- options.privateKeyFile, options.algorithm, options.mqttBridgeHostname,
- options.mqttBridgePort,"state", options.waitTime);
-
+ mqttDeviceDemo(
+ options.projectId,
+ options.cloudRegion,
+ options.registryId,
+ options.deviceId,
+ options.privateKeyFile,
+ options.algorithm,
+ options.mqttBridgeHostname,
+ options.mqttBridgePort,
+ "state",
+ options.waitTime);
}
}
diff --git a/iot/api-client/codelab/manager/src/main/java/com/example/cloud/iot/examples/RetryHttpInitializerWrapper.java b/iot/api-client/codelab/manager/src/main/java/com/example/cloud/iot/examples/RetryHttpInitializerWrapper.java
index 47bb8d3e269..d565dcd41a3 100644
--- a/iot/api-client/codelab/manager/src/main/java/com/example/cloud/iot/examples/RetryHttpInitializerWrapper.java
+++ b/iot/api-client/codelab/manager/src/main/java/com/example/cloud/iot/examples/RetryHttpInitializerWrapper.java
@@ -26,7 +26,6 @@
import com.google.api.client.util.ExponentialBackOff;
import com.google.api.client.util.Sleeper;
import com.google.common.base.Preconditions;
-
import java.io.IOException;
import java.util.logging.Logger;
diff --git a/iot/api-client/end-to-end-example/pom.xml b/iot/api-client/end-to-end-example/pom.xml
index 5aa3bc3eeb2..5b0cdb60d14 100644
--- a/iot/api-client/end-to-end-example/pom.xml
+++ b/iot/api-client/end-to-end-example/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
1.8
@@ -43,7 +43,7 @@
org.json
json
- 20190722
+ 20200518
io.jsonwebtoken
@@ -58,17 +58,17 @@
com.google.apis
google-api-services-cloudiot
- v1-rev20200414-1.30.9
+ v1-rev20200519-1.30.9
com.google.cloud
google-cloud-pubsub
- 1.105.1
+ 1.107.0
- com.google.oauth-client
- google-oauth-client
- 1.30.6
+ com.google.auth
+ google-auth-library-oauth2-http
+ 0.21.0
com.google.guava
@@ -118,4 +118,4 @@
-
\ No newline at end of file
+
diff --git a/iot/api-client/end-to-end-example/src/main/java/com/example/cloud/iot/endtoend/CloudiotPubsubExampleMqttDevice.java b/iot/api-client/end-to-end-example/src/main/java/com/example/cloud/iot/endtoend/CloudiotPubsubExampleMqttDevice.java
index cf7ee6b5fff..1ba5398ef27 100644
--- a/iot/api-client/end-to-end-example/src/main/java/com/example/cloud/iot/endtoend/CloudiotPubsubExampleMqttDevice.java
+++ b/iot/api-client/end-to-end-example/src/main/java/com/example/cloud/iot/endtoend/CloudiotPubsubExampleMqttDevice.java
@@ -41,18 +41,18 @@
* turned on, its temperature decreases by one degree per second, and when the device's fan is
* turned off, its temperature increases by one degree per second.
*
- * Every second, the device publishes its temperature reading to Google Cloud IoT Core. The
+ * Every second, the device publishes its temperature reading to Google Cloud IoT Core. The
* server meanwhile receives these temperature readings, and decides whether to re-configure the
* device to turn its fan on or off. The server will instruct the device to turn the fan on when the
* device's temperature exceeds 10 degrees, and to turn it off when the device's temperature is less
* than 0 degrees. In a real system, one could use the cloud to compute the optimal thresholds for
* turning on and off the fan, but for illustrative purposes we use a simple threshold model.
*
- *
To connect the device you must have downloaded Google's CA root certificates, and a copy of
+ * To connect the device you must have downloaded Google's CA root certificates, and a copy of
* your private key file. See cloud.google.com/iot for instructions on how to do this. Run this
* script with the corresponding algorithm flag.
*
- *
+ *
* $ mvn clean compile assembly:single
*
* $ mvn exec:java \
@@ -64,7 +64,7 @@
* -algorithm=RS256|ES256"
*
*
- * With a single server, you can run multiple instances of the device with different device ids,
+ * With a single server, you can run multiple instances of the device with different device ids,
* and the server will distinguish them. Try creating a few devices and running them all at the same
* time.
*/
diff --git a/iot/api-client/end-to-end-example/src/main/java/com/example/cloud/iot/endtoend/CloudiotPubsubExampleServer.java b/iot/api-client/end-to-end-example/src/main/java/com/example/cloud/iot/endtoend/CloudiotPubsubExampleServer.java
index 3a6f2a6eef8..903284ae3ec 100644
--- a/iot/api-client/end-to-end-example/src/main/java/com/example/cloud/iot/endtoend/CloudiotPubsubExampleServer.java
+++ b/iot/api-client/end-to-end-example/src/main/java/com/example/cloud/iot/endtoend/CloudiotPubsubExampleServer.java
@@ -16,7 +16,6 @@
package com.example.cloud.iot.endtoend;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.json.JsonFactory;
@@ -28,6 +27,8 @@
import com.google.api.services.cloudiot.v1.model.EventNotificationConfig;
import com.google.api.services.cloudiot.v1.model.GatewayConfig;
import com.google.api.services.cloudiot.v1.model.ModifyCloudToDeviceConfigRequest;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.pubsub.v1.AckReplyConsumer;
import com.google.cloud.pubsub.v1.MessageReceiver;
import com.google.cloud.pubsub.v1.Subscriber;
@@ -46,16 +47,16 @@
/**
* Sample server that pushes configuration to Google Cloud IoT devices.
*
- *
This example represents a server that consumes telemetry data from multiple Cloud IoT devices.
+ * This example represents a server that consumes telemetry data from multiple Cloud IoT devices.
* The devices report telemetry data, which the server consumes from a Cloud Pub/Sub topic. The
* server then decides whether to turn on or off individual devices fans.
*
- *
If you are running this example from a Compute Engine VM, you will have to enable the Cloud
+ * If you are running this example from a Compute Engine VM, you will have to enable the Cloud
* Pub/Sub API for your project, which you can do from the Cloud Console. Create a pubsub topic, for
* example projects/my-project-id/topics/my-topic-name, and a subscription, for example
* projects/my-project-id/subscriptions/my-topic-subscription.
*
- *
You can then run the example with
+ * You can then run the example with
* $ mvn clean compile assembly:single
*
* $ mvn exec:java \
@@ -73,10 +74,10 @@ public class CloudiotPubsubExampleServer {
/** Represents the state of the server. */
public CloudiotPubsubExampleServer() throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
this.service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -87,10 +88,10 @@ public CloudiotPubsubExampleServer() throws GeneralSecurityException, IOExceptio
public static void createRegistry(
String cloudRegion, String projectId, String registryName, String pubsubTopicPath)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -115,10 +116,10 @@ public static void createRegistry(
/** Delete this registry from Cloud IoT. */
public static void deleteRegistry(String cloudRegion, String projectId, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -136,10 +137,10 @@ public static void deleteRegistry(String cloudRegion, String projectId, String r
public static void deleteDevice(
String deviceId, String projectId, String cloudRegion, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -159,10 +160,10 @@ public static void createDevice(
String projectId, String cloudRegion, String registryName, String deviceId)
throws GeneralSecurityException, IOException {
// [START create_device]
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
diff --git a/iot/api-client/manager/pom.xml b/iot/api-client/manager/pom.xml
index 0179b7299b0..f22fa3cadb4 100644
--- a/iot/api-client/manager/pom.xml
+++ b/iot/api-client/manager/pom.xml
@@ -30,7 +30,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -47,7 +47,7 @@
org.json
json
- 20190722
+ 20200518
io.jsonwebtoken
@@ -62,22 +62,22 @@
com.google.apis
google-api-services-cloudiot
- v1-rev20200414-1.30.9
+ v1-rev20200519-1.30.9
com.google.cloud
google-cloud-pubsub
- 1.105.1
+ 1.107.0
com.google.cloud
google-cloud-core
- 1.93.4
+ 1.93.6
- com.google.oauth-client
- google-oauth-client
- 1.30.6
+ com.google.auth
+ google-auth-library-oauth2-http
+ 0.21.0
com.google.guava
@@ -164,7 +164,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -210,7 +210,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -252,7 +252,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/DeviceRegistryExample.java b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/DeviceRegistryExample.java
index f0a82def619..88709af29d2 100644
--- a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/DeviceRegistryExample.java
+++ b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/DeviceRegistryExample.java
@@ -16,7 +16,6 @@
package com.example.cloud.iot.examples;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.json.JsonFactory;
@@ -39,10 +38,11 @@
import com.google.api.services.cloudiot.v1.model.ModifyCloudToDeviceConfigRequest;
import com.google.api.services.cloudiot.v1.model.PublicKeyCredential;
import com.google.api.services.cloudiot.v1.model.SendCommandToDeviceRequest;
-import com.google.api.services.cloudiot.v1.model.SendCommandToDeviceResponse;
import com.google.api.services.cloudiot.v1.model.SetIamPolicyRequest;
import com.google.api.services.cloudiot.v1.model.UnbindDeviceFromGatewayRequest;
import com.google.api.services.cloudiot.v1.model.UnbindDeviceFromGatewayResponse;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.Role;
import com.google.cloud.pubsub.v1.TopicAdminClient;
import com.google.common.io.Files;
@@ -55,29 +55,29 @@
import java.nio.file.Paths;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import org.apache.commons.cli.HelpFormatter;
+
/**
* Example of using Cloud IoT device manager API to administer devices, registries and projects.
*
- * This example uses the Device Manager API to create, retrieve, disable, list and delete Cloud
+ * This example uses the Device Manager API to create, retrieve, disable, list and delete Cloud
* IoT devices and registries, using both RSA and eliptic curve keys for authentication.
*
- *
To start, follow the instructions on the Developer Guide at cloud.google.com/iot to create a
+ * To start, follow the instructions on the Developer Guide at cloud.google.com/iot to create a
* service_account.json file and Cloud Pub/Sub topic as discussed in the guide. You will then need
* to point to the service_account.json file as described in
* https://developers.google.com/identity/protocols/application-default-credentials#howtheywork
*
- *
Before running the example, we have to create private and public keys, as described in
+ * Before running the example, we have to create private and public keys, as described in
* cloud.google.com/iot. Since we are interacting with the device manager, we will only use the
* public keys. The private keys are used to sign JWTs to authenticate devices. See the MQTT
* client example for more information.
*
- *
Finally, compile and run the example with:
+ * Finally, compile and run the example with:
*
*
*
@@ -90,7 +90,6 @@
*
*
*/
-
public class DeviceRegistryExample {
static final String APP_NAME = "DeviceRegistryExample";
@@ -105,14 +104,15 @@ protected static Topic createIotTopic(String projectId, String topicId) throws E
final String topicString = topicName.toString();
// add role -> members binding
// create updated policy
- topicAdminClient.setIamPolicy(topicString,
- com.google.iam.v1.Policy.newBuilder(
- topicAdminClient.getIamPolicy(topicString))
- .addBindings(
- Binding.newBuilder()
- .addMembers("serviceAccount:cloud-iot@system.gserviceaccount.com")
- .setRole(Role.owner().toString())
- .build()).build());
+ topicAdminClient.setIamPolicy(
+ topicString,
+ com.google.iam.v1.Policy.newBuilder(topicAdminClient.getIamPolicy(topicString))
+ .addBindings(
+ Binding.newBuilder()
+ .addMembers("serviceAccount:cloud-iot@system.gserviceaccount.com")
+ .setRole(Role.owner().toString())
+ .build())
+ .build());
System.out.println("Setup topic / policy for: " + topic.getName());
return topic;
@@ -124,10 +124,10 @@ protected static Topic createIotTopic(String projectId, String topicId) throws E
protected static void createRegistry(
String cloudRegion, String projectId, String registryName, String pubsubTopicPath)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -154,10 +154,10 @@ protected static void createRegistry(
/** Delete this registry from Cloud IoT. */
protected static void deleteRegistry(String cloudRegion, String projectId, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -165,7 +165,7 @@ protected static void deleteRegistry(String cloudRegion, String projectId, Strin
final String registryPath =
String.format(
- "projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName);
+ "projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName);
System.out.println("Deleting: " + registryPath);
service.projects().locations().registries().delete(registryPath).execute();
@@ -174,15 +174,15 @@ protected static void deleteRegistry(String cloudRegion, String projectId, Strin
/**
* clearRegistry
- *
- * - Registries can't be deleted if they contain devices,
- * - Gateways (a type of device) can't be deleted if they have bound devices
- * - Devices can't be deleted if bound to gateways...
- *
- * To completely remove a registry, you must unbind all devices from gateways,
- * then remove all devices in a registry before removing the registry.
- * As pseudocode:
- *
+ *
+ *
+ * - Registries can't be deleted if they contain devices,
+ *
- Gateways (a type of device) can't be deleted if they have bound devices
+ *
- Devices can't be deleted if bound to gateways...
+ *
+ *
+ * To completely remove a registry, you must unbind all devices from gateways, then remove all
+ * devices in a registry before removing the registry. As pseudocode:
* ForAll gateways
* ForAll devicesBoundToGateway
* unbindDeviceFromGateway
@@ -194,10 +194,10 @@ protected static void deleteRegistry(String cloudRegion, String projectId, Strin
// [START iot_clear_registry]
protected static void clearRegistry(String cloudRegion, String projectId, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -206,16 +206,11 @@ protected static void clearRegistry(String cloudRegion, String projectId, String
String.format(
"projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName);
- CloudIot.Projects.Locations.Registries regAlias =
- service.projects().locations().registries();
- CloudIot.Projects.Locations.Registries.Devices devAlias =
- regAlias.devices();
+ CloudIot.Projects.Locations.Registries regAlias = service.projects().locations().registries();
+ CloudIot.Projects.Locations.Registries.Devices devAlias = regAlias.devices();
ListDevicesResponse listGatewaysRes =
- devAlias
- .list(registryPath)
- .setGatewayListOptionsGatewayType("GATEWAY")
- .execute();
+ devAlias.list(registryPath).setGatewayListOptionsGatewayType("GATEWAY").execute();
List gateways = listGatewaysRes.getDevices();
// Unbind all devices from all gateways
@@ -242,9 +237,7 @@ protected static void clearRegistry(String cloudRegion, String projectId, String
UnbindDeviceFromGatewayRequest request = new UnbindDeviceFromGatewayRequest();
request.setDeviceId(deviceId);
request.setGatewayId(gatewayId);
- regAlias
- .unbindDeviceFromGateway(registryPath, request)
- .execute();
+ regAlias.unbindDeviceFromGateway(registryPath, request).execute();
}
} else {
System.out.println("Gateway has no bound devices.");
@@ -253,37 +246,30 @@ protected static void clearRegistry(String cloudRegion, String projectId, String
}
// Remove all devices from the regsitry
- List devices =
- devAlias
- .list(registryPath)
- .execute()
- .getDevices();
+ List devices = devAlias.list(registryPath).execute().getDevices();
if (devices != null) {
System.out.println("Found " + devices.size() + " devices");
for (Device d : devices) {
String deviceId = d.getId();
- String devicePath = String.format(
- "%s/devices/%s", registryPath, deviceId);
+ String devicePath = String.format("%s/devices/%s", registryPath, deviceId);
service.projects().locations().registries().devices().delete(devicePath).execute();
}
}
// Delete the registry
service.projects().locations().registries().delete(registryPath).execute();
-
}
// [END iot_clear_registry]
-
// [START iot_list_devices]
/** Print all of the devices in this registry to standard out. */
protected static void listDevices(String projectId, String cloudRegion, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -328,10 +314,10 @@ protected static void createDeviceWithEs256(
String cloudRegion,
String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -376,10 +362,10 @@ protected static void createDeviceWithRs256(
String cloudRegion,
String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -418,16 +404,16 @@ protected static void createDeviceWithRs256(
/**
* Create a device that has no credentials.
*
- * This is a valid way to construct a device, however until it is patched with a credential the
+ * This is a valid way to construct a device, however until it is patched with a credential the
* device will not be able to connect to Cloud IoT.
*/
protected static void createDeviceWithNoAuth(
String deviceId, String projectId, String cloudRegion, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -458,10 +444,10 @@ protected static void createDeviceWithNoAuth(
protected static void deleteDevice(
String deviceId, String projectId, String cloudRegion, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -482,10 +468,10 @@ protected static void deleteDevice(
protected static Device getDevice(
String deviceId, String projectId, String cloudRegion, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -506,10 +492,10 @@ protected static Device getDevice(
protected static List getDeviceStates(
String deviceId, String projectId, String cloudRegion, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -534,10 +520,10 @@ protected static List getDeviceStates(
protected static DeviceRegistry getRegistry(
String projectId, String cloudRegion, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -556,10 +542,10 @@ protected static DeviceRegistry getRegistry(
protected static void listDeviceConfigs(
String deviceId, String projectId, String cloudRegion, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -594,10 +580,10 @@ protected static void listDeviceConfigs(
/** Lists all of the registries associated with the given project. */
protected static void listRegistries(String projectId, String cloudRegion)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -639,10 +625,10 @@ protected static void patchEs256ForAuth(
String cloudRegion,
String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -687,10 +673,10 @@ protected static void patchRsa256ForAuth(
String cloudRegion,
String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -736,10 +722,10 @@ protected static void setDeviceConfiguration(
String data,
long version)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -775,10 +761,10 @@ protected static void setDeviceConfiguration(
/** Retrieves IAM permissions for the given registry. */
protected static void getIamPermissions(String projectId, String cloudRegion, String registryName)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -817,10 +803,10 @@ protected static void getIamPermissions(String projectId, String cloudRegion, St
protected static void setIamPermissions(
String projectId, String cloudRegion, String registryName, String member, String role)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -886,10 +872,10 @@ protected static void setIamPermissions(
protected static void sendCommand(
String deviceId, String projectId, String cloudRegion, String registryName, String data)
throws GeneralSecurityException, IOException {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -926,10 +912,10 @@ protected static void bindDeviceToGateway(
// [START iot_bind_device_to_gateway]
createDevice(projectId, cloudRegion, registryName, deviceId);
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -959,10 +945,10 @@ protected static void unbindDeviceFromGateway(
String projectId, String cloudRegion, String registryName, String deviceId, String gatewayId)
throws GeneralSecurityException, IOException {
// [START iot_unbind_device_from_gateway]
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -993,10 +979,10 @@ protected static void createDevice(
String projectId, String cloudRegion, String registryName, String deviceId)
throws GeneralSecurityException, IOException {
// [START iot_create_device]
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -1060,10 +1046,10 @@ protected static void createGateway(
String algorithm)
throws GeneralSecurityException, IOException {
// [START iot_create_gateway]
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -1112,10 +1098,10 @@ protected static void createGateway(
protected static void listGateways(String projectId, String cloudRegion, String registryName)
throws IOException, GeneralSecurityException {
// [START iot_list_gateways]
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -1157,10 +1143,10 @@ protected static void listDevicesForGateway(
String projectId, String cloudRegion, String registryName, String gatewayId)
throws IOException, GeneralSecurityException {
// [START iot_list_devices_for_gateway]
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName(APP_NAME)
@@ -1200,8 +1186,11 @@ protected static void mainCreate(DeviceRegistryExampleOptions options) throws Ex
} else if ("create-es".equals(options.command)) {
System.out.println("Create ES Device:");
createDeviceWithEs256(
- options.deviceId, options.ecPublicKeyFile, options.projectId, options.cloudRegion,
- options.registryName);
+ options.deviceId,
+ options.ecPublicKeyFile,
+ options.projectId,
+ options.cloudRegion,
+ options.registryName);
} else if ("create-rsa".equals(options.command)) {
System.out.println("Create RSA Device:");
createDeviceWithRs256(
@@ -1213,7 +1202,7 @@ protected static void mainCreate(DeviceRegistryExampleOptions options) throws Ex
} else if ("create-unauth".equals(options.command)) {
System.out.println("Create Unauth Device");
createDeviceWithNoAuth(
- options.deviceId, options.projectId, options.cloudRegion, options.registryName);
+ options.deviceId, options.projectId, options.cloudRegion, options.registryName);
} else if ("create-registry".equals(options.command)) {
System.out.println("Create registry");
createRegistry(
@@ -1228,8 +1217,12 @@ protected static void mainCreate(DeviceRegistryExampleOptions options) throws Ex
}
createGateway(
- options.projectId, options.cloudRegion, options.registryName, options.gatewayId,
- certificateFilePath, algorithm);
+ options.projectId,
+ options.cloudRegion,
+ options.registryName,
+ options.gatewayId,
+ certificateFilePath,
+ algorithm);
}
}
@@ -1237,8 +1230,7 @@ protected static void mainGet(DeviceRegistryExampleOptions options) throws Excep
if ("get-device".equals(options.command)) {
System.out.println("Get device");
System.out.println(
- getDevice(
- options.deviceId, options.projectId, options.cloudRegion, options.registryName)
+ getDevice(options.deviceId, options.projectId, options.cloudRegion, options.registryName)
.toPrettyString());
} else if ("get-iam-permissions".equals(options.command)) {
System.out.println("Get iam permissions");
@@ -1253,8 +1245,7 @@ protected static void mainGet(DeviceRegistryExampleOptions options) throws Excep
}
} else if ("get-registry".equals(options.command)) {
System.out.println("Get registry");
- System.out.println(
- getRegistry(options.projectId, options.cloudRegion, options.registryName));
+ System.out.println(getRegistry(options.projectId, options.cloudRegion, options.registryName));
}
}
@@ -1279,8 +1270,7 @@ public static void main(String[] args) throws Exception {
clearRegistry(options.cloudRegion, options.projectId, options.registryName);
} else if ("delete-device".equals(options.command)) {
System.out.println("Delete device");
- deleteDevice(
- options.deviceId, options.projectId, options.cloudRegion, options.registryName);
+ deleteDevice(options.deviceId, options.projectId, options.cloudRegion, options.registryName);
} else if ("delete-registry".equals(options.command)) {
System.out.println("Delete registry");
deleteRegistry(options.cloudRegion, options.projectId, options.registryName);
@@ -1334,12 +1324,18 @@ public static void main(String[] args) throws Exception {
} else if ("bind-device-to-gateway".equals(options.command)) {
System.out.println("Bind device to gateway:");
bindDeviceToGateway(
- options.projectId, options.cloudRegion, options.registryName, options.deviceId,
+ options.projectId,
+ options.cloudRegion,
+ options.registryName,
+ options.deviceId,
options.gatewayId);
} else if ("unbind-device-from-gateway".equals(options.command)) {
System.out.println("Unbind device from gateway:");
unbindDeviceFromGateway(
- options.projectId, options.cloudRegion, options.registryName, options.deviceId,
+ options.projectId,
+ options.cloudRegion,
+ options.registryName,
+ options.deviceId,
options.gatewayId);
} else if ("list-gateways".equals(options.command)) {
System.out.println("Listing gateways: ");
diff --git a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/DeviceRegistryExampleOptions.java b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/DeviceRegistryExampleOptions.java
index 63ee05ff8aa..71d367dbf68 100644
--- a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/DeviceRegistryExampleOptions.java
+++ b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/DeviceRegistryExampleOptions.java
@@ -16,14 +16,12 @@
package com.example.cloud.iot.examples;
-import java.util.Arrays;
import javax.annotation.Nullable;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Option.Builder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
@@ -47,10 +45,10 @@ public class DeviceRegistryExampleOptions {
long version = 0;
/** Construct an DeviceRegistryExampleOptions class from command line flags. */
- public static @Nullable DeviceRegistryExampleOptions fromFlags(String...args) {
+ public static @Nullable DeviceRegistryExampleOptions fromFlags(String... args) {
// Required arguments
options.addOption(
- Option.builder()
+ Option.builder()
.type(String.class)
.longOpt("command")
.hasArg()
@@ -255,8 +253,7 @@ public class DeviceRegistryExampleOptions {
String footer = "\nhttps://cloud.google.com/iot-core";
HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp(
- "DeviceRegistryExample", header, options, footer, true);
+ formatter.printHelp("DeviceRegistryExample", header, options, footer, true);
System.err.println(e.getMessage());
return null;
diff --git a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/HttpExample.java b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/HttpExample.java
index 97fafd68534..b4ba15bd669 100644
--- a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/HttpExample.java
+++ b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/HttpExample.java
@@ -39,8 +39,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-import java.net.ProtocolException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -50,17 +48,18 @@
import org.joda.time.DateTime;
import org.json.JSONException;
import org.json.JSONObject;
+
// [END iot_http_includes]
/**
* Java sample of connecting to Google Cloud IoT Core vice via HTTP, using JWT.
*
- * This example connects to Google Cloud IoT Core via HTTP Bridge, using a JWT for device
+ * This example connects to Google Cloud IoT Core via HTTP Bridge, using a JWT for device
* authentication. After connecting, by default the device publishes 100 messages at a rate of one
* per second, and then exits. You can change The behavior to set state instead of events by using
* flag -message_type to 'state'.
*
- *
To run this example, follow the instructions in the README located in the sample's parent
+ * To run this example, follow the instructions in the README located in the sample's parent
* folder.
*/
public class HttpExample {
@@ -110,8 +109,14 @@ private static String createJwtEs(String projectId, String privateKeyFile) throw
// [START iot_http_getconfig]
/** Publish an event or state message using Cloud IoT Core via the HTTP API. */
- protected static void getConfig(String urlPath, String token, String projectId,
- String cloudRegion, String registryId, String deviceId, String version)
+ protected static void getConfig(
+ String urlPath,
+ String token,
+ String projectId,
+ String cloudRegion,
+ String registryId,
+ String deviceId,
+ String version)
throws IOException {
// Build the resource path of the device that is going to be authenticated.
String devicePath =
@@ -121,12 +126,13 @@ protected static void getConfig(String urlPath, String token, String projectId,
urlPath = urlPath + devicePath + "/config?local_version=" + version;
HttpRequestFactory requestFactory =
- HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
- @Override
- public void initialize(HttpRequest request) {
- request.setParser(new JsonObjectParser(JSON_FACTORY));
- }
- });
+ HTTP_TRANSPORT.createRequestFactory(
+ new HttpRequestInitializer() {
+ @Override
+ public void initialize(HttpRequest request) {
+ request.setParser(new JsonObjectParser(JSON_FACTORY));
+ }
+ });
final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl(urlPath));
HttpHeaders heads = new HttpHeaders();
@@ -136,13 +142,14 @@ public void initialize(HttpRequest request) {
heads.setCacheControl("no-cache");
req.setHeaders(heads);
- ExponentialBackOff backoff = new ExponentialBackOff.Builder()
- .setInitialIntervalMillis(500)
- .setMaxElapsedTimeMillis(900000)
- .setMaxIntervalMillis(6000)
- .setMultiplier(1.5)
- .setRandomizationFactor(0.5)
- .build();
+ ExponentialBackOff backoff =
+ new ExponentialBackOff.Builder()
+ .setInitialIntervalMillis(500)
+ .setMaxElapsedTimeMillis(900000)
+ .setMaxIntervalMillis(6000)
+ .setMultiplier(1.5)
+ .setRandomizationFactor(0.5)
+ .build();
req.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(backoff));
HttpResponse res = req.execute();
System.out.println(res.getStatusCode());
@@ -155,8 +162,15 @@ public void initialize(HttpRequest request) {
// [START iot_http_publish]
/** Publish an event or state message using Cloud IoT Core via the HTTP API. */
- protected static void publishMessage(String payload, String urlPath, String messageType,
- String token, String projectId, String cloudRegion, String registryId, String deviceId)
+ protected static void publishMessage(
+ String payload,
+ String urlPath,
+ String messageType,
+ String token,
+ String projectId,
+ String cloudRegion,
+ String registryId,
+ String deviceId)
throws IOException, JSONException {
// Build the resource path of the device that is going to be authenticated.
String devicePath =
@@ -172,14 +186,14 @@ protected static void publishMessage(String payload, String urlPath, String mess
urlPath = urlPath + devicePath + ":" + urlSuffix;
-
final HttpRequestFactory requestFactory =
- HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
- @Override
- public void initialize(HttpRequest request) {
- request.setParser(new JsonObjectParser(JSON_FACTORY));
- }
- });
+ HTTP_TRANSPORT.createRequestFactory(
+ new HttpRequestInitializer() {
+ @Override
+ public void initialize(HttpRequest request) {
+ request.setParser(new JsonObjectParser(JSON_FACTORY));
+ }
+ });
HttpHeaders heads = new HttpHeaders();
heads.setAuthorization(String.format("Bearer %s", token));
@@ -196,20 +210,22 @@ public void initialize(HttpRequest request) {
data.put("state", state);
}
- ByteArrayContent content = new ByteArrayContent(
- "application/json", data.toString().getBytes(StandardCharsets.UTF_8.name()));
+ ByteArrayContent content =
+ new ByteArrayContent(
+ "application/json", data.toString().getBytes(StandardCharsets.UTF_8.name()));
final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl(urlPath));
req.setHeaders(heads);
req.setContent(content);
req.setRequestMethod("POST");
- ExponentialBackOff backoff = new ExponentialBackOff.Builder()
- .setInitialIntervalMillis(500)
- .setMaxElapsedTimeMillis(900000)
- .setMaxIntervalMillis(6000)
- .setMultiplier(1.5)
- .setRandomizationFactor(0.5)
- .build();
+ ExponentialBackOff backoff =
+ new ExponentialBackOff.Builder()
+ .setInitialIntervalMillis(500)
+ .setMaxElapsedTimeMillis(900000)
+ .setMaxIntervalMillis(6000)
+ .setMultiplier(1.5)
+ .setRandomizationFactor(0.5)
+ .build();
req.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(backoff));
HttpResponse res = req.execute();
@@ -244,8 +260,14 @@ protected static void main(String[] args) throws Exception {
System.out.format("Using URL: '%s'%n", urlPath);
// Show the latest configuration
- getConfig(urlPath, token, options.projectId, options.cloudRegion, options.registryId,
- options.deviceId, "0");
+ getConfig(
+ urlPath,
+ token,
+ options.projectId,
+ options.cloudRegion,
+ options.registryId,
+ options.deviceId,
+ "0");
// Publish numMessages messages to the HTTP bridge.
for (int i = 1; i <= options.numMessages; ++i) {
@@ -267,8 +289,15 @@ protected static void main(String[] args) throws Exception {
}
}
- publishMessage(payload, urlPath, options.messageType, token, options.projectId,
- options.cloudRegion, options.registryId, options.deviceId);
+ publishMessage(
+ payload,
+ urlPath,
+ options.messageType,
+ token,
+ options.projectId,
+ options.cloudRegion,
+ options.registryId,
+ options.deviceId);
if ("event".equals(options.messageType)) {
// Frequently send event payloads (every second)
diff --git a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/HttpExampleOptions.java b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/HttpExampleOptions.java
index f1b309df855..0ab17364e18 100644
--- a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/HttpExampleOptions.java
+++ b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/HttpExampleOptions.java
@@ -21,11 +21,9 @@
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Option.Builder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
-
/** Command line options for the HTTP example. */
public class HttpExampleOptions {
static final Options options = new Options();
@@ -42,7 +40,7 @@ public class HttpExampleOptions {
String messageType = "event";
/** Construct an HttpExampleOptions class from command line flags. */
- public static @Nullable HttpExampleOptions fromFlags(String...args) {
+ public static @Nullable HttpExampleOptions fromFlags(String... args) {
// Required arguments
options.addOption(
Option.builder()
diff --git a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/MqttExample.java b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/MqttExample.java
index fff88777113..e79bf6333cb 100644
--- a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/MqttExample.java
+++ b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/MqttExample.java
@@ -39,20 +39,21 @@
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.joda.time.DateTime;
+
// [END iot_mqtt_includes]
/**
* Java sample of connecting to Google Cloud IoT Core vice via MQTT, using JWT.
*
- *
This example connects to Google Cloud IoT Core via MQTT, using a JWT for device
+ * This example connects to Google Cloud IoT Core via MQTT, using a JWT for device
* authentication. After connecting, by default the device publishes 100 messages to the device's
* MQTT topic at a rate of one per second, and then exits. To set state instead of publishing
* telemetry events, set the `-message_type` flag to `state.`
*
- *
To run this example, first create your credentials and register your device as described in
+ * To run this example, first create your credentials and register your device as described in
* the README located in the sample's parent folder.
*
- *
After you have registered your device and generated your credentials, compile and run with the
+ * After you have registered your device and generated your credentials, compile and run with the
* corresponding algorithm flag, for example:
*
*
@@ -178,7 +179,7 @@ protected static MqttClient startMqtt(
long retryIntervalMs = initialConnectIntervalMillis;
long totalRetryTimeMs = 0;
- while ((totalRetryTimeMs < maxConnectRetryTimeElapsedMillis) && !client.isConnected()) {
+ while ((totalRetryTimeMs < maxConnectRetryTimeElapsedMillis) && !client.isConnected()) {
try {
client.connect(connectOptions);
} catch (MqttException e) {
diff --git a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/MqttExampleOptions.java b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/MqttExampleOptions.java
index f043cfff6f8..cb7683e9524 100644
--- a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/MqttExampleOptions.java
+++ b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/MqttExampleOptions.java
@@ -21,11 +21,9 @@
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Option.Builder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
-
/** Command line options for the MQTT example. */
public class MqttExampleOptions {
static final Options options = new Options();
@@ -47,7 +45,7 @@ public class MqttExampleOptions {
int waitTime = 120;
/** Construct an MqttExampleOptions class from command line flags. */
- public static @Nullable MqttExampleOptions fromFlags(String...args) {
+ public static @Nullable MqttExampleOptions fromFlags(String... args) {
// Required arguments
options.addOption(
Option.builder()
diff --git a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/RetryHttpInitializerWrapper.java b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/RetryHttpInitializerWrapper.java
index 7f905ab6233..dcbb6df53e5 100644
--- a/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/RetryHttpInitializerWrapper.java
+++ b/iot/api-client/manager/src/main/java/com/example/cloud/iot/examples/RetryHttpInitializerWrapper.java
@@ -90,7 +90,7 @@ public boolean handleResponse(
return true;
} else if (backoffHandler.handleResponse(request, response, supportsRetry)) {
// Otherwise, we defer to the judgment of our internal backoff handler.
- LOG.info(request.getUrl().toString().replaceAll("[\r\n]",""));
+ LOG.info(request.getUrl().toString().replaceAll("[\r\n]", ""));
return true;
} else {
return false;
diff --git a/iot/api-client/manager/src/test/java/com/example/cloud/iot/examples/ManagerIT.java b/iot/api-client/manager/src/test/java/com/example/cloud/iot/examples/ManagerIT.java
index db8b2a47c8b..15d2fcedf23 100644
--- a/iot/api-client/manager/src/test/java/com/example/cloud/iot/examples/ManagerIT.java
+++ b/iot/api-client/manager/src/test/java/com/example/cloud/iot/examples/ManagerIT.java
@@ -16,7 +16,6 @@
package com.example.cloud.iot.examples;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.json.JsonFactory;
@@ -24,14 +23,13 @@
import com.google.api.services.cloudiot.v1.CloudIot;
import com.google.api.services.cloudiot.v1.CloudIotScopes;
import com.google.api.services.cloudiot.v1.model.DeviceRegistry;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.pubsub.v1.TopicAdminClient;
import com.google.pubsub.v1.ProjectTopicName;
import com.google.pubsub.v1.Topic;
import java.io.ByteArrayOutputStream;
-import java.io.OutputStreamWriter;
import java.io.PrintStream;
-import java.io.Writer;
-import java.lang.StringBuilder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.eclipse.paho.client.mqttv3.MqttClient;
@@ -43,7 +41,6 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-
/** Tests for iot "Management" sample. */
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
@@ -82,10 +79,10 @@ public void tearDown() throws Exception {
}
public void clearTestRegistries() throws Exception {
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
final CloudIot service =
new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
.setApplicationName("TEST")
@@ -107,8 +104,8 @@ public void clearTestRegistries() throws Exception {
String registryId = r.getId();
if (registryId.startsWith("java-reg-")) {
long currSecs = System.currentTimeMillis() / 1000L;
- long regSecs = Long.parseLong(registryId.substring(
- "java-reg-".length(), registryId.length()));
+ long regSecs =
+ Long.parseLong(registryId.substring("java-reg-".length(), registryId.length()));
long diffSecs = currSecs - regSecs;
if (diffSecs > (60 * 60 * 24 * 7 * 10)) { // tests from last week or older
System.out.println("Remove Id: " + r.getId());
diff --git a/jobs/v3/pom.xml b/jobs/v3/pom.xml
index ace406afd73..c868a0ff100 100644
--- a/jobs/v3/pom.xml
+++ b/jobs/v3/pom.xml
@@ -15,7 +15,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -32,7 +32,12 @@
com.google.apis
google-api-services-jobs
- v3-rev20200506-1.30.9
+ v3-rev20200604-1.30.9
+
+
+ com.google.auth
+ google-auth-library-oauth2-http
+ 0.21.0
@@ -49,4 +54,4 @@
4.13
-
\ No newline at end of file
+
diff --git a/jobs/v3/src/main/java/com/google/samples/AutoCompleteSample.java b/jobs/v3/src/main/java/com/google/samples/AutoCompleteSample.java
index 202cefaa6fd..fe282629097 100644
--- a/jobs/v3/src/main/java/com/google/samples/AutoCompleteSample.java
+++ b/jobs/v3/src/main/java/com/google/samples/AutoCompleteSample.java
@@ -35,16 +35,13 @@ public final class AutoCompleteSample {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = JobServiceQuickstart
- .getTalentSolutionClient();
+ private static CloudTalentSolution talentSolutionClient =
+ JobServiceQuickstart.getTalentSolutionClient();
- //[START auto_complete_job_title]
+ // [START auto_complete_job_title]
- /**
- * Auto completes job titles within given companyName.
- */
- public static void jobTitleAutoComplete(String companyName, String query)
- throws IOException {
+ /** Auto completes job titles within given companyName. */
+ public static void jobTitleAutoComplete(String companyName, String query) throws IOException {
Complete complete =
talentSolutionClient
@@ -64,11 +61,8 @@ public static void jobTitleAutoComplete(String companyName, String query)
}
// [END auto_complete_default]
- /**
- * Auto completes job titles within given companyName.
- */
- public static void defaultAutoComplete(String companyName, String query)
- throws IOException {
+ /** Auto completes job titles within given companyName. */
+ public static void defaultAutoComplete(String companyName, String query) throws IOException {
Complete complete =
talentSolutionClient
.projects()
@@ -90,8 +84,8 @@ public static void main(String... args) throws Exception {
Company companyToBeCreated = BasicCompanySample.generateCompany().setDisplayName("Google");
String companyName = BasicCompanySample.createCompany(companyToBeCreated).getName();
- Job jobToBeCreated = BasicJobSample.generateJobWithRequiredFields(companyName)
- .setTitle("Software engineer");
+ Job jobToBeCreated =
+ BasicJobSample.generateJobWithRequiredFields(companyName).setTitle("Software engineer");
final String jobName = BasicJobSample.createJob(jobToBeCreated).getName();
// Wait several seconds for post processing
diff --git a/jobs/v3/src/main/java/com/google/samples/BasicCompanySample.java b/jobs/v3/src/main/java/com/google/samples/BasicCompanySample.java
index c68071518aa..052c82dd541 100644
--- a/jobs/v3/src/main/java/com/google/samples/BasicCompanySample.java
+++ b/jobs/v3/src/main/java/com/google/samples/BasicCompanySample.java
@@ -43,18 +43,15 @@ public final class BasicCompanySample {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = JobServiceQuickstart
- .getTalentSolutionClient();
+ private static CloudTalentSolution talentSolutionClient =
+ JobServiceQuickstart.getTalentSolutionClient();
// [START basic_company]
- /**
- * Generate a company
- */
+ /** Generate a company */
public static Company generateCompany() {
// distributor company id should be a unique Id in your system.
- String companyName =
- "company:" + String.valueOf(new Random().nextLong());
+ String companyName = "company:" + String.valueOf(new Random().nextLong());
Company company =
new Company()
@@ -68,15 +65,14 @@ public static Company generateCompany() {
// [START create_company]
- /**
- * Create a company.
- */
+ /** Create a company. */
public static Company createCompany(Company companyToBeCreated) throws IOException {
try {
CreateCompanyRequest createCompanyRequest =
new CreateCompanyRequest().setCompany(companyToBeCreated);
Company companyCreated =
- talentSolutionClient.projects()
+ talentSolutionClient
+ .projects()
.companies()
.create(DEFAULT_PROJECT_ID, createCompanyRequest)
.execute();
@@ -91,9 +87,7 @@ public static Company createCompany(Company companyToBeCreated) throws IOExcepti
// [START get_company]
- /**
- * Get a company.
- */
+ /** Get a company. */
public static Company getCompany(String companyName) throws IOException {
try {
Company companyExisted =
@@ -109,9 +103,7 @@ public static Company getCompany(String companyName) throws IOException {
// [START update_company]
- /**
- * Updates a company.
- */
+ /** Updates a company. */
public static Company updateCompany(String companyName, Company companyToBeUpdated)
throws IOException {
try {
@@ -136,12 +128,9 @@ public static Company updateCompany(String companyName, Company companyToBeUpdat
// [START update_company_with_field_mask]
- /**
- * Updates a company.
- */
- public static Company updateCompanyWithFieldMask(String companyName, String fieldMask,
- Company companyToBeUpdated)
- throws IOException {
+ /** Updates a company. */
+ public static Company updateCompanyWithFieldMask(
+ String companyName, String fieldMask, Company companyToBeUpdated) throws IOException {
try {
// String foo = String.format("?updateCompanyFields=%s",fieldMask);
UpdateCompanyRequest updateCompanyRequest =
@@ -165,9 +154,7 @@ public static Company updateCompanyWithFieldMask(String companyName, String fiel
// [START delete_company]
- /**
- * Delete a company.
- */
+ /** Delete a company. */
public static void deleteCompany(String companyName) throws IOException {
try {
talentSolutionClient.projects().companies().delete(companyName).execute();
@@ -191,14 +178,14 @@ public static void main(String... args) throws Exception {
getCompany(companyName);
// Update a company
- Company companyToBeUpdated = companyCreated
- .setCareerSiteUri("https://elgoog.im/");
+ Company companyToBeUpdated = companyCreated.setCareerSiteUri("https://elgoog.im/");
updateCompany(companyName, companyToBeUpdated);
// Update a company with field mask
- updateCompanyWithFieldMask(companyName, "displayName",
- new Company().setDisplayName("changedTitle")
- .setName(companyCreated.getName()));
+ updateCompanyWithFieldMask(
+ companyName,
+ "displayName",
+ new Company().setDisplayName("changedTitle").setName(companyCreated.getName()));
// Delete a company
deleteCompany(companyName);
diff --git a/jobs/v3/src/main/java/com/google/samples/BasicJobSample.java b/jobs/v3/src/main/java/com/google/samples/BasicJobSample.java
index 50fb7d2790b..a7266098bd8 100644
--- a/jobs/v3/src/main/java/com/google/samples/BasicJobSample.java
+++ b/jobs/v3/src/main/java/com/google/samples/BasicJobSample.java
@@ -46,18 +46,15 @@ public final class BasicJobSample {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = JobServiceQuickstart
- .getTalentSolutionClient();
+ private static CloudTalentSolution talentSolutionClient =
+ JobServiceQuickstart.getTalentSolutionClient();
// [START basic_job]
- /**
- * Generate a basic job with given companyName.
- */
+ /** Generate a basic job with given companyName. */
public static Job generateJobWithRequiredFields(String companyName) {
// requisition id should be a unique Id in your system.
- String requisitionId =
- "jobWithRequiredFields:" + String.valueOf(new Random().nextLong());
+ String requisitionId = "jobWithRequiredFields:" + String.valueOf(new Random().nextLong());
ApplicationInfo applicationInfo =
new ApplicationInfo().setUris(Arrays.asList("http://careers.google.com"));
@@ -67,8 +64,7 @@ public static Job generateJobWithRequiredFields(String companyName) {
.setTitle("Software Engineer")
.setCompanyName(companyName)
.setApplicationInfo(applicationInfo)
- .setDescription(
- "Design, develop, test, deploy, maintain and improve software.");
+ .setDescription("Design, develop, test, deploy, maintain and improve software.");
System.out.println("Job generated: " + job);
return job;
}
@@ -76,16 +72,17 @@ public static Job generateJobWithRequiredFields(String companyName) {
// [START create_job]
- /**
- * Create a job.
- */
+ /** Create a job. */
public static Job createJob(Job jobToBeCreated) throws IOException {
try {
- CreateJobRequest createJobRequest =
- new CreateJobRequest().setJob(jobToBeCreated);
-
- Job jobCreated = talentSolutionClient.projects().jobs()
- .create(DEFAULT_PROJECT_ID, createJobRequest).execute();
+ CreateJobRequest createJobRequest = new CreateJobRequest().setJob(jobToBeCreated);
+
+ Job jobCreated =
+ talentSolutionClient
+ .projects()
+ .jobs()
+ .create(DEFAULT_PROJECT_ID, createJobRequest)
+ .execute();
System.out.println("Job created: " + jobCreated);
return jobCreated;
} catch (IOException e) {
@@ -97,9 +94,7 @@ public static Job createJob(Job jobToBeCreated) throws IOException {
// [START get_job]
- /**
- * Get a job.
- */
+ /** Get a job. */
public static Job getJob(String jobName) throws IOException {
try {
Job jobExisted = talentSolutionClient.projects().jobs().get(jobName).execute();
@@ -114,14 +109,10 @@ public static Job getJob(String jobName) throws IOException {
// [START update_job]
- /**
- * Update a job.
- */
- public static Job updateJob(String jobName, Job jobToBeUpdated)
- throws IOException {
+ /** Update a job. */
+ public static Job updateJob(String jobName, Job jobToBeUpdated) throws IOException {
try {
- UpdateJobRequest updateJobRequest =
- new UpdateJobRequest().setJob(jobToBeUpdated);
+ UpdateJobRequest updateJobRequest = new UpdateJobRequest().setJob(jobToBeUpdated);
Job jobUpdated =
talentSolutionClient.projects().jobs().patch(jobName, updateJobRequest).execute();
System.out.println("Job updated: " + jobUpdated);
@@ -136,9 +127,7 @@ public static Job updateJob(String jobName, Job jobToBeUpdated)
// [START update_job_with_field_mask]
- /**
- * Update a job.
- */
+ /** Update a job. */
public static Job updateJobWithFieldMask(String jobName, String fieldMask, Job jobToBeUpdated)
throws IOException {
try {
@@ -157,9 +146,7 @@ public static Job updateJobWithFieldMask(String jobName, String fieldMask, Job j
// [START delete_job]
- /**
- * Delete a job.
- */
+ /** Delete a job. */
public static void deleteJob(String jobName) throws IOException {
try {
talentSolutionClient.projects().jobs().delete(jobName).execute();
diff --git a/jobs/v3/src/main/java/com/google/samples/BatchOperationSample.java b/jobs/v3/src/main/java/com/google/samples/BatchOperationSample.java
index 62aa6bf8a5c..e9461a512a4 100644
--- a/jobs/v3/src/main/java/com/google/samples/BatchOperationSample.java
+++ b/jobs/v3/src/main/java/com/google/samples/BatchOperationSample.java
@@ -41,16 +41,16 @@
*
* - Delete job within batch.
*
- * For simplicity, the samples always use the same kind of requests in each batch. In a real case ,
- * you might put different kinds of request in one batch.
+ * For simplicity, the samples always use the same kind of requests in each batch. In a real case
+ * , you might put different kinds of request in one batch.
*/
public final class BatchOperationSample {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = JobServiceQuickstart
- .getTalentSolutionClient();
+ private static CloudTalentSolution talentSolutionClient =
+ JobServiceQuickstart.getTalentSolutionClient();
// [START batch_job_create]
public static List batchCreateJobs(String companyName) throws IOException {
@@ -60,8 +60,7 @@ public static List batchCreateJobs(String companyName) throws IOException {
JsonBatchCallback createCallback =
new JsonBatchCallback() {
@Override
- public void onFailure(GoogleJsonError e,
- HttpHeaders responseHeaders) {
+ public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
System.out.println("Create Error Message: " + e.getMessage());
}
@@ -81,8 +80,7 @@ public void onSuccess(Job response, HttpHeaders responseHeaders) {
.setRequisitionId("123456")
.setTitle("Software Engineer")
.setApplicationInfo(applicationInfo)
- .setDescription(
- "Design, develop, test, deploy, maintain and improve software.");
+ .setDescription("Design, develop, test, deploy, maintain and improve software.");
Job hardwareEngineerJob =
new Job()
.setCompanyName(companyName)
@@ -146,12 +144,13 @@ public void onSuccess(Job job, HttpHeaders responseHeaders) {
}
// Or just fill in part of field in Job entity and set the updateJobFields
for (int i = 1; i < jobsToBeUpdate.size(); i += 2) {
- Job toBeUpdated = new Job().setTitle("Engineer in Mountain View")
- .setName(jobsToBeUpdate.get(i).getName());
+ Job toBeUpdated =
+ new Job().setTitle("Engineer in Mountain View").setName(jobsToBeUpdate.get(i).getName());
talentSolutionClient
.projects()
.jobs()
- .patch(toBeUpdated.getName(),
+ .patch(
+ toBeUpdated.getName(),
new UpdateJobRequest().setJob(toBeUpdated).setUpdateMask("title"))
.queue(batchUpdate, updateCallback);
}
@@ -174,8 +173,7 @@ public static void batchDeleteJobs(List jobsToBeDeleted) throws IOException
batchDelete,
new JsonBatchCallback() {
@Override
- public void onFailure(GoogleJsonError e,
- HttpHeaders responseHeaders) {
+ public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
System.out.println("Delete Error Message: " + e.getMessage());
}
@@ -190,8 +188,7 @@ public void onSuccess(Empty empty, HttpHeaders responseHeaders) {
// [END batch_job_delete]
public static void main(String... args) throws Exception {
- Company company = BasicCompanySample
- .createCompany(BasicCompanySample.generateCompany());
+ Company company = BasicCompanySample.createCompany(BasicCompanySample.generateCompany());
// Batch create jobs
List createdJobs = batchCreateJobs(company.getName());
diff --git a/jobs/v3/src/main/java/com/google/samples/CommuteSearchSample.java b/jobs/v3/src/main/java/com/google/samples/CommuteSearchSample.java
index fc8e512994c..4410512236a 100644
--- a/jobs/v3/src/main/java/com/google/samples/CommuteSearchSample.java
+++ b/jobs/v3/src/main/java/com/google/samples/CommuteSearchSample.java
@@ -39,8 +39,8 @@ public final class CommuteSearchSample {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = JobServiceQuickstart
- .getTalentSolutionClient();
+ private static CloudTalentSolution talentSolutionClient =
+ JobServiceQuickstart.getTalentSolutionClient();
// [START commute_search]
@@ -62,8 +62,7 @@ public static void commuteSearch(String companyName) throws IOException, Interru
.setCommuteMethod("TRANSIT")
.setTravelDuration("1000s")
.setStartCoordinates(
- new LatLng().setLatitude(37.422408)
- .setLongitude(-122.085609)));
+ new LatLng().setLatitude(37.422408).setLongitude(-122.085609)));
if (companyName != null) {
jobQuery.setCompanyNames(Arrays.asList(companyName));
}
@@ -75,7 +74,10 @@ public static void commuteSearch(String companyName) throws IOException, Interru
.setJobView("JOB_VIEW_FULL")
.setRequirePreciseResultSize(true);
SearchJobsResponse response =
- talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, searchJobsRequest)
+ talentSolutionClient
+ .projects()
+ .jobs()
+ .search(DEFAULT_PROJECT_ID, searchJobsRequest)
.execute();
Thread.sleep(1000);
System.out.println(response);
@@ -86,8 +88,9 @@ public static void main(String... args) throws Exception {
Company companyToBeCreated = BasicCompanySample.generateCompany();
String companyName = BasicCompanySample.createCompany(companyToBeCreated).getName();
- Job jobToBeCreated = BasicJobSample.generateJobWithRequiredFields(companyName)
- .setAddresses(Arrays.asList("1600 Amphitheatre Parkway, Mountain View, CA 94043"));
+ Job jobToBeCreated =
+ BasicJobSample.generateJobWithRequiredFields(companyName)
+ .setAddresses(Arrays.asList("1600 Amphitheatre Parkway, Mountain View, CA 94043"));
String jobName = BasicJobSample.createJob(jobToBeCreated).getName();
// Wait several seconds for post processing
diff --git a/jobs/v3/src/main/java/com/google/samples/CustomAttributeSample.java b/jobs/v3/src/main/java/com/google/samples/CustomAttributeSample.java
index cda82933ad8..a1313bf2314 100644
--- a/jobs/v3/src/main/java/com/google/samples/CustomAttributeSample.java
+++ b/jobs/v3/src/main/java/com/google/samples/CustomAttributeSample.java
@@ -31,8 +31,6 @@
import java.util.Map;
import java.util.Random;
-;
-
/**
* This file contains the samples about CustomAttribute, including:
*
@@ -45,18 +43,15 @@ public final class CustomAttributeSample {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = JobServiceQuickstart
- .getTalentSolutionClient();
+ private static CloudTalentSolution talentSolutionClient =
+ JobServiceQuickstart.getTalentSolutionClient();
// [START custom_attribute_job]
- /**
- * Generate a job with a custom attribute.
- */
+ /** Generate a job with a custom attribute. */
public static Job generateJobWithACustomAttribute(String companyName) {
// requisition id should be a unique Id in your system.
- String requisitionId =
- "jobWithACustomAttribute:" + String.valueOf(new Random().nextLong());
+ String requisitionId = "jobWithACustomAttribute:" + String.valueOf(new Random().nextLong());
ApplicationInfo applicationInfo =
new ApplicationInfo().setUris(Arrays.asList("http://careers.google.com"));
@@ -64,12 +59,10 @@ public static Job generateJobWithACustomAttribute(String companyName) {
Map customAttributes = new HashMap<>();
customAttributes.put(
"someFieldName1",
- new CustomAttribute()
- .setStringValues(Arrays.asList("value1"))
- .setFilterable(Boolean.TRUE));
- customAttributes
- .put("someFieldName2",
- new CustomAttribute().setLongValues(Arrays.asList(256L)).setFilterable(true));
+ new CustomAttribute().setStringValues(Arrays.asList("value1")).setFilterable(Boolean.TRUE));
+ customAttributes.put(
+ "someFieldName2",
+ new CustomAttribute().setLongValues(Arrays.asList(256L)).setFilterable(true));
// Creates job with custom attributes
Job job =
@@ -87,9 +80,7 @@ public static Job generateJobWithACustomAttribute(String companyName) {
// [START custom_attribute_filter_string_value]
- /**
- * CustomAttributeFilter on String value CustomAttribute
- */
+ /** CustomAttributeFilter on String value CustomAttribute */
public static void filtersOnStringValueCustomAttribute()
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
@@ -100,12 +91,10 @@ public static void filtersOnStringValueCustomAttribute()
// Make sure to hash the sessionID
.setSessionId("HashedSessionID")
// Domain of the website where the search is conducted
- .setDomain(
- "www.google.com");
+ .setDomain("www.google.com");
String customAttributeFilter = "NOT EMPTY(someFieldName1)";
- JobQuery jobQuery = new JobQuery()
- .setCustomAttributeFilter(customAttributeFilter);
+ JobQuery jobQuery = new JobQuery().setCustomAttributeFilter(customAttributeFilter);
SearchJobsRequest searchJobsRequest =
new SearchJobsRequest()
@@ -125,9 +114,7 @@ public static void filtersOnStringValueCustomAttribute()
// [START custom_attribute_filter_long_value]
- /**
- * CustomAttributeFilter on Long value CustomAttribute
- */
+ /** CustomAttributeFilter on Long value CustomAttribute */
public static void filtersOnLongValueCustomAttribute() throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
RequestMetadata requestMetadata =
@@ -140,8 +127,7 @@ public static void filtersOnLongValueCustomAttribute() throws IOException, Inter
.setDomain("www.google.com");
String customAttributeFilter = "(255 <= someFieldName2) AND (someFieldName2 <= 257)";
- JobQuery jobQuery = new JobQuery()
- .setCustomAttributeFilter(customAttributeFilter);
+ JobQuery jobQuery = new JobQuery().setCustomAttributeFilter(customAttributeFilter);
SearchJobsRequest searchJobsRequest =
new SearchJobsRequest()
@@ -162,9 +148,7 @@ public static void filtersOnLongValueCustomAttribute() throws IOException, Inter
// [START custom_attribute_filter_multi_attributes]
- /**
- * CustomAttributeFilter on multiple CustomAttributes
- */
+ /** CustomAttributeFilter on multiple CustomAttributes */
public static void filtersOnMultiCustomAttributes() throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
RequestMetadata requestMetadata =
@@ -174,13 +158,12 @@ public static void filtersOnMultiCustomAttributes() throws IOException, Interrup
// Make sure to hash the sessionID
.setSessionId("HashedSessionID")
// Domain of the website where the search is conducted
- .setDomain(
- "www.google.com");
+ .setDomain("www.google.com");
- String customAttributeFilter = "(someFieldName1 = \"value1\") "
- + "AND ((255 <= someFieldName2) OR (someFieldName2 <= 213))";
- JobQuery jobQuery = new JobQuery()
- .setCustomAttributeFilter(customAttributeFilter);
+ String customAttributeFilter =
+ "(someFieldName1 = \"value1\") "
+ + "AND ((255 <= someFieldName2) OR (someFieldName2 <= 213))";
+ JobQuery jobQuery = new JobQuery().setCustomAttributeFilter(customAttributeFilter);
SearchJobsRequest searchJobsRequest =
new SearchJobsRequest()
diff --git a/jobs/v3/src/main/java/com/google/samples/EmailAlertSearchSample.java b/jobs/v3/src/main/java/com/google/samples/EmailAlertSearchSample.java
index 6d8f3061770..48bb37be531 100644
--- a/jobs/v3/src/main/java/com/google/samples/EmailAlertSearchSample.java
+++ b/jobs/v3/src/main/java/com/google/samples/EmailAlertSearchSample.java
@@ -26,21 +26,17 @@
import java.io.IOException;
import java.util.Arrays;
-/**
- * The sample in this file introduce how to do a email alert search.
- */
+/** The sample in this file introduce how to do a email alert search. */
public final class EmailAlertSearchSample {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = JobServiceQuickstart
- .getTalentSolutionClient();
+ private static CloudTalentSolution talentSolutionClient =
+ JobServiceQuickstart.getTalentSolutionClient();
// [START search_for_alerts]
- /**
- * Search jobs for alert.
- */
+ /** Search jobs for alert. */
public static void searchForAlerts(String companyName) throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
RequestMetadata requestMetadata =
diff --git a/jobs/v3/src/main/java/com/google/samples/FeaturedJobsSearchSample.java b/jobs/v3/src/main/java/com/google/samples/FeaturedJobsSearchSample.java
index e654033db6e..1957c406aea 100644
--- a/jobs/v3/src/main/java/com/google/samples/FeaturedJobsSearchSample.java
+++ b/jobs/v3/src/main/java/com/google/samples/FeaturedJobsSearchSample.java
@@ -31,9 +31,9 @@
/**
* The sample in this file introduce featured job, including:
*
- * - Construct a featured job
+ * - Construct a featured job
*
- *
- Search featured job
+ * - Search featured job
*/
public final class FeaturedJobsSearchSample {
diff --git a/jobs/v3/src/main/java/com/google/samples/GeneralSearchSample.java b/jobs/v3/src/main/java/com/google/samples/GeneralSearchSample.java
index eb807412f54..3405aa34264 100644
--- a/jobs/v3/src/main/java/com/google/samples/GeneralSearchSample.java
+++ b/jobs/v3/src/main/java/com/google/samples/GeneralSearchSample.java
@@ -55,14 +55,12 @@ public final class GeneralSearchSample {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = JobServiceQuickstart
- .getTalentSolutionClient();
+ private static CloudTalentSolution talentSolutionClient =
+ JobServiceQuickstart.getTalentSolutionClient();
- //[START basic_keyword_search]
+ // [START basic_keyword_search]
- /**
- * Simple search jobs with keyword.
- */
+ /** Simple search jobs with keyword. */
public static void basicSearcJobs(String companyName, String query)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
@@ -97,13 +95,11 @@ public static void basicSearcJobs(String companyName, String query)
System.out.println(searchJobsResponse);
}
- //[END basic_keyword_search]
+ // [END basic_keyword_search]
// [START category_filter]
- /**
- * Search on category filter.
- */
+ /** Search on category filter. */
public static void categoryFilterSearch(String companyName, List categories)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
@@ -141,9 +137,7 @@ public static void categoryFilterSearch(String companyName, List categor
// [START employment_types_filter]
- /**
- * Search on employment types.
- */
+ /** Search on employment types. */
public static void employmentTypesSearch(String companyName, List employmentTypes)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
@@ -202,7 +196,7 @@ public static void dateRangeSearch(String companyName, String startTime, String
new TimestampRange().setStartTime(startTime).setEndTime(endTime);
JobQuery jobQuery = new JobQuery().setPublishTimeRange(timestampRange);
- //JobQuery jobQuery = new JobQuery().setPublishTimeRange(dateRange);
+ // JobQuery jobQuery = new JobQuery().setPublishTimeRange(dateRange);
if (companyName != null) {
jobQuery.setCompanyNames(Arrays.asList(companyName));
@@ -228,9 +222,7 @@ public static void dateRangeSearch(String companyName, String startTime, String
// [START language_code_filter]
- /**
- * Search on language codes.
- */
+ /** Search on language codes. */
public static void languageCodeSearch(String companyName, List languageCodes)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
@@ -268,9 +260,7 @@ public static void languageCodeSearch(String companyName, List languageC
// [START company_display_name_filter]
- /**
- * Search on company display name.
- */
+ /** Search on company display name. */
public static void companyDisplayNameSearch(String companyName, List companyDisplayNames)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
@@ -308,9 +298,7 @@ public static void companyDisplayNameSearch(String companyName, List com
// [START compensation_filter]
- /**
- * Search on compensation.
- */
+ /** Search on compensation. */
public static void compensationSearch(String companyName)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
@@ -332,8 +320,7 @@ public static void compensationSearch(String companyName)
.setUnits(Arrays.asList("HOURLY"))
.setRange(
new CompensationRange()
- .setMaxCompensation(new Money().setCurrencyCode("USD")
- .setUnits(15L))
+ .setMaxCompensation(new Money().setCurrencyCode("USD").setUnits(15L))
.setMinCompensation(
new Money()
.setCurrencyCode("USD")
@@ -365,25 +352,26 @@ public static void main(String... args) throws Exception {
Company companyToBeCreated = BasicCompanySample.generateCompany().setDisplayName("Google");
String companyName = BasicCompanySample.createCompany(companyToBeCreated).getName();
- Job jobToBeCreated = BasicJobSample.generateJobWithRequiredFields(companyName)
- .setTitle("Systems Administrator")
- .setEmploymentTypes(Arrays.asList("FULL_TIME"))
- .setLanguageCode("en-US")
- .setCompensationInfo(
- new CompensationInfo().setEntries(Arrays.asList(
- new CompensationEntry()
- .setType("BASE")
- .setUnit("HOURLY")
- .setAmount(new Money().setCurrencyCode("USD").setUnits(12L)))));
+ Job jobToBeCreated =
+ BasicJobSample.generateJobWithRequiredFields(companyName)
+ .setTitle("Systems Administrator")
+ .setEmploymentTypes(Arrays.asList("FULL_TIME"))
+ .setLanguageCode("en-US")
+ .setCompensationInfo(
+ new CompensationInfo()
+ .setEntries(
+ Arrays.asList(
+ new CompensationEntry()
+ .setType("BASE")
+ .setUnit("HOURLY")
+ .setAmount(new Money().setCurrencyCode("USD").setUnits(12L)))));
final String jobName = BasicJobSample.createJob(jobToBeCreated).getName();
// Wait several seconds for post processing
Thread.sleep(10000);
basicSearcJobs(companyName, "Systems Administrator");
categoryFilterSearch(companyName, Arrays.asList("COMPUTER_AND_IT"));
- dateRangeSearch(companyName,
- "1980-01-15T01:30:15.01Z",
- "2099-01-15T01:30:15.01Z");
+ dateRangeSearch(companyName, "1980-01-15T01:30:15.01Z", "2099-01-15T01:30:15.01Z");
employmentTypesSearch(companyName, Arrays.asList("FULL_TIME", "CONTRACTOR", "PER_DIEM"));
companyDisplayNameSearch(companyName, Arrays.asList("Google"));
compensationSearch(companyName);
@@ -393,4 +381,3 @@ public static void main(String... args) throws Exception {
BasicCompanySample.deleteCompany(companyName);
}
}
-
diff --git a/jobs/v3/src/main/java/com/google/samples/HistogramSample.java b/jobs/v3/src/main/java/com/google/samples/HistogramSample.java
index 5a26b29367f..a8eaebf2764 100644
--- a/jobs/v3/src/main/java/com/google/samples/HistogramSample.java
+++ b/jobs/v3/src/main/java/com/google/samples/HistogramSample.java
@@ -28,22 +28,18 @@
import java.io.IOException;
import java.util.Arrays;
-/**
- * The sample in this file introduce how to do a histogram search.
- */
+/** The sample in this file introduce how to do a histogram search. */
public final class HistogramSample {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = JobServiceQuickstart
- .getTalentSolutionClient();
+ private static CloudTalentSolution talentSolutionClient =
+ JobServiceQuickstart.getTalentSolutionClient();
// [START histogram_search]
- /**
- * Histogram search
- */
+ /** Histogram search */
public static void histogramSearch(String companyName) throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
RequestMetadata requestMetadata =
@@ -53,8 +49,7 @@ public static void histogramSearch(String companyName) throws IOException, Inter
// Make sure to hash the sessionID
.setSessionId("HashedSessionID")
// Domain of the website where the search is conducted
- .setDomain(
- "www.google.com");
+ .setDomain("www.google.com");
HistogramFacets histogramFacets =
new HistogramFacets()
diff --git a/jobs/v3/src/main/java/com/google/samples/JobServiceQuickstart.java b/jobs/v3/src/main/java/com/google/samples/JobServiceQuickstart.java
index 05836db9367..a50090326a3 100644
--- a/jobs/v3/src/main/java/com/google/samples/JobServiceQuickstart.java
+++ b/jobs/v3/src/main/java/com/google/samples/JobServiceQuickstart.java
@@ -16,7 +16,6 @@
package com.google.samples;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
@@ -25,12 +24,12 @@
import com.google.api.services.jobs.v3.CloudTalentSolution;
import com.google.api.services.jobs.v3.model.Company;
import com.google.api.services.jobs.v3.model.ListCompaniesResponse;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
-/**
- * The quickstart for Cloud Job Discovery
- */
+/** The quickstart for Cloud Job Discovery */
public class JobServiceQuickstart {
// [START quickstart]
@@ -41,26 +40,25 @@ public class JobServiceQuickstart {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = createTalentSolutionClient(
- generateCredential());
+ private static CloudTalentSolution talentSolutionClient =
+ createTalentSolutionClient(generateCredential());
- private static CloudTalentSolution createTalentSolutionClient(GoogleCredential credential) {
+ private static CloudTalentSolution createTalentSolutionClient(GoogleCredentials credential) {
String url = "https://jobs.googleapis.com";
+ HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credential);
return new CloudTalentSolution.Builder(
- NET_HTTP_TRANSPORT, JSON_FACTORY, setHttpTimeout(credential))
+ NET_HTTP_TRANSPORT, JSON_FACTORY, setHttpTimeout(requestInitializer))
.setApplicationName("JobServiceClientSamples")
.setRootUrl(url)
.build();
}
- private static GoogleCredential generateCredential() {
+ private static GoogleCredentials generateCredential() {
try {
// Credentials could be downloaded after creating service account
// set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable, for example:
// export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/key.json
- return GoogleCredential
- .getApplicationDefault(NET_HTTP_TRANSPORT, JSON_FACTORY)
- .createScoped(Collections.singleton(SCOPES));
+ return GoogleCredentials.getApplicationDefault().createScoped(Collections.singleton(SCOPES));
} catch (Exception e) {
System.out.print("Error in generating credential");
throw new RuntimeException(e);
@@ -83,9 +81,8 @@ public static CloudTalentSolution getTalentSolutionClient() {
public static void main(String... args) throws Exception {
try {
- ListCompaniesResponse listCompaniesResponse = talentSolutionClient.projects().companies()
- .list(DEFAULT_PROJECT_ID)
- .execute();
+ ListCompaniesResponse listCompaniesResponse =
+ talentSolutionClient.projects().companies().list(DEFAULT_PROJECT_ID).execute();
System.out.println("Request Id is " + listCompaniesResponse.getMetadata().getRequestId());
if (listCompaniesResponse.getCompanies() != null) {
for (Company company : listCompaniesResponse.getCompanies()) {
diff --git a/jobs/v3/src/main/java/com/google/samples/LocationSearchSample.java b/jobs/v3/src/main/java/com/google/samples/LocationSearchSample.java
index efe81dc330b..f52b2974acd 100644
--- a/jobs/v3/src/main/java/com/google/samples/LocationSearchSample.java
+++ b/jobs/v3/src/main/java/com/google/samples/LocationSearchSample.java
@@ -45,14 +45,12 @@ public final class LocationSearchSample {
private static final String DEFAULT_PROJECT_ID =
"projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");
- private static CloudTalentSolution talentSolutionClient = JobServiceQuickstart
- .getTalentSolutionClient();
+ private static CloudTalentSolution talentSolutionClient =
+ JobServiceQuickstart.getTalentSolutionClient();
// [START basic_location_search]
- /**
- * Basic location Search
- */
+ /** Basic location Search */
public static void basicLocationSearch(String companyName, String location, double distance)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
@@ -65,10 +63,8 @@ public static void basicLocationSearch(String companyName, String location, doub
// Domain of the website where the search is conducted
.setDomain("www.google.com");
LocationFilter locationFilter =
- new LocationFilter().setAddress(location)
- .setDistanceInMiles(distance);
- JobQuery jobQuery = new JobQuery()
- .setLocationFilters(Arrays.asList(locationFilter));
+ new LocationFilter().setAddress(location).setDistanceInMiles(distance);
+ JobQuery jobQuery = new JobQuery().setLocationFilters(Arrays.asList(locationFilter));
if (companyName != null) {
jobQuery.setCompanyNames(Arrays.asList(companyName));
}
@@ -86,11 +82,9 @@ public static void basicLocationSearch(String companyName, String location, doub
// [START keyword_location_search]
- /**
- * Keyword location Search
- */
- public static void keywordLocationSearch(String companyName, String location, double distance,
- String keyword)
+ /** Keyword location Search */
+ public static void keywordLocationSearch(
+ String companyName, String location, double distance, String keyword)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
RequestMetadata requestMetadata =
@@ -102,12 +96,9 @@ public static void keywordLocationSearch(String companyName, String location, do
// Domain of the website where the search is conducted
.setDomain("www.google.com");
LocationFilter locationFilter =
- new LocationFilter().setAddress(location)
- .setDistanceInMiles(distance);
+ new LocationFilter().setAddress(location).setDistanceInMiles(distance);
JobQuery jobQuery =
- new JobQuery()
- .setQuery(keyword)
- .setLocationFilters(Arrays.asList(locationFilter));
+ new JobQuery().setQuery(keyword).setLocationFilters(Arrays.asList(locationFilter));
if (companyName != null) {
jobQuery.setCompanyNames(Arrays.asList(companyName));
}
@@ -125,9 +116,7 @@ public static void keywordLocationSearch(String companyName, String location, do
// [START city_location_search]
- /**
- * City location Search
- */
+ /** City location Search */
public static void cityLocationSearch(String companyName, String location)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
@@ -139,10 +128,8 @@ public static void cityLocationSearch(String companyName, String location)
.setSessionId("HashedSessionID")
// Domain of the website where the search is conducted
.setDomain("www.google.com");
- LocationFilter locationFilter = new LocationFilter()
- .setAddress(location);
- JobQuery jobQuery = new JobQuery()
- .setLocationFilters(Arrays.asList(locationFilter));
+ LocationFilter locationFilter = new LocationFilter().setAddress(location);
+ JobQuery jobQuery = new JobQuery().setLocationFilters(Arrays.asList(locationFilter));
if (companyName != null) {
jobQuery.setCompanyNames(Arrays.asList(companyName));
}
@@ -160,11 +147,9 @@ public static void cityLocationSearch(String companyName, String location)
// [START multi_locations_search]
- /**
- * Multiple locations Search
- */
- public static void multiLocationsSearch(String companyName, String location1, double distance1,
- String location2)
+ /** Multiple locations Search */
+ public static void multiLocationsSearch(
+ String companyName, String location1, double distance1, String location2)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
RequestMetadata requestMetadata =
@@ -198,9 +183,7 @@ public static void multiLocationsSearch(String companyName, String location1, do
// [START broadening_location_search]
- /**
- * Broadening location Search
- */
+ /** Broadening location Search */
public static void broadeningLocationsSearch(String companyName, String location)
throws IOException, InterruptedException {
// Make sure to set the requestMetadata the same as the associated search request
@@ -213,9 +196,7 @@ public static void broadeningLocationsSearch(String companyName, String location
// Domain of the website where the search is conducted
.setDomain("www.google.com");
JobQuery jobQuery =
- new JobQuery()
- .setLocationFilters(Arrays
- .asList(new LocationFilter().setAddress(location)));
+ new JobQuery().setLocationFilters(Arrays.asList(new LocationFilter().setAddress(location)));
if (companyName != null) {
jobQuery.setCompanyNames(Arrays.asList(companyName));
}
@@ -241,11 +222,15 @@ public static void main(String... args) throws Exception {
Company companyToBeCreated = BasicCompanySample.generateCompany();
String companyName = BasicCompanySample.createCompany(companyToBeCreated).getName();
- Job jobToBeCreated = BasicJobSample.generateJobWithRequiredFields(companyName)
- .setAddresses(Arrays.asList(location)).setTitle(keyword);
+ Job jobToBeCreated =
+ BasicJobSample.generateJobWithRequiredFields(companyName)
+ .setAddresses(Arrays.asList(location))
+ .setTitle(keyword);
final String jobName = BasicJobSample.createJob(jobToBeCreated).getName();
- Job jobToBeCreated2 = BasicJobSample.generateJobWithRequiredFields(companyName)
- .setAddresses(Arrays.asList(location2)).setTitle(keyword);
+ Job jobToBeCreated2 =
+ BasicJobSample.generateJobWithRequiredFields(companyName)
+ .setAddresses(Arrays.asList(location2))
+ .setTitle(keyword);
final String jobName2 = BasicJobSample.createJob(jobToBeCreated2).getName();
// Wait several seconds for post processing
diff --git a/jobs/v3/src/test/java/SampleTests.java b/jobs/v3/src/test/java/SampleTests.java
index 149a3a7fc77..9a53a3aac9e 100644
--- a/jobs/v3/src/test/java/SampleTests.java
+++ b/jobs/v3/src/test/java/SampleTests.java
@@ -104,7 +104,6 @@ public void batchOperationSampleTest() throws Exception {
public void commuteSearchSampleTest() throws Exception {
CommuteSearchSample.main();
String result = bout.toString();
- assertThat(result).containsMatch(".*matchingJobs.*commuteInfo.*");
assertThat(result).containsMatch(".*matchingJobs.*1600 Amphitheatre Pkwy.*");
bout.reset();
}
@@ -169,7 +168,7 @@ public void jobServiceQuickStartTest() throws Exception {
assertThat(bout.toString()).contains("Request Id is");
bout.reset();
}
-
+
@Test
public void locationSearchSampleTest() throws Exception {
LocationSearchSample.main();
diff --git a/jobs/v4/pom.xml b/jobs/v4/pom.xml
index d193d2ce329..210c2066a14 100644
--- a/jobs/v4/pom.xml
+++ b/jobs/v4/pom.xml
@@ -15,7 +15,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -24,7 +24,7 @@
- 3.5
+ 3.5.4
@@ -32,7 +32,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -50,7 +50,7 @@
com.google.apis
google-api-services-jobs
- v3-rev20200506-1.30.9
+ v3-rev20200604-1.30.9
diff --git a/jobs/v4/src/main/java/com/example/jobs/CommuteSearchJobs.java b/jobs/v4/src/main/java/com/example/jobs/CommuteSearchJobs.java
index 2dad6176bcb..e8e8e04b094 100644
--- a/jobs/v4/src/main/java/com/example/jobs/CommuteSearchJobs.java
+++ b/jobs/v4/src/main/java/com/example/jobs/CommuteSearchJobs.java
@@ -42,6 +42,9 @@ public static void searchJobs() throws IOException {
// Search Jobs with histogram queries.
public static void searchJobs(String projectId, String tenantId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
String domain = "www.example.com";
@@ -80,11 +83,11 @@ public static void searchJobs(String projectId, String tenantId) throws IOExcept
for (SearchJobsResponse.MatchingJob responseItem :
jobServiceClient.searchJobs(request).iterateAll()) {
- System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
- System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
+ System.out.format("Job summary: %s%n", responseItem.getJobSummary());
+ System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
Job job = responseItem.getJob();
- System.out.printf("Job name: %s\n", job.getName());
- System.out.printf("Job title: %s\n", job.getTitle());
+ System.out.format("Job name: %s%n", job.getName());
+ System.out.format("Job title: %s%n", job.getTitle());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/CustomRankingSearchJobs.java b/jobs/v4/src/main/java/com/example/jobs/CustomRankingSearchJobs.java
index dac2f276832..94899b282f4 100644
--- a/jobs/v4/src/main/java/com/example/jobs/CustomRankingSearchJobs.java
+++ b/jobs/v4/src/main/java/com/example/jobs/CustomRankingSearchJobs.java
@@ -37,6 +37,9 @@ public static void searchCustomRankingJobs() throws IOException {
// Search Jobs using custom rankings.
public static void searchCustomRankingJobs(String projectId, String tenantId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
String domain = "www.example.com";
@@ -66,11 +69,11 @@ public static void searchCustomRankingJobs(String projectId, String tenantId) th
.build();
for (SearchJobsResponse.MatchingJob responseItem :
jobServiceClient.searchJobs(request).iterateAll()) {
- System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
- System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
+ System.out.format("Job summary: %s%n", responseItem.getJobSummary());
+ System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
Job job = responseItem.getJob();
- System.out.printf("Job name: %s\n", job.getName());
- System.out.printf("Job title: %s\n", job.getTitle());
+ System.out.format("Job name: %s%n", job.getName());
+ System.out.format("Job title: %s%n", job.getTitle());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/HistogramSearchJobs.java b/jobs/v4/src/main/java/com/example/jobs/HistogramSearchJobs.java
index 0ec97a2b957..57c34123392 100644
--- a/jobs/v4/src/main/java/com/example/jobs/HistogramSearchJobs.java
+++ b/jobs/v4/src/main/java/com/example/jobs/HistogramSearchJobs.java
@@ -40,6 +40,9 @@ public static void searchJobs() throws IOException {
// Search Jobs with histogram queries.
public static void searchJobs(String projectId, String tenantId, String query)
throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
@@ -63,11 +66,11 @@ public static void searchJobs(String projectId, String tenantId, String query)
for (SearchJobsResponse.MatchingJob responseItem :
jobServiceClient.searchJobs(request).iterateAll()) {
- System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
- System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
+ System.out.format("Job summary: %s%n", responseItem.getJobSummary());
+ System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
Job job = responseItem.getJob();
- System.out.printf("Job name: %s\n", job.getName());
- System.out.printf("Job title: %s\n", job.getTitle());
+ System.out.format("Job name: %s%n", job.getName());
+ System.out.format("Job title: %s%n", job.getTitle());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchAutoCompleteJobTitle.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchAutoCompleteJobTitle.java
index 675f32a0002..842d77a05d1 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchAutoCompleteJobTitle.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchAutoCompleteJobTitle.java
@@ -37,6 +37,9 @@ public static void completeQuery() throws IOException {
// Complete job title given partial text (autocomplete).
public static void completeQuery(String projectId, String tenantId, String query)
throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (CompletionClient completionClient = CompletionClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
CompleteQueryRequest request =
@@ -48,9 +51,9 @@ public static void completeQuery(String projectId, String tenantId, String query
.build();
CompleteQueryResponse response = completionClient.completeQuery(request);
for (CompleteQueryResponse.CompletionResult result : response.getCompletionResultsList()) {
- System.out.printf("Suggested title: %s\n", result.getSuggestion());
+ System.out.format("Suggested title: %s%n", result.getSuggestion());
// Suggestion type is JOB_TITLE or COMPANY_TITLE
- System.out.printf("Suggestion type: %s\n", result.getType());
+ System.out.format("Suggestion type: %s%n", result.getType());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateClientEvent.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateClientEvent.java
index 5df585cf7e5..d7c835cf147 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateClientEvent.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateClientEvent.java
@@ -42,6 +42,9 @@ public static void createClientEvent() throws IOException {
// Creates a client event.
public static void createClientEvent(
String projectId, String tenantId, String requestId, String eventId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (EventServiceClient eventServiceClient = EventServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateCompany.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateCompany.java
index f823259e3b9..baa890a51d9 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateCompany.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateCompany.java
@@ -38,6 +38,9 @@ public static void createCompany() throws IOException {
// Create a company.
public static void createCompany(
String projectId, String tenantId, String displayName, String externalId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
Company company =
@@ -51,9 +54,9 @@ public static void createCompany(
Company response = companyServiceClient.createCompany(request);
System.out.println("Created Company");
- System.out.printf("Name: %s\n", response.getName());
- System.out.printf("Display Name: %s\n", response.getDisplayName());
- System.out.printf("External ID: %s\n", response.getExternalId());
+ System.out.format("Name: %s%n", response.getName());
+ System.out.format("Display Name: %s%n", response.getDisplayName());
+ System.out.format("External ID: %s%n", response.getExternalId());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJob.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJob.java
index e7652c5b8ce..ecbc0e9433e 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJob.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJob.java
@@ -23,8 +23,13 @@
import com.google.cloud.talent.v4beta1.JobServiceClient;
import com.google.cloud.talent.v4beta1.TenantName;
import java.io.IOException;
+import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
import java.util.Arrays;
+import java.util.Calendar;
import java.util.List;
+import java.util.Locale;
public class JobSearchCreateJob {
@@ -46,14 +51,21 @@ public static void createJob(
String requisitionId,
String jobApplicationUrl)
throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
Job.ApplicationInfo applicationInfo =
Job.ApplicationInfo.newBuilder().addUris(jobApplicationUrl).build();
- List addresses = Arrays.asList("1600 Amphitheatre Parkway, Mountain View, CA 94043",
+ List addresses =
+ Arrays.asList(
+ "1600 Amphitheatre Parkway, Mountain View, CA 94043",
"111 8th Avenue, New York, NY 10011");
+ // By default, job will expire in 30 days.
+ // https://cloud.google.com/talent-solution/job-search/docs/jobs
Job job =
Job.newBuilder()
.setCompany(companyId)
@@ -69,7 +81,7 @@ public static void createJob(
CreateJobRequest.newBuilder().setParent(parent.toString()).setJob(job).build();
Job response = jobServiceClient.createJob(request);
- System.out.printf("Created job: %s\n", response.getName());
+ System.out.format("Created job: %s%n", response.getName());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJobCustomAttributes.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJobCustomAttributes.java
index 5eeabce8f4e..8c8e1b9dcf5 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJobCustomAttributes.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateJobCustomAttributes.java
@@ -43,6 +43,9 @@ public static void createJob(
String companyId,
String requisitionId)
throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateTenant.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateTenant.java
index d5389406825..5d9b1a5f46c 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateTenant.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchCreateTenant.java
@@ -35,6 +35,9 @@ public static void createTenant() throws IOException {
// Create Tenant for scoping resources, e.g. companies and jobs.
public static void createTenant(String projectId, String externalId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
Tenant tenant = Tenant.newBuilder().setExternalId(externalId).build();
@@ -44,8 +47,8 @@ public static void createTenant(String projectId, String externalId) throws IOEx
Tenant response = tenantServiceClient.createTenant(request);
System.out.println("Created Tenant");
- System.out.printf("Name: %s\n", response.getName());
- System.out.printf("External ID: %s\n", response.getExternalId());
+ System.out.format("Name: %s%n", response.getName());
+ System.out.format("External ID: %s%n", response.getExternalId());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteCompany.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteCompany.java
index 18599edc8b6..44d8b33aff6 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteCompany.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteCompany.java
@@ -36,6 +36,9 @@ public static void deleteCompany() throws IOException {
// Delete Company.
public static void deleteCompany(String projectId, String tenantId, String companyId)
throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
CompanyName name = CompanyName.ofProjectTenantCompanyName(projectId, tenantId, companyId);
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteJob.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteJob.java
index 9fc5fd7b32b..82ff8b0a096 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteJob.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteJob.java
@@ -35,6 +35,9 @@ public static void deleteJob() throws IOException {
// Delete Job.
public static void deleteJob(String projectId, String tenantId, String jobId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
JobName name = JobName.ofProjectTenantJobName(projectId, tenantId, jobId);
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteTenant.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteTenant.java
index f984c48d8e6..5d112da04d8 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteTenant.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchDeleteTenant.java
@@ -34,6 +34,9 @@ public static void deleteTenant() throws IOException {
// Delete Tenant.
public static void deleteTenant(String projectId, String tenantId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
TenantName name = TenantName.of(projectId, tenantId);
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchGetCompany.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchGetCompany.java
index 6aff009185b..639b15979cc 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchGetCompany.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchGetCompany.java
@@ -37,14 +37,17 @@ public static void getCompany() throws IOException {
// Get Company.
public static void getCompany(String projectId, String tenantId, String companyId)
throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
CompanyName name = CompanyName.ofProjectTenantCompanyName(projectId, tenantId, companyId);
GetCompanyRequest request = GetCompanyRequest.newBuilder().setName(name.toString()).build();
Company response = companyServiceClient.getCompany(request);
- System.out.printf("Company name: %s\n", response.getName());
- System.out.printf("Display name: %s\n", response.getDisplayName());
+ System.out.format("Company name: %s%n", response.getName());
+ System.out.format("Display name: %s%n", response.getDisplayName());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchGetJob.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchGetJob.java
index 8d6545a5d94..84a88801792 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchGetJob.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchGetJob.java
@@ -36,25 +36,28 @@ public static void getJob() throws IOException {
// Get Job.
public static void getJob(String projectId, String tenantId, String jobId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
JobName name = JobName.ofProjectTenantJobName(projectId, tenantId, jobId);
GetJobRequest request = GetJobRequest.newBuilder().setName(name.toString()).build();
Job response = jobServiceClient.getJob(request);
- System.out.printf("Job name: %s\n", response.getName());
- System.out.printf("Requisition ID: %s\n", response.getRequisitionId());
- System.out.printf("Title: %s\n", response.getTitle());
- System.out.printf("Description: %s\n", response.getDescription());
- System.out.printf("Posting language: %s\n", response.getLanguageCode());
+ System.out.format("Job name: %s%n", response.getName());
+ System.out.format("Requisition ID: %s%n", response.getRequisitionId());
+ System.out.format("Title: %s%n", response.getTitle());
+ System.out.format("Description: %s%n", response.getDescription());
+ System.out.format("Posting language: %s%n", response.getLanguageCode());
for (String address : response.getAddressesList()) {
- System.out.printf("Address: %s\n", address);
+ System.out.format("Address: %s%n", address);
}
for (String email : response.getApplicationInfo().getEmailsList()) {
- System.out.printf("Email: %s\n", email);
+ System.out.format("Email: %s%n", email);
}
for (String websiteUri : response.getApplicationInfo().getUrisList()) {
- System.out.printf("Website: %s\n", websiteUri);
+ System.out.format("Website: %s%n", websiteUri);
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchGetTenant.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchGetTenant.java
index c59f90e27a8..527ba34d295 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchGetTenant.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchGetTenant.java
@@ -35,14 +35,17 @@ public static void getTenant() throws IOException {
// Get Tenant by name.
public static void getTenant(String projectId, String tenantId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
TenantName name = TenantName.of(projectId, tenantId);
GetTenantRequest request = GetTenantRequest.newBuilder().setName(name.toString()).build();
Tenant response = tenantServiceClient.getTenant(request);
- System.out.printf("Name: %s\n", response.getName());
- System.out.printf("External ID: %s\n", response.getExternalId());
+ System.out.format("Name: %s%n", response.getName());
+ System.out.format("External ID: %s%n", response.getExternalId());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchListCompanies.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchListCompanies.java
index 4e9878f7d9e..cef24dc2087 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchListCompanies.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchListCompanies.java
@@ -35,6 +35,9 @@ public static void listCompanies() throws IOException {
// List Companies.
public static void listCompanies(String projectId, String tenantId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
@@ -42,9 +45,9 @@ public static void listCompanies(String projectId, String tenantId) throws IOExc
ListCompaniesRequest.newBuilder().setParent(parent.toString()).build();
for (Company responseItem : companyServiceClient.listCompanies(request).iterateAll()) {
- System.out.printf("Company Name: %s\n", responseItem.getName());
- System.out.printf("Display Name: %s\n", responseItem.getDisplayName());
- System.out.printf("External ID: %s\n", responseItem.getExternalId());
+ System.out.format("Company Name: %s%n", responseItem.getName());
+ System.out.format("Display Name: %s%n", responseItem.getDisplayName());
+ System.out.format("External ID: %s%n", responseItem.getExternalId());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchListJobs.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchListJobs.java
index df1342c843c..81f844226ea 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchListJobs.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchListJobs.java
@@ -36,15 +36,18 @@ public static void listJobs() throws IOException {
// Search Jobs with histogram queries.
public static void listJobs(String projectId, String tenantId, String filter) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
ListJobsRequest request =
ListJobsRequest.newBuilder().setParent(parent.toString()).setFilter(filter).build();
for (Job responseItem : jobServiceClient.listJobs(request).iterateAll()) {
- System.out.printf("Job name: %s\n", responseItem.getName());
- System.out.printf("Job requisition ID: %s\n", responseItem.getRequisitionId());
- System.out.printf("Job title: %s\n", responseItem.getTitle());
- System.out.printf("Job description: %s\n", responseItem.getDescription());
+ System.out.format("Job name: %s%n", responseItem.getName());
+ System.out.format("Job requisition ID: %s%n", responseItem.getRequisitionId());
+ System.out.format("Job title: %s%n", responseItem.getTitle());
+ System.out.format("Job description: %s%n", responseItem.getDescription());
}
}
}
diff --git a/jobs/v4/src/main/java/com/example/jobs/JobSearchListTenants.java b/jobs/v4/src/main/java/com/example/jobs/JobSearchListTenants.java
index 565e75e4714..4b0be36b2cf 100644
--- a/jobs/v4/src/main/java/com/example/jobs/JobSearchListTenants.java
+++ b/jobs/v4/src/main/java/com/example/jobs/JobSearchListTenants.java
@@ -34,6 +34,9 @@ public static void listTenants() throws IOException {
// List Tenants.
public static void listTenants(String projectId) throws IOException {
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
@@ -41,8 +44,8 @@ public static void listTenants(String projectId) throws IOException {
ListTenantsRequest.newBuilder().setParent(parent.toString()).build();
for (Tenant responseItem : tenantServiceClient.listTenants(request).iterateAll()) {
- System.out.printf("Tenant Name: %s\n", responseItem.getName());
- System.out.printf("External ID: %s\n", responseItem.getExternalId());
+ System.out.format("Tenant Name: %s%n", responseItem.getName());
+ System.out.format("External ID: %s%n", responseItem.getExternalId());
}
}
}
diff --git a/jobs/v4/src/test/java/JobSearchCreateCompanyTest.java b/jobs/v4/src/test/java/JobSearchCreateCompanyTest.java
index 9a546b8e008..926dbe3556b 100644
--- a/jobs/v4/src/test/java/JobSearchCreateCompanyTest.java
+++ b/jobs/v4/src/test/java/JobSearchCreateCompanyTest.java
@@ -20,6 +20,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
+import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -28,7 +29,8 @@ public class JobSearchCreateCompanyTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String TENANT_ID = System.getenv("CTS_TENANT_ID");
- private static final String COMPANY_EXT_ID = "DO_NOT_DELETE_EXT_ID";
+ private static final String COMPANY_EXT_ID =
+ String.format("COMP_EXT_ID_%s", UUID.randomUUID().toString().substring(0, 20));
private static final String COMPANY_DISPLAY_NAME = "DO_NOT_DELETE_COMPANY";
private String companyId;
diff --git a/jobs/v4/src/test/java/JobSearchCreateTenantTest.java b/jobs/v4/src/test/java/JobSearchCreateTenantTest.java
index ed0315e7391..96596b09971 100644
--- a/jobs/v4/src/test/java/JobSearchCreateTenantTest.java
+++ b/jobs/v4/src/test/java/JobSearchCreateTenantTest.java
@@ -21,14 +21,15 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
+import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
public class JobSearchCreateTenantTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
- private static final String TENANT_EXT_ID = "EXTERNAL_TEMP_TENANT_ID";
+ private static final String TENANT_EXT_ID =
+ String.format("EXTERNAL_TEMP_TENANT_ID_%s", UUID.randomUUID().toString().substring(0, 20));
private String tenantId;
private ByteArrayOutputStream bout;
diff --git a/jobs/v4/src/test/java/JobSearchDeleteCompanyTest.java b/jobs/v4/src/test/java/JobSearchDeleteCompanyTest.java
index 6f2ca284430..2f367a6755f 100644
--- a/jobs/v4/src/test/java/JobSearchDeleteCompanyTest.java
+++ b/jobs/v4/src/test/java/JobSearchDeleteCompanyTest.java
@@ -21,16 +21,17 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
+import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
public class JobSearchDeleteCompanyTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String TENANT_ID = System.getenv("CTS_TENANT_ID");
- private static final String COMPANY_EXT_ID = "DO_NOT_DELETE_EXT_ID";
+ private static final String COMPANY_EXT_ID =
+ String.format("COMP_EXT_ID_%s", UUID.randomUUID().toString().substring(0, 20));
private static final String COMPANY_DISPLAY_NAME = "DO_NOT_DELETE_COMPANY";
private String companyId;
diff --git a/jobs/v4/src/test/java/JobSearchDeleteTenantTest.java b/jobs/v4/src/test/java/JobSearchDeleteTenantTest.java
index 91e986203bf..5d111237acc 100644
--- a/jobs/v4/src/test/java/JobSearchDeleteTenantTest.java
+++ b/jobs/v4/src/test/java/JobSearchDeleteTenantTest.java
@@ -21,13 +21,15 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
+import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class JobSearchDeleteTenantTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
- private static final String TENANT_EXT_ID = "EXTERNAL_TEMP_TENANT_ID";
+ private static final String TENANT_EXT_ID =
+ String.format("EXTERNAL_TEMP_TENANT_ID_%s", UUID.randomUUID().toString().substring(0, 20));
private String tenantId;
private ByteArrayOutputStream bout;
diff --git a/kms/pom.xml b/kms/pom.xml
index 58f221cbe38..642ed537f72 100644
--- a/kms/pom.xml
+++ b/kms/pom.xml
@@ -12,7 +12,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -25,7 +25,13 @@
com.google.cloud
google-cloud-kms
- 1.38.1
+ 1.39.0
+
+
+
+ com.google.protobuf
+ protobuf-java-util
+ 3.12.2
diff --git a/language/analysis/pom.xml b/language/analysis/pom.xml
index 6cdcf7fe306..4b56bb03dd7 100644
--- a/language/analysis/pom.xml
+++ b/language/analysis/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
1.8
@@ -42,7 +42,7 @@ limitations under the License.
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -93,7 +93,7 @@ limitations under the License.
org.apache.maven.plugins
maven-failsafe-plugin
- 3.0.0-M4
+ 3.0.0-M5
@@ -107,19 +107,6 @@ limitations under the License.
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
-
-
- -XDcompilePolicy=simple
- -Xplugin:ErrorProne
-
-
-
- com.google.errorprone
- error_prone_core
- 2.3.4
-
-
-
diff --git a/language/cloud-client/pom.xml b/language/cloud-client/pom.xml
index 5543ca622cd..eb65d52bdb7 100644
--- a/language/cloud-client/pom.xml
+++ b/language/cloud-client/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
1.8
diff --git a/logging/cloud-client/pom.xml b/logging/cloud-client/pom.xml
index 598859f180a..544f665e242 100644
--- a/logging/cloud-client/pom.xml
+++ b/logging/cloud-client/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -40,7 +40,7 @@
com.google.cloud
google-cloud-logging
- 1.101.1
+ 1.101.2
@@ -63,7 +63,7 @@
org.apache.maven.plugins
maven-failsafe-plugin
- 3.0.0-M4
+ 3.0.0-M5
${project.build.outputDirectory}
3
diff --git a/logging/jul/pom.xml b/logging/jul/pom.xml
index 769103ab408..17845d8e6ec 100644
--- a/logging/jul/pom.xml
+++ b/logging/jul/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -39,7 +39,7 @@
com.google.cloud
google-cloud-logging
- 1.101.1
+ 1.101.2
diff --git a/logging/logback/pom.xml b/logging/logback/pom.xml
index 0164656b187..abb786c3beb 100644
--- a/logging/logback/pom.xml
+++ b/logging/logback/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
diff --git a/memorystore/redis/pom.xml b/memorystore/redis/pom.xml
index ea3d0860a47..59e5d96ab41 100644
--- a/memorystore/redis/pom.xml
+++ b/memorystore/redis/pom.xml
@@ -27,13 +27,13 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
1.8
1.8
- 9.4.29.v20200521
+ 9.4.30.v20200611
false
@@ -69,7 +69,7 @@
com.google.cloud.tools
appengine-maven-plugin
- 2.2.0
+ 2.3.0
diff --git a/mlengine/online-prediction/pom.xml b/mlengine/online-prediction/pom.xml
index 54efe7a9a03..e74983f75ae 100644
--- a/mlengine/online-prediction/pom.xml
+++ b/mlengine/online-prediction/pom.xml
@@ -24,7 +24,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -37,7 +37,7 @@ limitations under the License.
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -64,9 +64,9 @@ limitations under the License.
2.10.6
- com.google.api-client
- google-api-client
- 1.30.9
+ com.google.auth
+ google-auth-library-oauth2-http
+ 0.21.0
com.google.apis
diff --git a/mlengine/online-prediction/src/main/java/OnlinePredictionSample.java b/mlengine/online-prediction/src/main/java/OnlinePredictionSample.java
index fced73e444c..007f91896d2 100644
--- a/mlengine/online-prediction/src/main/java/OnlinePredictionSample.java
+++ b/mlengine/online-prediction/src/main/java/OnlinePredictionSample.java
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.FileContent;
import com.google.api.client.http.GenericUrl;
@@ -29,6 +28,8 @@
import com.google.api.services.discovery.model.JsonSchema;
import com.google.api.services.discovery.model.RestDescription;
import com.google.api.services.discovery.model.RestMethod;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -63,16 +64,16 @@ public static void main(String[] args) throws Exception {
File requestBodyFile = new File("input.txt");
HttpContent content = new FileContent(contentType, requestBodyFile);
System.out.println(content.getLength());
-
+
List scopes = new ArrayList<>();
scopes.add("https://www.googleapis.com/auth/cloud-platform");
-
- GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(scopes);
- HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
+
+ GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(scopes);
+ HttpRequestFactory requestFactory =
+ httpTransport.createRequestFactory(new HttpCredentialsAdapter(credential));
HttpRequest request = requestFactory.buildRequest(method.getHttpMethod(), url, content);
String response = request.execute().parseAsString();
System.out.println(response);
}
}
-
diff --git a/monitoring/cloud-client/pom.xml b/monitoring/cloud-client/pom.xml
index 8884d9ec9af..54b1f63fd46 100644
--- a/monitoring/cloud-client/pom.xml
+++ b/monitoring/cloud-client/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -45,7 +45,7 @@
com.google.auth
google-auth-library-oauth2-http
- 0.20.0
+ 0.21.0
diff --git a/monitoring/cloud-client/src/main/java/com/example/monitoring/QuickstartSample.java b/monitoring/cloud-client/src/main/java/com/example/monitoring/QuickstartSample.java
index fcfd392a43f..6b6e2579736 100644
--- a/monitoring/cloud-client/src/main/java/com/example/monitoring/QuickstartSample.java
+++ b/monitoring/cloud-client/src/main/java/com/example/monitoring/QuickstartSample.java
@@ -55,7 +55,7 @@ public static void main(String... args) throws Exception {
TimeInterval.newBuilder()
.setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
.build();
- TypedValue value = TypedValue.newBuilder().setDoubleValue(123.45).build();
+ TypedValue value = TypedValue.newBuilder().setDoubleValue(3.14).build();
Point point = Point.newBuilder().setInterval(interval).setValue(value).build();
List pointList = new ArrayList<>();
@@ -68,15 +68,16 @@ public static void main(String... args) throws Exception {
metricLabels.put("store_id", "Pittsburg");
Metric metric =
Metric.newBuilder()
- .setType("custom.googleapis.com/stores/daily_sales")
+ .setType("custom.googleapis.com/my_metric")
.putAllLabels(metricLabels)
.build();
// Prepares the monitored resource descriptor
Map resourceLabels = new HashMap();
- resourceLabels.put("project_id", projectId);
+ resourceLabels.put("instance_id", "1234567890123456789");
+ resourceLabels.put("zone", "us-central1-f");
MonitoredResource resource =
- MonitoredResource.newBuilder().setType("global").putAllLabels(resourceLabels).build();
+ MonitoredResource.newBuilder().setType("gce_instance").putAllLabels(resourceLabels).build();
// Prepares the time series request
TimeSeries timeSeries =
diff --git a/monitoring/v3/pom.xml b/monitoring/v3/pom.xml
index 4f3b5f79d91..31d824c0a30 100644
--- a/monitoring/v3/pom.xml
+++ b/monitoring/v3/pom.xml
@@ -27,7 +27,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
diff --git a/opencensus/pom.xml b/opencensus/pom.xml
index c3b67ce483a..7427e9fc893 100644
--- a/opencensus/pom.xml
+++ b/opencensus/pom.xml
@@ -29,7 +29,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -64,7 +64,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/pubsub/cloud-client/README.md b/pubsub/cloud-client/README.md
index 6b85c97ada6..26aa0bfb89d 100644
--- a/pubsub/cloud-client/README.md
+++ b/pubsub/cloud-client/README.md
@@ -1,56 +1,3 @@
# Getting Started with Cloud Pub/Sub and the Google Cloud Client libraries
-
-
-
-[Google Cloud Pub/Sub][pubsub] is a fully-managed real-time messaging service that allows you to
-send and receive messages between independent applications.
-This sample Java application demonstrates how to access the Pub/Sub API using
-the [Google Cloud Client Library for Java][google-cloud-java].
-
-[pubsub]: https://cloud.google.com/pubsub/
-[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java
-
-For more samples, see the samples in
-[google-cloud-java](https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub).
-
-## Quickstart
-
-#### Setup
-- Install [Maven](http://maven.apache.org/).
-- [Enable](https://console.cloud.google.com/apis/api/pubsub.googleapis.com/overview) Pub/Sub API.
-- Set up [authentication](https://cloud.google.com/docs/authentication/getting-started).
-
-#### Build
-- Build your project with:
-```
- mvn clean package -DskipTests
-```
-
-#### Create a new topic
-```
- mvn exec:java -Dexec.mainClass=com.example.pubsub.CreateTopicExample -Dexec.args=my-topic
-```
-
-#### Create a subscription
-```
- mvn exec:java -Dexec.mainClass=com.example.pubsub.CreatePullSubscriptionExample -Dexec.args="my-topic my-sub"
-```
-
-#### Publish messages
-```
- mvn exec:java -Dexec.mainClass=com.example.pubsub.PublisherExample -Dexec.args="my-topic 5"
-```
-Publishes 5 messages to the topic `my-topic`.
-
-#### Receive messages
-```
- mvn exec:java -Dexec.mainClass=com.example.pubsub.SubscriberExample -Dexec.args=my-sub
-```
-Subscriber will continue to listen on the topic and print out message id and data as messages are received. Press `Ctrl+C` to exit the application.
-
-#### Testing
-Run the test with Maven.
-```
- mvn verify
-```
+The samples have been moved to live alongside the Java client library for Cloud Pub/Sub: https://github.com/googleapis/java-pubsub/tree/master/samples/snippets/src/main/java/pubsub/
\ No newline at end of file
diff --git a/pubsub/cloud-client/pom.xml b/pubsub/cloud-client/pom.xml
deleted file mode 100644
index fff92355864..00000000000
--- a/pubsub/cloud-client/pom.xml
+++ /dev/null
@@ -1,92 +0,0 @@
-
-
- 4.0.0
- com.example.pubsub
- pubsub-google-cloud-samples
- jar
-
-
-
- com.google.cloud.samples
- shared-configuration
- 1.0.17
-
-
-
- 1.8
- 1.8
-
-
-
-
-
-
-
- com.google.cloud
- libraries-bom
- 5.4.0
- pom
- import
-
-
-
-
-
-
- com.google.cloud
- google-cloud-pubsub
-
-
- com.google.cloud
- google-cloud-core
-
-
-
-
-
- junit
- junit
- 4.13
- test
-
-
- com.google.truth
- truth
- 1.0.1
- test
-
-
-
-
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.6.0
-
- false
-
-
-
-
-
diff --git a/pubsub/cloud-client/src/main/java/com/example/pubsub/CreatePullSubscriptionExample.java b/pubsub/cloud-client/src/main/java/com/example/pubsub/CreatePullSubscriptionExample.java
deleted file mode 100644
index 4de91bcbdfe..00000000000
--- a/pubsub/cloud-client/src/main/java/com/example/pubsub/CreatePullSubscriptionExample.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * 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
- *
- * http://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.example.pubsub;
-
-// [START pubsub_quickstart_create_subscription]
-
-import com.google.api.gax.rpc.ApiException;
-import com.google.cloud.ServiceOptions;
-import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
-import com.google.pubsub.v1.ProjectSubscriptionName;
-import com.google.pubsub.v1.ProjectTopicName;
-import com.google.pubsub.v1.PushConfig;
-import com.google.pubsub.v1.Subscription;
-
-public class CreatePullSubscriptionExample {
-
- /**
- * Create a pull subscription.
- *
- * @param args topic subscriptionId
- * @throws Exception exception thrown if operation is unsuccessful
- */
- public static void main(String... args) throws Exception {
-
- // Your Google Cloud Platform project ID
- String projectId = ServiceOptions.getDefaultProjectId();
-
- // Your topic ID, eg. "my-topic"
- String topicId = args[0];
-
- // Your subscription ID eg. "my-sub"
- String subscriptionId = args[1];
-
- ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
-
- // Create a new subscription
- ProjectSubscriptionName subscriptionName =
- ProjectSubscriptionName.of(projectId, subscriptionId);
- try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
- // create a pull subscription with default acknowledgement deadline (= 10 seconds)
- Subscription subscription =
- subscriptionAdminClient.createSubscription(
- subscriptionName, topicName, PushConfig.getDefaultInstance(), 0);
- System.out.printf(
- "Subscription %s:%s created.\n",
- subscriptionName.getProject(), subscriptionName.getSubscription());
- } catch (ApiException e) {
- // example : code = ALREADY_EXISTS(409) implies subscription already exists
- System.out.print(e.getStatusCode().getCode());
- System.out.print(e.isRetryable());
- }
- }
-}
-// [END pubsub_quickstart_create_subscription]
diff --git a/pubsub/cloud-client/src/main/java/com/example/pubsub/CreateTopicExample.java b/pubsub/cloud-client/src/main/java/com/example/pubsub/CreateTopicExample.java
deleted file mode 100644
index 66c6f8213d5..00000000000
--- a/pubsub/cloud-client/src/main/java/com/example/pubsub/CreateTopicExample.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * 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
- *
- * http://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.example.pubsub;
-
-// [START pubsub_quickstart_create_topic]
-// Imports the Google Cloud client library
-
-import com.google.api.gax.rpc.ApiException;
-import com.google.cloud.ServiceOptions;
-import com.google.cloud.pubsub.v1.TopicAdminClient;
-import com.google.pubsub.v1.ProjectTopicName;
-
-public class CreateTopicExample {
-
- /**
- * Create a topic.
- *
- * @param args topicId
- * @throws Exception exception thrown if operation is unsuccessful
- */
- public static void main(String... args) throws Exception {
-
- // Your Google Cloud Platform project ID
- String projectId = ServiceOptions.getDefaultProjectId();
-
- // Your topic ID, eg. "my-topic"
- String topicId = args[0];
-
- // Create a new topic
- ProjectTopicName topic = ProjectTopicName.of(projectId, topicId);
- try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
- topicAdminClient.createTopic(topic);
- System.out.printf("Topic %s:%s created.\n", topic.getProject(), topic.getTopic());
- } catch (ApiException e) {
- // example : code = ALREADY_EXISTS(409) implies topic already exists
- System.out.print(e.getStatusCode().getCode());
- System.out.print(e.isRetryable());
- }
- }
-}
-// [END pubsub_quickstart_create_topic]
diff --git a/pubsub/cloud-client/src/main/java/com/example/pubsub/PublisherExample.java b/pubsub/cloud-client/src/main/java/com/example/pubsub/PublisherExample.java
deleted file mode 100644
index 1242eed6b23..00000000000
--- a/pubsub/cloud-client/src/main/java/com/example/pubsub/PublisherExample.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * 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
- *
- * http://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.example.pubsub;
-// [START pubsub_quickstart_publisher]
-
-import com.google.api.core.ApiFuture;
-import com.google.api.core.ApiFutures;
-import com.google.cloud.ServiceOptions;
-import com.google.cloud.pubsub.v1.Publisher;
-import com.google.protobuf.ByteString;
-import com.google.pubsub.v1.ProjectTopicName;
-import com.google.pubsub.v1.PubsubMessage;
-import java.util.ArrayList;
-import java.util.List;
-
-public class PublisherExample {
-
- // use the default project id
- private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId();
-
- /**
- * Publish messages to a topic.
- *
- * @param args topic name, number of messages
- */
- public static void main(String... args) throws Exception {
- // topic id, eg. "my-topic"
- String topicId = args[0];
- int messageCount = Integer.parseInt(args[1]);
- ProjectTopicName topicName = ProjectTopicName.of(PROJECT_ID, topicId);
- Publisher publisher = null;
- List> futures = new ArrayList<>();
-
- try {
- // Create a publisher instance with default settings bound to the topic
- publisher = Publisher.newBuilder(topicName).build();
-
- for (int i = 0; i < messageCount; i++) {
- String message = "message-" + i;
-
- // convert message to bytes
- ByteString data = ByteString.copyFromUtf8(message);
- PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
-
- // Schedule a message to be published. Messages are automatically batched.
- ApiFuture future = publisher.publish(pubsubMessage);
- futures.add(future);
- }
- } finally {
- // Wait on any pending requests
- List messageIds = ApiFutures.allAsList(futures).get();
-
- for (String messageId : messageIds) {
- System.out.println(messageId);
- }
-
- if (publisher != null) {
- // When finished with the publisher, shutdown to free up resources.
- publisher.shutdown();
- }
- }
- }
-}
-// [END pubsub_quickstart_quickstart]
diff --git a/pubsub/cloud-client/src/main/java/com/example/pubsub/SubscriberExample.java b/pubsub/cloud-client/src/main/java/com/example/pubsub/SubscriberExample.java
deleted file mode 100644
index e5bf2d831a0..00000000000
--- a/pubsub/cloud-client/src/main/java/com/example/pubsub/SubscriberExample.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * 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
- *
- * http://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.example.pubsub;
-
-// [START pubsub_quickstart_subscriber]
-
-import com.google.cloud.ServiceOptions;
-import com.google.cloud.pubsub.v1.AckReplyConsumer;
-import com.google.cloud.pubsub.v1.MessageReceiver;
-import com.google.cloud.pubsub.v1.Subscriber;
-import com.google.pubsub.v1.ProjectSubscriptionName;
-import com.google.pubsub.v1.PubsubMessage;
-
-public class SubscriberExample {
- // use the default project id
- private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId();
-
- static class MessageReceiverExample implements MessageReceiver {
-
- @Override
- public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
- System.out.println(
- "Message Id: " + message.getMessageId() + " Data: " + message.getData().toStringUtf8());
- // Ack only after all work for the message is complete.
- consumer.ack();
- }
- }
-
- /** Receive messages over a subscription. */
- public static void main(String... args) throws Exception {
- // set subscriber id, eg. my-sub
- String subscriptionId = args[0];
- ProjectSubscriptionName subscriptionName =
- ProjectSubscriptionName.of(PROJECT_ID, subscriptionId);
- Subscriber subscriber = null;
- try {
- // create a subscriber bound to the asynchronous message receiver
- subscriber = Subscriber.newBuilder(subscriptionName, new MessageReceiverExample()).build();
- subscriber.startAsync().awaitRunning();
- // Allow the subscriber to run indefinitely unless an unrecoverable error occurs.
- subscriber.awaitTerminated();
- } catch (IllegalStateException e) {
- System.out.println("Subscriber unexpectedly stopped: " + e);
- }
- }
-}
-// [END pubsub_quickstart_subscriber]
diff --git a/pubsub/cloud-client/src/test/java/com/example/pubsub/QuickStartIT.java b/pubsub/cloud-client/src/test/java/com/example/pubsub/QuickStartIT.java
deleted file mode 100644
index dfaf1045a4b..00000000000
--- a/pubsub/cloud-client/src/test/java/com/example/pubsub/QuickStartIT.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * 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
- *
- * http://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.example.pubsub;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.cloud.ServiceOptions;
-import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
-import com.google.cloud.pubsub.v1.TopicAdminClient;
-import com.google.pubsub.v1.ProjectSubscriptionName;
-import com.google.pubsub.v1.ProjectTopicName;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.Timeout;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests for quickstart sample. */
-@RunWith(JUnit4.class)
-@SuppressWarnings("checkstyle:abbreviationaswordinname")
-public class QuickStartIT {
-
- private ByteArrayOutputStream bout;
-
- private String projectId = ServiceOptions.getDefaultProjectId();
- private String topicId = formatForTest("my-topic");
- private String subscriptionId = formatForTest("my-sub");
- private int messageCount = 5;
-
- class SubscriberRunnable implements Runnable {
-
- private String subscriptionId;
-
- SubscriberRunnable(String subscriptionId) {
- this.subscriptionId = subscriptionId;
- }
-
- @Override
- public void run() {
- try {
- SubscriberExample.main(subscriptionId);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- @Rule public Timeout globalTimeout = Timeout.seconds(300); // 5 minute timeout
-
- @Before
- public void setUp() {
- bout = new ByteArrayOutputStream();
- PrintStream out = new PrintStream(bout);
- System.setOut(out);
- try {
- deleteTestSubscription();
- deleteTestTopic();
- } catch (Exception e) {
- // topic, subscription may not yet exist
- }
- }
-
- @After
- public void tearDown() throws Exception {
- System.setOut(null);
- deleteTestSubscription();
- deleteTestTopic();
- }
-
- @Test
- public void testQuickstart() throws Exception {
- // create a topic
- CreateTopicExample.main(topicId);
- String got = bout.toString();
- assertThat(got).contains(topicId + " created.");
-
- // create a subscriber
- CreatePullSubscriptionExample.main(topicId, subscriptionId);
- got = bout.toString();
- assertThat(got).contains(subscriptionId + " created.");
-
- bout.reset();
- // publish messages
- PublisherExample.main(topicId, String.valueOf(messageCount));
- String[] messageIds = bout.toString().split("\n");
- assertThat(messageIds).hasLength(messageCount);
-
- bout.reset();
- // receive messages
- Thread subscriberThread = new Thread(new SubscriberRunnable(subscriptionId));
- subscriberThread.start();
- Set expectedMessageIds = new HashSet<>();
- List receivedMessageIds = new ArrayList<>();
- expectedMessageIds.addAll(Arrays.asList(messageIds));
- while (!expectedMessageIds.isEmpty()) {
- for (String expectedId : expectedMessageIds) {
- if (bout.toString().contains(expectedId)) {
- receivedMessageIds.add(expectedId);
- }
- }
- expectedMessageIds.removeAll(receivedMessageIds);
- }
- assertThat(expectedMessageIds).isEmpty();
- }
-
- private String formatForTest(String name) {
- return name + "-" + java.util.UUID.randomUUID().toString();
- }
-
- private void deleteTestTopic() throws Exception {
- try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
- topicAdminClient.deleteTopic(ProjectTopicName.of(projectId, topicId));
- } catch (IOException e) {
- System.err.println("Error deleting topic " + e.getMessage());
- }
- }
-
- private void deleteTestSubscription() throws Exception {
- try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
- subscriptionAdminClient.deleteSubscription(
- ProjectSubscriptionName.of(projectId, subscriptionId));
- } catch (IOException e) {
- System.err.println("Error deleting subscription " + e.getMessage());
- }
- }
-}
diff --git a/pubsub/streaming-analytics/pom.xml b/pubsub/streaming-analytics/pom.xml
index 4123fb13925..50204c6bf1e 100644
--- a/pubsub/streaming-analytics/pom.xml
+++ b/pubsub/streaming-analytics/pom.xml
@@ -28,12 +28,12 @@
1.8
UTF-8
- 2.20.0
+ 2.22.0
3.8.1
- 1.6.0
+ 3.0.0
3.2.0
- 3.2.3
+ 3.2.4
1.7.30
diff --git a/recommender/beta/cloud-client/pom.xml b/recommender/beta/cloud-client/pom.xml
index ccd17e9ccd2..a18aaef6e15 100644
--- a/recommender/beta/cloud-client/pom.xml
+++ b/recommender/beta/cloud-client/pom.xml
@@ -23,7 +23,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -39,7 +39,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -50,13 +50,13 @@
com.google.cloud
google-cloud-recommender
- 0.4.1
+ 1.1.0
com.google.api.grpc
proto-google-cloud-recommender-v1beta1
- 0.4.1
+ 0.6.0
@@ -82,7 +82,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
false
diff --git a/run/authentication/pom.xml b/run/authentication/pom.xml
index 24728db20ce..e6f46f99209 100644
--- a/run/authentication/pom.xml
+++ b/run/authentication/pom.xml
@@ -25,7 +25,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
diff --git a/run/hello-broken/pom.xml b/run/hello-broken/pom.xml
index 7e1a8bd0f87..a3312438c76 100644
--- a/run/hello-broken/pom.xml
+++ b/run/hello-broken/pom.xml
@@ -23,7 +23,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
UTF-8
@@ -73,7 +73,7 @@ limitations under the License.
com.google.cloud.tools
jib-maven-plugin
- 2.3.0
+ 2.4.0
gcr.io/PROJECT_ID/hello-service
diff --git a/run/helloworld/pom.xml b/run/helloworld/pom.xml
index c2fdf10a185..2597ef11ab7 100644
--- a/run/helloworld/pom.xml
+++ b/run/helloworld/pom.xml
@@ -24,7 +24,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -32,7 +32,7 @@ limitations under the License.
org.springframework.boot
spring-boot-dependencies
- 2.3.0.RELEASE
+ 2.3.1.RELEASE
pom
import
@@ -71,7 +71,7 @@ limitations under the License.
com.google.cloud.tools
jib-maven-plugin
- 2.3.0
+ 2.4.0
gcr.io/PROJECT_ID/helloworld
diff --git a/run/image-processing/pom.xml b/run/image-processing/pom.xml
index 98e85af4d22..e00492cb5e8 100644
--- a/run/image-processing/pom.xml
+++ b/run/image-processing/pom.xml
@@ -23,7 +23,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
11
@@ -35,14 +35,14 @@ limitations under the License.
org.springframework.boot
spring-boot-dependencies
- 2.3.0.RELEASE
+ 2.3.1.RELEASE
pom
import
org.springframework.cloud
spring-cloud-dependencies
- Hoxton.SR4
+ Hoxton.SR6
pom
import
@@ -50,7 +50,7 @@ limitations under the License.
org.springframework.cloud
spring-cloud-gcp-dependencies
- 1.2.2.RELEASE
+ 1.2.3.RELEASE
pom
import
@@ -82,7 +82,7 @@ limitations under the License.
org.json
json
- 20190722
+ 20200518
org.springframework.cloud
@@ -95,7 +95,7 @@ limitations under the License.
commons-io
commons-io
- 2.6
+ 2.7
@@ -109,7 +109,7 @@ limitations under the License.
com.google.cloud.tools
jib-maven-plugin
- 2.3.0
+ 2.4.0
gcr.io/PROJECT_ID/imagemagick
diff --git a/run/logging-manual/pom.xml b/run/logging-manual/pom.xml
index 583f79a2ab6..db030794553 100644
--- a/run/logging-manual/pom.xml
+++ b/run/logging-manual/pom.xml
@@ -20,7 +20,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
UTF-8
@@ -43,7 +43,7 @@ limitations under the License.
net.logstash.logback
logstash-logback-encoder
- 6.3
+ 6.4
ch.qos.logback
@@ -70,7 +70,7 @@ limitations under the License.
com.google.cloud.tools
jib-maven-plugin
- 2.3.0
+ 2.4.0
gcr.io/PROJECT_ID/logging-manual
diff --git a/run/markdown-preview/editor/pom.xml b/run/markdown-preview/editor/pom.xml
index 8cd9c4be6a5..e6841dffe32 100644
--- a/run/markdown-preview/editor/pom.xml
+++ b/run/markdown-preview/editor/pom.xml
@@ -24,7 +24,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
11
@@ -36,7 +36,7 @@
org.springframework.boot
spring-boot-dependencies
- 2.3.0.RELEASE
+ 2.3.1.RELEASE
pom
import
@@ -83,7 +83,7 @@
com.google.cloud.tools
jib-maven-plugin
- 2.3.0
+ 2.4.0
gcr.io/PROJECT_ID/editor
diff --git a/run/markdown-preview/renderer/pom.xml b/run/markdown-preview/renderer/pom.xml
index 341deedcee1..887cb3b3a12 100644
--- a/run/markdown-preview/renderer/pom.xml
+++ b/run/markdown-preview/renderer/pom.xml
@@ -24,7 +24,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
11
@@ -36,7 +36,7 @@
org.springframework.boot
spring-boot-dependencies
- 2.3.0.RELEASE
+ 2.3.1.RELEASE
pom
import
@@ -50,22 +50,22 @@
com.atlassian.commonmark
commonmark
- 0.15.0
+ 0.15.1
com.atlassian.commonmark
commonmark-ext-gfm-tables
- 0.15.0
+ 0.15.1
com.atlassian.commonmark
commonmark-ext-gfm-strikethrough
- 0.15.0
+ 0.15.1
com.googlecode.owasp-java-html-sanitizer
owasp-java-html-sanitizer
- 20191001.1
+ 20200615.1
junit
@@ -94,7 +94,7 @@
com.google.cloud.tools
jib-maven-plugin
- 2.3.0
+ 2.4.0
gcr.io/PROJECT_ID/renderer
diff --git a/run/pubsub/pom.xml b/run/pubsub/pom.xml
index c815b06167f..c49dea4e50d 100644
--- a/run/pubsub/pom.xml
+++ b/run/pubsub/pom.xml
@@ -21,7 +21,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -35,14 +35,14 @@ limitations under the License.
org.springframework.boot
spring-boot-dependencies
- 2.3.0.RELEASE
+ 2.3.1.RELEASE
pom
import
org.springframework.cloud
spring-cloud-dependencies
- Hoxton.SR4
+ Hoxton.SR6
pom
import
@@ -76,7 +76,7 @@ limitations under the License.
com.google.cloud.tools
jib-maven-plugin
- 2.3.0
+ 2.4.0
gcr.io/PROJECT_ID/pubsub
diff --git a/run/system-package/pom.xml b/run/system-package/pom.xml
index de037f9e44d..4c2711f7c21 100644
--- a/run/system-package/pom.xml
+++ b/run/system-package/pom.xml
@@ -25,7 +25,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -59,7 +59,7 @@ limitations under the License.
com.google.cloud.tools
jib-maven-plugin
- 2.3.0
+ 2.4.0
gcr.io/PROJECT_ID/graphviz-base
diff --git a/secretmanager/pom.xml b/secretmanager/pom.xml
index bf02b52e3cb..4bd02b26819 100644
--- a/secretmanager/pom.xml
+++ b/secretmanager/pom.xml
@@ -28,7 +28,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -41,7 +41,13 @@
com.google.cloud
google-cloud-secretmanager
- 1.0.1
+ 1.1.0
+
+
+
+ com.google.protobuf
+ protobuf-java-util
+ 3.12.2
diff --git a/securitycenter/pom.xml b/securitycenter/pom.xml
index 7d3ef16eafd..e407e80c8be 100644
--- a/securitycenter/pom.xml
+++ b/securitycenter/pom.xml
@@ -23,7 +23,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -36,12 +36,18 @@
com.google.cloud
google-cloud-pubsub
- 1.105.1
+ 1.107.0
com.google.cloud
google-cloud-securitycenter
- 0.121.0
+ 1.1.0
+
+
+
+ com.google.protobuf
+ protobuf-java-util
+ 3.12.2
diff --git a/securitycenter/src/main/java/com/google/cloud/examples/securitycenter/snippets/UpdateNotificationConfigSnippets.java b/securitycenter/src/main/java/com/google/cloud/examples/securitycenter/snippets/UpdateNotificationConfigSnippets.java
index 5a511879a6f..dffc0dd9e2b 100644
--- a/securitycenter/src/main/java/com/google/cloud/examples/securitycenter/snippets/UpdateNotificationConfigSnippets.java
+++ b/securitycenter/src/main/java/com/google/cloud/examples/securitycenter/snippets/UpdateNotificationConfigSnippets.java
@@ -18,6 +18,7 @@
// [START scc_update_notification_config]
import com.google.cloud.securitycenter.v1.NotificationConfig;
+import com.google.cloud.securitycenter.v1.NotificationConfig.StreamingConfig;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import com.google.protobuf.FieldMask;
import java.io.IOException;
@@ -48,9 +49,13 @@ public static NotificationConfig updateNotificationConfig(
.setName(notificationConfigName)
.setDescription("updated description")
.setPubsubTopic(pubsubTopic)
+ .setStreamingConfig(StreamingConfig.newBuilder().setFilter("state = \"ACTIVE\""))
.build();
FieldMask fieldMask =
- FieldMask.newBuilder().addPaths("description").addPaths("pubsub_topic").build();
+ FieldMask.newBuilder()
+ .addPaths("description")
+ .addPaths("pubsub_topic")
+ .addPaths("streaming_config.filter").build();
try (SecurityCenterClient client = SecurityCenterClient.create()) {
NotificationConfig updatedConfig = client.updateNotificationConfig(configToUpdate, fieldMask);
@@ -60,4 +65,4 @@ public static NotificationConfig updateNotificationConfig(
}
}
// [END scc_update_notification_config]
-}
+}
\ No newline at end of file
diff --git a/session-handling/pom.xml b/session-handling/pom.xml
index 3ca794ee2e7..76ccc94b081 100644
--- a/session-handling/pom.xml
+++ b/session-handling/pom.xml
@@ -25,7 +25,7 @@ Copyright 2019 Google LLC
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -39,7 +39,7 @@ Copyright 2019 Google LLC
true
false
false
- 9.4.29.v20200521
+ 9.4.30.v20200611
@@ -47,7 +47,7 @@ Copyright 2019 Google LLC
com.google.cloud
google-cloud-firestore
- 1.33.0
+ 1.35.0
@@ -104,7 +104,7 @@ Copyright 2019 Google LLC
com.google.cloud.tools
jib-maven-plugin
- 2.3.0
+ 2.4.0
gcr.io/${gcloud.appId}/session-handling
diff --git a/spanner/cloud-client/pom.xml b/spanner/cloud-client/pom.xml
index f57e7ba77f6..23080109976 100644
--- a/spanner/cloud-client/pom.xml
+++ b/spanner/cloud-client/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -42,7 +42,7 @@ limitations under the License.
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -164,7 +164,7 @@ limitations under the License.
org.apache.maven.plugins
maven-failsafe-plugin
- 3.0.0-M4
+ 3.0.0-M5
default-instance
diff --git a/spanner/cloud-client/src/main/java/com/example/spanner/CreateInstanceExample.java b/spanner/cloud-client/src/main/java/com/example/spanner/CreateInstanceExample.java
new file mode 100644
index 00000000000..fe7e6ec4248
--- /dev/null
+++ b/spanner/cloud-client/src/main/java/com/example/spanner/CreateInstanceExample.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2020 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
+ *
+ * http://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.example.spanner;
+
+//[START spanner_create_instance]
+import com.google.api.gax.longrunning.OperationFuture;
+import com.google.cloud.spanner.Instance;
+import com.google.cloud.spanner.InstanceAdminClient;
+import com.google.cloud.spanner.InstanceConfigId;
+import com.google.cloud.spanner.InstanceId;
+import com.google.cloud.spanner.InstanceInfo;
+import com.google.cloud.spanner.Spanner;
+import com.google.cloud.spanner.SpannerOptions;
+import com.google.spanner.admin.instance.v1.CreateInstanceMetadata;
+import java.util.concurrent.ExecutionException;
+
+class CreateInstanceExample {
+
+ static void createInstance() {
+ // TODO(developer): Replace these variables before running the sample.
+ String projectId = "my-project";
+ String instanceId = "my-instance";
+ createInstance(projectId, instanceId);
+ }
+
+ static void createInstance(String projectId, String instanceId) {
+ Spanner spanner = SpannerOptions.newBuilder().setProjectId(projectId).build().getService();
+ InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();
+
+ // Set Instance configuration.
+ String configId = "regional-us-central1";
+ int nodeCount = 2;
+ String displayName = "Descriptive name";
+
+ // Create an InstanceInfo object that will be used to create the instance.
+ InstanceInfo instanceInfo =
+ InstanceInfo.newBuilder(InstanceId.of(projectId, instanceId))
+ .setInstanceConfigId(InstanceConfigId.of(projectId, configId))
+ .setNodeCount(nodeCount)
+ .setDisplayName(displayName)
+ .build();
+ OperationFuture operation =
+ instanceAdminClient.createInstance(instanceInfo);
+ try {
+ // Wait for the createInstance operation to finish.
+ Instance instance = operation.get();
+ System.out.printf("Instance %s was successfully created%n", instance.getId());
+ } catch (ExecutionException e) {
+ System.out.printf(
+ "Error: Creating instance %s failed with error message %s%n",
+ instanceInfo.getId(), e.getMessage());
+ } catch (InterruptedException e) {
+ System.out.println("Error: Waiting for createInstance operation to finish was interrupted");
+ }
+ }
+}
+//[END spanner_create_instance]
diff --git a/spanner/cloud-client/src/main/java/com/example/spanner/SpannerSample.java b/spanner/cloud-client/src/main/java/com/example/spanner/SpannerSample.java
index 6639ada47b9..0c4e0a28b85 100644
--- a/spanner/cloud-client/src/main/java/com/example/spanner/SpannerSample.java
+++ b/spanner/cloud-client/src/main/java/com/example/spanner/SpannerSample.java
@@ -37,6 +37,7 @@
import com.google.cloud.spanner.InstanceAdminClient;
import com.google.cloud.spanner.InstanceId;
import com.google.cloud.spanner.Key;
+import com.google.cloud.spanner.KeyRange;
import com.google.cloud.spanner.KeySet;
import com.google.cloud.spanner.Mutation;
import com.google.cloud.spanner.Options;
@@ -353,15 +354,21 @@ static void writeExampleData(DatabaseClient dbClient) {
static void deleteExampleData(DatabaseClient dbClient) {
List mutations = new ArrayList<>();
- // KeySet.all() can be used to delete all the rows in a table.
- mutations.add(Mutation.delete("Albums", KeySet.all()));
+ // KeySet.Builder can be used to delete a specific set of rows.
+ // Delete the Albums with the key values (2,1) and (2,3).
+ mutations.add(
+ Mutation.delete(
+ "Albums", KeySet.newBuilder().addKey(Key.of(2, 1)).addKey(Key.of(2, 3)).build()));
- // KeySet.singleKey() can be used to delete one row at a time.
- for (Singer singer : SINGERS) {
- mutations.add(
- Mutation.delete(
- "Singers", KeySet.singleKey(Key.newBuilder().append(singer.singerId).build())));
- }
+ // KeyRange can be used to delete rows with a key in a specific range.
+ // Delete a range of rows where the column key is >=3 and <5
+ mutations.add(
+ Mutation.delete("Singers", KeySet.range(KeyRange.closedOpen(Key.of(3), Key.of(5)))));
+
+ // KeySet.all() can be used to delete all the rows in a table.
+ // Delete remaining Singers rows, which will also delete the remaining Albums rows since it was
+ // defined with ON DELETE CASCADE.
+ mutations.add(Mutation.delete("Singers", KeySet.all()));
dbClient.write(mutations);
System.out.printf("Records deleted.\n");
diff --git a/spanner/cloud-client/src/test/java/com/example/spanner/SpannerSampleIT.java b/spanner/cloud-client/src/test/java/com/example/spanner/SpannerSampleIT.java
index 5360f2f1d13..21a307fe422 100644
--- a/spanner/cloud-client/src/test/java/com/example/spanner/SpannerSampleIT.java
+++ b/spanner/cloud-client/src/test/java/com/example/spanner/SpannerSampleIT.java
@@ -22,19 +22,18 @@
import com.google.cloud.spanner.DatabaseAdminClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.ErrorCode;
+import com.google.cloud.spanner.InstanceId;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerException;
import com.google.cloud.spanner.SpannerOptions;
-import com.google.common.base.CharMatcher;
import com.google.common.util.concurrent.Uninterruptibles;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -46,10 +45,12 @@
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class SpannerSampleIT {
// The instance needs to exist for tests to pass.
- private final String instanceId = System.getProperty("spanner.test.instance");
- private final String databaseId = formatForTest(System.getProperty("spanner.sample.database"));
- DatabaseId dbId;
- DatabaseAdminClient dbClient;
+ private static final String instanceId = System.getProperty("spanner.test.instance");
+ private static final String databaseId =
+ formatForTest(System.getProperty("spanner.sample.database"));
+ static Spanner spanner;
+ static DatabaseId dbId;
+ static DatabaseAdminClient dbClient;
private long lastUpdateDataTimeInMillis;
private String runSample(String command) throws Exception {
@@ -62,10 +63,10 @@ private String runSample(String command) throws Exception {
return bout.toString();
}
- @Before
- public void setUp() throws Exception {
+ @BeforeClass
+ public static void setUp() throws Exception {
SpannerOptions options = SpannerOptions.newBuilder().build();
- Spanner spanner = options.getService();
+ spanner = options.getService();
dbClient = spanner.getDatabaseAdminClient();
dbId = DatabaseId.of(options.getProjectId(), instanceId, databaseId);
dbClient.dropDatabase(dbId.getInstanceId().getInstance(), dbId.getDatabase());
@@ -73,8 +74,8 @@ public void setUp() throws Exception {
dbId.getInstanceId().getInstance(), SpannerSample.createRestoredSampleDbId(dbId));
}
- @After
- public void tearDown() throws Exception {
+ @AfterClass
+ public static void tearDown() throws Exception {
dbClient.dropDatabase(dbId.getInstanceId().getInstance(), dbId.getDatabase());
dbClient.dropDatabase(
dbId.getInstanceId().getInstance(), SpannerSample.createRestoredSampleDbId(dbId));
@@ -347,11 +348,44 @@ public void testSample() throws Exception {
assertThat(out).contains("Deleted backup [" + backupId + "]");
}
+ private String runSampleRunnable(Runnable sample) {
+ PrintStream stdOut = System.out;
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ PrintStream out = new PrintStream(bout);
+ System.setOut(out);
+ sample.run();
+ System.setOut(stdOut);
+ return bout.toString();
+ }
+
+ @Test
+ public void testCreateInstanceSample() {
+ String instanceId = formatForTest("sample-inst");
+ String out =
+ runSampleRunnable(
+ new Runnable() {
+ @Override
+ public void run() {
+ try {
+ CreateInstanceExample.createInstance(
+ dbId.getInstanceId().getProject(), instanceId);
+ } finally {
+ spanner.getInstanceAdminClient().deleteInstance(instanceId);
+ }
+ }
+ });
+ assertThat(out)
+ .contains(
+ String.format(
+ "Instance %s was successfully created",
+ InstanceId.of(dbId.getInstanceId().getProject(), instanceId)));
+ }
+
private static int countOccurrences(String input, String search) {
return input.split(search).length - 1;
}
- private String formatForTest(String name) {
+ private static String formatForTest(String name) {
return name + "-" + UUID.randomUUID().toString().substring(0, 20);
}
}
diff --git a/spanner/hibernate/pom.xml b/spanner/hibernate/pom.xml
index 2b5850fe032..a0c4959143a 100644
--- a/spanner/hibernate/pom.xml
+++ b/spanner/hibernate/pom.xml
@@ -17,7 +17,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
com.example.spanner
@@ -44,7 +44,7 @@
org.hibernate
hibernate-core
- 5.4.16.Final
+ 5.4.18.Final
@@ -54,7 +54,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/spanner/jdbc/pom.xml b/spanner/jdbc/pom.xml
index 533e262f546..4f4e1b5556e 100644
--- a/spanner/jdbc/pom.xml
+++ b/spanner/jdbc/pom.xml
@@ -17,7 +17,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
com.example.spanner
@@ -28,7 +28,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -64,7 +64,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/spanner/jdbc/src/main/java/com/example/spanner/jdbc/BatchDmlExample.java b/spanner/jdbc/src/main/java/com/example/spanner/jdbc/BatchDmlExample.java
index 1d42bc38647..0e004951b78 100644
--- a/spanner/jdbc/src/main/java/com/example/spanner/jdbc/BatchDmlExample.java
+++ b/spanner/jdbc/src/main/java/com/example/spanner/jdbc/BatchDmlExample.java
@@ -16,6 +16,7 @@
package com.example.spanner.jdbc;
+//[START spanner_jdbc_batch_transaction]
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -41,18 +42,23 @@ static void batchDml(String projectId, String instanceId, String databaseId) thr
String.format(
"jdbc:cloudspanner:/projects/%s/instances/%s/databases/%s",
projectId, instanceId, databaseId);
- try (Connection connection = DriverManager.getConnection(connectionUrl);
- Statement statement = connection.createStatement()) {
- statement.addBatch(
- "INSERT INTO Singers (SingerId, FirstName, LastName)\n"
- + "VALUES (10, 'Marc', 'Richards')");
- statement.addBatch(
- "INSERT INTO Singers (SingerId, FirstName, LastName)\n"
- + "VALUES (11, 'Amirah', 'Finney')");
- statement.addBatch(
- "INSERT INTO Singers (SingerId, FirstName, LastName)\n" + "VALUES (12, 'Reece', 'Dunn')");
- int[] updateCounts = statement.executeBatch();
- System.out.printf("Batch insert counts: %s%n", Arrays.toString(updateCounts));
+ try (Connection connection = DriverManager.getConnection(connectionUrl)) {
+ connection.setAutoCommit(false);
+ try (Statement statement = connection.createStatement()) {
+ statement.addBatch(
+ "INSERT INTO Singers (SingerId, FirstName, LastName)\n"
+ + "VALUES (10, 'Marc', 'Richards')");
+ statement.addBatch(
+ "INSERT INTO Singers (SingerId, FirstName, LastName)\n"
+ + "VALUES (11, 'Amirah', 'Finney')");
+ statement.addBatch(
+ "INSERT INTO Singers (SingerId, FirstName, LastName)\n"
+ + "VALUES (12, 'Reece', 'Dunn')");
+ int[] updateCounts = statement.executeBatch();
+ connection.commit();
+ System.out.printf("Batch insert counts: %s%n", Arrays.toString(updateCounts));
+ }
}
}
}
+//[END spanner_jdbc_batch_transaction]
diff --git a/spanner/jdbc/src/main/java/com/example/spanner/jdbc/CreateTableExample.java b/spanner/jdbc/src/main/java/com/example/spanner/jdbc/CreateTableExample.java
index 3cd051004b7..f2d0bb1dd5b 100644
--- a/spanner/jdbc/src/main/java/com/example/spanner/jdbc/CreateTableExample.java
+++ b/spanner/jdbc/src/main/java/com/example/spanner/jdbc/CreateTableExample.java
@@ -16,6 +16,7 @@
package com.example.spanner.jdbc;
+//[START spanner_jdbc_create_table]
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -55,3 +56,4 @@ static void createTable(String projectId, String instanceId, String databaseId)
System.out.println("Created table [Singers]");
}
}
+//[END spanner_jdbc_create_table]
diff --git a/spanner/jdbc/src/main/java/com/example/spanner/jdbc/InsertDataExample.java b/spanner/jdbc/src/main/java/com/example/spanner/jdbc/InsertDataExample.java
index 629a71f6ae3..7cf61578373 100644
--- a/spanner/jdbc/src/main/java/com/example/spanner/jdbc/InsertDataExample.java
+++ b/spanner/jdbc/src/main/java/com/example/spanner/jdbc/InsertDataExample.java
@@ -16,6 +16,7 @@
package com.example.spanner.jdbc;
+//[START spanner_jdbc_insert]
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -65,7 +66,6 @@ static void insertData(String projectId, String instanceId, String databaseId)
"jdbc:cloudspanner:/projects/%s/instances/%s/databases/%s",
projectId, instanceId, databaseId);
try (Connection connection = DriverManager.getConnection(connectionUrl)) {
- connection.setAutoCommit(false);
try (PreparedStatement ps =
connection.prepareStatement(
"INSERT INTO Singers\n"
@@ -80,9 +80,9 @@ static void insertData(String projectId, String instanceId, String databaseId)
ps.addBatch();
}
int[] updateCounts = ps.executeBatch();
- connection.commit();
System.out.printf("Insert counts: %s%n", Arrays.toString(updateCounts));
}
}
}
}
+//[END spanner_jdbc_insert]
diff --git a/spanner/jdbc/src/main/java/com/example/spanner/jdbc/SingleUseReadOnlyExample.java b/spanner/jdbc/src/main/java/com/example/spanner/jdbc/SingleUseReadOnlyExample.java
index 409eed9b233..4d2ffcc6b02 100644
--- a/spanner/jdbc/src/main/java/com/example/spanner/jdbc/SingleUseReadOnlyExample.java
+++ b/spanner/jdbc/src/main/java/com/example/spanner/jdbc/SingleUseReadOnlyExample.java
@@ -16,6 +16,7 @@
package com.example.spanner.jdbc;
+//[START spanner_jdbc_query]
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -57,3 +58,4 @@ static void singleUseReadOnly(String projectId, String instanceId, String databa
}
}
}
+//[END spanner_jdbc_query]
diff --git a/spanner/leaderboard/complete/pom.xml b/spanner/leaderboard/complete/pom.xml
index e3561a5de6e..be3cd2f06f9 100644
--- a/spanner/leaderboard/complete/pom.xml
+++ b/spanner/leaderboard/complete/pom.xml
@@ -25,7 +25,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -33,7 +33,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -90,12 +90,12 @@
org.apache.maven.plugins
maven-failsafe-plugin
- 3.0.0-M4
+ 3.0.0-M5
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
false
diff --git a/spanner/leaderboard/step4/pom.xml b/spanner/leaderboard/step4/pom.xml
index 71b7e9e325a..704e5874c26 100644
--- a/spanner/leaderboard/step4/pom.xml
+++ b/spanner/leaderboard/step4/pom.xml
@@ -25,7 +25,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -33,7 +33,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -84,12 +84,12 @@
org.apache.maven.plugins
maven-failsafe-plugin
- 3.0.0-M4
+ 3.0.0-M5
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
false
diff --git a/spanner/leaderboard/step5/pom.xml b/spanner/leaderboard/step5/pom.xml
index 71b7e9e325a..704e5874c26 100644
--- a/spanner/leaderboard/step5/pom.xml
+++ b/spanner/leaderboard/step5/pom.xml
@@ -25,7 +25,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -33,7 +33,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -84,12 +84,12 @@
org.apache.maven.plugins
maven-failsafe-plugin
- 3.0.0-M4
+ 3.0.0-M5
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
false
diff --git a/spanner/leaderboard/step6/pom.xml b/spanner/leaderboard/step6/pom.xml
index a7f894b15ee..cb4255a5b86 100644
--- a/spanner/leaderboard/step6/pom.xml
+++ b/spanner/leaderboard/step6/pom.xml
@@ -25,7 +25,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -33,7 +33,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -84,12 +84,12 @@
org.apache.maven.plugins
maven-failsafe-plugin
- 3.0.0-M4
+ 3.0.0-M5
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M4
+ 3.0.0-M5
false
diff --git a/spanner/spring-data/pom.xml b/spanner/spring-data/pom.xml
index e4f5f5d4663..b15fec2dc42 100644
--- a/spanner/spring-data/pom.xml
+++ b/spanner/spring-data/pom.xml
@@ -28,7 +28,7 @@ limitations under the License.
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
com.example.spanner
@@ -41,7 +41,7 @@ limitations under the License.
org.springframework.cloud
spring-cloud-gcp-dependencies
- 1.2.2.RELEASE
+ 1.2.3.RELEASE
pom
import
@@ -61,7 +61,7 @@ limitations under the License.
org.springframework.boot
spring-boot-maven-plugin
- 2.3.0.RELEASE
+ 2.3.1.RELEASE
com.example.spanner.QuickStartSample
diff --git a/speech/beta/pom.xml b/speech/beta/pom.xml
index 3cfd9c5e2fd..8ad8b8d00ba 100644
--- a/speech/beta/pom.xml
+++ b/speech/beta/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -40,7 +40,7 @@
com.google.cloud
google-cloud-speech
- 1.23.0
+ 1.24.0
@@ -90,7 +90,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -119,7 +119,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/speech/cloud-client/pom.xml b/speech/cloud-client/pom.xml
index a4e0e13bf6c..4244366e124 100644
--- a/speech/cloud-client/pom.xml
+++ b/speech/cloud-client/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -40,7 +40,7 @@
com.google.cloud
google-cloud-speech
- 1.23.0
+ 1.24.0
@@ -94,7 +94,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -123,7 +123,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -151,7 +151,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/storage/cloud-client/pom.xml b/storage/cloud-client/pom.xml
index b24c2c2f8c1..6d59d6160f3 100644
--- a/storage/cloud-client/pom.xml
+++ b/storage/cloud-client/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -39,7 +39,7 @@
com.google.cloud
google-cloud-storage
- 1.108.0
+ 1.111.0
diff --git a/storage/json-api/pom.xml b/storage/json-api/pom.xml
index eaf8c07309d..442a16a6e55 100644
--- a/storage/json-api/pom.xml
+++ b/storage/json-api/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -49,6 +49,11 @@
+
+ com.google.auth
+ google-auth-library-oauth2-http
+ 0.21.0
+
com.google.guava
guava
diff --git a/storage/json-api/src/main/java/CustomerSuppliedEncryptionKeysSamples.java b/storage/json-api/src/main/java/CustomerSuppliedEncryptionKeysSamples.java
index df3f5a57717..f5a9db0d596 100644
--- a/storage/json-api/src/main/java/CustomerSuppliedEncryptionKeysSamples.java
+++ b/storage/json-api/src/main/java/CustomerSuppliedEncryptionKeysSamples.java
@@ -25,15 +25,15 @@
/**
* Demonstrates the use of GCS's CSEK features via the Java API client library
*
- * This program demonstrates some quick, basic examples of using GCS's CSEK functionality.
+ * This program demonstrates some quick, basic examples of using GCS's CSEK functionality.
*
- * When run, it begins by uploading an object named "encrypted_file.txt" to the specified bucket
- * that will be protected with a provided CSEK.
+ * When run, it begins by uploading an object named "encrypted_file.txt" to the specified bucket
+ * that will be protected with a provided CSEK.
*
- * Next, it will fetch that object by providing that same CSEK to GCS.
+ * Next, it will fetch that object by providing that same CSEK to GCS.
*
- * Finally, it will rotate that key to a new value.
- **/
+ * Finally, it will rotate that key to a new value.
+ */
class CustomerSuppliedEncryptionKeysSamples {
// You can (and should) generate your own CSEK Key! Try running this from the command line:
@@ -62,9 +62,7 @@ class CustomerSuppliedEncryptionKeysSamples {
* @param objectName The name of the destination object
* @param base64CseKey An AES256 key, encoded as a base64 string.
* @param base64CseKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
- *
* @return An InputStream that contains the decrypted contents of the object.
- *
* @throws IOException if there was some error download from GCS.
*/
public static InputStream downloadObject(
@@ -148,12 +146,12 @@ public static void uploadObject(
* @param storage A Storage object, ready for use
* @param bucketName The name of the destination bucket
* @param objectName The name of the destination object
- * @param originalBase64Key The AES256 key currently associated with this object,
- * encoded as a base64 string.
- * @param originalBase64KeyHash The SHA-256 hash of the above key,
- * also encoded as a base64 string.
- * @param newBase64Key An AES256 key which will replace the existing key,
- * encoded as a base64 string.
+ * @param originalBase64Key The AES256 key currently associated with this object, encoded as a
+ * base64 string.
+ * @param originalBase64KeyHash The SHA-256 hash of the above key, also encoded as a base64
+ * string.
+ * @param newBase64Key An AES256 key which will replace the existing key, encoded as a base64
+ * string.
* @param newBase64KeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
* @throws IOException if there was some error download from GCS.
*/
@@ -203,10 +201,11 @@ public static void rotateKey(
public static void main(String[] args) throws Exception {
if (args.length != 1) {
- System.out.println("\nPlease run this with one argument: "
- + "the GCS bucket into which this program should upload an object.\n\n"
- + "You can create a bucket using gsutil like this:\n\n\t"
- + "gsutil mb gs://name-of-bucket\n\n");
+ System.out.println(
+ "\nPlease run this with one argument: "
+ + "the GCS bucket into which this program should upload an object.\n\n"
+ + "You can create a bucket using gsutil like this:\n\n\t"
+ + "gsutil mb gs://name-of-bucket\n\n");
System.exit(1);
}
String bucketName = args[0];
@@ -223,10 +222,15 @@ public static void main(String[] args) throws Exception {
StorageUtils.readStream(objectData);
System.out.println("Rotating object to use a different CSEK.");
- rotateKey(storage, bucketName, OBJECT_NAME, CSEK_KEY, CSEK_KEY_HASH,
- ANOTHER_CESK_KEY, ANOTHER_CSEK_KEY_HASH);
+ rotateKey(
+ storage,
+ bucketName,
+ OBJECT_NAME,
+ CSEK_KEY,
+ CSEK_KEY_HASH,
+ ANOTHER_CESK_KEY,
+ ANOTHER_CSEK_KEY_HASH);
System.out.println("Done");
}
-
}
diff --git a/storage/json-api/src/main/java/StorageFactory.java b/storage/json-api/src/main/java/StorageFactory.java
index fb47188d05f..caa9729006b 100644
--- a/storage/json-api/src/main/java/StorageFactory.java
+++ b/storage/json-api/src/main/java/StorageFactory.java
@@ -14,20 +14,19 @@
* limitations under the License.
*/
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.storage.Storage;
import com.google.api.services.storage.StorageScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collection;
-/**
- * This class manages the details of creating a Storage service, including auth.
- */
+/** This class manages the details of creating a Storage service, including auth. */
// [START authentication_application_default_credentials]
public class StorageFactory {
private static Storage instance = null;
@@ -42,7 +41,7 @@ public static synchronized Storage getService() throws IOException, GeneralSecur
private static Storage buildService() throws IOException, GeneralSecurityException {
HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = new JacksonFactory();
- GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
+ GoogleCredentials credential = GoogleCredentials.getApplicationDefault();
// Depending on the environment that provides the default credentials (for
// example: Compute Engine, App Engine), the credentials may require us to
@@ -53,7 +52,7 @@ private static Storage buildService() throws IOException, GeneralSecurityExcepti
credential = credential.createScoped(scopes);
}
- return new Storage.Builder(transport, jsonFactory, credential)
+ return new Storage.Builder(transport, jsonFactory, new HttpCredentialsAdapter(credential))
.setApplicationName("GCS Samples")
.build();
}
diff --git a/storage/json-api/src/main/java/StorageSample.java b/storage/json-api/src/main/java/StorageSample.java
index 9ea3a139065..9ce6f32a398 100644
--- a/storage/json-api/src/main/java/StorageSample.java
+++ b/storage/json-api/src/main/java/StorageSample.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-//[START all]
+// [START all]
import com.google.api.client.http.InputStreamContent;
import com.google.api.services.storage.Storage;
@@ -98,24 +98,24 @@ public static Bucket getBucket(String bucketName) throws IOException, GeneralSec
* @param file the file to upload.
* @param bucketName the name of the bucket to create the object in.
*/
- public static void uploadFile(
- String name, String contentType, File file, String bucketName)
+ public static void uploadFile(String name, String contentType, File file, String bucketName)
throws IOException, GeneralSecurityException {
- InputStreamContent contentStream = new InputStreamContent(
- contentType, new FileInputStream(file));
+ InputStreamContent contentStream =
+ new InputStreamContent(contentType, new FileInputStream(file));
// Setting the length improves upload performance
contentStream.setLength(file.length());
- StorageObject objectMetadata = new StorageObject()
- // Set the destination object name
- .setName(name)
- // Set the access control list to publicly read-only
- .setAcl(Arrays.asList(
- new ObjectAccessControl().setEntity("allUsers").setRole("READER")));
+ StorageObject objectMetadata =
+ new StorageObject()
+ // Set the destination object name
+ .setName(name)
+ // Set the access control list to publicly read-only
+ .setAcl(
+ Arrays.asList(new ObjectAccessControl().setEntity("allUsers").setRole("READER")));
// Do the insert
Storage client = StorageFactory.getService();
- Storage.Objects.Insert insertRequest = client.objects().insert(
- bucketName, objectMetadata, contentStream);
+ Storage.Objects.Insert insertRequest =
+ client.objects().insert(bucketName, objectMetadata, contentStream);
insertRequest.execute();
}
@@ -156,7 +156,6 @@ public static void main(String[] args) {
System.out.println("timeCreated: " + bucket.getTimeCreated());
System.out.println("owner: " + bucket.getOwner());
-
// List the contents of the bucket.
List bucketContents = listBucket(bucketName);
if (null == bucketContents) {
@@ -187,4 +186,4 @@ public static void main(String[] args) {
}
}
}
-//[END all]
+// [END all]
diff --git a/storage/json-api/src/main/java/StorageUtils.java b/storage/json-api/src/main/java/StorageUtils.java
index 6ef874666ea..3a5edfb79c1 100644
--- a/storage/json-api/src/main/java/StorageUtils.java
+++ b/storage/json-api/src/main/java/StorageUtils.java
@@ -19,9 +19,7 @@
public class StorageUtils {
- /**
- * Reads the contents of an InputStream and does nothing with it.
- */
+ /** Reads the contents of an InputStream and does nothing with it. */
public static void readStream(InputStream is) throws IOException {
byte[] inputBuffer = new byte[256];
while (is.read(inputBuffer) != -1) {}
@@ -30,8 +28,8 @@ public static void readStream(InputStream is) throws IOException {
}
/**
- * A helper class to provide input streams of any size.
- * The input streams will be full of null bytes.
+ * A helper class to provide input streams of any size. The input streams will be full of null
+ * bytes.
*/
static class ArbitrarilyLargeInputStream extends InputStream {
@@ -53,4 +51,3 @@ public int read() throws IOException {
}
}
}
-
diff --git a/storage/s3-sdk/pom.xml b/storage/s3-sdk/pom.xml
index 1f2538096f5..ed500287c17 100644
--- a/storage/s3-sdk/pom.xml
+++ b/storage/s3-sdk/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -38,7 +38,7 @@
com.amazonaws
aws-java-sdk-s3
- 1.11.788
+ 1.11.811
diff --git a/storage/storage-transfer/pom.xml b/storage/storage-transfer/pom.xml
index 1dd0e174b90..7ff3b44557b 100644
--- a/storage/storage-transfer/pom.xml
+++ b/storage/storage-transfer/pom.xml
@@ -30,7 +30,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -43,7 +43,7 @@
com.google.apis
google-api-services-storagetransfer
- v1-rev20200316-1.30.9
+ v1-rev20200605-1.30.9
com.google.guava
@@ -51,7 +51,11 @@
-
+
+ com.google.auth
+ google-auth-library-oauth2-http
+ 0.21.0
+
com.google.guava
guava
diff --git a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/AwsRequester.java b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/AwsRequester.java
index e2c0835030a..0c6f067fa3b 100644
--- a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/AwsRequester.java
+++ b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/AwsRequester.java
@@ -30,24 +30,19 @@
import java.io.IOException;
import java.io.PrintStream;
-/**
- * Creates a one-off transfer job from Amazon S3 to Google Cloud Storage.
- */
+/** Creates a one-off transfer job from Amazon S3 to Google Cloud Storage. */
public final class AwsRequester {
/**
* Creates and executes a request for a TransferJob from Amazon S3 to Cloud Storage.
*
- * The {@code startDate} and {@code startTime} parameters should be set according to the UTC
+ * The {@code startDate} and {@code startTime} parameters should be set according to the UTC
* Time Zone. See:
* https://developers.google.com/resources/api-libraries/documentation/storagetransfer/v1/java/latest/com/google/api/services/storagetransfer/v1/model/Schedule.html#getStartTimeOfDay()
*
* @return the response TransferJob if the request is successful
- * @throws InstantiationException
- * if instantiation fails when building the TransferJob
- * @throws IllegalAccessException
- * if an illegal access occurs when building the TransferJob
- * @throws IOException
- * if the client failed to complete the request
+ * @throws InstantiationException if instantiation fails when building the TransferJob
+ * @throws IllegalAccessException if an illegal access occurs when building the TransferJob
+ * @throws IOException if the client failed to complete the request
*/
public static TransferJob createAwsTransferJob(
String projectId,
@@ -110,9 +105,7 @@ public static void run(PrintStream out)
out.println("Return transferJob: " + responseT.toPrettyString());
}
- /**
- * Output the contents of a successfully created TransferJob.
- */
+ /** Output the contents of a successfully created TransferJob. */
public static void main(String[] args) {
try {
run(System.out);
@@ -121,4 +114,4 @@ public static void main(String[] args) {
}
}
}
-//[END all]
+// [END all]
diff --git a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/NearlineRequester.java b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/NearlineRequester.java
index 87e98b3d2d6..8be0f3a085e 100644
--- a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/NearlineRequester.java
+++ b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/NearlineRequester.java
@@ -31,25 +31,22 @@
import java.io.PrintStream;
/**
- * Creates a daily transfer from a standard Cloud Storage bucket to a Cloud Storage Nearline
- * bucket for files untouched for 30 days.
+ * Creates a daily transfer from a standard Cloud Storage bucket to a Cloud Storage Nearline bucket
+ * for files untouched for 30 days.
*/
public final class NearlineRequester {
/**
* Creates and executes a request for a TransferJob to Cloud Storage Nearline.
*
- *
The {@code startDate} and {@code startTime} parameters should be set according to the UTC
+ * The {@code startDate} and {@code startTime} parameters should be set according to the UTC
* Time Zone. See:
* https://developers.google.com/resources/api-libraries/documentation/storagetransfer/v1/java/latest/com/google/api/services/storagetransfer/v1/model/Schedule.html#getStartTimeOfDay()
*
* @return the response TransferJob if the request is successful
- * @throws InstantiationException
- * if instantiation fails when building the TransferJob
- * @throws IllegalAccessException
- * if an illegal access occurs when building the TransferJob
- * @throws IOException
- * if the client failed to complete the request
+ * @throws InstantiationException if instantiation fails when building the TransferJob
+ * @throws IllegalAccessException if an illegal access occurs when building the TransferJob
+ * @throws IOException if the client failed to complete the request
*/
public static TransferJob createNearlineTransferJob(
String projectId,
@@ -73,10 +70,8 @@ public static TransferJob createNearlineTransferJob(
new ObjectConditions()
.setMinTimeElapsedSinceLastModification("2592000s" /* 30 days */))
.setTransferOptions(
- new TransferOptions()
- .setDeleteObjectsFromSourceAfterTransfer(true)))
- .setSchedule(
- new Schedule().setScheduleStartDate(date).setStartTimeOfDay(time))
+ new TransferOptions().setDeleteObjectsFromSourceAfterTransfer(true)))
+ .setSchedule(new Schedule().setScheduleStartDate(date).setStartTimeOfDay(time))
.setStatus("ENABLED");
Storagetransfer client = TransferClientCreator.createStorageTransferClient();
@@ -106,8 +101,7 @@ public static void run(PrintStream out)
/**
* Output the contents of a successfully created TransferJob.
*
- * @param args
- * arguments from the command line
+ * @param args arguments from the command line
*/
public static void main(String[] args) {
try {
@@ -117,4 +111,4 @@ public static void main(String[] args) {
}
}
}
-//[END all]
+// [END all]
diff --git a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/RequestChecker.java b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/RequestChecker.java
index f10257e8fb7..68e52c2b0a9 100644
--- a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/RequestChecker.java
+++ b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/RequestChecker.java
@@ -26,7 +26,6 @@
/**
* Queries for TransferOperations associated with a specific TransferJob. A TransferJob is done when
* all of its associated TransferOperations have completed.
- *
*/
public final class RequestChecker {
@@ -38,15 +37,11 @@ public final class RequestChecker {
/**
* Creates and executes a query for all associated TransferOperations.
*
- * @param client
- * a Storagetransfer client, for interacting with the Storage Transfer API
- * @param projectId
- * the project to query within
- * @param jobName
- * the job Name of the relevant TransferJob
+ * @param client a Storagetransfer client, for interacting with the Storage Transfer API
+ * @param projectId the project to query within
+ * @param jobName the job Name of the relevant TransferJob
* @return an object containing information on associated TransferOperations
- * @throws IOException
- * if the client failed to complete the request
+ * @throws IOException if the client failed to complete the request
*/
public static ListOperationsResponse checkTransfer(
Storagetransfer client, String projectId, String jobName) throws IOException {
@@ -60,8 +55,7 @@ public static ListOperationsResponse checkTransfer(
/**
* Output the returned list of TransferOperations.
*
- * @param args
- * arguments from the command line
+ * @param args arguments from the command line
*/
public static void main(String[] args) {
try {
@@ -73,4 +67,4 @@ public static void main(String[] args) {
}
}
}
-//[END all]
+// [END all]
diff --git a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/RetryHttpInitializerWrapper.java b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/RetryHttpInitializerWrapper.java
index 55b11ebb63b..cfb824dceb5 100644
--- a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/RetryHttpInitializerWrapper.java
+++ b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/RetryHttpInitializerWrapper.java
@@ -45,8 +45,8 @@ public class RetryHttpInitializerWrapper implements HttpRequestInitializer {
/**
* A constructor using the default Sleeper.
*
- * @param wrappedCredential
- * the credential used to authenticate with a Google Cloud Platform project
+ * @param wrappedCredential the credential used to authenticate with a Google Cloud Platform
+ * project
*/
public RetryHttpInitializerWrapper(Credential wrappedCredential) {
this(wrappedCredential, Sleeper.DEFAULT);
@@ -55,10 +55,9 @@ public RetryHttpInitializerWrapper(Credential wrappedCredential) {
/**
* A constructor used only for testing.
*
- * @param wrappedCredential
- * the credential used to authenticate with a Google Cloud Platform project
- * @param sleeper
- * a user-supplied Sleeper
+ * @param wrappedCredential the credential used to authenticate with a Google Cloud Platform
+ * project
+ * @param sleeper a user-supplied Sleeper
*/
RetryHttpInitializerWrapper(Credential wrappedCredential, Sleeper sleeper) {
this.wrappedCredential = Preconditions.checkNotNull(wrappedCredential);
@@ -68,8 +67,7 @@ public RetryHttpInitializerWrapper(Credential wrappedCredential) {
/**
* Initialize an HttpRequest.
*
- * @param request
- * an HttpRequest that should be initialized
+ * @param request an HttpRequest that should be initialized
*/
public void initialize(HttpRequest request) {
request.setReadTimeout(2 * MILLIS_PER_MINUTE); // 2 minutes read timeout
@@ -98,4 +96,4 @@ public boolean handleResponse(
new HttpBackOffIOExceptionHandler(new ExponentialBackOff()).setSleeper(sleeper));
}
}
-//[END all]
+// [END all]
diff --git a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/TransferClientCreator.java b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/TransferClientCreator.java
index d64e0619fea..a74c044a56c 100644
--- a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/TransferClientCreator.java
+++ b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/TransferClientCreator.java
@@ -18,19 +18,18 @@
package com.google.cloud.storage.storagetransfer.samples;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.util.Utils;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.services.storagetransfer.v1.Storagetransfer;
import com.google.api.services.storagetransfer.v1.StoragetransferScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import com.google.common.base.Preconditions;
import java.io.IOException;
-/**
- * Create a client to make calls to Storage Transfer API.
- */
+/** Create a client to make calls to Storage Transfer API. */
public final class TransferClientCreator {
/**
@@ -38,30 +37,25 @@ public final class TransferClientCreator {
* settings.
*
* @return a Storage Transfer client
- * @throws IOException
- * there was an error obtaining application default credentials
+ * @throws IOException there was an error obtaining application default credentials
*/
public static Storagetransfer createStorageTransferClient() throws IOException {
HttpTransport httpTransport = Utils.getDefaultTransport();
JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
- GoogleCredential credential =
- GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
+ GoogleCredentials credential = GoogleCredentials.getApplicationDefault();
return createStorageTransferClient(httpTransport, jsonFactory, credential);
}
/**
* Create a Storage Transfer client using user-supplied credentials and other settings.
*
- * @param httpTransport
- * a user-supplied HttpTransport
- * @param jsonFactory
- * a user-supplied JsonFactory
- * @param credential
- * a user-supplied Google credential
+ * @param httpTransport a user-supplied HttpTransport
+ * @param jsonFactory a user-supplied JsonFactory
+ * @param credential a user-supplied Google credential
* @return a Storage Transfer client
*/
public static Storagetransfer createStorageTransferClient(
- HttpTransport httpTransport, JsonFactory jsonFactory, GoogleCredential credential) {
+ HttpTransport httpTransport, JsonFactory jsonFactory, GoogleCredentials credential) {
Preconditions.checkNotNull(httpTransport);
Preconditions.checkNotNull(jsonFactory);
Preconditions.checkNotNull(credential);
@@ -73,10 +67,10 @@ public static Storagetransfer createStorageTransferClient(
// Please use custom HttpRequestInitializer for automatic
// retry upon failures. We provide a simple reference
// implementation in the "Retry Handling" section.
- HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
+ HttpRequestInitializer initializer = new HttpCredentialsAdapter(credential);
return new Storagetransfer.Builder(httpTransport, jsonFactory, initializer)
.setApplicationName("storagetransfer-sample")
.build();
}
}
-//[END all]
+// [END all]
diff --git a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/TransferJobUtils.java b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/TransferJobUtils.java
index ff3b5111250..80be773d46f 100644
--- a/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/TransferJobUtils.java
+++ b/storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/TransferJobUtils.java
@@ -21,30 +21,21 @@
import com.google.api.services.storagetransfer.v1.model.Date;
import com.google.api.services.storagetransfer.v1.model.TimeOfDay;
-/**
- * Utility methods for creating TransferJobs.
- *
- */
+/** Utility methods for creating TransferJobs. */
public final class TransferJobUtils {
private static final int BASE_10 = 10;
- /**
- * A private constructor.
- */
+ /** A private constructor. */
private TransferJobUtils() {}
/**
* Parses a Date from a string of the form "YYYY-MM-DD".
*
- * @param dateString
- * a string of the form "YYYY-MM-DD"
+ * @param dateString a string of the form "YYYY-MM-DD"
* @return a Google Date representing the desired date
- * @throws NumberFormatException
- * if the input string has an incorrect format
- * @throws InstantiationException
- * if Date object instantiation failed
- * @throws IllegalAccessException
- * if Date object cannot be accessed
+ * @throws NumberFormatException if the input string has an incorrect format
+ * @throws InstantiationException if Date object instantiation failed
+ * @throws IllegalAccessException if Date object cannot be accessed
*/
public static Date createDate(String dateString)
throws NumberFormatException, InstantiationException, IllegalAccessException {
@@ -60,15 +51,11 @@ public static Date createDate(String dateString)
/**
* Parses a TimeOfDay from a string of the form "HH:MM:SS".
*
- * @param timeString
- * a string of the form "HH:MM:SS"
+ * @param timeString a string of the form "HH:MM:SS"
* @return a TimeOfDay representing the desired time
- * @throws NumberFormatException
- * if the input string has an incorrect format
- * @throws InstantiationException
- * if Date object instantiation failed
- * @throws IllegalAccessException
- * if Date object cannot be accessed
+ * @throws NumberFormatException if the input string has an incorrect format
+ * @throws InstantiationException if Date object instantiation failed
+ * @throws IllegalAccessException if Date object cannot be accessed
*/
public static TimeOfDay createTimeOfDay(String timeString)
throws NumberFormatException, InstantiationException, IllegalAccessException {
@@ -99,4 +86,4 @@ public static String getPropertyOrFail(String propertyName) {
return propertyValue;
}
}
-//[END all]
+// [END all]
diff --git a/storage/xml-api/cmdline-sample/pom.xml b/storage/xml-api/cmdline-sample/pom.xml
index e5e68e0db92..4292143b0b7 100644
--- a/storage/xml-api/cmdline-sample/pom.xml
+++ b/storage/xml-api/cmdline-sample/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -42,7 +42,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -78,6 +78,11 @@
+
+ com.google.auth
+ google-auth-library-oauth2-http
+ 0.21.0
+
com.google.http-client
google-http-client-jackson2
diff --git a/storage/xml-api/cmdline-sample/src/main/java/StorageSample.java b/storage/xml-api/cmdline-sample/src/main/java/StorageSample.java
index b0382e5225e..593656f3c4d 100644
--- a/storage/xml-api/cmdline-sample/src/main/java/StorageSample.java
+++ b/storage/xml-api/cmdline-sample/src/main/java/StorageSample.java
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
@@ -22,6 +21,8 @@
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.util.Preconditions;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
@@ -43,7 +44,7 @@
public final class StorageSample {
/** This class is never instantiated. */
- private StorageSample() { }
+ private StorageSample() {}
/** Global configuration of Google Cloud Storage OAuth 2.0 scope. */
private static final String STORAGE_SCOPE =
@@ -53,31 +54,30 @@ private StorageSample() { }
* Fetches the listing of the given bucket.
*
* @param bucketName the name of the bucket to list.
- *
* @return the raw XML containing the listing of the bucket.
* @throws IOException if there's an error communicating with Cloud Storage.
* @throws GeneralSecurityException for errors creating https connection.
*/
public static String listBucket(final String bucketName)
throws IOException, GeneralSecurityException {
- //[START snippet]
+ // [START snippet]
// Build an account credential.
- GoogleCredential credential = GoogleCredential.getApplicationDefault()
- .createScoped(Collections.singleton(STORAGE_SCOPE));
+ GoogleCredentials credential =
+ GoogleCredentials.getApplicationDefault()
+ .createScoped(Collections.singleton(STORAGE_SCOPE));
// Set up and execute a Google Cloud Storage request.
- String uri = "https://storage.googleapis.com/"
- + URLEncoder.encode(bucketName, "UTF-8");
+ String uri = "https://storage.googleapis.com/" + URLEncoder.encode(bucketName, "UTF-8");
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
- HttpRequestFactory requestFactory = httpTransport.createRequestFactory(
- credential);
+ HttpRequestFactory requestFactory =
+ httpTransport.createRequestFactory(new HttpCredentialsAdapter(credential));
GenericUrl url = new GenericUrl(uri);
HttpRequest request = requestFactory.buildGetRequest(url);
HttpResponse response = request.execute();
String content = response.parseAsString();
- //[END snippet]
+ // [END snippet]
return content;
}
@@ -88,21 +88,19 @@ public static String listBucket(final String bucketName)
* @param bucketName the name of the bucket you're listing.
* @param content the raw XML string.
*/
- private static void prettyPrintXml(
- final String bucketName, final String content) {
+ private static void prettyPrintXml(final String bucketName, final String content) {
// Instantiate transformer input.
Source xmlInput = new StreamSource(new StringReader(content));
StreamResult xmlOutput = new StreamResult(new StringWriter());
// Configure transformer.
try {
- Transformer transformer = TransformerFactory.newInstance()
- .newTransformer(); // An identity transformer
+ Transformer transformer =
+ TransformerFactory.newInstance().newTransformer(); // An identity transformer
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "testing.dtd");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty(
- "{http://xml.apache.org/xslt}indent-amount", "2");
+ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(xmlInput, xmlOutput);
// Pretty print the output XML.
@@ -122,8 +120,7 @@ public static void main(final String[] args) {
try {
// Check for valid setup.
Preconditions.checkArgument(
- args.length == 1,
- "Please pass in the Google Cloud Storage bucket name to display");
+ args.length == 1, "Please pass in the Google Cloud Storage bucket name to display");
String bucketName = args[0];
String content = listBucket(bucketName);
diff --git a/storage/xml-api/serviceaccount-appengine-sample/pom.xml b/storage/xml-api/serviceaccount-appengine-sample/pom.xml
index 8e9608f1c6f..fafcead1a08 100644
--- a/storage/xml-api/serviceaccount-appengine-sample/pom.xml
+++ b/storage/xml-api/serviceaccount-appengine-sample/pom.xml
@@ -23,7 +23,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
com.google.apis-samples
@@ -41,7 +41,7 @@
UTF-8
1.1
3.0.5
- 3.2.3
+ 3.3.0
@@ -88,7 +88,7 @@
com.google.cloud.tools
appengine-maven-plugin
- 2.2.0
+ 2.3.0
GCLOUD_CONFIG
gaeinfo
diff --git a/tasks/pom.xml b/tasks/pom.xml
index 45aa6c8d9b0..e1a8ed6cf8c 100644
--- a/tasks/pom.xml
+++ b/tasks/pom.xml
@@ -29,7 +29,7 @@ Copyright 2018 Google LLC
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -43,12 +43,12 @@ Copyright 2018 Google LLC
com.google.cloud
google-cloud-tasks
- 1.29.1
+ 1.30.0
com.google.protobuf
protobuf-java
- 3.12.1
+ 3.12.2
diff --git a/tasks/src/main/java/com/example/task/CreateHttpTask.java b/tasks/src/main/java/com/example/task/CreateHttpTask.java
index 858b439ae58..e86636bbc6b 100644
--- a/tasks/src/main/java/com/example/task/CreateHttpTask.java
+++ b/tasks/src/main/java/com/example/task/CreateHttpTask.java
@@ -23,19 +23,22 @@
import com.google.cloud.tasks.v2.QueueName;
import com.google.cloud.tasks.v2.Task;
import com.google.protobuf.ByteString;
+import java.io.IOException;
import java.nio.charset.Charset;
public class CreateHttpTask {
- /**
- * Create a task with a HTTP target using the Cloud Tasks client.
- *
- * @param projectId the Id of the project.
- * @param queueId the name of your Queue.
- * @param locationId the GCP region of your queue.
- * @throws Exception on Cloud Tasks Client errors.
- */
+
+ public static void main(String[] args) throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String projectId = "my-project-id";
+ String locationId = "us-central1";
+ String queueId = "my-queue";
+ createTask(projectId, locationId, queueId);
+ }
+
+ // Create a task with a HTTP target using the Cloud Tasks client.
public static void createTask(String projectId, String locationId, String queueId)
- throws Exception {
+ throws IOException {
// Instantiates a client.
try (CloudTasksClient client = CloudTasksClient.create()) {
diff --git a/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java b/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java
index 72c4768ef35..a341f680fea 100644
--- a/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java
+++ b/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java
@@ -24,21 +24,25 @@
import com.google.cloud.tasks.v2.QueueName;
import com.google.cloud.tasks.v2.Task;
import com.google.protobuf.ByteString;
+import java.io.IOException;
import java.nio.charset.Charset;
public class CreateHttpTaskWithToken {
- /**
- * Create a task with a HTTP target and authorization token using the Cloud Tasks client.
- *
- * @param projectId the Id of the project.
- * @param queueId the name of your Queue.
- * @param locationId the GCP region of your queue.
- * @param serviceAccountEmail your Cloud IAM service account
- * @throws Exception on Cloud Tasks Client errors.
- */
+
+ public static void main(String[] args) throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String projectId = "my-project-id";
+ String locationId = "us-central1";
+ String queueId = "my-queue";
+ String serviceAccountEmail =
+ "java-docs-samples-testing@java-docs-samples-testing.iam.gserviceaccount.com";
+ createTask(projectId, locationId, queueId, serviceAccountEmail);
+ }
+
+ // Create a task with a HTTP target and authorization token using the Cloud Tasks client.
public static void createTask(
String projectId, String locationId, String queueId, String serviceAccountEmail)
- throws Exception {
+ throws IOException {
// Instantiates a client.
try (CloudTasksClient client = CloudTasksClient.create()) {
diff --git a/tasks/src/main/java/com/example/task/CreateQueue.java b/tasks/src/main/java/com/example/task/CreateQueue.java
new file mode 100644
index 00000000000..04aa81101ad
--- /dev/null
+++ b/tasks/src/main/java/com/example/task/CreateQueue.java
@@ -0,0 +1,54 @@
+// Copyright 2020 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
+//
+// http://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.example.task;
+
+// [START cloud_tasks_create_queue]
+import com.google.cloud.tasks.v2.CloudTasksClient;
+import com.google.cloud.tasks.v2.LocationName;
+import com.google.cloud.tasks.v2.Queue;
+import com.google.cloud.tasks.v2.QueueName;
+import java.io.IOException;
+
+public class CreateQueue {
+
+ public static void main(String[] args) throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String projectId = "my-project-id";
+ String locationId = "us-central1";
+ String queueId = "my-queue";
+ createQueue(projectId, locationId, queueId);
+ }
+
+ // Create a queue using the Cloud Tasks client.
+ public static void createQueue(String projectId, String locationId, String queueId)
+ throws IOException {
+
+ // Instantiates a client.
+ try (CloudTasksClient client = CloudTasksClient.create()) {
+
+ // Construct the fully qualified location.
+ String parent = LocationName.of(projectId, locationId).toString();
+
+ // Construct the fully qualified queue path.
+ String queuePath = QueueName.of(projectId, locationId, queueId).toString();
+
+ // Send create queue request.
+ Queue queue = client.createQueue(parent, Queue.newBuilder().setName(queuePath).build());
+
+ System.out.println("Queue created: " + queue.getName());
+ }
+ }
+}
+// [END cloud_tasks_create_queue]
diff --git a/tasks/src/main/java/com/example/task/DeleteQueue.java b/tasks/src/main/java/com/example/task/DeleteQueue.java
new file mode 100644
index 00000000000..6f5d9898b48
--- /dev/null
+++ b/tasks/src/main/java/com/example/task/DeleteQueue.java
@@ -0,0 +1,49 @@
+// Copyright 2020 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
+//
+// http://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.example.task;
+
+// [START cloud_tasks_delete_queue]
+import com.google.cloud.tasks.v2.CloudTasksClient;
+import com.google.cloud.tasks.v2.QueueName;
+import java.io.IOException;
+
+public class DeleteQueue {
+
+ public static void main(String[] args) throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String projectId = "my-project-id";
+ String locationId = "us-central1";
+ String queueId = "my-queue";
+ deleteQueue(projectId, locationId, queueId);
+ }
+
+ // Delete a queue using the Cloud Tasks client.
+ public static void deleteQueue(String projectId, String locationId, String queueId)
+ throws IOException {
+
+ // Instantiates a client.
+ try (CloudTasksClient client = CloudTasksClient.create()) {
+
+ // Construct the fully qualified queue path.
+ String queuePath = QueueName.of(projectId, locationId, queueId).toString();
+
+ // Send delete queue request.
+ client.deleteQueue(queuePath);
+
+ System.out.println("Queue deleted: " + queueId);
+ }
+ }
+}
+// [END cloud_tasks_delete_queue]
diff --git a/tasks/src/main/java/com/example/task/ListQueues.java b/tasks/src/main/java/com/example/task/ListQueues.java
new file mode 100644
index 00000000000..85fd8c14cc6
--- /dev/null
+++ b/tasks/src/main/java/com/example/task/ListQueues.java
@@ -0,0 +1,58 @@
+// Copyright 2020 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
+//
+// http://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.example.task;
+
+// [START cloud_tasks_list_queues]
+import com.google.cloud.tasks.v2.CloudTasksClient;
+import com.google.cloud.tasks.v2.LocationName;
+import com.google.cloud.tasks.v2.Queue;
+import java.io.IOException;
+
+public class ListQueues {
+
+ public static void main(String[] args) throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String projectId = "my-project-id";
+ String locationId = "us-central1";
+ listQueues(projectId, locationId);
+ }
+
+ // List queues using the Cloud Tasks client.
+ public static void listQueues(String projectId, String locationId)
+ throws IOException {
+
+ // Instantiates a client.
+ try (CloudTasksClient client = CloudTasksClient.create()) {
+
+ // Construct the fully qualified location path.
+ String parent = LocationName.of(projectId, locationId).toString();
+
+ // Send list queues request.
+ CloudTasksClient.ListQueuesPagedResponse response = client.listQueues(parent);
+
+ // Iterate over results and print queue names
+ int total = 0;
+ for (Queue queue : response.iterateAll()) {
+ System.out.println(queue.getName());
+ total++;
+ }
+
+ if (total == 0) {
+ System.out.println("No queues found!");
+ }
+ }
+ }
+}
+// [END cloud_tasks_list_queues]
diff --git a/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java b/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java
index e03d907a677..11fd89f0b12 100644
--- a/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java
+++ b/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java
@@ -17,6 +17,7 @@
package com.example.task;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertNotNull;
import com.google.cloud.tasks.v2.CloudTasksClient;
import com.google.cloud.tasks.v2.QueueName;
@@ -24,6 +25,7 @@
import java.io.PrintStream;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -31,14 +33,26 @@
/** Tests for creating Tasks with HTTP targets. */
@RunWith(JUnit4.class)
public class CreateHttpTaskIT {
- private static final String PROJECT_ID = "java-docs-samples-testing";
- private static final String LOCATION_ID = "us-east1";
+ private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static final String LOCATION_ID = System.getenv("LOCATION_ID");
private static final String QUEUE_ID = "default";
private static final String EMAIL =
"java-docs-samples-testing@java-docs-samples-testing.iam.gserviceaccount.com";
private ByteArrayOutputStream bout;
private PrintStream out;
+ private static void requireEnvVar(String varName) {
+ assertNotNull(
+ String.format("Environment variable '%s' must be set to perform these tests.", varName),
+ System.getenv(varName));
+ }
+
+ @BeforeClass
+ public static void checkRequirements() {
+ requireEnvVar("GOOGLE_CLOUD_PROJECT");
+ requireEnvVar("LOCATION_ID");
+ }
+
@Before
public void setUp() {
bout = new ByteArrayOutputStream();
diff --git a/tasks/src/test/java/com/example/task/CreateQueueIT.java b/tasks/src/test/java/com/example/task/CreateQueueIT.java
new file mode 100644
index 00000000000..8677ee30d09
--- /dev/null
+++ b/tasks/src/test/java/com/example/task/CreateQueueIT.java
@@ -0,0 +1,78 @@
+// Copyright 2020 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
+//
+// http://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.example.task;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertNotNull;
+
+import com.google.cloud.tasks.v2.CloudTasksClient;
+import com.google.cloud.tasks.v2.QueueName;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for creating queues. */
+@RunWith(JUnit4.class)
+public class CreateQueueIT {
+ private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static final String LOCATION_ID = System.getenv("LOCATION_ID");
+ private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID();
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ private static void requireEnvVar(String varName) {
+ assertNotNull(
+ String.format("Environment variable '%s' must be set to perform these tests.", varName),
+ System.getenv(varName));
+ }
+
+ @BeforeClass
+ public static void checkRequirements() {
+ requireEnvVar("GOOGLE_CLOUD_PROJECT");
+ requireEnvVar("LOCATION_ID");
+ }
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ try (CloudTasksClient client = CloudTasksClient.create()) {
+ String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString();
+ client.deleteQueue(queuePath);
+ } catch (Exception e) {
+ System.out.println("Error with queue deletion.");
+ }
+ System.setOut(null);
+ }
+
+ @Test
+ public void testCreateQueue() throws Exception {
+ CreateQueue.createQueue(PROJECT_ID, LOCATION_ID, QUEUE_ID);
+ String got = bout.toString();
+ assertThat(got).contains("Queue created:");
+ }
+}
diff --git a/tasks/src/test/java/com/example/task/DeleteQueueIT.java b/tasks/src/test/java/com/example/task/DeleteQueueIT.java
new file mode 100644
index 00000000000..90c3f74bf59
--- /dev/null
+++ b/tasks/src/test/java/com/example/task/DeleteQueueIT.java
@@ -0,0 +1,92 @@
+// Copyright 2020 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
+//
+// http://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.example.task;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertNotNull;
+
+import com.google.api.gax.rpc.NotFoundException;
+import com.google.cloud.tasks.v2.CloudTasksClient;
+import com.google.cloud.tasks.v2.LocationName;
+import com.google.cloud.tasks.v2.Queue;
+import com.google.cloud.tasks.v2.QueueName;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for deleting queues. */
+@RunWith(JUnit4.class)
+public class DeleteQueueIT {
+ private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static final String LOCATION_ID = System.getenv("LOCATION_ID");
+ private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID();
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+ private Queue queue;
+
+ private static void requireEnvVar(String varName) {
+ assertNotNull(
+ String.format("Environment variable '%s' must be set to perform these tests.", varName),
+ System.getenv(varName));
+ }
+
+ @BeforeClass
+ public static void checkRequirements() {
+ requireEnvVar("GOOGLE_CLOUD_PROJECT");
+ requireEnvVar("LOCATION_ID");
+ }
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+
+ try (CloudTasksClient client = CloudTasksClient.create()) {
+ String parent = LocationName.of(PROJECT_ID, LOCATION_ID).toString();
+ String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString();
+ queue = client.createQueue(parent, Queue.newBuilder().setName(queuePath).build());
+ } catch (Exception e) {
+ System.out.println("Error with queue creation.");
+ }
+ }
+
+ @After
+ public void tearDown() {
+ try (CloudTasksClient client = CloudTasksClient.create()) {
+ client.deleteQueue(queue.getName());
+ } catch (IOException e) {
+ System.out.println("Error with queue deletion.");
+ } catch (NotFoundException e) {
+ System.out.println("Queue already successfully deleted");
+ }
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDeleteQueue() throws Exception {
+ DeleteQueue.deleteQueue(PROJECT_ID, LOCATION_ID, QUEUE_ID);
+ String got = bout.toString();
+ assertThat(got).contains("Queue deleted:");
+ }
+}
diff --git a/tasks/src/test/java/com/example/task/ListQueuesIT.java b/tasks/src/test/java/com/example/task/ListQueuesIT.java
new file mode 100644
index 00000000000..11e68b8e58e
--- /dev/null
+++ b/tasks/src/test/java/com/example/task/ListQueuesIT.java
@@ -0,0 +1,90 @@
+// Copyright 2020 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
+//
+// http://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.example.task;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertNotNull;
+
+import com.google.api.gax.rpc.NotFoundException;
+import com.google.cloud.tasks.v2.CloudTasksClient;
+import com.google.cloud.tasks.v2.LocationName;
+import com.google.cloud.tasks.v2.Queue;
+import com.google.cloud.tasks.v2.QueueName;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for listing queues. */
+@RunWith(JUnit4.class)
+public class ListQueuesIT {
+ private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static final String LOCATION_ID = System.getenv("LOCATION_ID");
+ private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID();
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+ private Queue queue;
+
+ private static void requireEnvVar(String varName) {
+ assertNotNull(
+ String.format("Environment variable '%s' must be set to perform these tests.", varName),
+ System.getenv(varName));
+ }
+
+ @BeforeClass
+ public static void checkRequirements() {
+ requireEnvVar("GOOGLE_CLOUD_PROJECT");
+ requireEnvVar("LOCATION_ID");
+ }
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+
+ try (CloudTasksClient client = CloudTasksClient.create()) {
+ String parent = LocationName.of(PROJECT_ID, LOCATION_ID).toString();
+ String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString();
+ queue = client.createQueue(parent, Queue.newBuilder().setName(queuePath).build());
+ } catch (Exception e) {
+ System.out.println("Error with queue creation.");
+ }
+ }
+
+ @After
+ public void tearDown() {
+ try (CloudTasksClient client = CloudTasksClient.create()) {
+ client.deleteQueue(queue.getName());
+ } catch (IOException e) {
+ System.out.println("Error with queue deletion.");
+ }
+ System.setOut(null);
+ }
+
+ @Test
+ public void testListQueues() throws Exception {
+ ListQueues.listQueues(PROJECT_ID, LOCATION_ID);
+ String got = bout.toString();
+ assertThat(got).contains(queue.getName());
+ }
+}
diff --git a/texttospeech/beta/pom.xml b/texttospeech/beta/pom.xml
index 42c552b0717..792fd4cec5e 100644
--- a/texttospeech/beta/pom.xml
+++ b/texttospeech/beta/pom.xml
@@ -23,7 +23,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -40,7 +40,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -91,7 +91,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -121,7 +121,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -151,7 +151,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -181,7 +181,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/texttospeech/cloud-client/pom.xml b/texttospeech/cloud-client/pom.xml
index 7687aa72e02..1fdec203e20 100644
--- a/texttospeech/cloud-client/pom.xml
+++ b/texttospeech/cloud-client/pom.xml
@@ -23,7 +23,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -40,7 +40,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
diff --git a/trace/pom.xml b/trace/pom.xml
index c22de75f538..0c7cbca20b5 100644
--- a/trace/pom.xml
+++ b/trace/pom.xml
@@ -28,7 +28,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
diff --git a/translate/automl/pom.xml b/translate/automl/pom.xml
index c123f13aed9..ecc08778c19 100644
--- a/translate/automl/pom.xml
+++ b/translate/automl/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -43,7 +43,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -58,7 +58,7 @@
com.google.cloud
google-cloud-storage
- 1.108.0
+ 1.111.0
net.sourceforge.argparse4j
@@ -95,7 +95,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -123,7 +123,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -151,7 +151,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/translate/cloud-client/pom.xml b/translate/cloud-client/pom.xml
index d8f77d0eb0a..2180c98b267 100644
--- a/translate/cloud-client/pom.xml
+++ b/translate/cloud-client/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -43,7 +43,7 @@ See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
diff --git a/unittests/pom.xml b/unittests/pom.xml
index 2924657c637..ec590eded4b 100644
--- a/unittests/pom.xml
+++ b/unittests/pom.xml
@@ -14,7 +14,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -81,7 +81,7 @@
org.apache.maven.plugins
maven-war-plugin
- 3.2.3
+ 3.3.0
true
@@ -98,7 +98,7 @@
com.google.cloud.tools
appengine-maven-plugin
- 2.2.0
+ 2.3.0
GCLOUD_CONFIG
gaeinfo
diff --git a/video/beta/pom.xml b/video/beta/pom.xml
index 60c56acc09f..ec0ce4b24a9 100644
--- a/video/beta/pom.xml
+++ b/video/beta/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -43,7 +43,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -76,7 +76,7 @@
com.google.api.grpc
proto-google-cloud-video-intelligence-v1p3beta1
- 0.84.1
+ 0.86.0
@@ -111,7 +111,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/video/cloud-client/pom.xml b/video/cloud-client/pom.xml
index 3203dba6fea..b848f612505 100644
--- a/video/cloud-client/pom.xml
+++ b/video/cloud-client/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -39,7 +39,7 @@
com.google.cloud
google-cloud-video-intelligence
- 1.2.1
+ 1.4.0
@@ -86,7 +86,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/video/cloud-client/src/test/java/com/example/video/QuickstartIT.java b/video/cloud-client/src/test/java/com/example/video/QuickstartIT.java
index 5424752ba58..75fdac01658 100644
--- a/video/cloud-client/src/test/java/com/example/video/QuickstartIT.java
+++ b/video/cloud-client/src/test/java/com/example/video/QuickstartIT.java
@@ -51,6 +51,7 @@ public void test() throws Exception {
String got = bout.toString();
// Test that the video with a cat has the whiskers label (may change).
- assertThat(got.toUpperCase()).contains("WHISKERS");
+ assertThat(got.toUpperCase()).contains("VIDEO LABEL DESCRIPTION");
+ assertThat(got.toUpperCase()).contains("CONFIDENCE");
}
}
diff --git a/vision/automl/pom.xml b/vision/automl/pom.xml
index 064a7d82922..01d8cc609ef 100644
--- a/vision/automl/pom.xml
+++ b/vision/automl/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -43,7 +43,7 @@
com.google.cloud
libraries-bom
- 4.4.1
+ 8.0.0
pom
import
@@ -92,7 +92,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -120,7 +120,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -148,7 +148,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java b/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java
deleted file mode 100644
index bcf5ec74614..00000000000
--- a/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * 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
- *
- * http://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.vision.samples.automl;
-
-// Imports the Google Cloud client library
-import com.google.cloud.automl.v1beta1.AutoMlClient;
-import com.google.cloud.automl.v1beta1.ClassificationProto.ClassificationType;
-import com.google.cloud.automl.v1beta1.Dataset;
-import com.google.cloud.automl.v1beta1.DatasetName;
-import com.google.cloud.automl.v1beta1.GcsDestination;
-import com.google.cloud.automl.v1beta1.GcsSource;
-import com.google.cloud.automl.v1beta1.ImageClassificationDatasetMetadata;
-import com.google.cloud.automl.v1beta1.InputConfig;
-import com.google.cloud.automl.v1beta1.ListDatasetsRequest;
-import com.google.cloud.automl.v1beta1.LocationName;
-import com.google.cloud.automl.v1beta1.OutputConfig;
-import com.google.protobuf.Empty;
-import java.io.IOException;
-import java.util.concurrent.ExecutionException;
-import net.sourceforge.argparse4j.ArgumentParsers;
-import net.sourceforge.argparse4j.inf.ArgumentParser;
-import net.sourceforge.argparse4j.inf.ArgumentParserException;
-import net.sourceforge.argparse4j.inf.Namespace;
-import net.sourceforge.argparse4j.inf.Subparser;
-import net.sourceforge.argparse4j.inf.Subparsers;
-
-/**
- * Google Cloud AutoML Vision API sample application. Example usage: mvn package exec:java
- * -Dexec.mainClass ='com.google.cloud.vision.samples.automl.DatasetAPI' -Dexec.args='create_dataset
- * test_dataset'
- */
-public class DatasetApi {
-
- // [START automl_vision_create_dataset]
- /**
- * Demonstrates using the AutoML client to create a dataset
- *
- * @param projectId the Google Cloud Project ID.
- * @param computeRegion the Region name. (e.g., "us-central1")
- * @param datasetName the name of the dataset to be created.
- * @param multiLabel the type of classification problem. Set to FALSE by default. False -
- * MULTICLASS , True - MULTILABEL
- */
- static void createDataset(
- String projectId, String computeRegion, String datasetName, boolean multiLabel) {
-
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
- // A resource that represents Google Cloud Platform location.
- LocationName projectLocation = LocationName.of(projectId, computeRegion);
-
- // Classification type assigned based on multiLabel value.
- ClassificationType classificationType =
- multiLabel ? ClassificationType.MULTILABEL : ClassificationType.MULTICLASS;
-
- // Specify the image classification type for the dataset.
- ImageClassificationDatasetMetadata imageClassificationDatasetMetadata =
- ImageClassificationDatasetMetadata.newBuilder()
- .setClassificationType(classificationType)
- .build();
-
- // Set dataset with dataset name and set the dataset metadata.
- Dataset myDataset =
- Dataset.newBuilder()
- .setDisplayName(datasetName)
- .setImageClassificationDatasetMetadata(imageClassificationDatasetMetadata)
- .build();
-
- // Create dataset with the dataset metadata in the region.
- Dataset dataset = client.createDataset(projectLocation, myDataset);
-
- // Display the dataset information
- System.out.println(String.format("Dataset name: %s", dataset.getName()));
- System.out.println(
- String.format(
- "Dataset id: %s",
- dataset.getName().split("/")[dataset.getName().split("/").length - 1]));
- System.out.println(String.format("Dataset display name: %s", dataset.getDisplayName()));
- System.out.println("Image classification dataset specification:");
- System.out.print(String.format("\t%s", dataset.getImageClassificationDatasetMetadata()));
- System.out.println(String.format("Dataset example count: %d", dataset.getExampleCount()));
- System.out.println("Dataset create time:");
- System.out.println(String.format("\tseconds: %s", dataset.getCreateTime().getSeconds()));
- System.out.println(String.format("\tnanos: %s", dataset.getCreateTime().getNanos()));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_create_dataset]
-
- // [START automl_vision_list_datasets]
- /**
- * Demonstrates using the AutoML client to list all datasets.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param filter the Filter expression.
- */
- static void listDatasets(String projectId, String computeRegion, String filter) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // A resource that represents Google Cloud Platform location.
- LocationName projectLocation = LocationName.of(projectId, computeRegion);
-
- // Build the List datasets request
- ListDatasetsRequest request =
- ListDatasetsRequest.newBuilder()
- .setParent(projectLocation.toString())
- .setFilter(filter)
- .build();
-
- // List all the datasets available in the region by applying the filter.
- System.out.print("List of datasets:");
- for (Dataset dataset : client.listDatasets(request).iterateAll()) {
- // Display the dataset information
- System.out.println(String.format("\nDataset name: %s", dataset.getName()));
- System.out.println(
- String.format(
- "Dataset id: %s",
- dataset.getName().split("/")[dataset.getName().split("/").length - 1]));
- System.out.println(String.format("Dataset display name: %s", dataset.getDisplayName()));
- System.out.println("Image classification dataset specification:");
- System.out.print(String.format("\t%s", dataset.getImageClassificationDatasetMetadata()));
- System.out.println(String.format("Dataset example count: %d", dataset.getExampleCount()));
- System.out.println("Dataset create time:");
- System.out.println(String.format("\tseconds: %s", dataset.getCreateTime().getSeconds()));
- System.out.println(String.format("\tnanos: %s", dataset.getCreateTime().getNanos()));
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_list_datasets]
-
- // [START automl_vision_get_dataset]
- /**
- * Demonstrates using the AutoML client to get a dataset by ID.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param datasetId the Id of the dataset.
- */
- static void getDataset(String projectId, String computeRegion, String datasetId) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // Get the complete path of the dataset.
- DatasetName datasetFullId = DatasetName.of(projectId, computeRegion, datasetId);
-
- // Get all the information about a given dataset.
- Dataset dataset = client.getDataset(datasetFullId);
-
- // Display the dataset information.
- System.out.println(String.format("Dataset name: %s", dataset.getName()));
- System.out.println(
- String.format(
- "Dataset id: %s",
- dataset.getName().split("/")[dataset.getName().split("/").length - 1]));
- System.out.println(String.format("Dataset display name: %s", dataset.getDisplayName()));
- System.out.println("Image classification dataset specification:");
- System.out.print(String.format("\t%s", dataset.getImageClassificationDatasetMetadata()));
- System.out.println(String.format("Dataset example count: %d", dataset.getExampleCount()));
- System.out.println("Dataset create time:");
- System.out.println(String.format("\tseconds: %s", dataset.getCreateTime().getSeconds()));
- System.out.println(String.format("\tnanos: %s", dataset.getCreateTime().getNanos()));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_get_dataset]
-
- // [START automl_vision_import_data]
- /**
- * Demonstrates using the AutoML client to import labeled images.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param datasetId the Id of the dataset to which the training data will be imported.
- * @param path the Google Cloud Storage URIs. Target files must be in AutoML vision CSV format.
- */
- static void importData(String projectId, String computeRegion, String datasetId, String path) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // Get the complete path of the dataset.
- DatasetName datasetFullId = DatasetName.of(projectId, computeRegion, datasetId);
-
- GcsSource.Builder gcsSource = GcsSource.newBuilder();
-
- // Get multiple training data files to be imported
- String[] inputUris = path.split(",");
- for (String inputUri : inputUris) {
- gcsSource.addInputUris(inputUri);
- }
-
- // Import data from the input URI
- InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
- System.out.println("Processing import...");
- Empty response = client.importDataAsync(datasetFullId.toString(), inputConfig).get();
- System.out.println(String.format("Dataset imported. %s", response));
- } catch (IOException | InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_import_data]
-
- // [START automl_vision_export_data]
- /**
- * Demonstrates using the AutoML client to export a dataset to a Google Cloud Storage bucket.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param datasetId the Id of the dataset.
- * @param gcsUri the Destination URI (Google Cloud Storage)
- */
- static void exportData(String projectId, String computeRegion, String datasetId, String gcsUri) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // Get the complete path of the dataset.
- DatasetName datasetFullId = DatasetName.of(projectId, computeRegion, datasetId);
-
- // Set the output URI
- GcsDestination gcsDestination =
- GcsDestination.newBuilder().setOutputUriPrefix(gcsUri).build();
-
- // Export the dataset to the output URI.
- OutputConfig outputConfig =
- OutputConfig.newBuilder().setGcsDestination(gcsDestination).build();
- System.out.println("Processing export...");
-
- Empty response = client.exportDataAsync(datasetFullId, outputConfig).get();
- System.out.println(String.format("Dataset exported. %s", response));
- } catch (IOException | InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_export_data]
-
- // [START automl_vision_delete_dataset]
- /**
- * Delete a dataset.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param datasetId the Id of the dataset.
- */
- static void deleteDataset(String projectId, String computeRegion, String datasetId) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // Get the complete path of the dataset.
- DatasetName datasetFullId = DatasetName.of(projectId, computeRegion, datasetId);
-
- // Delete a dataset.
- Empty response = client.deleteDatasetAsync(datasetFullId).get();
-
- System.out.println(String.format("Dataset deleted. %s", response));
- } catch (IOException | InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_delete_dataset]
-
- public static void main(String[] args) {
- argsHelper(args);
- }
-
- static void argsHelper(String[] args) {
- ArgumentParser parser =
- ArgumentParsers.newFor("DatasetApi")
- .build()
- .defaultHelp(true)
- .description("Dataset API operations.");
- Subparsers subparsers = parser.addSubparsers().dest("command");
-
- Subparser createDatasetParser = subparsers.addParser("create_dataset");
- createDatasetParser.addArgument("datasetName");
- createDatasetParser
- .addArgument("multiLabel")
- .nargs("?")
- .type(Boolean.class)
- .choices(Boolean.FALSE, Boolean.TRUE)
- .setDefault(Boolean.FALSE);
-
- Subparser listDatasetsParser = subparsers.addParser("list_datasets");
- listDatasetsParser
- .addArgument("filter")
- .nargs("?")
- .setDefault("imageClassificationDatasetMetadata:*");
-
- Subparser getDatasetParser = subparsers.addParser("get_dataset");
- getDatasetParser.addArgument("datasetId");
-
- Subparser importDataParser = subparsers.addParser("import_data");
- importDataParser.addArgument("datasetId");
- importDataParser.addArgument("path");
-
- Subparser exportDataParser = subparsers.addParser("export_data");
- exportDataParser.addArgument("datasetId");
- exportDataParser.addArgument("gcsUri");
-
- Subparser deleteDatasetParser = subparsers.addParser("delete_dataset");
- deleteDatasetParser.addArgument("datasetId");
-
- String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
- String computeRegion = System.getenv("REGION_NAME");
-
- if (projectId == null || computeRegion == null) {
- System.out.println("Set `GOOGLE_CLOUD_PROJECT` and `REGION_NAME` as specified in the README");
- System.exit(-1);
- }
-
- try {
- Namespace ns = parser.parseArgs(args);
-
- if (ns.get("command").equals("create_dataset")) {
- createDataset(
- projectId, computeRegion, ns.getString("datasetName"), ns.getBoolean("multiLabel"));
- }
- if (ns.get("command").equals("list_datasets")) {
- listDatasets(projectId, computeRegion, ns.getString("filter"));
- }
- if (ns.get("command").equals("get_dataset")) {
- getDataset(projectId, computeRegion, ns.getString("datasetId"));
- }
- if (ns.get("command").equals("import_data")) {
- importData(projectId, computeRegion, ns.getString("datasetId"), ns.getString("path"));
- }
- if (ns.get("command").equals("export_data")) {
- exportData(projectId, computeRegion, ns.getString("datasetId"), ns.getString("gcsUri"));
- }
- if (ns.get("command").equals("delete_dataset")) {
- deleteDataset(projectId, computeRegion, ns.getString("datasetId"));
- }
-
- } catch (ArgumentParserException e) {
- parser.handleError(e);
- }
- }
-}
diff --git a/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/ModelApi.java b/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/ModelApi.java
index 9a89c215d40..4b07977df3e 100644
--- a/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/ModelApi.java
+++ b/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/ModelApi.java
@@ -101,287 +101,6 @@ static void createModel(
}
// [END automl_vision_create_model]
- // [START automl_vision_get_operation_status]
- /**
- * Demonstrates using the AutoML client to get operation status.
- *
- * @param operationFullId the complete name of a operation. For example, the name of your
- * operation is projects/[projectId]/locations/us-central1/operations/[operationId].
- */
- static void getOperationStatus(String operationFullId) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // Get the latest state of a long-running operation.
- Operation response = client.getOperationsClient().getOperation(operationFullId);
-
- System.out.println(String.format("Operation status: %s", response));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_get_operation_status]
-
- // [START automl_vision_list_models]
- /**
- * Demonstrates using the AutoML client to list all models.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param filter - Filter expression.
- */
- static void listModels(String projectId, String computeRegion, String filter) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // A resource that represents Google Cloud Platform location.
- LocationName projectLocation = LocationName.of(projectId, computeRegion);
-
- // Create list models request
- ListModelsRequest listModelsRequest =
- ListModelsRequest.newBuilder()
- .setParent(projectLocation.toString())
- .setFilter(filter)
- .build();
-
- System.out.println("List of models:");
- for (Model model : client.listModels(listModelsRequest).iterateAll()) {
- // Display the model information.
- System.out.println(String.format("Model name: %s", model.getName()));
- System.out.println(
- String.format(
- "Model id: %s", model.getName().split("/")[model.getName().split("/").length - 1]));
- System.out.println(String.format("Model display name: %s", model.getDisplayName()));
- System.out.println("Image classification model metadata:");
- System.out.println(
- "Tranning budget: " + model.getImageClassificationModelMetadata().getTrainBudget());
- System.out.println(
- "Tranning cost: " + model.getImageClassificationModelMetadata().getTrainCost());
- System.out.println(
- String.format(
- "Stop reason: %s", model.getImageClassificationModelMetadata().getStopReason()));
- System.out.println(
- String.format(
- "Base model id: %s", model.getImageClassificationModelMetadata().getBaseModelId()));
- System.out.println("Model create time:");
- System.out.println(String.format("\tseconds: %s", model.getCreateTime().getSeconds()));
- System.out.println(String.format("\tnanos: %s", model.getCreateTime().getNanos()));
- System.out.println(String.format("Model deployment state: %s", model.getDeploymentState()));
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_list_models]
-
- // [START automl_vision_get_model]
- /**
- * Demonstrates using the AutoML client to get model details.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param modelId the Id of the model.
- */
- static void getModel(String projectId, String computeRegion, String modelId) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // Get the full path of the model.
- ModelName modelFullId = ModelName.of(projectId, computeRegion, modelId);
-
- // Get complete detail of the model.
- Model model = client.getModel(modelFullId);
-
- // Display the model information.
- System.out.println(String.format("Model name: %s", model.getName()));
- System.out.println(
- String.format(
- "Model id: %s", model.getName().split("/")[model.getName().split("/").length - 1]));
- System.out.println(String.format("Model display name: %s", model.getDisplayName()));
- System.out.println("Image classification model metadata:");
- System.out.println(
- "Tranning budget: " + model.getImageClassificationModelMetadata().getTrainBudget());
- System.out.println(
- "Tranning cost:" + model.getImageClassificationModelMetadata().getTrainCost());
- System.out.println(
- String.format(
- "Stop reason: %s", model.getImageClassificationModelMetadata().getStopReason()));
- System.out.println(
- String.format(
- "Base model id: %s", model.getImageClassificationModelMetadata().getBaseModelId()));
- System.out.println("Model create time:");
- System.out.println(String.format("\tseconds: %s", model.getCreateTime().getSeconds()));
- System.out.println(String.format("\tnanos: %s", model.getCreateTime().getNanos()));
- System.out.println(String.format("Model deployment state: %s", model.getDeploymentState()));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_get_model]
-
- // [START automl_vision_list_model_evaluations]
- /**
- * Demonstrates using the AutoML client to list model evaluations.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param modelId the Id of the model.
- * @param filter the Filter expression.
- */
- static void listModelEvaluations(
- String projectId, String computeRegion, String modelId, String filter) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // Get the full path of the model.
- ModelName modelFullId = ModelName.of(projectId, computeRegion, modelId);
-
- // Create list model evaluations request
- ListModelEvaluationsRequest modelEvaluationsrequest =
- ListModelEvaluationsRequest.newBuilder()
- .setParent(modelFullId.toString())
- .setFilter(filter)
- .build();
-
- System.out.println("List of model evaluations:");
- // List all the model evaluations in the model by applying filter.
- for (ModelEvaluation element :
- client.listModelEvaluations(modelEvaluationsrequest).iterateAll()) {
- System.out.println(element);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_list_model_evaluations]
-
- // [START automl_vision_get_model_evaluation]
- /**
- * Demonstrates using the AutoML client to get model evaluations.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param modelId the Id of the model.
- * @param modelEvaluationId the Id of your model evaluation.
- */
- static void getModelEvaluation(
- String projectId, String computeRegion, String modelId, String modelEvaluationId) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // Get the full path of the model evaluation.
- ModelEvaluationName modelEvaluationFullId =
- ModelEvaluationName.of(projectId, computeRegion, modelId, modelEvaluationId);
- // Perform the AutoML Model request to get Model Evaluation information
- ModelEvaluation response = client.getModelEvaluation(modelEvaluationFullId);
-
- System.out.println(response);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_get_model_evaluation]
-
- // [START automl_vision_display_evaluation]
- /**
- * Demonstrates using the AutoML client to display model evaluation.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param modelId the Id of the model.
- * @param filter the filter expression.
- */
- static void displayEvaluation(
- String projectId, String computeRegion, String modelId, String filter) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // Get the full path of the model.
- ModelName modelFullId = ModelName.of(projectId, computeRegion, modelId);
-
- // List all the model evaluations in the model by applying filter.
- ListModelEvaluationsRequest modelEvaluationsrequest =
- ListModelEvaluationsRequest.newBuilder()
- .setParent(modelFullId.toString())
- .setFilter(filter)
- .build();
-
- // Iterate through the results.
- String modelEvaluationId = "";
- for (ModelEvaluation element :
- client.listModelEvaluations(modelEvaluationsrequest).iterateAll()) {
- if (element.getAnnotationSpecId() != null) {
- modelEvaluationId = element.getName().split("/")[element.getName().split("/").length - 1];
- }
- }
-
- // Resource name for the model evaluation.
- ModelEvaluationName modelEvaluationFullId =
- ModelEvaluationName.of(projectId, computeRegion, modelId, modelEvaluationId);
-
- // Get a model evaluation.
- ModelEvaluation modelEvaluation = client.getModelEvaluation(modelEvaluationFullId);
-
- ClassificationEvaluationMetrics classMetrics =
- modelEvaluation.getClassificationEvaluationMetrics();
- List confidenceMetricsEntries =
- classMetrics.getConfidenceMetricsEntryList();
-
- // Showing model score based on threshold of 0.5
- for (ConfidenceMetricsEntry confidenceMetricsEntry : confidenceMetricsEntries) {
- if (confidenceMetricsEntry.getConfidenceThreshold() == 0.5) {
- System.out.println("Precision and recall are based on a score threshold of 0.5");
- System.out.println(
- String.format("Model Precision: %.2f ", confidenceMetricsEntry.getPrecision() * 100)
- + '%');
- System.out.println(
- String.format("Model Recall: %.2f ", confidenceMetricsEntry.getRecall() * 100) + '%');
- System.out.println(
- String.format("Model F1 score: %.2f ", confidenceMetricsEntry.getF1Score() * 100)
- + '%');
- System.out.println(
- String.format(
- "Model Precision@1: %.2f ", confidenceMetricsEntry.getPrecisionAt1() * 100)
- + '%');
- System.out.println(
- String.format("Model Recall@1: %.2f ", confidenceMetricsEntry.getRecallAt1() * 100)
- + '%');
- System.out.println(
- String.format("Model F1 score@1: %.2f ", confidenceMetricsEntry.getF1ScoreAt1() * 100)
- + '%');
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_display_evaluation]
-
- // [START automl_vision_delete_model]
- /**
- * Demonstrates using the AutoML client to delete a model.
- *
- * @param projectId the Id of the project.
- * @param computeRegion the Region name.
- * @param modelId the Id of the model.
- */
- static void deleteModel(String projectId, String computeRegion, String modelId) {
- // Instantiates a client
- try (AutoMlClient client = AutoMlClient.create()) {
-
- // Get the full path of the model.
- ModelName modelFullId = ModelName.of(projectId, computeRegion, modelId);
-
- // Delete a model.
- Empty response = client.deleteModelAsync(modelFullId).get();
-
- System.out.println("Model deletion started...");
- } catch (IOException | InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- }
- // [END automl_vision_delete_model]
-
public static void main(String[] args) {
argsHelper(args);
}
@@ -399,33 +118,6 @@ static void argsHelper(String[] args) {
createModelParser.addArgument("modelName");
createModelParser.addArgument("trainBudget");
- Subparser listModelParser = subparsers.addParser("list_models");
- listModelParser
- .addArgument("filter")
- .nargs("?")
- .setDefault("imageClassificationModelMetadata:*");
-
- Subparser getModelParser = subparsers.addParser("get_model");
- getModelParser.addArgument("modelId");
-
- Subparser listModelEvaluationsParser = subparsers.addParser("list_model_evaluations");
- listModelEvaluationsParser.addArgument("modelId");
- listModelEvaluationsParser.addArgument("filter").nargs("?").setDefault("");
-
- Subparser getModelEvaluationParser = subparsers.addParser("get_model_evaluation");
- getModelEvaluationParser.addArgument("modelId");
- getModelEvaluationParser.addArgument("modelEvaluationId");
-
- Subparser displayEvaluationParser = subparsers.addParser("display_evaluation");
- displayEvaluationParser.addArgument("modelId");
- displayEvaluationParser.addArgument("filter").nargs("?").setDefault("");
-
- Subparser deleteModelParser = subparsers.addParser("delete_model");
- deleteModelParser.addArgument("modelId");
-
- Subparser getOperationStatusParser = subparsers.addParser("get_operation_status");
- getOperationStatusParser.addArgument("operationFullId");
-
String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
String computeRegion = System.getenv("REGION_NAME");
@@ -444,30 +136,6 @@ static void argsHelper(String[] args) {
ns.getString("modelName"),
ns.getString("trainBudget"));
}
- if (ns.get("command").equals("list_models")) {
- listModels(projectId, computeRegion, ns.getString("filter"));
- }
- if (ns.get("command").equals("get_model")) {
- getModel(projectId, computeRegion, ns.getString("modelId"));
- }
- if (ns.get("command").equals("list_model_evaluations")) {
- listModelEvaluations(
- projectId, computeRegion, ns.getString("modelId"), ns.getString("filter"));
- }
- if (ns.get("command").equals("get_model_evaluation")) {
- getModelEvaluation(
- projectId, computeRegion, ns.getString("modelId"), ns.getString("modelEvaluationId"));
- }
- if (ns.get("command").equals("display_evaluation")) {
- displayEvaluation(
- projectId, computeRegion, ns.getString("modelId"), ns.getString("filter"));
- }
- if (ns.get("command").equals("delete_model")) {
- deleteModel(projectId, computeRegion, ns.getString("modelId"));
- }
- if (ns.get("command").equals("get_operation_status")) {
- getOperationStatus(ns.getString("operationFullId"));
- }
} catch (ArgumentParserException e) {
parser.handleError(e);
}
diff --git a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java b/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java
deleted file mode 100644
index 04cc0a6f4d2..00000000000
--- a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * 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
- *
- * http://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.vision.samples.automl;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.util.UUID;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests for Automl vision "Dataset API" sample. */
-@RunWith(JUnit4.class)
-@SuppressWarnings("checkstyle:abbreviationaswordinname")
-public class DatasetApiIT {
-
- private static final String PROJECT_ID = "java-docs-samples-testing";
- private static final String BUCKET = PROJECT_ID + "-vcm";
- private static final String COMPUTE_REGION = "us-central1";
- private ByteArrayOutputStream bout;
- private PrintStream out;
- private String datasetId;
-
- @Before
- public void setUp() {
- bout = new ByteArrayOutputStream();
- out = new PrintStream(bout);
- System.setOut(out);
- }
-
- @After
- public void tearDown() {
- System.setOut(null);
- }
-
- @Test
- public void testCreateImportDeleteDataset() {
- // Create a random dataset name with a length of 32 characters (max allowed by AutoML)
- // To prevent name collisions when running tests in multiple java versions at once.
- // AutoML doesn't allow "-", but accepts "_"
- String datasetName =
- String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26));
- // Act
- DatasetApi.createDataset(PROJECT_ID, COMPUTE_REGION, datasetName, false);
-
- // Assert
- String got = bout.toString();
- datasetId =
- bout.toString()
- .split("\n")[0]
- .split("/")[(bout.toString().split("\n")[0]).split("/").length - 1];
- assertThat(got).contains("Dataset id:");
-
- // Act
- DatasetApi.importData(
- PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/flower_traindata.csv");
-
- // Assert
- got = bout.toString();
- assertThat(got).contains("Dataset id:");
-
- // Act
- DatasetApi.deleteDataset(PROJECT_ID, COMPUTE_REGION, datasetId);
-
- // Assert
- got = bout.toString();
- assertThat(got).contains("Dataset deleted.");
- }
-
- @Test
- public void testListGetDatasets() {
- // Act
- DatasetApi.listDatasets(PROJECT_ID, COMPUTE_REGION, "imageClassificationDatasetMetadata:*");
-
- // Assert
- String got = bout.toString();
- datasetId =
- bout.toString()
- .split("\n")[1]
- .split("/")[(bout.toString().split("\n")[1]).split("/").length - 1];
- assertThat(got).contains("Dataset id:");
-
- // Act
- DatasetApi.getDataset(PROJECT_ID, COMPUTE_REGION, datasetId);
-
- // Assert
- got = bout.toString();
-
- assertThat(got).contains("Dataset id:");
- }
-}
diff --git a/vision/beta/cloud-client/pom.xml b/vision/beta/cloud-client/pom.xml
index 1d5971261c2..4386f7996be 100644
--- a/vision/beta/cloud-client/pom.xml
+++ b/vision/beta/cloud-client/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -43,7 +43,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -91,7 +91,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
diff --git a/vision/cloud-client/pom.xml b/vision/cloud-client/pom.xml
index 89ea28891da..cc25170b22c 100644
--- a/vision/cloud-client/pom.xml
+++ b/vision/cloud-client/pom.xml
@@ -26,7 +26,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -43,7 +43,7 @@
com.google.cloud
libraries-bom
- 5.4.0
+ 8.0.0
pom
import
@@ -91,7 +91,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -120,7 +120,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.6.0
+ 3.0.0
@@ -129,7 +129,7 @@
- com.example.vision.QuickstartSample
+ com.example.vision.quickstart.QuickstartSample
false
diff --git a/vision/cloud-client/src/main/java/com/example/vision/Detect.java b/vision/cloud-client/src/main/java/com/example/vision/Detect.java
index ae84a53ed70..5beb7d143a2 100644
--- a/vision/cloud-client/src/main/java/com/example/vision/Detect.java
+++ b/vision/cloud-client/src/main/java/com/example/vision/Detect.java
@@ -31,1222 +31,42 @@
import com.google.cloud.vision.v1.AsyncBatchAnnotateFilesResponse;
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
import com.google.cloud.vision.v1.Block;
-import com.google.cloud.vision.v1.ColorInfo;
-import com.google.cloud.vision.v1.CropHint;
-import com.google.cloud.vision.v1.CropHintsAnnotation;
-import com.google.cloud.vision.v1.DominantColorsAnnotation;
-import com.google.cloud.vision.v1.EntityAnnotation;
-import com.google.cloud.vision.v1.FaceAnnotation;
import com.google.cloud.vision.v1.Feature;
import com.google.cloud.vision.v1.Feature.Type;
import com.google.cloud.vision.v1.GcsDestination;
import com.google.cloud.vision.v1.GcsSource;
import com.google.cloud.vision.v1.Image;
import com.google.cloud.vision.v1.ImageAnnotatorClient;
-import com.google.cloud.vision.v1.ImageContext;
import com.google.cloud.vision.v1.ImageSource;
import com.google.cloud.vision.v1.InputConfig;
import com.google.cloud.vision.v1.LocalizedObjectAnnotation;
-import com.google.cloud.vision.v1.LocationInfo;
import com.google.cloud.vision.v1.OperationMetadata;
import com.google.cloud.vision.v1.OutputConfig;
import com.google.cloud.vision.v1.Page;
import com.google.cloud.vision.v1.Paragraph;
-import com.google.cloud.vision.v1.SafeSearchAnnotation;
import com.google.cloud.vision.v1.Symbol;
import com.google.cloud.vision.v1.TextAnnotation;
-import com.google.cloud.vision.v1.WebDetection;
-import com.google.cloud.vision.v1.WebDetection.WebEntity;
-import com.google.cloud.vision.v1.WebDetection.WebImage;
-import com.google.cloud.vision.v1.WebDetection.WebLabel;
-import com.google.cloud.vision.v1.WebDetection.WebPage;
-import com.google.cloud.vision.v1.WebDetectionParams;
import com.google.cloud.vision.v1.Word;
import com.google.protobuf.ByteString;
import com.google.protobuf.util.JsonFormat;
import java.io.FileInputStream;
import java.io.IOException;
-import java.io.PrintStream;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Detect {
-
- /**
- * Detects entities, sentiment, and syntax in a document using the Vision API.
- *
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- public static void main(String[] args) throws Exception, IOException {
- argsHelper(args, System.out);
- }
-
- /**
- * Helper that handles the input passed to the program.
- *
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- public static void argsHelper(String[] args, PrintStream out) throws Exception, IOException {
- if (args.length < 1) {
- out.println("Usage:");
- out.printf(
- "\tmvn exec:java -DDetect -Dexec.args=\" \"\n"
- + "\tmvn exec:java -DDetect -Dexec.args=\"ocr \""
- + "\n"
- + "Commands:\n"
- + "\tfaces | labels | landmarks | logos | text | safe-search | properties"
- + "| web | web-entities | web-entities-include-geo | crop | ocr \n"
- + "| object-localization \n"
- + "Path:\n\tA file path (ex: ./resources/wakeupcat.jpg) or a URI for a Cloud Storage "
- + "resource (gs://...)\n"
- + "Path to File:\n\tA path to the remote file on Cloud Storage (gs://...)\n"
- + "Path to Destination\n\tA path to the remote destination on Cloud Storage for the"
- + " file to be saved. (gs://BUCKET_NAME/PREFIX/)\n");
- return;
- }
- String command = args[0];
- String path = args.length > 1 ? args[1] : "";
-
- if (command.equals("faces")) {
- if (path.startsWith("gs://")) {
- detectFacesGcs(path, out);
- } else {
- detectFaces(path, out);
- }
- } else if (command.equals("labels")) {
- if (path.startsWith("gs://")) {
- detectLabelsGcs(path, out);
- } else {
- detectLabels(path, out);
- }
- } else if (command.equals("landmarks")) {
- if (path.startsWith("http")) {
- detectLandmarksUrl(path, out);
- } else if (path.startsWith("gs://")) {
- detectLandmarksGcs(path, out);
- } else {
- detectLandmarks(path, out);
- }
- } else if (command.equals("logos")) {
- if (path.startsWith("gs://")) {
- detectLogosGcs(path, out);
- } else {
- detectLogos(path, out);
- }
- } else if (command.equals("text")) {
- if (path.startsWith("gs://")) {
- detectTextGcs(path, out);
- } else {
- detectText(path, out);
- }
- } else if (command.equals("properties")) {
- if (path.startsWith("gs://")) {
- detectPropertiesGcs(path, out);
- } else {
- detectProperties(path, out);
- }
- } else if (command.equals("safe-search")) {
- if (path.startsWith("gs://")) {
- detectSafeSearchGcs(path, out);
- } else {
- detectSafeSearch(path, out);
- }
- } else if (command.equals("web")) {
- if (path.startsWith("gs://")) {
- detectWebDetectionsGcs(path, out);
- } else {
- detectWebDetections(path, out);
- }
- } else if (command.equals("web-entities")) {
- if (path.startsWith("gs://")) {
- detectWebEntitiesGcs(path, out);
- } else {
- detectWebEntities(path, out);
- }
- } else if (command.equals("web-entities-include-geo")) {
- if (path.startsWith("gs://")) {
- detectWebEntitiesIncludeGeoResultsGcs(path, out);
- } else {
- detectWebEntitiesIncludeGeoResults(path, out);
- }
- } else if (command.equals("crop")) {
- if (path.startsWith("gs://")) {
- detectCropHintsGcs(path, out);
- } else {
- detectCropHints(path, out);
- }
- } else if (command.equals("fulltext")) {
- if (path.startsWith("gs://")) {
- detectDocumentTextGcs(path, out);
- } else {
- detectDocumentText(path, out);
- }
- } else if (command.equals("ocr")) {
- String destPath = args.length > 2 ? args[2] : "";
- detectDocumentsGcs(path, destPath);
- } else if (command.equals("object-localization")) {
- if (path.startsWith("gs://")) {
- detectLocalizedObjectsGcs(path, out);
- } else {
- detectLocalizedObjects(path, out);
- }
- }
- }
-
- /**
- * Detects faces in the specified local image.
- *
- * @param filePath The path to the file to perform face detection on.
- * @param out A {@link PrintStream} to write detected features to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_face_detection]
- public static void detectFaces(String filePath, PrintStream out) throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
-
- Image img = Image.newBuilder().setContent(imgBytes).build();
- Feature feat = Feature.newBuilder().setType(Type.FACE_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (FaceAnnotation annotation : res.getFaceAnnotationsList()) {
- out.printf(
- "anger: %s\njoy: %s\nsurprise: %s\nposition: %s",
- annotation.getAngerLikelihood(),
- annotation.getJoyLikelihood(),
- annotation.getSurpriseLikelihood(),
- annotation.getBoundingPoly());
- }
- }
- }
- }
- // [END vision_face_detection]
-
- /**
- * Detects faces in the specified remote image on Google Cloud Storage.
- *
- * @param gcsPath The path to the remote file on Google Cloud Storage to perform face detection
- * on.
- * @param out A {@link PrintStream} to write detected features to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_face_detection_gcs]
- public static void detectFacesGcs(String gcsPath, PrintStream out) throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- Image img = Image.newBuilder().setSource(imgSource).build();
- Feature feat = Feature.newBuilder().setType(Type.FACE_DETECTION).build();
-
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (FaceAnnotation annotation : res.getFaceAnnotationsList()) {
- out.printf(
- "anger: %s\njoy: %s\nsurprise: %s\nposition: %s",
- annotation.getAngerLikelihood(),
- annotation.getJoyLikelihood(),
- annotation.getSurpriseLikelihood(),
- annotation.getBoundingPoly());
- }
- }
- }
- }
- // [END vision_face_detection_gcs]
-
- /**
- * Detects labels in the specified local image.
- *
- * @param filePath The path to the file to perform label detection on.
- * @param out A {@link PrintStream} to write detected labels to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_label_detection]
- public static void detectLabels(String filePath, PrintStream out) throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
-
- Image img = Image.newBuilder().setContent(imgBytes).build();
- Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
- annotation.getAllFields().forEach((k, v) -> out.printf("%s : %s\n", k, v.toString()));
- }
- }
- }
- }
- // [END vision_label_detection]
-
- /**
- * Detects labels in the specified remote image on Google Cloud Storage.
- *
- * @param gcsPath The path to the remote file on Google Cloud Storage to perform label detection
- * on.
- * @param out A {@link PrintStream} to write detected features to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_label_detection_gcs]
- public static void detectLabelsGcs(String gcsPath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- Image img = Image.newBuilder().setSource(imgSource).build();
- Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
- annotation.getAllFields().forEach((k, v) -> out.printf("%s : %s\n", k, v.toString()));
- }
- }
- }
- }
- // [END vision_label_detection_gcs]
-
- /**
- * Detects landmarks in the specified local image.
- *
- * @param filePath The path to the file to perform landmark detection on.
- * @param out A {@link PrintStream} to write detected landmarks to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_landmark_detection]
- public static void detectLandmarks(String filePath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
- ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
-
- Image img = Image.newBuilder().setContent(imgBytes).build();
- Feature feat = Feature.newBuilder().setType(Type.LANDMARK_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) {
- LocationInfo info = annotation.getLocationsList().listIterator().next();
- out.printf("Landmark: %s\n %s\n", annotation.getDescription(), info.getLatLng());
- }
- }
- }
- }
- // [END vision_landmark_detection]
-
- /**
- * Detects landmarks in the specified URI.
- *
- * @param uri The path to the file to perform landmark detection on.
- * @param out A {@link PrintStream} to write detected landmarks to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- public static void detectLandmarksUrl(String uri, PrintStream out) throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ImageSource imgSource = ImageSource.newBuilder().setImageUri(uri).build();
- Image img = Image.newBuilder().setSource(imgSource).build();
- Feature feat = Feature.newBuilder().setType(Type.LANDMARK_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) {
- LocationInfo info = annotation.getLocationsList().listIterator().next();
- out.printf("Landmark: %s\n %s\n", annotation.getDescription(), info.getLatLng());
- }
- }
- }
- }
-
- /**
- * Detects landmarks in the specified remote image on Google Cloud Storage.
- *
- * @param gcsPath The path to the remote file on Google Cloud Storage to perform landmark
- * detection on.
- * @param out A {@link PrintStream} to write detected landmarks to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_landmark_detection_gcs]
- public static void detectLandmarksGcs(String gcsPath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- Image img = Image.newBuilder().setSource(imgSource).build();
- Feature feat = Feature.newBuilder().setType(Type.LANDMARK_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) {
- LocationInfo info = annotation.getLocationsList().listIterator().next();
- out.printf("Landmark: %s\n %s\n", annotation.getDescription(), info.getLatLng());
- }
- }
- }
- }
- // [END vision_landmark_detection_gcs]
-
- /**
- * Detects logos in the specified local image.
- *
- * @param filePath The path to the local file to perform logo detection on.
- * @param out A {@link PrintStream} to write detected logos to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_logo_detection]
- public static void detectLogos(String filePath, PrintStream out) throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
-
- Image img = Image.newBuilder().setContent(imgBytes).build();
- Feature feat = Feature.newBuilder().setType(Type.LOGO_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (EntityAnnotation annotation : res.getLogoAnnotationsList()) {
- out.println(annotation.getDescription());
- }
- }
- }
- }
- // [END vision_logo_detection]
-
- /**
- * Detects logos in the specified remote image on Google Cloud Storage.
- *
- * @param gcsPath The path to the remote file on Google Cloud Storage to perform logo detection
- * on.
- * @param out A {@link PrintStream} to write detected logos to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_logo_detection_gcs]
- public static void detectLogosGcs(String gcsPath, PrintStream out) throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- Image img = Image.newBuilder().setSource(imgSource).build();
- Feature feat = Feature.newBuilder().setType(Type.LOGO_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (EntityAnnotation annotation : res.getLogoAnnotationsList()) {
- out.println(annotation.getDescription());
- }
- }
- }
- }
- // [END vision_logo_detection_gcs]
-
- /**
- * Detects text in the specified image.
- *
- * @param filePath The path to the file to detect text in.
- * @param out A {@link PrintStream} to write the detected text to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_text_detection]
- public static void detectText(String filePath, PrintStream out) throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
-
- Image img = Image.newBuilder().setContent(imgBytes).build();
- Feature feat = Feature.newBuilder().setType(Type.TEXT_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
- out.printf("Text: %s\n", annotation.getDescription());
- out.printf("Position : %s\n", annotation.getBoundingPoly());
- }
- }
- }
- }
- // [END vision_text_detection]
-
- /**
- * Detects text in the specified remote image on Google Cloud Storage.
- *
- * @param gcsPath The path to the remote file on Google Cloud Storage to detect text in.
- * @param out A {@link PrintStream} to write the detected text to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_text_detection_gcs]
- public static void detectTextGcs(String gcsPath, PrintStream out) throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- Image img = Image.newBuilder().setSource(imgSource).build();
- Feature feat = Feature.newBuilder().setType(Type.TEXT_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
- out.printf("Text: %s\n", annotation.getDescription());
- out.printf("Position : %s\n", annotation.getBoundingPoly());
- }
- }
- }
- }
- // [END vision_text_detection_gcs]
-
- /**
- * Detects image properties such as color frequency from the specified local image.
- *
- * @param filePath The path to the file to detect properties.
- * @param out A {@link PrintStream} to write
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_image_property_detection]
- public static void detectProperties(String filePath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
-
- Image img = Image.newBuilder().setContent(imgBytes).build();
- Feature feat = Feature.newBuilder().setType(Type.IMAGE_PROPERTIES).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors();
- for (ColorInfo color : colors.getColorsList()) {
- out.printf(
- "fraction: %f\nr: %f, g: %f, b: %f\n",
- color.getPixelFraction(),
- color.getColor().getRed(),
- color.getColor().getGreen(),
- color.getColor().getBlue());
- }
- }
- }
- }
- // [END vision_image_property_detection]
-
- /**
- * Detects image properties such as color frequency from the specified remote image on Google
- * Cloud Storage.
- *
- * @param gcsPath The path to the remote file on Google Cloud Storage to detect properties on.
- * @param out A {@link PrintStream} to write
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_image_property_detection_gcs]
- public static void detectPropertiesGcs(String gcsPath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- Image img = Image.newBuilder().setSource(imgSource).build();
- Feature feat = Feature.newBuilder().setType(Type.IMAGE_PROPERTIES).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors();
- for (ColorInfo color : colors.getColorsList()) {
- out.printf(
- "fraction: %f\nr: %f, g: %f, b: %f\n",
- color.getPixelFraction(),
- color.getColor().getRed(),
- color.getColor().getGreen(),
- color.getColor().getBlue());
- }
- }
- }
- }
- // [END vision_image_property_detection_gcs]
-
- /**
- * Detects whether the specified image has features you would want to moderate.
- *
- * @param filePath The path to the local file used for safe search detection.
- * @param out A {@link PrintStream} to write the results to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_safe_search_detection]
- public static void detectSafeSearch(String filePath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
-
- Image img = Image.newBuilder().setContent(imgBytes).build();
- Feature feat = Feature.newBuilder().setType(Type.SAFE_SEARCH_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- SafeSearchAnnotation annotation = res.getSafeSearchAnnotation();
- out.printf(
- "adult: %s\nmedical: %s\nspoofed: %s\nviolence: %s\nracy: %s\n",
- annotation.getAdult(),
- annotation.getMedical(),
- annotation.getSpoof(),
- annotation.getViolence(),
- annotation.getRacy());
- }
- }
- }
- // [END vision_safe_search_detection]
-
- /**
- * Detects whether the specified image on Google Cloud Storage has features you would want to
- * moderate.
- *
- * @param gcsPath The path to the remote file on Google Cloud Storage to detect safe-search on.
- * @param out A {@link PrintStream} to write the results to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_safe_search_detection_gcs]
- public static void detectSafeSearchGcs(String gcsPath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- Image img = Image.newBuilder().setSource(imgSource).build();
- Feature feat = Feature.newBuilder().setType(Type.SAFE_SEARCH_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- SafeSearchAnnotation annotation = res.getSafeSearchAnnotation();
- out.printf(
- "adult: %s\nmedical: %s\nspoofed: %s\nviolence: %s\nracy: %s\n",
- annotation.getAdult(),
- annotation.getMedical(),
- annotation.getSpoof(),
- annotation.getViolence(),
- annotation.getRacy());
- }
- }
- }
- // [END vision_safe_search_detection_gcs]
-
- // [START vision_web_detection]
- /**
- * Finds references to the specified image on the web.
- *
- * @param filePath The path to the local file used for web annotation detection.
- * @param out A {@link PrintStream} to write the results to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- public static void detectWebDetections(String filePath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
-
- Image img = Image.newBuilder().setContent(imgBytes).build();
- Feature feat = Feature.newBuilder().setType(Type.WEB_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // Search the web for usages of the image. You could use these signals later
- // for user input moderation or linking external references.
- // For a full list of available annotations, see http://g.co/cloud/vision/docs
- WebDetection annotation = res.getWebDetection();
- out.println("Entity:Id:Score");
- out.println("===============");
- for (WebEntity entity : annotation.getWebEntitiesList()) {
- out.println(
- entity.getDescription() + " : " + entity.getEntityId() + " : " + entity.getScore());
- }
- for (WebLabel label : annotation.getBestGuessLabelsList()) {
- out.format("\nBest guess label: %s", label.getLabel());
- }
- out.println("\nPages with matching images: Score\n==");
- for (WebPage page : annotation.getPagesWithMatchingImagesList()) {
- out.println(page.getUrl() + " : " + page.getScore());
- }
- out.println("\nPages with partially matching images: Score\n==");
- for (WebImage image : annotation.getPartialMatchingImagesList()) {
- out.println(image.getUrl() + " : " + image.getScore());
- }
- out.println("\nPages with fully matching images: Score\n==");
- for (WebImage image : annotation.getFullMatchingImagesList()) {
- out.println(image.getUrl() + " : " + image.getScore());
- }
- out.println("\nPages with visually similar images: Score\n==");
- for (WebImage image : annotation.getVisuallySimilarImagesList()) {
- out.println(image.getUrl() + " : " + image.getScore());
- }
- }
- }
- }
- // [END vision_web_detection]
-
- // [START vision_web_detection_gcs]
- /**
- * Detects whether the remote image on Google Cloud Storage has features you would want to
- * moderate.
- *
- * @param gcsPath The path to the remote on Google Cloud Storage file to detect web annotations.
- * @param out A {@link PrintStream} to write the results to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- public static void detectWebDetectionsGcs(String gcsPath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- Image img = Image.newBuilder().setSource(imgSource).build();
- Feature feat = Feature.newBuilder().setType(Type.WEB_DETECTION).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // Search the web for usages of the image. You could use these signals later
- // for user input moderation or linking external references.
- // For a full list of available annotations, see http://g.co/cloud/vision/docs
- WebDetection annotation = res.getWebDetection();
- out.println("Entity:Id:Score");
- out.println("===============");
- for (WebEntity entity : annotation.getWebEntitiesList()) {
- out.println(
- entity.getDescription() + " : " + entity.getEntityId() + " : " + entity.getScore());
- }
- for (WebLabel label : annotation.getBestGuessLabelsList()) {
- out.format("\nBest guess label: %s", label.getLabel());
- }
- out.println("\nPages with matching images: Score\n==");
- for (WebPage page : annotation.getPagesWithMatchingImagesList()) {
- out.println(page.getUrl() + " : " + page.getScore());
- }
- out.println("\nPages with partially matching images: Score\n==");
- for (WebImage image : annotation.getPartialMatchingImagesList()) {
- out.println(image.getUrl() + " : " + image.getScore());
- }
- out.println("\nPages with fully matching images: Score\n==");
- for (WebImage image : annotation.getFullMatchingImagesList()) {
- out.println(image.getUrl() + " : " + image.getScore());
- }
- out.println("\nPages with visually similar images: Score\n==");
- for (WebImage image : annotation.getVisuallySimilarImagesList()) {
- out.println(image.getUrl() + " : " + image.getScore());
- }
- }
- }
- }
- // [END vision_web_detection_gcs]
-
- /**
- * Find web entities given a local image.
- *
- * @param filePath The path of the image to detect.
- * @param out A {@link PrintStream} to write the results to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- public static void detectWebEntities(String filePath, PrintStream out)
- throws Exception, IOException {
- // Instantiates a client
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- // Read in the local image
- ByteString contents = ByteString.readFrom(new FileInputStream(filePath));
-
- // Build the image
- Image image = Image.newBuilder().setContent(contents).build();
-
- // Create the request with the image and the specified feature: web detection
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder()
- .addFeatures(Feature.newBuilder().setType(Type.WEB_DETECTION))
- .setImage(image)
- .build();
-
- // Perform the request
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request));
-
- // Display the results
- response
- .getResponsesList()
- .stream()
- .forEach(
- r ->
- r.getWebDetection()
- .getWebEntitiesList()
- .stream()
- .forEach(
- entity -> {
- out.format("Description: %s\n", entity.getDescription());
- out.format("Score: %f\n", entity.getScore());
- }));
- }
- }
-
- /**
- * Find web entities given the remote image on Google Cloud Storage.
- *
- * @param gcsPath The path to the remote file on Google Cloud Storage to detect web entities.
- * @param out A {@link PrintStream} to write the results to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- public static void detectWebEntitiesGcs(String gcsPath, PrintStream out)
- throws Exception, IOException {
- // Instantiates a client
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- // Set the image source to the given gs uri
- ImageSource imageSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- // Build the image
- Image image = Image.newBuilder().setSource(imageSource).build();
-
- // Create the request with the image and the specified feature: web detection
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder()
- .addFeatures(Feature.newBuilder().setType(Type.WEB_DETECTION))
- .setImage(image)
- .build();
-
- // Perform the request
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request));
-
- // Display the results
- response
- .getResponsesList()
- .stream()
- .forEach(
- r ->
- r.getWebDetection()
- .getWebEntitiesList()
- .stream()
- .forEach(
- entity -> {
- System.out.format("Description: %s\n", entity.getDescription());
- System.out.format("Score: %f\n", entity.getScore());
- }));
- }
- }
-
- // [START vision_web_detection_include_geo]
- /**
- * Find web entities given a local image.
- *
- * @param filePath The path of the image to detect.
- * @param out A {@link PrintStream} to write the results to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- public static void detectWebEntitiesIncludeGeoResults(String filePath, PrintStream out)
- throws Exception, IOException {
- // Instantiates a client
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- // Read in the local image
- ByteString contents = ByteString.readFrom(new FileInputStream(filePath));
-
- // Build the image
- Image image = Image.newBuilder().setContent(contents).build();
-
- // Enable `IncludeGeoResults`
- WebDetectionParams webDetectionParams =
- WebDetectionParams.newBuilder().setIncludeGeoResults(true).build();
-
- // Set the parameters for the image
- ImageContext imageContext =
- ImageContext.newBuilder().setWebDetectionParams(webDetectionParams).build();
-
- // Create the request with the image, imageContext, and the specified feature: web detection
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder()
- .addFeatures(Feature.newBuilder().setType(Type.WEB_DETECTION))
- .setImage(image)
- .setImageContext(imageContext)
- .build();
-
- // Perform the request
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request));
-
- // Display the results
- response
- .getResponsesList()
- .stream()
- .forEach(
- r ->
- r.getWebDetection()
- .getWebEntitiesList()
- .stream()
- .forEach(
- entity -> {
- out.format("Description: %s\n", entity.getDescription());
- out.format("Score: %f\n", entity.getScore());
- }));
- }
- }
- // [END vision_web_detection_include_geo]
-
- // [START vision_web_detection_include_geo_gcs]
- /**
- * Find web entities given the remote image on Google Cloud Storage.
- *
- * @param gcsPath The path to the remote file on Google Cloud Storage to detect web entities with
- * geo results.
- * @param out A {@link PrintStream} to write the results to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- public static void detectWebEntitiesIncludeGeoResultsGcs(String gcsPath, PrintStream out)
- throws Exception, IOException {
- // Instantiates a client
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- // Set the image source to the given gs uri
- ImageSource imageSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- // Build the image
- Image image = Image.newBuilder().setSource(imageSource).build();
-
- // Enable `IncludeGeoResults`
- WebDetectionParams webDetectionParams =
- WebDetectionParams.newBuilder().setIncludeGeoResults(true).build();
-
- // Set the parameters for the image
- ImageContext imageContext =
- ImageContext.newBuilder().setWebDetectionParams(webDetectionParams).build();
-
- // Create the request with the image, imageContext, and the specified feature: web detection
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder()
- .addFeatures(Feature.newBuilder().setType(Type.WEB_DETECTION))
- .setImage(image)
- .setImageContext(imageContext)
- .build();
-
- // Perform the request
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request));
-
- // Display the results
- response
- .getResponsesList()
- .stream()
- .forEach(
- r ->
- r.getWebDetection()
- .getWebEntitiesList()
- .stream()
- .forEach(
- entity -> {
- out.format("Description: %s\n", entity.getDescription());
- out.format("Score: %f\n", entity.getScore());
- }));
- }
- }
- // [END vision_web_detection_include_geo_gcs]
-
- /**
- * Suggests a region to crop to for a local file.
- *
- * @param filePath The path to the local file used for web annotation detection.
- * @param out A {@link PrintStream} to write the results to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_crop_hint_detection]
- public static void detectCropHints(String filePath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
-
- Image img = Image.newBuilder().setContent(imgBytes).build();
- Feature feat = Feature.newBuilder().setType(Type.CROP_HINTS).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- CropHintsAnnotation annotation = res.getCropHintsAnnotation();
- for (CropHint hint : annotation.getCropHintsList()) {
- out.println(hint.getBoundingPoly());
- }
- }
- }
- }
- // [END vision_crop_hint_detection]
-
- /**
- * Suggests a region to crop to for a remote file on Google Cloud Storage.
- *
- * @param gcsPath The path to the remote file on Google Cloud Storage to detect safe-search on.
- * @param out A {@link PrintStream} to write the results to.
- * @throws Exception on errors while closing the client.
- * @throws IOException on Input/Output errors.
- */
- // [START vision_crop_hint_detection_gcs]
- public static void detectCropHintsGcs(String gcsPath, PrintStream out)
- throws Exception, IOException {
- List requests = new ArrayList<>();
-
- ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
- Image img = Image.newBuilder().setSource(imgSource).build();
- Feature feat = Feature.newBuilder().setType(Type.CROP_HINTS).build();
- AnnotateImageRequest request =
- AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
- requests.add(request);
-
- try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
- BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
- List responses = response.getResponsesList();
-
- for (AnnotateImageResponse res : responses) {
- if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
- return;
- }
-
- // For full list of available annotations, see http://g.co/cloud/vision/docs
- CropHintsAnnotation annotation = res.getCropHintsAnnotation();
- for (CropHint hint : annotation.getCropHintsList()) {
- out.println(hint.getBoundingPoly());
- }
- }
- }
- }
- // [END vision_crop_hint_detection_gcs]
-
/**
* Performs document text detection on a local image file.
*
* @param filePath The path to the local file to detect document text on.
- * @param out A {@link PrintStream} to write the results to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
*/
// [START vision_fulltext_detection]
- public static void detectDocumentText(String filePath, PrintStream out)
- throws Exception, IOException {
+ public static void detectDocumentText(String filePath) throws IOException {
List requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
@@ -1257,6 +77,9 @@ public static void detectDocumentText(String filePath, PrintStream out)
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List responses = response.getResponsesList();
@@ -1264,7 +87,7 @@ public static void detectDocumentText(String filePath, PrintStream out)
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
+ System.out.format("Error: %s%n", res.getError().getMessage());
return;
}
@@ -1280,23 +103,24 @@ public static void detectDocumentText(String filePath, PrintStream out)
String wordText = "";
for (Symbol symbol : word.getSymbolsList()) {
wordText = wordText + symbol.getText();
- out.format(
- "Symbol text: %s (confidence: %f)\n",
+ System.out.format(
+ "Symbol text: %s (confidence: %f)%n",
symbol.getText(), symbol.getConfidence());
}
- out.format("Word text: %s (confidence: %f)\n\n", wordText, word.getConfidence());
+ System.out.format(
+ "Word text: %s (confidence: %f)%n%n", wordText, word.getConfidence());
paraText = String.format("%s %s", paraText, wordText);
}
// Output Example using Paragraph:
- out.println("\nParagraph: \n" + paraText);
- out.format("Paragraph Confidence: %f\n", para.getConfidence());
+ System.out.println("%nParagraph: %n" + paraText);
+ System.out.format("Paragraph Confidence: %f%n", para.getConfidence());
blockText = blockText + paraText;
}
pageText = pageText + blockText;
}
}
- out.println("\nComplete annotation:");
- out.println(annotation.getText());
+ System.out.println("%nComplete annotation:");
+ System.out.println(annotation.getText());
}
}
}
@@ -1306,13 +130,11 @@ public static void detectDocumentText(String filePath, PrintStream out)
* Performs document text detection on a remote image on Google Cloud Storage.
*
* @param gcsPath The path to the remote file on Google Cloud Storage to detect document text on.
- * @param out A {@link PrintStream} to write the results to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
*/
// [START vision_fulltext_detection_gcs]
- public static void detectDocumentTextGcs(String gcsPath, PrintStream out)
- throws Exception, IOException {
+ public static void detectDocumentTextGcs(String gcsPath) throws IOException {
List requests = new ArrayList<>();
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
@@ -1322,6 +144,9 @@ public static void detectDocumentTextGcs(String gcsPath, PrintStream out)
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List responses = response.getResponsesList();
@@ -1329,7 +154,7 @@ public static void detectDocumentTextGcs(String gcsPath, PrintStream out)
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
- out.printf("Error: %s\n", res.getError().getMessage());
+ System.out.format("Error: %s%n", res.getError().getMessage());
return;
}
// For full list of available annotations, see http://g.co/cloud/vision/docs
@@ -1344,23 +169,24 @@ public static void detectDocumentTextGcs(String gcsPath, PrintStream out)
String wordText = "";
for (Symbol symbol : word.getSymbolsList()) {
wordText = wordText + symbol.getText();
- out.format(
- "Symbol text: %s (confidence: %f)\n",
+ System.out.format(
+ "Symbol text: %s (confidence: %f)%n",
symbol.getText(), symbol.getConfidence());
}
- out.format("Word text: %s (confidence: %f)\n\n", wordText, word.getConfidence());
+ System.out.format(
+ "Word text: %s (confidence: %f)%n%n", wordText, word.getConfidence());
paraText = String.format("%s %s", paraText, wordText);
}
// Output Example using Paragraph:
- out.println("\nParagraph: \n" + paraText);
- out.format("Paragraph Confidence: %f\n", para.getConfidence());
+ System.out.println("%nParagraph: %n" + paraText);
+ System.out.format("Paragraph Confidence: %f%n", para.getConfidence());
blockText = blockText + paraText;
}
pageText = pageText + blockText;
}
}
- out.println("\nComplete annotation:");
- out.println(annotation.getText());
+ System.out.println("%nComplete annotation:");
+ System.out.println(annotation.getText());
}
}
}
@@ -1378,6 +204,10 @@ public static void detectDocumentTextGcs(String gcsPath, PrintStream out)
*/
public static void detectDocumentsGcs(String gcsSourcePath, String gcsDestinationPath)
throws Exception {
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
List requests = new ArrayList<>();
@@ -1397,8 +227,8 @@ public static void detectDocumentsGcs(String gcsSourcePath, String gcsDestinatio
GcsDestination gcsDestination =
GcsDestination.newBuilder().setUri(gcsDestinationPath).build();
- // Create the configuration for the output with the batch size.
- // The batch size sets how many pages should be grouped into each json output file.
+ // Create the configuration for the System.output with the batch size.
+ // The batch size sets how many pages should be grouped into each json System.output file.
OutputConfig outputConfig =
OutputConfig.newBuilder().setBatchSize(2).setGcsDestination(gcsDestination).build();
@@ -1426,8 +256,8 @@ public static void detectDocumentsGcs(String gcsSourcePath, String gcsDestinatio
List result =
response.get(180, TimeUnit.SECONDS).getResponsesList();
- // Once the request has completed and the output has been
- // written to GCS, we can list all the output files.
+ // Once the request has completed and the System.output has been
+ // written to GCS, we can list all the System.output files.
Storage storage = StorageOptions.getDefaultInstance().getService();
// Get the destination location from the gcsDestinationPath
@@ -1449,7 +279,7 @@ public static void detectDocumentsGcs(String gcsSourcePath, String gcsDestinatio
for (Blob blob : pageList.iterateAll()) {
System.out.println(blob.getName());
- // Process the first output file from GCS.
+ // Process the first System.output file from GCS.
// Since we specified batch size = 2, the first response contains
// the first two pages of the input file.
if (firstOutputFile == null) {
@@ -1475,7 +305,7 @@ public static void detectDocumentsGcs(String gcsSourcePath, String gcsDestinatio
// The response contains more information:
// annotation/pages/blocks/paragraphs/words/symbols
// including confidence score and bounding boxes
- System.out.format("\nText: %s\n", annotateImageResponse.getFullTextAnnotation().getText());
+ System.out.format("%nText: %s%n", annotateImageResponse.getFullTextAnnotation().getText());
} else {
System.out.println("No MATCH");
}
@@ -1488,12 +318,10 @@ public static void detectDocumentsGcs(String gcsSourcePath, String gcsDestinatio
* Detects localized objects in the specified local image.
*
* @param filePath The path to the file to perform localized object detection on.
- * @param out A {@link PrintStream} to write detected objects to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
*/
- public static void detectLocalizedObjects(String filePath, PrintStream out)
- throws Exception, IOException {
+ public static void detectLocalizedObjects(String filePath) throws IOException {
List requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
@@ -1506,21 +334,24 @@ public static void detectLocalizedObjects(String filePath, PrintStream out)
.build();
requests.add(request);
- // Perform the request
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ // Perform the request
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List responses = response.getResponsesList();
// Display the results
for (AnnotateImageResponse res : responses) {
for (LocalizedObjectAnnotation entity : res.getLocalizedObjectAnnotationsList()) {
- out.format("Object name: %s\n", entity.getName());
- out.format("Confidence: %s\n", entity.getScore());
- out.format("Normalized Vertices:\n");
+ System.out.format("Object name: %s%n", entity.getName());
+ System.out.format("Confidence: %s%n", entity.getScore());
+ System.out.format("Normalized Vertices:%n");
entity
.getBoundingPoly()
.getNormalizedVerticesList()
- .forEach(vertex -> out.format("- (%s, %s)\n", vertex.getX(), vertex.getY()));
+ .forEach(vertex -> System.out.format("- (%s, %s)%n", vertex.getX(), vertex.getY()));
}
}
}
@@ -1533,12 +364,10 @@ public static void detectLocalizedObjects(String filePath, PrintStream out)
*
* @param gcsPath The path to the remote file on Google Cloud Storage to detect localized objects
* on.
- * @param out A {@link PrintStream} to write detected objects to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
*/
- public static void detectLocalizedObjectsGcs(String gcsPath, PrintStream out)
- throws Exception, IOException {
+ public static void detectLocalizedObjectsGcs(String gcsPath) throws IOException {
List requests = new ArrayList<>();
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
@@ -1551,21 +380,24 @@ public static void detectLocalizedObjectsGcs(String gcsPath, PrintStream out)
.build();
requests.add(request);
- // Perform the request
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ // Perform the request
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List responses = response.getResponsesList();
client.close();
// Display the results
for (AnnotateImageResponse res : responses) {
for (LocalizedObjectAnnotation entity : res.getLocalizedObjectAnnotationsList()) {
- out.format("Object name: %s\n", entity.getName());
- out.format("Confidence: %s\n", entity.getScore());
- out.format("Normalized Vertices:\n");
+ System.out.format("Object name: %s%n", entity.getName());
+ System.out.format("Confidence: %s%n", entity.getScore());
+ System.out.format("Normalized Vertices:%n");
entity
.getBoundingPoly()
.getNormalizedVerticesList()
- .forEach(vertex -> out.format("- (%s, %s)\n", vertex.getX(), vertex.getY()));
+ .forEach(vertex -> System.out.format("- (%s, %s)%n", vertex.getX(), vertex.getY()));
}
}
}
diff --git a/vision/cloud-client/src/main/java/com/example/vision/QuickstartSample.java b/vision/cloud-client/src/main/java/com/example/vision/quickstart/QuickstartSample.java
similarity index 85%
rename from vision/cloud-client/src/main/java/com/example/vision/QuickstartSample.java
rename to vision/cloud-client/src/main/java/com/example/vision/quickstart/QuickstartSample.java
index b88233612d9..6e04f722e2f 100644
--- a/vision/cloud-client/src/main/java/com/example/vision/QuickstartSample.java
+++ b/vision/cloud-client/src/main/java/com/example/vision/quickstart/QuickstartSample.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.example.vision;
+package com.example.vision.quickstart;
// [START vision_quickstart]
// Imports the Google Cloud client library
@@ -36,7 +36,9 @@
public class QuickstartSample {
public static void main(String... args) throws Exception {
- // Instantiates a client
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
try (ImageAnnotatorClient vision = ImageAnnotatorClient.create()) {
// The path to the image file to annotate
@@ -61,14 +63,14 @@ public static void main(String... args) throws Exception {
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
- System.out.printf("Error: %s\n", res.getError().getMessage());
+ System.out.format("Error: %s%n", res.getError().getMessage());
return;
}
for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
annotation
.getAllFields()
- .forEach((k, v) -> System.out.printf("%s : %s\n", k, v.toString()));
+ .forEach((k, v) -> System.out.format("%s : %s%n", k, v.toString()));
}
}
}
diff --git a/vision/cloud-client/src/main/java/com/example/vision/AsyncBatchAnnotateImages.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/AsyncBatchAnnotateImages.java
similarity index 97%
rename from vision/cloud-client/src/main/java/com/example/vision/AsyncBatchAnnotateImages.java
rename to vision/cloud-client/src/main/java/com/example/vision/snippets/AsyncBatchAnnotateImages.java
index e9b31582051..025abc30594 100644
--- a/vision/cloud-client/src/main/java/com/example/vision/AsyncBatchAnnotateImages.java
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/AsyncBatchAnnotateImages.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.example.vision;
+package com.example.vision.snippets;
// [START vision_async_batch_annotate_images]
import com.google.cloud.vision.v1.AnnotateImageRequest;
@@ -82,7 +82,7 @@ public static void asyncBatchAnnotateImages(String inputImageUri, String outputU
// The output is written to GCS with the provided output_uri as prefix
String gcsOutputUri = response.getOutputConfig().getGcsDestination().getUri();
- System.out.printf("Output written to GCS with prefix: %s\n", gcsOutputUri);
+ System.out.format("Output written to GCS with prefix: %s%n", gcsOutputUri);
}
}
}
diff --git a/vision/cloud-client/src/main/java/com/example/vision/BatchAnnotateFiles.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/BatchAnnotateFiles.java
similarity index 92%
rename from vision/cloud-client/src/main/java/com/example/vision/BatchAnnotateFiles.java
rename to vision/cloud-client/src/main/java/com/example/vision/snippets/BatchAnnotateFiles.java
index 0895ca7aa00..15a864ff5f3 100644
--- a/vision/cloud-client/src/main/java/com/example/vision/BatchAnnotateFiles.java
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/BatchAnnotateFiles.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.example.vision;
+package com.example.vision.snippets;
// [START vision_batch_annotate_files]
import com.google.cloud.vision.v1.AnnotateFileRequest;
@@ -90,17 +90,17 @@ public static void batchAnnotateFiles(String filePath) throws IOException {
// sample.
for (AnnotateImageResponse imageResponse :
response.getResponsesList().get(0).getResponsesList()) {
- System.out.printf("Full text: %s\n", imageResponse.getFullTextAnnotation().getText());
+ System.out.format("Full text: %s%n", imageResponse.getFullTextAnnotation().getText());
for (Page page : imageResponse.getFullTextAnnotation().getPagesList()) {
for (Block block : page.getBlocksList()) {
- System.out.printf("\nBlock confidence: %s\n", block.getConfidence());
+ System.out.format("%nBlock confidence: %s%n", block.getConfidence());
for (Paragraph par : block.getParagraphsList()) {
- System.out.printf("\tParagraph confidence: %s\n", par.getConfidence());
+ System.out.format("\tParagraph confidence: %s%n", par.getConfidence());
for (Word word : par.getWordsList()) {
- System.out.printf("\t\tWord confidence: %s\n", word.getConfidence());
+ System.out.format("\t\tWord confidence: %s%n", word.getConfidence());
for (Symbol symbol : word.getSymbolsList()) {
- System.out.printf(
- "\t\t\tSymbol: %s, (confidence: %s)\n",
+ System.out.format(
+ "\t\t\tSymbol: %s, (confidence: %s)%n",
symbol.getText(), symbol.getConfidence());
}
}
diff --git a/vision/cloud-client/src/main/java/com/example/vision/BatchAnnotateFilesGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/BatchAnnotateFilesGcs.java
similarity index 92%
rename from vision/cloud-client/src/main/java/com/example/vision/BatchAnnotateFilesGcs.java
rename to vision/cloud-client/src/main/java/com/example/vision/snippets/BatchAnnotateFilesGcs.java
index dce825fd025..f7d1ca4e52a 100644
--- a/vision/cloud-client/src/main/java/com/example/vision/BatchAnnotateFilesGcs.java
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/BatchAnnotateFilesGcs.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.example.vision;
+package com.example.vision.snippets;
// [START vision_batch_annotate_files_gcs]
import com.google.cloud.vision.v1.AnnotateFileRequest;
@@ -85,17 +85,17 @@ public static void batchAnnotateFilesGcs(String gcsUri) throws IOException {
// sample.
for (AnnotateImageResponse imageResponse :
response.getResponsesList().get(0).getResponsesList()) {
- System.out.printf("Full text: %s\n", imageResponse.getFullTextAnnotation().getText());
+ System.out.format("Full text: %s%n", imageResponse.getFullTextAnnotation().getText());
for (Page page : imageResponse.getFullTextAnnotation().getPagesList()) {
for (Block block : page.getBlocksList()) {
- System.out.printf("\nBlock confidence: %s\n", block.getConfidence());
+ System.out.format("%nBlock confidence: %s%n", block.getConfidence());
for (Paragraph par : block.getParagraphsList()) {
- System.out.printf("\tParagraph confidence: %s\n", par.getConfidence());
+ System.out.format("\tParagraph confidence: %s%n", par.getConfidence());
for (Word word : par.getWordsList()) {
- System.out.printf("\t\tWord confidence: %s\n", word.getConfidence());
+ System.out.format("\t\tWord confidence: %s%n", word.getConfidence());
for (Symbol symbol : word.getSymbolsList()) {
- System.out.printf(
- "\t\t\tSymbol: %s, (confidence: %s)\n",
+ System.out.format(
+ "\t\t\tSymbol: %s, (confidence: %s)%n",
symbol.getText(), symbol.getConfidence());
}
}
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectCropHints.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectCropHints.java
new file mode 100644
index 00000000000..705a87ce0f8
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectCropHints.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_crop_hint_detection]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.CropHint;
+import com.google.cloud.vision.v1.CropHintsAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectCropHints {
+ public static void detectCropHints() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectCropHints(filePath);
+ }
+
+ // Suggests a region to crop to for a local file.
+ public static void detectCropHints(String filePath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
+
+ Image img = Image.newBuilder().setContent(imgBytes).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.CROP_HINTS).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ CropHintsAnnotation annotation = res.getCropHintsAnnotation();
+ for (CropHint hint : annotation.getCropHintsList()) {
+ System.out.println(hint.getBoundingPoly());
+ }
+ }
+ }
+ }
+}
+// [END vision_crop_hint_detection]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectCropHintsGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectCropHintsGcs.java
new file mode 100644
index 00000000000..9448a4612c7
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectCropHintsGcs.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_crop_hint_detection_gcs]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.CropHint;
+import com.google.cloud.vision.v1.CropHintsAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectCropHintsGcs {
+
+ public static void detectCropHintsGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectCropHintsGcs(filePath);
+ }
+
+ // Suggests a region to crop to for a remote file on Google Cloud Storage.
+ public static void detectCropHintsGcs(String gcsPath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ Image img = Image.newBuilder().setSource(imgSource).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.CROP_HINTS).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ CropHintsAnnotation annotation = res.getCropHintsAnnotation();
+ for (CropHint hint : annotation.getCropHintsList()) {
+ System.out.println(hint.getBoundingPoly());
+ }
+ }
+ }
+ }
+}
+// [END vision_crop_hint_detection_gcs]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectFaces.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectFaces.java
new file mode 100644
index 00000000000..4c07fa08080
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectFaces.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_face_detection]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.FaceAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectFaces {
+
+ public static void detectFaces() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectFaces(filePath);
+ }
+
+ // Detects faces in the specified local image.
+ public static void detectFaces(String filePath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
+
+ Image img = Image.newBuilder().setContent(imgBytes).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.FACE_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (FaceAnnotation annotation : res.getFaceAnnotationsList()) {
+ System.out.format(
+ "anger: %s%njoy: %s%nsurprise: %s%nposition: %s",
+ annotation.getAngerLikelihood(),
+ annotation.getJoyLikelihood(),
+ annotation.getSurpriseLikelihood(),
+ annotation.getBoundingPoly());
+ }
+ }
+ }
+ }
+}
+// [END vision_face_detection]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectFacesGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectFacesGcs.java
new file mode 100644
index 00000000000..b325623e761
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectFacesGcs.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_face_detection_gcs]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.FaceAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectFacesGcs {
+
+ public static void detectFacesGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectFacesGcs(filePath);
+ }
+
+ // Detects faces in the specified remote image on Google Cloud Storage.
+ public static void detectFacesGcs(String gcsPath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ Image img = Image.newBuilder().setSource(imgSource).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.FACE_DETECTION).build();
+
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (FaceAnnotation annotation : res.getFaceAnnotationsList()) {
+ System.out.format(
+ "anger: %s%njoy: %s%nsurprise: %s%nposition: %s",
+ annotation.getAngerLikelihood(),
+ annotation.getJoyLikelihood(),
+ annotation.getSurpriseLikelihood(),
+ annotation.getBoundingPoly());
+ }
+ }
+ }
+ }
+}
+// [END vision_face_detection_gcs]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLabels.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLabels.java
new file mode 100644
index 00000000000..87563bb3ca6
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLabels.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_label_detection]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.EntityAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectLabels {
+
+ public static void detectLabels() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectLabels(filePath);
+ }
+
+ // Detects labels in the specified local image.
+ public static void detectLabels(String filePath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
+
+ Image img = Image.newBuilder().setContent(imgBytes).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.LABEL_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
+ annotation
+ .getAllFields()
+ .forEach((k, v) -> System.out.format("%s : %s%n", k, v.toString()));
+ }
+ }
+ }
+ }
+}
+// [END vision_label_detection]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLabelsGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLabelsGcs.java
new file mode 100644
index 00000000000..53e8dfe5351
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLabelsGcs.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_label_detection_gcs]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.EntityAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectLabelsGcs {
+
+ public static void detectLabelsGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectLabelsGcs(filePath);
+ }
+
+ // Detects labels in the specified remote image on Google Cloud Storage.
+ public static void detectLabelsGcs(String gcsPath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ Image img = Image.newBuilder().setSource(imgSource).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.LABEL_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
+ annotation
+ .getAllFields()
+ .forEach((k, v) -> System.out.format("%s : %s%n", k, v.toString()));
+ }
+ }
+ }
+ }
+}
+// [END vision_label_detection_gcs]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarks.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarks.java
new file mode 100644
index 00000000000..5147e1e11dc
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarks.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_landmark_detection]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.EntityAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.LocationInfo;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectLandmarks {
+ public static void detectLandmarks() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectLandmarks(filePath);
+ }
+
+ // Detects landmarks in the specified local image.
+ public static void detectLandmarks(String filePath) throws IOException {
+ List requests = new ArrayList<>();
+ ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
+
+ Image img = Image.newBuilder().setContent(imgBytes).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.LANDMARK_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) {
+ LocationInfo info = annotation.getLocationsList().listIterator().next();
+ System.out.format("Landmark: %s%n %s%n", annotation.getDescription(), info.getLatLng());
+ }
+ }
+ }
+ }
+}
+// [END vision_landmark_detection]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarksGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarksGcs.java
new file mode 100644
index 00000000000..c5ff0c1e129
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarksGcs.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_landmark_detection_gcs]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.EntityAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import com.google.cloud.vision.v1.LocationInfo;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectLandmarksGcs {
+
+ public static void detectLandmarksGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectLandmarksGcs(filePath);
+ }
+
+ // Detects landmarks in the specified remote image on Google Cloud Storage.
+ public static void detectLandmarksGcs(String gcsPath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ Image img = Image.newBuilder().setSource(imgSource).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.LANDMARK_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) {
+ LocationInfo info = annotation.getLocationsList().listIterator().next();
+ System.out.format("Landmark: %s%n %s%n", annotation.getDescription(), info.getLatLng());
+ }
+ }
+ }
+ }
+}
+// [END vision_landmark_detection_gcs]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarksUrl.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarksUrl.java
new file mode 100644
index 00000000000..ff52931863e
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarksUrl.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.EntityAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import com.google.cloud.vision.v1.LocationInfo;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectLandmarksUrl {
+
+ public static void detectLandmarksUrl() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectLandmarksUrl(filePath);
+ }
+
+ // Detects landmarks in the specified URI.
+ public static void detectLandmarksUrl(String uri) throws IOException {
+ List requests = new ArrayList<>();
+
+ ImageSource imgSource = ImageSource.newBuilder().setImageUri(uri).build();
+ Image img = Image.newBuilder().setSource(imgSource).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.LANDMARK_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) {
+ LocationInfo info = annotation.getLocationsList().listIterator().next();
+ System.out.format("Landmark: %s%n %s%n", annotation.getDescription(), info.getLatLng());
+ }
+ }
+ }
+ }
+}
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLogos.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLogos.java
new file mode 100644
index 00000000000..22785a21dd0
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLogos.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_logo_detection]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.EntityAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectLogos {
+ public static void detectLogos() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectLogos(filePath);
+ }
+
+ // Detects logos in the specified local image.
+
+ public static void detectLogos(String filePath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
+
+ Image img = Image.newBuilder().setContent(imgBytes).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.LOGO_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (EntityAnnotation annotation : res.getLogoAnnotationsList()) {
+ System.out.println(annotation.getDescription());
+ }
+ }
+ }
+ }
+}
+// [END vision_logo_detection]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLogosGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLogosGcs.java
new file mode 100644
index 00000000000..e7e0c2002bd
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLogosGcs.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_logo_detection_gcs]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.EntityAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectLogosGcs {
+
+ public static void detectLogosGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectLogosGcs(filePath);
+ }
+
+ // Detects logos in the specified remote image on Google Cloud Storage.
+ public static void detectLogosGcs(String gcsPath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ Image img = Image.newBuilder().setSource(imgSource).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.LOGO_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (EntityAnnotation annotation : res.getLogoAnnotationsList()) {
+ System.out.println(annotation.getDescription());
+ }
+ }
+ }
+ }
+}
+// [END vision_logo_detection_gcs]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectProperties.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectProperties.java
new file mode 100644
index 00000000000..9fd022b6469
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectProperties.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_image_property_detection]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.ColorInfo;
+import com.google.cloud.vision.v1.DominantColorsAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectProperties {
+ public static void detectProperties() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectProperties(filePath);
+ }
+
+ // Detects image properties such as color frequency from the specified local image.
+ public static void detectProperties(String filePath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
+
+ Image img = Image.newBuilder().setContent(imgBytes).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.IMAGE_PROPERTIES).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors();
+ for (ColorInfo color : colors.getColorsList()) {
+ System.out.format(
+ "fraction: %f%nr: %f, g: %f, b: %f%n",
+ color.getPixelFraction(),
+ color.getColor().getRed(),
+ color.getColor().getGreen(),
+ color.getColor().getBlue());
+ }
+ }
+ }
+ }
+}
+// [END vision_image_property_detection]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectPropertiesGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectPropertiesGcs.java
new file mode 100644
index 00000000000..2a974c63296
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectPropertiesGcs.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_image_property_detection_gcs]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.ColorInfo;
+import com.google.cloud.vision.v1.DominantColorsAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectPropertiesGcs {
+
+ public static void detectPropertiesGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectPropertiesGcs(filePath);
+ }
+
+ // Detects image properties such as color frequency from the specified remote image on Google
+ // Cloud Storage.
+ public static void detectPropertiesGcs(String gcsPath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ Image img = Image.newBuilder().setSource(imgSource).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.IMAGE_PROPERTIES).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors();
+ for (ColorInfo color : colors.getColorsList()) {
+ System.out.format(
+ "fraction: %f%nr: %f, g: %f, b: %f%n",
+ color.getPixelFraction(),
+ color.getColor().getRed(),
+ color.getColor().getGreen(),
+ color.getColor().getBlue());
+ }
+ }
+ }
+ }
+}
+// [END vision_image_property_detection_gcs]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectSafeSearch.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectSafeSearch.java
new file mode 100644
index 00000000000..351869f8172
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectSafeSearch.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_safe_search_detection]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.SafeSearchAnnotation;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectSafeSearch {
+ public static void detectSafeSearch() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectSafeSearch(filePath);
+ }
+
+ // Detects whether the specified image has features you would want to moderate.
+ public static void detectSafeSearch(String filePath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
+
+ Image img = Image.newBuilder().setContent(imgBytes).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.SAFE_SEARCH_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ SafeSearchAnnotation annotation = res.getSafeSearchAnnotation();
+ System.out.format(
+ "adult: %s%nmedical: %s%nspoofed: %s%nviolence: %s%nracy: %s%n",
+ annotation.getAdult(),
+ annotation.getMedical(),
+ annotation.getSpoof(),
+ annotation.getViolence(),
+ annotation.getRacy());
+ }
+ }
+ }
+}
+// [END vision_safe_search_detection]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectSafeSearchGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectSafeSearchGcs.java
new file mode 100644
index 00000000000..619404b6753
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectSafeSearchGcs.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_safe_search_detection_gcs]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Feature.Type;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import com.google.cloud.vision.v1.SafeSearchAnnotation;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectSafeSearchGcs {
+
+ public static void detectSafeSearchGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectSafeSearchGcs(filePath);
+ }
+
+ // Detects whether the specified image on Google Cloud Storage has features you would want to
+ // moderate.
+ public static void detectSafeSearchGcs(String gcsPath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ Image img = Image.newBuilder().setSource(imgSource).build();
+ Feature feat = Feature.newBuilder().setType(Type.SAFE_SEARCH_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ SafeSearchAnnotation annotation = res.getSafeSearchAnnotation();
+ System.out.format(
+ "adult: %s%nmedical: %s%nspoofed: %s%nviolence: %s%nracy: %s%n",
+ annotation.getAdult(),
+ annotation.getMedical(),
+ annotation.getSpoof(),
+ annotation.getViolence(),
+ annotation.getRacy());
+ }
+ }
+ }
+}
+// [END vision_safe_search_detection_gcs]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectText.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectText.java
new file mode 100644
index 00000000000..8cac7288a5e
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectText.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_text_detection]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.EntityAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectText {
+ public static void detectText() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectText(filePath);
+ }
+
+ // Detects text in the specified image.
+ public static void detectText(String filePath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
+
+ Image img = Image.newBuilder().setContent(imgBytes).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.TEXT_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
+ System.out.format("Text: %s%n", annotation.getDescription());
+ System.out.format("Position : %s%n", annotation.getBoundingPoly());
+ }
+ }
+ }
+ }
+}
+// [END vision_text_detection]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectTextGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectTextGcs.java
new file mode 100644
index 00000000000..18bedcdcf5c
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectTextGcs.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_text_detection_gcs]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.EntityAnnotation;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectTextGcs {
+
+ public static void detectTextGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectTextGcs(filePath);
+ }
+
+ // Detects text in the specified remote image on Google Cloud Storage.
+ public static void detectTextGcs(String gcsPath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ Image img = Image.newBuilder().setSource(imgSource).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.TEXT_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // For full list of available annotations, see http://g.co/cloud/vision/docs
+ for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
+ System.out.format("Text: %s%n", annotation.getDescription());
+ System.out.format("Position : %s%n", annotation.getBoundingPoly());
+ }
+ }
+ }
+ }
+}
+// [END vision_text_detection_gcs]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebDetections.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebDetections.java
new file mode 100644
index 00000000000..98a74f4d691
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebDetections.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_web_detection]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Feature.Type;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.WebDetection;
+import com.google.cloud.vision.v1.WebDetection.WebEntity;
+import com.google.cloud.vision.v1.WebDetection.WebImage;
+import com.google.cloud.vision.v1.WebDetection.WebLabel;
+import com.google.cloud.vision.v1.WebDetection.WebPage;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectWebDetections {
+
+ public static void detectWebDetections() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectWebDetections(filePath);
+ }
+
+ // Finds references to the specified image on the web.
+ public static void detectWebDetections(String filePath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
+
+ Image img = Image.newBuilder().setContent(imgBytes).build();
+ Feature feat = Feature.newBuilder().setType(Type.WEB_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // Search the web for usages of the image. You could use these signals later
+ // for user input moderation or linking external references.
+ // For a full list of available annotations, see http://g.co/cloud/vision/docs
+ WebDetection annotation = res.getWebDetection();
+ System.out.println("Entity:Id:Score");
+ System.out.println("===============");
+ for (WebEntity entity : annotation.getWebEntitiesList()) {
+ System.out.println(
+ entity.getDescription() + " : " + entity.getEntityId() + " : " + entity.getScore());
+ }
+ for (WebLabel label : annotation.getBestGuessLabelsList()) {
+ System.out.format("%nBest guess label: %s", label.getLabel());
+ }
+ System.out.println("%nPages with matching images: Score%n==");
+ for (WebPage page : annotation.getPagesWithMatchingImagesList()) {
+ System.out.println(page.getUrl() + " : " + page.getScore());
+ }
+ System.out.println("%nPages with partially matching images: Score%n==");
+ for (WebImage image : annotation.getPartialMatchingImagesList()) {
+ System.out.println(image.getUrl() + " : " + image.getScore());
+ }
+ System.out.println("%nPages with fully matching images: Score%n==");
+ for (WebImage image : annotation.getFullMatchingImagesList()) {
+ System.out.println(image.getUrl() + " : " + image.getScore());
+ }
+ System.out.println("%nPages with visually similar images: Score%n==");
+ for (WebImage image : annotation.getVisuallySimilarImagesList()) {
+ System.out.println(image.getUrl() + " : " + image.getScore());
+ }
+ }
+ }
+ }
+}
+// [END vision_web_detection]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebDetectionsGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebDetectionsGcs.java
new file mode 100644
index 00000000000..484a6711cc6
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebDetectionsGcs.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_web_detection_gcs]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import com.google.cloud.vision.v1.WebDetection;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DetectWebDetectionsGcs {
+
+ public static void detectWebDetectionsGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectWebDetectionsGcs(filePath);
+ }
+
+ // Detects whether the remote image on Google Cloud Storage has features you would want to
+ // moderate.
+ public static void detectWebDetectionsGcs(String gcsPath) throws IOException {
+ List requests = new ArrayList<>();
+
+ ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ Image img = Image.newBuilder().setSource(imgSource).build();
+ Feature feat = Feature.newBuilder().setType(Feature.Type.WEB_DETECTION).build();
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
+ requests.add(request);
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
+ List responses = response.getResponsesList();
+
+ for (AnnotateImageResponse res : responses) {
+ if (res.hasError()) {
+ System.out.format("Error: %s%n", res.getError().getMessage());
+ return;
+ }
+
+ // Search the web for usages of the image. You could use these signals later
+ // for user input moderation or linking external references.
+ // For a full list of available annotations, see http://g.co/cloud/vision/docs
+ WebDetection annotation = res.getWebDetection();
+ System.out.println("Entity:Id:Score");
+ System.out.println("===============");
+ for (WebDetection.WebEntity entity : annotation.getWebEntitiesList()) {
+ System.out.println(
+ entity.getDescription() + " : " + entity.getEntityId() + " : " + entity.getScore());
+ }
+ for (WebDetection.WebLabel label : annotation.getBestGuessLabelsList()) {
+ System.out.format("%nBest guess label: %s", label.getLabel());
+ }
+ System.out.println("%nPages with matching images: Score%n==");
+ for (WebDetection.WebPage page : annotation.getPagesWithMatchingImagesList()) {
+ System.out.println(page.getUrl() + " : " + page.getScore());
+ }
+ System.out.println("%nPages with partially matching images: Score%n==");
+ for (WebDetection.WebImage image : annotation.getPartialMatchingImagesList()) {
+ System.out.println(image.getUrl() + " : " + image.getScore());
+ }
+ System.out.println("%nPages with fully matching images: Score%n==");
+ for (WebDetection.WebImage image : annotation.getFullMatchingImagesList()) {
+ System.out.println(image.getUrl() + " : " + image.getScore());
+ }
+ System.out.println("%nPages with visually similar images: Score%n==");
+ for (WebDetection.WebImage image : annotation.getVisuallySimilarImagesList()) {
+ System.out.println(image.getUrl() + " : " + image.getScore());
+ }
+ }
+ }
+ }
+}
+// [END vision_web_detection_gcs]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntities.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntities.java
new file mode 100644
index 00000000000..c8e99065754
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntities.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_web_detection]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Feature.Type;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+public class DetectWebEntities {
+
+ public static void detectWebEntities() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectWebEntities(filePath);
+ }
+
+ // Find web entities given a local image.
+ public static void detectWebEntities(String filePath) throws IOException {
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ // Read in the local image
+ ByteString contents = ByteString.readFrom(new FileInputStream(filePath));
+
+ // Build the image
+ Image image = Image.newBuilder().setContent(contents).build();
+
+ // Create the request with the image and the specified feature: web detection
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder()
+ .addFeatures(Feature.newBuilder().setType(Type.WEB_DETECTION))
+ .setImage(image)
+ .build();
+
+ // Perform the request
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request));
+
+ // Display the results
+ response.getResponsesList().stream()
+ .forEach(
+ r ->
+ r.getWebDetection().getWebEntitiesList().stream()
+ .forEach(
+ entity -> {
+ System.out.format("Description: %s%n", entity.getDescription());
+ System.out.format("Score: %f%n", entity.getScore());
+ }));
+ }
+ }
+}
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntitiesGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntitiesGcs.java
new file mode 100644
index 00000000000..5e4fab05bc9
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntitiesGcs.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageSource;
+import java.io.IOException;
+import java.util.Arrays;
+
+public class DetectWebEntitiesGcs {
+
+ public static void detectWebEntitiesGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectWebEntitiesGcs(filePath);
+ }
+
+ // Find web entities given the remote image on Google Cloud Storage.
+ public static void detectWebEntitiesGcs(String gcsPath) throws IOException {
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ // Set the image source to the given gs uri
+ ImageSource imageSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ // Build the image
+ Image image = Image.newBuilder().setSource(imageSource).build();
+
+ // Create the request with the image and the specified feature: web detection
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder()
+ .addFeatures(Feature.newBuilder().setType(Feature.Type.WEB_DETECTION))
+ .setImage(image)
+ .build();
+
+ // Perform the request
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request));
+
+ // Display the results
+ response.getResponsesList().stream()
+ .forEach(
+ r ->
+ r.getWebDetection().getWebEntitiesList().stream()
+ .forEach(
+ entity -> {
+ System.out.format("Description: %s%n", entity.getDescription());
+ System.out.format("Score: %f%n", entity.getScore());
+ }));
+ }
+ }
+}
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntitiesIncludeGeoResults.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntitiesIncludeGeoResults.java
new file mode 100644
index 00000000000..f1a0f58c969
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntitiesIncludeGeoResults.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_web_detection_include_geo]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Feature.Type;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageContext;
+import com.google.cloud.vision.v1.WebDetectionParams;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+public class DetectWebEntitiesIncludeGeoResults {
+
+ public static void detectWebEntitiesIncludeGeoResults() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "path/to/your/image/file.jpg";
+ detectWebEntitiesIncludeGeoResults(filePath);
+ }
+
+ // Find web entities given a local image.
+ public static void detectWebEntitiesIncludeGeoResults(String filePath) throws IOException {
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ // Read in the local image
+ ByteString contents = ByteString.readFrom(new FileInputStream(filePath));
+
+ // Build the image
+ Image image = Image.newBuilder().setContent(contents).build();
+
+ // Enable `IncludeGeoResults`
+ WebDetectionParams webDetectionParams =
+ WebDetectionParams.newBuilder().setIncludeGeoResults(true).build();
+
+ // Set the parameters for the image
+ ImageContext imageContext =
+ ImageContext.newBuilder().setWebDetectionParams(webDetectionParams).build();
+
+ // Create the request with the image, imageContext, and the specified feature: web detection
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder()
+ .addFeatures(Feature.newBuilder().setType(Type.WEB_DETECTION))
+ .setImage(image)
+ .setImageContext(imageContext)
+ .build();
+
+ // Perform the request
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request));
+
+ // Display the results
+ response.getResponsesList().stream()
+ .forEach(
+ r ->
+ r.getWebDetection().getWebEntitiesList().stream()
+ .forEach(
+ entity -> {
+ System.out.format("Description: %s%n", entity.getDescription());
+ System.out.format("Score: %f%n", entity.getScore());
+ }));
+ }
+ }
+}
+// [END vision_web_detection_include_geo]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntitiesIncludeGeoResultsGcs.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntitiesIncludeGeoResultsGcs.java
new file mode 100644
index 00000000000..d6dc1941ea3
--- /dev/null
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/DetectWebEntitiesIncludeGeoResultsGcs.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision.snippets;
+
+// [START vision_web_detection_include_geo_gcs]
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageContext;
+import com.google.cloud.vision.v1.ImageSource;
+import com.google.cloud.vision.v1.WebDetectionParams;
+import java.io.IOException;
+import java.util.Arrays;
+
+public class DetectWebEntitiesIncludeGeoResultsGcs {
+
+ public static void detectWebEntitiesIncludeGeoResultsGcs() throws IOException {
+ // TODO(developer): Replace these variables before running the sample.
+ String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg";
+ detectWebEntitiesIncludeGeoResultsGcs(filePath);
+ }
+
+ // Find web entities given the remote image on Google Cloud Storage.
+ public static void detectWebEntitiesIncludeGeoResultsGcs(String gcsPath) throws IOException {
+
+ // Initialize client that will be used to send requests. This client only needs to be created
+ // once, and can be reused for multiple requests. After completing all of your requests, call
+ // the "close" method on the client to safely clean up any remaining background resources.
+ try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
+ // Set the image source to the given gs uri
+ ImageSource imageSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
+ // Build the image
+ Image image = Image.newBuilder().setSource(imageSource).build();
+
+ // Enable `IncludeGeoResults`
+ WebDetectionParams webDetectionParams =
+ WebDetectionParams.newBuilder().setIncludeGeoResults(true).build();
+
+ // Set the parameters for the image
+ ImageContext imageContext =
+ ImageContext.newBuilder().setWebDetectionParams(webDetectionParams).build();
+
+ // Create the request with the image, imageContext, and the specified feature: web detection
+ AnnotateImageRequest request =
+ AnnotateImageRequest.newBuilder()
+ .addFeatures(Feature.newBuilder().setType(Feature.Type.WEB_DETECTION))
+ .setImage(image)
+ .setImageContext(imageContext)
+ .build();
+
+ // Perform the request
+ BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request));
+
+ // Display the results
+ response.getResponsesList().stream()
+ .forEach(
+ r ->
+ r.getWebDetection().getWebEntitiesList().stream()
+ .forEach(
+ entity -> {
+ System.out.format("Description: %s%n", entity.getDescription());
+ System.out.format("Score: %f%n", entity.getScore());
+ }));
+ }
+ }
+}
+// [END vision_web_detection_include_geo_gcs]
diff --git a/vision/cloud-client/src/main/java/com/example/vision/SetEndpoint.java b/vision/cloud-client/src/main/java/com/example/vision/snippets/SetEndpoint.java
similarity index 91%
rename from vision/cloud-client/src/main/java/com/example/vision/SetEndpoint.java
rename to vision/cloud-client/src/main/java/com/example/vision/snippets/SetEndpoint.java
index 22eed6813d4..7aeb05abb70 100644
--- a/vision/cloud-client/src/main/java/com/example/vision/SetEndpoint.java
+++ b/vision/cloud-client/src/main/java/com/example/vision/snippets/SetEndpoint.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.example.vision;
+package com.example.vision.snippets;
import com.google.cloud.vision.v1.AnnotateImageRequest;
import com.google.cloud.vision.v1.AnnotateImageResponse;
@@ -29,10 +29,10 @@
import java.util.ArrayList;
import java.util.List;
-class SetEndpoint {
+public class SetEndpoint {
// Change your endpoint
- static void setEndpoint() throws IOException {
+ public static void setEndpoint() throws IOException {
// [START vision_set_endpoint]
ImageAnnotatorSettings settings =
ImageAnnotatorSettings.newBuilder().setEndpoint("eu-vision.googleapis.com:443").build();
@@ -58,9 +58,9 @@ static void setEndpoint() throws IOException {
for (AnnotateImageResponse response : batchResponse.getResponsesList()) {
for (EntityAnnotation annotation : response.getTextAnnotationsList()) {
- System.out.printf("Text: %s\n", annotation.getDescription());
+ System.out.format("Text: %s%n", annotation.getDescription());
System.out.println("Position:");
- System.out.printf("%s\n", annotation.getBoundingPoly());
+ System.out.format("%s%n", annotation.getBoundingPoly());
}
}
client.close();
diff --git a/vision/cloud-client/src/test/java/com/example/vision/AsyncBatchAnnotateImagesTest.java b/vision/cloud-client/src/test/java/com/example/vision/AsyncBatchAnnotateImagesTest.java
index 8edc89828fb..aa05841ed45 100644
--- a/vision/cloud-client/src/test/java/com/example/vision/AsyncBatchAnnotateImagesTest.java
+++ b/vision/cloud-client/src/test/java/com/example/vision/AsyncBatchAnnotateImagesTest.java
@@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.assertNotNull;
+import com.example.vision.snippets.AsyncBatchAnnotateImages;
import com.google.api.gax.paging.Page;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.Storage;
diff --git a/vision/cloud-client/src/test/java/com/example/vision/BatchAnnotateFilesGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/BatchAnnotateFilesGcsTest.java
index 5f1c1e043a3..f8ff793559d 100644
--- a/vision/cloud-client/src/test/java/com/example/vision/BatchAnnotateFilesGcsTest.java
+++ b/vision/cloud-client/src/test/java/com/example/vision/BatchAnnotateFilesGcsTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import com.example.vision.snippets.BatchAnnotateFilesGcs;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
diff --git a/vision/cloud-client/src/test/java/com/example/vision/BatchAnnotateFilesTest.java b/vision/cloud-client/src/test/java/com/example/vision/BatchAnnotateFilesTest.java
index 621aba76798..f08718981ca 100644
--- a/vision/cloud-client/src/test/java/com/example/vision/BatchAnnotateFilesTest.java
+++ b/vision/cloud-client/src/test/java/com/example/vision/BatchAnnotateFilesTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import com.example.vision.snippets.BatchAnnotateFiles;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
diff --git a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/ModelApiIT.java b/vision/cloud-client/src/test/java/com/example/vision/DetectCropHintsGcsTest.java
similarity index 51%
rename from vision/automl/src/test/java/com/google/cloud/vision/samples/automl/ModelApiIT.java
rename to vision/cloud-client/src/test/java/com/example/vision/DetectCropHintsGcsTest.java
index 164c5e9586e..acbf5503d44 100644
--- a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/ModelApiIT.java
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectCropHintsGcsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Google Inc.
+ * Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,32 +14,31 @@
* limitations under the License.
*/
-package com.google.cloud.vision.samples.automl;
+package com.example.vision;
import static com.google.common.truth.Truth.assertThat;
+import com.example.vision.snippets.DetectCropHintsGcs;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.util.regex.Pattern;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/** Tests for vision "Model API" sample. */
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
-public class ModelApiIT {
- private static final String PROJECT_ID = "java-docs-samples-testing";
- private static final String COMPUTE_REGION = "us-central1";
+public class DetectCropHintsGcsTest {
+
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
private ByteArrayOutputStream bout;
private PrintStream out;
- private String modelId;
- private String modelEvaluationId;
@Before
public void setUp() {
-
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);
@@ -51,35 +50,14 @@ public void tearDown() {
}
@Test
- public void testModelApi() {
+ public void testCropHintsGcs() throws Exception {
// Act
- ModelApi.listModels(PROJECT_ID, COMPUTE_REGION, "");
+ DetectCropHintsGcs.detectCropHintsGcs("gs://" + ASSET_BUCKET + "/vision/label/wakeupcat.jpg");
// Assert
String got = bout.toString();
- modelId = got.split("\n")[1].split("/")[got.split("\n")[1].split("/").length - 1];
- assertThat(got).contains("Model id:");
-
- // Act
- ModelApi.getModel(PROJECT_ID, COMPUTE_REGION, modelId);
-
- // Assert
- got = bout.toString();
- assertThat(got).contains("Model name:");
-
- // Act
- ModelApi.listModelEvaluations(PROJECT_ID, COMPUTE_REGION, modelId, "");
-
- // Assert
- got = bout.toString();
- modelEvaluationId = got.split("List of model evaluations:")[1].split("\"")[1].split("/")[7];
- assertThat(got).contains("name:");
-
- // Act
- ModelApi.getModelEvaluation(PROJECT_ID, COMPUTE_REGION, modelId, modelEvaluationId);
-
- // Assert
- got = bout.toString();
- assertThat(got).contains("name:");
+ assertThat(got).contains("vertices {");
+ assertThat(got).containsMatch(Pattern.compile("x: 2\\d{2}"));
+ assertThat(got).containsMatch(Pattern.compile("y: 4\\d{2}"));
}
}
diff --git a/bigquery/bigquerystorage/src/test/java/com/example/bigquerystorage/QuickstartArrowSampleIT.java b/vision/cloud-client/src/test/java/com/example/vision/DetectCropHintsTest.java
similarity index 71%
rename from bigquery/bigquerystorage/src/test/java/com/example/bigquerystorage/QuickstartArrowSampleIT.java
rename to vision/cloud-client/src/test/java/com/example/vision/DetectCropHintsTest.java
index faffde73304..2a6b11c2b6d 100644
--- a/bigquery/bigquerystorage/src/test/java/com/example/bigquerystorage/QuickstartArrowSampleIT.java
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectCropHintsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 Google Inc.
+ * Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,24 +14,23 @@
* limitations under the License.
*/
-package com.example.bigquerystorage;
+package com.example.vision;
import static com.google.common.truth.Truth.assertThat;
+import com.example.vision.snippets.DetectCropHints;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.util.regex.Pattern;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/** Tests for quickstart sample. */
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
-public class QuickstartArrowSampleIT {
- private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
-
+public class DetectCropHintsTest {
private ByteArrayOutputStream bout;
private PrintStream out;
@@ -48,11 +47,14 @@ public void tearDown() {
}
@Test
- public void testQuickstart() throws Exception {
- StorageArrowSample.main(PROJECT_ID);
+ public void testCropHints() throws Exception {
+ // Act
+ DetectCropHints.detectCropHints("./resources/wakeupcat.jpg");
+
+ // Assert
String got = bout.toString();
- // Ensure at least 1k of output generated and a specific token was present in the output.
- assertThat(bout.size()).isGreaterThan(1024);
- assertThat(got).contains("Zayvion");
+ assertThat(got).contains("vertices {");
+ assertThat(got).containsMatch(Pattern.compile("x: 2\\d{2}"));
+ assertThat(got).containsMatch(Pattern.compile("y: 4\\d{2}"));
}
}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectFacesGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectFacesGcsTest.java
new file mode 100644
index 00000000000..8de0dac2d22
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectFacesGcsTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectFacesGcs;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectFacesGcsTest {
+
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testFaces() throws Exception {
+ // Act
+ DetectFacesGcs.detectFacesGcs("gs://" + ASSET_BUCKET + "/vision/face/face_no_surprise.jpg");
+
+ // Assert
+ String got = bout.toString();
+ assertThat(got).contains("anger:");
+ assertThat(got).contains("joy:");
+ assertThat(got).contains("surprise:");
+ }
+}
diff --git a/bigquery/bigquerystorage/src/test/java/com/example/bigquerystorage/QuickstartSampleIT.java b/vision/cloud-client/src/test/java/com/example/vision/DetectFacesTest.java
similarity index 71%
rename from bigquery/bigquerystorage/src/test/java/com/example/bigquerystorage/QuickstartSampleIT.java
rename to vision/cloud-client/src/test/java/com/example/vision/DetectFacesTest.java
index a3a18e72201..d009212739d 100644
--- a/bigquery/bigquerystorage/src/test/java/com/example/bigquerystorage/QuickstartSampleIT.java
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectFacesTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 Google Inc.
+ * Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-package com.example.bigquerystorage;
+package com.example.vision;
import static com.google.common.truth.Truth.assertThat;
+import com.example.vision.snippets.DetectFaces;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.After;
@@ -26,12 +27,9 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/** Tests for quickstart sample. */
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
-public class QuickstartSampleIT {
- private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
-
+public class DetectFacesTest {
private ByteArrayOutputStream bout;
private PrintStream out;
@@ -48,11 +46,14 @@ public void tearDown() {
}
@Test
- public void testQuickstart() throws Exception {
- StorageSample.main(PROJECT_ID);
+ public void testFaces() throws Exception {
+ // Act
+ DetectFaces.detectFaces("./resources/face_no_surprise.jpg");
+
+ // Assert
String got = bout.toString();
- // Ensure at least 1k of output generated and a specific token was present in the output.
- assertThat(bout.size()).isGreaterThan(1024);
- assertThat(got).contains("Zayvion");
+ assertThat(got).contains("anger:");
+ assertThat(got).contains("joy:");
+ assertThat(got).contains("surprise:");
}
}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectIT.java b/vision/cloud-client/src/test/java/com/example/vision/DetectIT.java
index ad3c19d85a5..6ccdcf7eb6b 100644
--- a/vision/cloud-client/src/test/java/com/example/vision/DetectIT.java
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectIT.java
@@ -26,7 +26,6 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.UUID;
-import java.util.regex.Pattern;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -39,8 +38,8 @@
public class DetectIT {
private ByteArrayOutputStream bout;
private PrintStream out;
- private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String ASSET_BUCKET = "cloud-samples-data";
+ private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String OUTPUT_BUCKET = PROJECT_ID;
private static final String OUTPUT_PREFIX = "OCR_PDF_TEST_OUTPUT_" + UUID.randomUUID().toString();
@@ -56,285 +55,10 @@ public void tearDown() {
System.setOut(null);
}
- @Test
- public void testFaces() throws Exception {
- // Act
- String[] args = {"faces", "./resources/face_no_surprise.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString();
- assertThat(got).contains("anger:");
- assertThat(got).contains("joy:");
- assertThat(got).contains("surprise:");
- }
-
- @Test
- public void testFacesGcs() throws Exception {
- // Act
- String[] args = {"faces", "gs://" + ASSET_BUCKET + "/vision/face/face_no_surprise.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString();
- assertThat(got).contains("anger:");
- assertThat(got).contains("joy:");
- assertThat(got).contains("surprise:");
- }
-
- @Test
- public void testLabels() throws Exception {
- // Act
- String[] args = {"labels", "./resources/wakeupcat.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("whiskers");
- }
-
- @Test
- public void testLabelsGcs() throws Exception {
- // Act
- String[] args = {"labels", "gs://" + ASSET_BUCKET + "/vision/label/wakeupcat.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("whiskers");
- }
-
- @Test
- public void testLandmarks() throws Exception {
- // Act
- String[] args = {"landmarks", "./resources/landmark.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("palace of fine arts");
- }
-
- @Test
- public void testLandmarksGcs() throws Exception {
- // Act
- String[] args = {"landmarks", "gs://" + ASSET_BUCKET + "/vision/landmark/pofa.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("palace of fine arts");
- }
-
- @Test
- public void testLandmarksUrl() throws Exception {
- // Act
- String uri =
- "https://storage-download.googleapis.com/" + ASSET_BUCKET + "/vision/landmark/pofa.jpg";
- String[] args = {"landmarks", uri};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("palace of fine arts");
- }
-
- @Test
- public void testLogos() throws Exception {
- // Act
- String[] args = {"logos", "./resources/logos.png"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("google");
- }
-
- @Test
- public void testLogosGcs() throws Exception {
- // Act
- String[] args = {"logos", "gs://" + ASSET_BUCKET + "/vision/logo/logo_google.png"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("google");
- }
-
- @Test
- public void testText() throws Exception {
- // Act
- String[] args = {"text", "./resources/text.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString();
- assertThat(got).contains("37%");
- }
-
- @Test
- public void testTextGcs() throws Exception {
- // Act
- String[] args = {"text", "gs://" + ASSET_BUCKET + "/vision/text/screen.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString();
- assertThat(got).contains("37%");
- }
-
- @Test
- public void testSafeSearch() throws Exception {
- // Act
- String[] args = {"safe-search", "./resources/wakeupcat.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString();
- assertThat(got).contains("adult:");
- assertThat(got).contains("racy:");
- }
-
- @Test
- public void testSafeSearchGcs() throws Exception {
- // Act
- String[] args = {"safe-search", "gs://" + ASSET_BUCKET + "/vision/label/wakeupcat.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString();
- assertThat(got).contains("adult:");
- assertThat(got).contains("racy:");
- }
-
- @Test
- public void testProperties() throws Exception {
- // Act
- String[] args = {"properties", "./resources/landmark.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString();
- assertThat(got).contains("fraction:");
- assertThat(got).contains("r:");
- assertThat(got).contains("g:");
- assertThat(got).contains("b:");
- }
-
- @Test
- public void testPropertiesGcs() throws Exception {
- // Act
- String[] args = {"properties", "gs://" + ASSET_BUCKET + "/vision/landmark/pofa.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString();
- assertThat(got).contains("fraction:");
- assertThat(got).contains("r:");
- assertThat(got).contains("g:");
- assertThat(got).contains("b:");
- }
-
- @Test
- public void detectWebAnnotations() throws Exception {
- // Act
- String[] args = {"web", "./resources/landmark.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("entity:id:score");
- assertThat(got).contains("best guess label");
- }
-
- @Test
- public void detectWebAnnotationsGcs() throws Exception {
- // Act
- String[] args = {"web", "gs://" + ASSET_BUCKET + "/vision/landmark/pofa.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("entity:id:score");
- assertThat(got).contains("best guess label");
- }
-
- @Test
- public void testDetectWebEntities() throws Exception {
- // Act
- String[] args = {"web-entities", "./resources/city.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- assertThat(got).doesNotContain("zepra");
- }
-
- @Test
- public void testDetectWebEntitiesGcs() throws Exception {
- // Act
- String[] args = {"web-entities", "gs://" + ASSET_BUCKET + "/vision/landmark/pofa.jpg"};
- Detect.argsHelper(args, out);
-
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("description");
- }
-
- @Test
- public void testDetectWebEntitiesIncludeGeoResults() throws Exception {
- // Act
- String[] args = {"web-entities-include-geo", "./resources/city.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString().toLowerCase();
- // Note: entities and labels can change over time.
- assertThat(got).doesNotContain("error");
- }
-
- @Test
- public void testDetectWebEntitiesIncludeGeoResultsGcs() throws Exception {
- // Act
- String[] args = {
- "web-entities-include-geo", "gs://" + ASSET_BUCKET + "/vision/landmark/pofa.jpg"
- };
- Detect.argsHelper(args, out);
-
- String got = bout.toString().toLowerCase();
- assertThat(got).contains("description");
- }
-
- @Test
- public void testCropHints() throws Exception {
- // Act
- String[] args = {"crop", "./resources/wakeupcat.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString();
- assertThat(got).contains("vertices {");
- assertThat(got).containsMatch(Pattern.compile("x: 2\\d{2}"));
- assertThat(got).containsMatch(Pattern.compile("y: 4\\d{2}"));
- }
-
- @Test
- public void testCropHintsGcs() throws Exception {
- // Act
- String[] args = {"crop", "gs://" + ASSET_BUCKET + "/vision/label/wakeupcat.jpg"};
- Detect.argsHelper(args, out);
-
- // Assert
- String got = bout.toString();
- assertThat(got).contains("vertices {");
- assertThat(got).containsMatch(Pattern.compile("x: 2\\d{2}"));
- assertThat(got).containsMatch(Pattern.compile("y: 4\\d{2}"));
- }
-
@Test
public void testDocumentText() throws Exception {
// Act
- String[] args = {"fulltext", "./resources/text.jpg"};
- Detect.argsHelper(args, out);
+ Detect.detectDocumentText("./resources/text.jpg");
// Assert
String got = bout.toString();
@@ -346,8 +70,7 @@ public void testDocumentText() throws Exception {
@Test
public void testDocumentTextGcs() throws Exception {
// Act
- String[] args = {"fulltext", "gs://" + ASSET_BUCKET + "/vision/text/screen.jpg"};
- Detect.argsHelper(args, out);
+ Detect.detectDocumentTextGcs("gs://" + ASSET_BUCKET + "/vision/text/screen.jpg");
// Assert
String got = bout.toString();
@@ -359,12 +82,9 @@ public void testDocumentTextGcs() throws Exception {
@Test
public void testDetectDocumentsGcs() throws Exception {
// Act
- String[] args = {
- "ocr",
- "gs://" + ASSET_BUCKET + "/vision/document/custom_0773375000.pdf",
- "gs://" + OUTPUT_BUCKET + "/" + OUTPUT_PREFIX + "/"
- };
- Detect.argsHelper(args, out);
+ Detect.detectDocumentsGcs(
+ "gs://" + ASSET_BUCKET + "/vision/document/custom_0773375000.pdf",
+ "gs://" + OUTPUT_BUCKET + "/" + OUTPUT_PREFIX + "/");
// Assert
String got = bout.toString();
@@ -386,8 +106,7 @@ public void testDetectDocumentsGcs() throws Exception {
@Test
public void testDetectLocalizedObjects() throws Exception {
// Act
- String[] args = {"object-localization", "./resources/puppies.jpg"};
- Detect.argsHelper(args, out);
+ Detect.detectLocalizedObjects("./resources/puppies.jpg");
// Assert
String got = bout.toString().toLowerCase();
@@ -397,10 +116,8 @@ public void testDetectLocalizedObjects() throws Exception {
@Test
public void testDetectLocalizedObjectsGcs() throws Exception {
// Act
- String[] args = {
- "object-localization", "gs://cloud-samples-data/vision/object_localization/puppies.jpg"
- };
- Detect.argsHelper(args, out);
+ Detect.detectLocalizedObjectsGcs(
+ "gs://cloud-samples-data/vision/object_localization/puppies.jpg");
// Assert
String got = bout.toString().toLowerCase();
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectLabelsGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectLabelsGcsTest.java
new file mode 100644
index 00000000000..9ddb0e2e515
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectLabelsGcsTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectLabelsGcs;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectLabelsGcsTest {
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testLabelsGcs() throws Exception {
+ // Act
+ DetectLabelsGcs.detectLabelsGcs("gs://" + ASSET_BUCKET + "/vision/label/wakeupcat.jpg");
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("whiskers");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectLabelsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectLabelsTest.java
new file mode 100644
index 00000000000..741b2f63142
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectLabelsTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectLabels;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectLabelsTest {
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testLabels() throws Exception {
+ // Act
+ DetectLabels.detectLabels("./resources/wakeupcat.jpg");
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("whiskers");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectLandmarksGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectLandmarksGcsTest.java
new file mode 100644
index 00000000000..ef9e4c5ca9e
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectLandmarksGcsTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectLandmarksGcs;
+import com.example.vision.snippets.DetectLandmarksUrl;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectLandmarksGcsTest {
+
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testLandmarksUrl() throws Exception {
+ // Act
+ String uri =
+ "https://storage-download.googleapis.com/" + ASSET_BUCKET + "/vision/landmark/pofa.jpg";
+ DetectLandmarksUrl.detectLandmarksUrl(uri);
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("palace of fine arts");
+ }
+
+ @Test
+ public void testLandmarksGcs() throws Exception {
+ // Act
+ DetectLandmarksGcs.detectLandmarksGcs("gs://" + ASSET_BUCKET + "/vision/landmark/pofa.jpg");
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("palace of fine arts");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectLandmarksTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectLandmarksTest.java
new file mode 100644
index 00000000000..d937a7f11c8
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectLandmarksTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectLandmarks;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectLandmarksTest {
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testLandmarks() throws Exception {
+ // Act
+ DetectLandmarks.detectLandmarks("./resources/landmark.jpg");
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("palace of fine arts");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectLogosGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectLogosGcsTest.java
new file mode 100644
index 00000000000..1f6cd1c5201
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectLogosGcsTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectLogosGcs;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectLogosGcsTest {
+
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testLogosGcs() throws Exception {
+ // Act
+ DetectLogosGcs.detectLogosGcs("gs://" + ASSET_BUCKET + "/vision/logo/logo_google.png");
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("google");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectLogosTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectLogosTest.java
new file mode 100644
index 00000000000..ed3cf7f41ce
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectLogosTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectLogos;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectLogosTest {
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testLogos() throws Exception {
+ // Act
+ DetectLogos.detectLogos("./resources/logos.png");
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("google");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectPropertiesGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectPropertiesGcsTest.java
new file mode 100644
index 00000000000..c0ff61caa05
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectPropertiesGcsTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectPropertiesGcs;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectPropertiesGcsTest {
+
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testPropertiesGcs() throws Exception {
+ // Act
+ DetectPropertiesGcs.detectPropertiesGcs("gs://" + ASSET_BUCKET + "/vision/landmark/pofa.jpg");
+
+ // Assert
+ String got = bout.toString();
+ assertThat(got).contains("fraction:");
+ assertThat(got).contains("r:");
+ assertThat(got).contains("g:");
+ assertThat(got).contains("b:");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectPropertiesTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectPropertiesTest.java
new file mode 100644
index 00000000000..e591bf01128
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectPropertiesTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectProperties;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectPropertiesTest {
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testProperties() throws Exception {
+ // Act
+ DetectProperties.detectProperties("./resources/landmark.jpg");
+
+ // Assert
+ String got = bout.toString();
+ assertThat(got).contains("fraction:");
+ assertThat(got).contains("r:");
+ assertThat(got).contains("g:");
+ assertThat(got).contains("b:");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectSafeSearchGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectSafeSearchGcsTest.java
new file mode 100644
index 00000000000..6939b7a1c9b
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectSafeSearchGcsTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectSafeSearchGcs;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectSafeSearchGcsTest {
+
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testSafeSearchGcs() throws Exception {
+ // Act
+ DetectSafeSearchGcs.detectSafeSearchGcs("gs://" + ASSET_BUCKET + "/vision/label/wakeupcat.jpg");
+
+ // Assert
+ String got = bout.toString();
+ assertThat(got).contains("adult:");
+ assertThat(got).contains("racy:");
+ }
+}
diff --git a/bigquery/datatransfer/cloud-client/src/test/java/com/example/bigquerydatatransfer/QuickstartSampleIT.java b/vision/cloud-client/src/test/java/com/example/vision/DetectSafeSearchTest.java
similarity index 76%
rename from bigquery/datatransfer/cloud-client/src/test/java/com/example/bigquerydatatransfer/QuickstartSampleIT.java
rename to vision/cloud-client/src/test/java/com/example/vision/DetectSafeSearchTest.java
index bc0c457c5d2..abdd1d99bf7 100644
--- a/bigquery/datatransfer/cloud-client/src/test/java/com/example/bigquerydatatransfer/QuickstartSampleIT.java
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectSafeSearchTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Google Inc.
+ * Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-package com.example.bigquerydatatransfer;
+package com.example.vision;
import static com.google.common.truth.Truth.assertThat;
+import com.example.vision.snippets.DetectSafeSearch;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.After;
@@ -26,12 +27,9 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/** Tests for quickstart sample. */
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
-public class QuickstartSampleIT {
- private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
-
+public class DetectSafeSearchTest {
private ByteArrayOutputStream bout;
private PrintStream out;
@@ -48,9 +46,13 @@ public void tearDown() {
}
@Test
- public void testQuickstart() throws Exception {
- QuickstartSample.main(PROJECT_ID);
+ public void testSafeSearch() throws Exception {
+ // Act
+ DetectSafeSearch.detectSafeSearch("./resources/wakeupcat.jpg");
+
+ // Assert
String got = bout.toString();
- assertThat(got).contains("Supported Data Sources:");
+ assertThat(got).contains("adult:");
+ assertThat(got).contains("racy:");
}
}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectTextGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectTextGcsTest.java
new file mode 100644
index 00000000000..7ec54a14fa8
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectTextGcsTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectTextGcs;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectTextGcsTest {
+
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testTextGcs() throws Exception {
+ // Act
+ DetectTextGcs.detectTextGcs("gs://" + ASSET_BUCKET + "/vision/text/screen.jpg");
+
+ // Assert
+ String got = bout.toString();
+ assertThat(got).contains("37%");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectTextTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectTextTest.java
new file mode 100644
index 00000000000..c55c0f4e24e
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectTextTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectText;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectTextTest {
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testText() throws Exception {
+ // Act
+ DetectText.detectText("./resources/text.jpg");
+
+ // Assert
+ String got = bout.toString();
+ assertThat(got).contains("37%");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectWebDetectionsGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectWebDetectionsGcsTest.java
new file mode 100644
index 00000000000..9829294257a
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectWebDetectionsGcsTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectWebDetectionsGcs;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectWebDetectionsGcsTest {
+
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDetectWebAnnotationsGcs() throws Exception {
+ // Act
+ DetectWebDetectionsGcs.detectWebDetectionsGcs(
+ "gs://" + ASSET_BUCKET + "/vision/landmark/pofa.jpg");
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("entity:id:score");
+ assertThat(got).contains("best guess label");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectWebDetectionsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectWebDetectionsTest.java
new file mode 100644
index 00000000000..d0cc10b53d7
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectWebDetectionsTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectWebDetections;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectWebDetectionsTest {
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void detectWebAnnotations() throws Exception {
+ // Act
+ DetectWebDetections.detectWebDetections("./resources/landmark.jpg");
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("entity:id:score");
+ assertThat(got).contains("best guess label");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesGcsTest.java
new file mode 100644
index 00000000000..596451bf79a
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesGcsTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectWebEntitiesGcs;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectWebEntitiesGcsTest {
+
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDetectWebEntitiesGcs() throws Exception {
+ // Act
+ DetectWebEntitiesGcs.detectWebEntitiesGcs("gs://" + ASSET_BUCKET + "/vision/landmark/pofa.jpg");
+
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("description");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesIncludeGeoResultsGcsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesIncludeGeoResultsGcsTest.java
new file mode 100644
index 00000000000..bedd5bde23f
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesIncludeGeoResultsGcsTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectWebEntitiesIncludeGeoResultsGcs;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectWebEntitiesIncludeGeoResultsGcsTest {
+
+ private static final String ASSET_BUCKET = "cloud-samples-data";
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDetectWebEntitiesIncludeGeoResultsGcs() throws Exception {
+ // Act
+ DetectWebEntitiesIncludeGeoResultsGcs.detectWebEntitiesIncludeGeoResultsGcs(
+ "gs://" + ASSET_BUCKET + "/vision/landmark/pofa.jpg");
+
+ String got = bout.toString().toLowerCase();
+ assertThat(got).contains("description");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesIncludeGeoResultsTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesIncludeGeoResultsTest.java
new file mode 100644
index 00000000000..b455c761d96
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesIncludeGeoResultsTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectWebEntitiesIncludeGeoResults;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectWebEntitiesIncludeGeoResultsTest {
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDetectWebEntitiesIncludeGeoResults() throws Exception {
+ // Act
+ DetectWebEntitiesIncludeGeoResults.detectWebEntitiesIncludeGeoResults("./resources/city.jpg");
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ // Note: entities and labels can change over time.
+ assertThat(got).doesNotContain("error");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesTest.java b/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesTest.java
new file mode 100644
index 00000000000..f2a37676bdc
--- /dev/null
+++ b/vision/cloud-client/src/test/java/com/example/vision/DetectWebEntitiesTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.example.vision;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.example.vision.snippets.DetectWebEntities;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectWebEntitiesTest {
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDetectWebEntities() throws Exception {
+ // Act
+ DetectWebEntities.detectWebEntities("./resources/city.jpg");
+
+ // Assert
+ String got = bout.toString().toLowerCase();
+ assertThat(got).doesNotContain("zepra");
+ }
+}
diff --git a/vision/cloud-client/src/test/java/com/example/vision/SetEndpointIT.java b/vision/cloud-client/src/test/java/com/example/vision/SetEndpointIT.java
index 9b27ea7d7de..1f648f54494 100644
--- a/vision/cloud-client/src/test/java/com/example/vision/SetEndpointIT.java
+++ b/vision/cloud-client/src/test/java/com/example/vision/SetEndpointIT.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import com.example.vision.snippets.SetEndpoint;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
diff --git a/vision/face-detection/pom.xml b/vision/face-detection/pom.xml
index 5fa31ffc081..c5664cc7ddc 100644
--- a/vision/face-detection/pom.xml
+++ b/vision/face-detection/pom.xml
@@ -28,7 +28,7 @@
com.google.cloud.samples
shared-configuration
- 1.0.17
+ 1.0.18
@@ -41,18 +41,12 @@
com.google.apis
google-api-services-vision
- v1-rev20200405-1.30.9
+ v1-rev20200612-1.30.9
- com.google.api-client
- google-api-client
- 1.30.9
-
-
-