diff --git a/.travis.yml b/.travis.yml index 3cea8e9d2a1..128e302fb89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Copyright 2016 Google Inc. All Rights Reserved. +# 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. diff --git a/README.md b/README.md index 40352cb272d..61281c1f694 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,41 @@ This is a repository that contains java code snippets on [Cloud Platform Documentation](https://cloud.google.com/docs/). +The repo is organized as follows: + +* [App Engine Standard](appengine) + * [TaskQueue](taskqueue) + * [Unit Tests](unittests) +* [App Engine Flexible](flexible) +* [Compute Engine](compute) + +Technology Samples: + +* [Bigquery](bigquery) +* [Datastore](datastore) +* [Endpoints](endpoints) +* [Key Management Service](kms) +* [Logging](logging) +* [Monitoring](monitoring) +* [Natural Language](language) +* [PubSub](pubsub) +* [Cloud Spanner](spanner) +* [Speech](speech) +* [Cloud Storage](storage) +* [Translate](translate) +* [Vision](vision) + +## Credentials Example + +The documentation for [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials). + +`BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();` + +The client library looks for credentials using the following rules: + +1. `GOOGLE_APPLICATION_CREDENTIALS` environment variable, pointing to a service account key JSON file path. +2. Cloud SDK credentials `gcloud auth application-default login` +3. App Engine standard environment credentials. +4. Compute Engine credentials. + +You can override this behavior using setCredentials in `BigQueryOptions.newBuilder()` by adding `setCredentials(Credentials credentials)` from [ServiceOptions.builder](http://googlecloudplatform.github.io/google-cloud-java/0.12.0/apidocs/com/google/cloud/ServiceOptions.Builder.html#setCredentials-com.google.auth.Credentials-) and [Credentials](http://google.github.io/google-auth-library-java/releases/0.6.0/apidocs/com/google/auth/Credentials.html?is-external=true). diff --git a/appengine/.gitignore b/appengine/.gitignore index 453750bc157..c94f025e98b 100644 --- a/appengine/.gitignore +++ b/appengine/.gitignore @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. All Rights Reserved. +# Copyright 2015 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 diff --git a/appengine/analytics/src/main/java/com/example/appengine/analytics/AnalyticsServlet.java b/appengine/analytics/src/main/java/com/example/appengine/analytics/AnalyticsServlet.java index ee8f5a678c4..4fd2d6186b6 100644 --- a/appengine/analytics/src/main/java/com/example/appengine/analytics/AnalyticsServlet.java +++ b/appengine/analytics/src/main/java/com/example/appengine/analytics/AnalyticsServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/appengine/analytics/src/main/webapp/WEB-INF/appengine-web.xml b/appengine/analytics/src/main/webapp/WEB-INF/appengine-web.xml index efa1efaa42f..68ee6e05f5e 100644 --- a/appengine/analytics/src/main/webapp/WEB-INF/appengine-web.xml +++ b/appengine/analytics/src/main/webapp/WEB-INF/appengine-web.xml @@ -1,7 +1,7 @@ mysql mysql-connector-java - 5.1.40 + 6.0.5 com.google.cloud.sql diff --git a/appengine/cloudsql/src/main/java/com/example/appengine/cloudsql/CloudSqlServlet.java b/appengine/cloudsql/src/main/java/com/example/appengine/cloudsql/CloudSqlServlet.java index da3ada939cb..9e09fbede8e 100644 --- a/appengine/cloudsql/src/main/java/com/example/appengine/cloudsql/CloudSqlServlet.java +++ b/appengine/cloudsql/src/main/java/com/example/appengine/cloudsql/CloudSqlServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/appengine/cloudsql/src/main/webapp/WEB-INF/appengine-web.xml b/appengine/cloudsql/src/main/webapp/WEB-INF/appengine-web.xml index 2ca4fde21ca..731d5aa24ed 100644 --- a/appengine/cloudsql/src/main/webapp/WEB-INF/appengine-web.xml +++ b/appengine/cloudsql/src/main/webapp/WEB-INF/appengine-web.xml @@ -1,6 +1,6 @@ + diff --git a/appengine/datastore/indexes-exploding/src/main/webapp/WEB-INF/web.xml b/appengine/datastore/indexes-exploding/src/main/webapp/WEB-INF/web.xml index 049fd7a05e7..6af27edbd87 100644 --- a/appengine/datastore/indexes-exploding/src/main/webapp/WEB-INF/web.xml +++ b/appengine/datastore/indexes-exploding/src/main/webapp/WEB-INF/web.xml @@ -1,6 +1,6 @@ + diff --git a/appengine/datastore/indexes/src/main/webapp/WEB-INF/web.xml b/appengine/datastore/indexes/src/main/webapp/WEB-INF/web.xml index 049fd7a05e7..6af27edbd87 100644 --- a/appengine/datastore/indexes/src/main/webapp/WEB-INF/web.xml +++ b/appengine/datastore/indexes/src/main/webapp/WEB-INF/web.xml @@ -1,6 +1,6 @@ javax.servlet servlet-api - 2.5 + 3.0-alpha-1 jar provided diff --git a/appengine/twilio/src/main/java/com/example/appengine/twilio/ReceiveCallServlet.java b/appengine/twilio/src/main/java/com/example/appengine/twilio/ReceiveCallServlet.java index 1332a62b08f..1e5aabda0cf 100644 --- a/appengine/twilio/src/main/java/com/example/appengine/twilio/ReceiveCallServlet.java +++ b/appengine/twilio/src/main/java/com/example/appengine/twilio/ReceiveCallServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/appengine/twilio/src/main/java/com/example/appengine/twilio/ReceiveSmsServlet.java b/appengine/twilio/src/main/java/com/example/appengine/twilio/ReceiveSmsServlet.java index cd99f8f083c..aa7bb6db308 100644 --- a/appengine/twilio/src/main/java/com/example/appengine/twilio/ReceiveSmsServlet.java +++ b/appengine/twilio/src/main/java/com/example/appengine/twilio/ReceiveSmsServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/appengine/twilio/src/main/java/com/example/appengine/twilio/SendSmsServlet.java b/appengine/twilio/src/main/java/com/example/appengine/twilio/SendSmsServlet.java index da6ecb0c941..6cb0c30a46e 100644 --- a/appengine/twilio/src/main/java/com/example/appengine/twilio/SendSmsServlet.java +++ b/appengine/twilio/src/main/java/com/example/appengine/twilio/SendSmsServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/appengine/twilio/src/main/webapp/WEB-INF/appengine-web.xml b/appengine/twilio/src/main/webapp/WEB-INF/appengine-web.xml index 34cd5e0b3ad..ffb8546d95f 100644 --- a/appengine/twilio/src/main/webapp/WEB-INF/appengine-web.xml +++ b/appengine/twilio/src/main/webapp/WEB-INF/appengine-web.xml @@ -1,6 +1,6 @@ - com.google.guava - guava-jdk5 - - - - - com.google.guava - guava - 20.0 - - - com.google.oauth-client - google-oauth-client - 1.22.0 - - - com.google.http-client - google-http-client-jackson2 - 1.22.0 - - - com.google.oauth-client - google-oauth-client-jetty - 1.22.0 - - - com.google.code.gson - gson - 2.8.0 - - - junit - junit - 4.12 - test - - - com.google.truth - truth - 0.32 - test - - - - - UTF-8 - - - - src/main/java - - - src/main/resources - - - - - diff --git a/bigquery/src/main/java/com/google/cloud/bigquery/samples/AsyncQuerySample.java b/bigquery/src/main/java/com/google/cloud/bigquery/samples/AsyncQuerySample.java deleted file mode 100644 index e0384da0867..00000000000 --- a/bigquery/src/main/java/com/google/cloud/bigquery/samples/AsyncQuerySample.java +++ /dev/null @@ -1,161 +0,0 @@ -/** - * Copyright (c) 2015 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.bigquery.samples; - -import com.google.api.services.bigquery.Bigquery; -import com.google.api.services.bigquery.Bigquery.Jobs.GetQueryResults; -import com.google.api.services.bigquery.model.GetQueryResultsResponse; -import com.google.api.services.bigquery.model.Job; -import com.google.api.services.bigquery.model.JobConfiguration; -import com.google.api.services.bigquery.model.JobConfigurationQuery; - -import java.io.IOException; -import java.util.Iterator; - -/** - * Example of authorizing with BigQuery and reading from a public dataset. - */ -public class AsyncQuerySample { - private static final String DEFAULT_QUERY = - "SELECT corpus FROM `publicdata.samples.shakespeare` GROUP BY corpus;"; - - // [START main] - /** - * Prompts for all the parameters required to make a query. - * - * @param args Command line args - * @throws IOException IOException - * @throws InterruptedException InterruptedException - */ - public static void main(final String[] args) throws IOException, InterruptedException { - String projectId = System.getProperty("projectId"); - if (projectId == null || projectId.isEmpty()) { - System.err.println("The projectId property must be set."); - System.exit(1); - } - System.out.printf("projectId: %s\n", projectId); - - String queryString = System.getProperty("query"); - if (queryString == null || queryString.isEmpty()) { - System.out.println("The query property was not set, using default."); - queryString = DEFAULT_QUERY; - } - System.out.printf("query: %s\n", queryString); - - String useBatchString = System.getProperty("useBatchMode"); - if (useBatchString == null || useBatchString.isEmpty()) { - useBatchString = "false"; - } - boolean useBatchMode = Boolean.parseBoolean(useBatchString); - System.out.printf("useBatchMode: %b\n", useBatchMode); - - String waitTimeString = System.getProperty("waitTime"); - if (waitTimeString == null || waitTimeString.isEmpty()) { - waitTimeString = "1000"; - } - long waitTime = Long.parseLong(waitTimeString); - System.out.printf("waitTime: %d (milliseconds)\n", waitTime); - - String useLegacySqlString = System.getProperty("useLegacySql"); - if (useLegacySqlString == null || useLegacySqlString.isEmpty()) { - useLegacySqlString = "false"; - } - boolean useLegacySql = Boolean.parseBoolean(useLegacySqlString); - - Iterator pages = - run(projectId, queryString, useBatchMode, waitTime, useLegacySql); - while (pages.hasNext()) { - BigQueryUtils.printRows(pages.next().getRows(), System.out); - } - } - // [END main] - - // [START run] - /** - * Run the query. - * - * @param projectId Get this from Google Developers console - * @param queryString Query we want to run against BigQuery - * @param useBatchMode True if you want to batch the queries - * @param waitTime How long to wait before retries - * @param useLegacySql Boolean that is false if using standard SQL syntax. - * @return An iterator to the result of your pages - * @throws IOException Thrown if there's an IOException - * @throws InterruptedException Thrown if there's an Interrupted Exception - */ - public static Iterator run( - final String projectId, - final String queryString, - final boolean useBatchMode, - final long waitTime, - final boolean useLegacySql) - throws IOException, InterruptedException { - - Bigquery bigquery = BigQueryServiceFactory.getService(); - - Job query = asyncQuery(bigquery, projectId, queryString, useBatchMode, useLegacySql); - Bigquery.Jobs.Get getRequest = - bigquery.jobs().get(projectId, query.getJobReference().getJobId()); - - // Poll every waitTime milliseconds, - // retrying at most retries times if there are errors - BigQueryUtils.pollJob(getRequest, waitTime); - - GetQueryResults resultsRequest = - bigquery.jobs().getQueryResults(projectId, query.getJobReference().getJobId()); - - return BigQueryUtils.getPages(resultsRequest); - } - // [END run] - - // [START asyncQuery] - /** - * Inserts an asynchronous query Job for a particular query. - * - * @param bigquery an authorized BigQuery client - * @param projectId a String containing the project ID - * @param querySql the actual query string - * @param useBatchMode True if you want to run the query as BATCH - * @param useLegacySql Boolean that is false if using standard SQL syntax. - * @return a reference to the inserted query job - * @throws IOException Thrown if there's a network exception - */ - public static Job asyncQuery( - final Bigquery bigquery, - final String projectId, - final String querySql, - final boolean useBatchMode, - final boolean useLegacySql) - throws IOException { - - JobConfigurationQuery queryConfig = - new JobConfigurationQuery() - .setQuery(querySql) - // Set the useLegacySql parameter to false to use standard SQL syntax. See: - // https://cloud.google.com/bigquery/sql-reference/enabling-standard-sql - .setUseLegacySql(useLegacySql); - - if (useBatchMode) { - queryConfig.setPriority("BATCH"); - } - - Job job = new Job().setConfiguration(new JobConfiguration().setQuery(queryConfig)); - - return bigquery.jobs().insert(projectId, job).execute(); - } - // [END asyncQuery] - -} diff --git a/bigquery/src/main/java/com/google/cloud/bigquery/samples/BigQueryServiceFactory.java b/bigquery/src/main/java/com/google/cloud/bigquery/samples/BigQueryServiceFactory.java deleted file mode 100644 index 9d6daee7185..00000000000 --- a/bigquery/src/main/java/com/google/cloud/bigquery/samples/BigQueryServiceFactory.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2015 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.bigquery.samples; - -// [START imports] -import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; -import com.google.api.client.http.HttpTransport; -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.bigquery.Bigquery; -import com.google.api.services.bigquery.BigqueryScopes; -// [END imports] - -import java.io.IOException; -import java.util.Collection; - -/** - * This class creates our Service to connect to BigQuery including auth. - */ -public final class BigQueryServiceFactory { - - /** - * Private constructor to disable creation of this utility Factory class. - */ - private BigQueryServiceFactory() {} - - /** - * Singleton service used through the app. - */ - private static Bigquery service = null; - - /** - * Mutex created to create the singleton in thread-safe fashion. - */ - private static Object serviceLock = new Object(); - - /** - * Threadsafe Factory that provides an authorized BigQuery service. - * @return The BigQuery service - * @throws IOException Throw if there is an error connecting to BigQuery. - */ - public static Bigquery getService() throws IOException { - if (service == null) { - synchronized (serviceLock) { - if (service == null) { - service = createAuthorizedClient(); - } - } - } - return service; - } - - /** - * Creates an authorized client to Google BigQuery. - * - * @return The BigQuery Service - * @throws IOException Thrown if there is an error connecting - */ - // [START get_service] - private static Bigquery createAuthorizedClient() throws IOException { - // Create the credential - HttpTransport transport = new NetHttpTransport(); - JsonFactory jsonFactory = new JacksonFactory(); - GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); - - // Depending on the environment that provides the default credentials (e.g. Compute Engine, App - // Engine), the credentials may require us to specify the scopes we need explicitly. - // Check for this case, and inject the BigQuery scope if required. - if (credential.createScopedRequired()) { - Collection bigqueryScopes = BigqueryScopes.all(); - credential = credential.createScoped(bigqueryScopes); - } - - return new Bigquery.Builder(transport, jsonFactory, credential) - .setApplicationName("BigQuery Samples") - .build(); - } - // [END get_service] - -} diff --git a/bigquery/src/main/java/com/google/cloud/bigquery/samples/BigQueryUtils.java b/bigquery/src/main/java/com/google/cloud/bigquery/samples/BigQueryUtils.java deleted file mode 100644 index 33f9fb247d6..00000000000 --- a/bigquery/src/main/java/com/google/cloud/bigquery/samples/BigQueryUtils.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - Copyright 2015, 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.bigquery.samples; - -import com.google.api.client.json.GenericJson; -import com.google.api.services.bigquery.Bigquery; -import com.google.api.services.bigquery.Bigquery.Datasets; -import com.google.api.services.bigquery.BigqueryRequest; -import com.google.api.services.bigquery.model.DatasetList; -import com.google.api.services.bigquery.model.Job; -import com.google.api.services.bigquery.model.TableCell; -import com.google.api.services.bigquery.model.TableFieldSchema; -import com.google.api.services.bigquery.model.TableRow; -import com.google.api.services.bigquery.model.TableSchema; -import com.google.gson.Gson; - -import java.io.IOException; -import java.io.PrintStream; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -/** - * Helper functions for the other classes. - */ -public class BigQueryUtils { - - /** - * Private constructor to prevent creation of this class, which is just all - * static helper methods. - */ - private BigQueryUtils() {} - - /** - * Print rows to the output stream in a formatted way. - * @param rows rows in bigquery - * @param out Output stream we want to print to - */ - // [START print_rows] - public static void printRows(final List rows, final PrintStream out) { - for (TableRow row : rows) { - for (TableCell field : row.getF()) { - out.printf("%-50s", field.getV()); - } - out.println(); - } - } - // [END print_rows] - - /** - * Polls the job for completion. - * @param request The bigquery request to poll for completion - * @param interval Number of milliseconds between each poll - * @return The finished job - * @throws IOException IOException - * @throws InterruptedException InterruptedException - */ - // [START poll_job] - public static Job pollJob(final Bigquery.Jobs.Get request, final long interval) - throws IOException, InterruptedException { - Job job = request.execute(); - while (!job.getStatus().getState().equals("DONE")) { - System.out.println( - "Job is " + job.getStatus().getState() + " waiting " + interval + " milliseconds..."); - Thread.sleep(interval); - job = request.execute(); - } - return job; - } - // [END poll_job] - - /** - * Pages through the results of an arbitrary Bigquery request. - * @param requestTemplate The object that represents the call to fetch - * the results. - * @param The type of the returned objects - * @return An iterator that pages through the returned object - */ - // [START paging] - public static Iterator getPages( - final BigqueryRequest requestTemplate) { - - /** - * An iterator class that pages through a Bigquery request. - */ - class PageIterator implements Iterator { - - private BigqueryRequest request; - private boolean hasNext = true; - - /** - * Inner class that represents our iterator to page through results. - * @param requestTemplate The object that represents the call to fetch - * the results. - */ - public PageIterator(final BigqueryRequest requestTemplate) { - this.request = requestTemplate; - } - - /** - * Checks whether there is another page of results. - * @return True if there is another page of results. - */ - public boolean hasNext() { - return hasNext; - } - - /** - * Returns the next page of results. - * @return The next page of resul.ts - */ - public T next() { - if (!hasNext) { - throw new NoSuchElementException(); - } - try { - T response = request.execute(); - if (response.containsKey("pageToken")) { - request = request.set("pageToken", response.get("pageToken")); - } else { - hasNext = false; - } - return response; - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - /** - * Skips the page by moving the iterator to the next page. - */ - public void remove() { - this.next(); - } - } - - return new PageIterator(requestTemplate); - } - // [END paging] - - /** - * Loads a Bigquery schema. - * @param schemaSource The source of the schema - * @return The TableSchema - */ - // [START load_schema] - public static TableSchema loadSchema(final Reader schemaSource) { - TableSchema sourceSchema = new TableSchema(); - - List fields = - (new Gson()) - .>fromJson( - schemaSource, (new ArrayList()).getClass()); - - sourceSchema.setFields(fields); - - return sourceSchema; - } - // [END load_schema] - - // [START list_datasets] - /** - * Display all BigQuery datasets associated with a project. - * - * @param bigquery an authorized BigQuery client - * @param projectId a string containing the current project ID - * @throws IOException Thrown if there is a network error connecting to - * Bigquery. - */ - public static void listDatasets(final Bigquery bigquery, final String projectId) - throws IOException { - Datasets.List datasetRequest = bigquery.datasets().list(projectId); - DatasetList datasetList = datasetRequest.execute(); - if (datasetList.getDatasets() != null) { - List datasets = datasetList.getDatasets(); - System.out.println("Available datasets\n----------------"); - System.out.println(datasets.toString()); - for (DatasetList.Datasets dataset : datasets) { - System.out.format("%s\n", dataset.getDatasetReference().getDatasetId()); - } - } - } - // [END list_datasets] -} diff --git a/bigquery/src/main/java/com/google/cloud/bigquery/samples/ExportDataCloudStorageSample.java b/bigquery/src/main/java/com/google/cloud/bigquery/samples/ExportDataCloudStorageSample.java deleted file mode 100644 index 03316dddc05..00000000000 --- a/bigquery/src/main/java/com/google/cloud/bigquery/samples/ExportDataCloudStorageSample.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - Copyright 2015, 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.bigquery.samples; - -import com.google.api.services.bigquery.Bigquery; -import com.google.api.services.bigquery.model.Job; -import com.google.api.services.bigquery.model.JobConfiguration; -import com.google.api.services.bigquery.model.JobConfigurationExtract; -import com.google.api.services.bigquery.model.TableReference; - -import java.io.IOException; -import java.util.Scanner; - -/** - * Sample of how to Export Cloud Data. - */ -public class ExportDataCloudStorageSample { - /** - * Protected constructor since this is a collection of static functions. - */ - protected ExportDataCloudStorageSample() { - super(); - } - - /** - * This program can be run to demonstrate running a Bigquery query from the - * CLI. - * @param args Command line args - * @throws IOException If there is an error connceting to bigquery - * @throws InterruptedException Should never be thrown. - */ - // [START main] - public static void main(final String[] args) throws IOException, InterruptedException { - Scanner scanner = new Scanner(System.in); - System.out.println("Enter your project id: "); - String projectId = scanner.nextLine(); - System.out.println("Enter your dataset id: "); - String datasetId = scanner.nextLine(); - System.out.println("Enter your table id: "); - String tableId = scanner.nextLine(); - System.out.println("Enter the Google Cloud Storage Path to which you'd " + "like to export: "); - String cloudStoragePath = scanner.nextLine(); - System.out.println("Enter how often to check if your job is complete " + "(milliseconds): "); - long interval = scanner.nextLong(); - scanner.close(); - - run(cloudStoragePath, projectId, datasetId, tableId, interval); - } - // [END main] - - /** - * Run the bigquery ClI. - * @param cloudStoragePath The bucket we are using - * @param projectId Project id - * @param datasetId datasetid - * @param tableId tableid - * @param interval interval to wait between polling in milliseconds - * @throws IOException Thrown if there is an error connecting to Bigquery. - * @throws InterruptedException Should never be thrown - */ - // [START run] - public static void run( - final String cloudStoragePath, - final String projectId, - final String datasetId, - final String tableId, - final long interval) - throws IOException, InterruptedException { - - Bigquery bigquery = BigQueryServiceFactory.getService(); - - Job extractJob = - extractJob( - bigquery, - cloudStoragePath, - new TableReference() - .setProjectId(projectId) - .setDatasetId(datasetId) - .setTableId(tableId)); - - Bigquery.Jobs.Get getJob = - bigquery - .jobs() - .get( - extractJob.getJobReference().getProjectId(), - extractJob.getJobReference().getJobId()); - - BigQueryUtils.pollJob(getJob, interval); - - System.out.println("Export is Done!"); - } - // [END run] - - /** - * A job that extracts data from a table. - * @param bigquery Bigquery service to use - * @param cloudStoragePath Cloud storage bucket we are inserting into - * @param table Table to extract from - * @return The job to extract data from the table - * @throws IOException Thrown if error connceting to Bigtable - */ - // [START extract_job] - public static Job extractJob( - final Bigquery bigquery, final String cloudStoragePath, final TableReference table) - throws IOException { - - JobConfigurationExtract extract = - new JobConfigurationExtract().setSourceTable(table).setDestinationUri(cloudStoragePath); - - return bigquery - .jobs() - .insert( - table.getProjectId(), - new Job().setConfiguration(new JobConfiguration().setExtract(extract))) - .execute(); - } - // [END extract_job] -} diff --git a/bigquery/src/main/java/com/google/cloud/bigquery/samples/GettingStarted.java b/bigquery/src/main/java/com/google/cloud/bigquery/samples/GettingStarted.java deleted file mode 100644 index b4549b62240..00000000000 --- a/bigquery/src/main/java/com/google/cloud/bigquery/samples/GettingStarted.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2012 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.bigquery.samples; - -// [START all] -import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; -import com.google.api.client.http.HttpTransport; -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.bigquery.Bigquery; -import com.google.api.services.bigquery.BigqueryScopes; -import com.google.api.services.bigquery.model.GetQueryResultsResponse; -import com.google.api.services.bigquery.model.QueryRequest; -import com.google.api.services.bigquery.model.QueryResponse; -import com.google.api.services.bigquery.model.TableCell; -import com.google.api.services.bigquery.model.TableRow; - -import java.io.IOException; -import java.util.List; -import java.util.Scanner; - -/** - * Example of authorizing with Bigquery and reading from a public dataset. - * - * Specifically, this queries the shakespeare dataset to fetch the 10 of Shakespeare's works with - * the greatest number of distinct words. - */ -public class GettingStarted { - // [START build_service] - /** - * Creates an authorized Bigquery client service using Application Default Credentials. - * - * @return an authorized Bigquery client - * @throws IOException if there's an error getting the default credentials. - */ - public static Bigquery createAuthorizedClient() throws IOException { - // Create the credential - HttpTransport transport = new NetHttpTransport(); - JsonFactory jsonFactory = new JacksonFactory(); - GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); - - // Depending on the environment that provides the default credentials (e.g. Compute Engine, App - // Engine), the credentials may require us to specify the scopes we need explicitly. - // Check for this case, and inject the Bigquery scope if required. - if (credential.createScopedRequired()) { - credential = credential.createScoped(BigqueryScopes.all()); - } - - return new Bigquery.Builder(transport, jsonFactory, credential) - .setApplicationName("Bigquery Samples") - .build(); - } - // [END build_service] - - // [START run_query] - /** - * Executes the given query synchronously. - * - * @param querySql the query to execute. - * @param bigquery the Bigquery service object. - * @param projectId the id of the project under which to run the query. - * @return a list of the results of the query. - * @throws IOException if there's an error communicating with the API. - */ - private static List executeQuery(String querySql, Bigquery bigquery, String projectId) - throws IOException { - QueryResponse query = - bigquery.jobs().query(projectId, new QueryRequest().setQuery(querySql)).execute(); - - // Execute it - GetQueryResultsResponse queryResult = - bigquery - .jobs() - .getQueryResults( - query.getJobReference().getProjectId(), query.getJobReference().getJobId()) - .execute(); - - return queryResult.getRows(); - } - // [END run_query] - - // [START print_results] - /** - * Prints the results to standard out. - * - * @param rows the rows to print. - */ - private static void printResults(List rows) { - System.out.print("\nQuery Results:\n------------\n"); - for (TableRow row : rows) { - for (TableCell field : row.getF()) { - System.out.printf("%-50s", field.getV()); - } - System.out.println(); - } - } - // [END print_results] - - /** - * Exercises the methods defined in this class. - * - * In particular, it creates an authorized Bigquery service object using Application Default - * Credentials, then executes a query against the public Shakespeare dataset and prints out the - * results. - * - * @param args the first argument, if it exists, should be the id of the project to run the test - * under. If no arguments are given, it will prompt for it. - * @throws IOException if there's an error communicating with the API. - */ - public static void main(String[] args) throws IOException { - Scanner sc; - if (args.length == 0) { - // Prompt the user to enter the id of the project to run the queries under - System.out.print("Enter the project ID: "); - sc = new Scanner(System.in); - } else { - sc = new Scanner(args[0]); - } - String projectId = sc.nextLine(); - - // Create a new Bigquery client authorized via Application Default Credentials. - Bigquery bigquery = createAuthorizedClient(); - - List rows = - executeQuery( - "SELECT TOP(corpus, 10) as title, COUNT(*) as unique_words " - + "FROM [publicdata:samples.shakespeare]", - bigquery, - projectId); - - printResults(rows); - } -} -// [END all] diff --git a/bigquery/src/main/java/com/google/cloud/bigquery/samples/ListDatasetsProjects.java b/bigquery/src/main/java/com/google/cloud/bigquery/samples/ListDatasetsProjects.java deleted file mode 100644 index 0334a2f2eda..00000000000 --- a/bigquery/src/main/java/com/google/cloud/bigquery/samples/ListDatasetsProjects.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2015 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.bigquery.samples; - -import com.google.api.client.util.Data; -import com.google.api.services.bigquery.Bigquery; -import com.google.api.services.bigquery.Bigquery.Datasets; -import com.google.api.services.bigquery.model.DatasetList; -import com.google.api.services.bigquery.model.GetQueryResultsResponse; -import com.google.api.services.bigquery.model.ProjectList; -import com.google.api.services.bigquery.model.QueryRequest; -import com.google.api.services.bigquery.model.QueryResponse; -import com.google.api.services.bigquery.model.TableCell; -import com.google.api.services.bigquery.model.TableRow; - -import java.io.IOException; -import java.io.PrintStream; -import java.lang.Thread; -import java.util.List; - -/** - * Invokes the BigQuery basic APIs for the given project id specified. - * - * Samples used in this page: - * - * https://cloud.google.com/bigquery/bigquery-api-quickstart - */ -public class ListDatasetsProjects { - /** - * Run the sample. - */ - public static void main(String[] args) throws IOException, InterruptedException { - if (args.length != 1) { - System.err.println("Usage: QuickStart "); - return; - } - String projectId = args[0]; - - Bigquery bigquery = BigQueryServiceFactory.getService(); - String query = - "SELECT TOP( title, 10) as title, COUNT(*) as revision_count " - + "FROM [publicdata:samples.wikipedia] WHERE wp_namespace = 0;"; - - System.out.println(); - System.out.println("----- Running the asynchronous query and printing it to stdout."); - runQueryRpcAndPrint(bigquery, projectId, query, System.out); - - System.out.println(); - System.out.println("----- Listing all the Datasets in the projectId"); - listDatasets(bigquery, projectId); - - System.out.println(); - System.out.println("----- Listing all the Projects"); - listProjects(bigquery); - } - - /** - * Lists all Datasets in a project specified by the projectId. - * - * @param bigquery The BigQuery object. - * @param projectId The projectId from which lists the existing Datasets. - * @throws IOException if there's trouble with the network request. - */ - // [START listDatasets] - public static void listDatasets(Bigquery bigquery, String projectId) throws IOException { - Datasets.List datasetRequest = bigquery.datasets().list(projectId); - DatasetList datasetList = datasetRequest.execute(); - - if (datasetList.getDatasets() != null) { - List datasets = datasetList.getDatasets(); - System.out.println("Dataset list:"); - - for (DatasetList.Datasets dataset : datasets) { - System.out.format("%s\n", dataset.getDatasetReference().getDatasetId()); - } - } - } - // [END listDatasets] - - /** - * Lists all Projects. - * - * @param bigquery The BigQuery object. - * @throws IOException if there's trouble with the network request. - */ - // [START listProjects] - public static void listProjects(Bigquery bigquery) throws IOException { - Bigquery.Projects.List projectListRequest = bigquery.projects().list(); - ProjectList projectList = projectListRequest.execute(); - - if (projectList.getProjects() != null) { - List projects = projectList.getProjects(); - System.out.println("Project list:"); - - for (ProjectList.Projects project : projects) { - System.out.format("%s\n", project.getFriendlyName()); - } - } - } - // [END listProjects] - - /** - * Runs a synchronous BigQuery query and displays the result. - * - * @param bigquery An authorized BigQuery client - * @param projectId The current project id - * @param query A String containing a BigQuery SQL statement - * @param out A PrintStream for output, normally System.out - */ - static void runQueryRpcAndPrint( - Bigquery bigquery, String projectId, String query, PrintStream out) - throws IOException, InterruptedException { - QueryRequest queryRequest = new QueryRequest().setQuery(query); - QueryResponse queryResponse = bigquery.jobs().query(projectId, queryRequest).execute(); - if (queryResponse.getJobComplete()) { - printRows(queryResponse.getRows(), out); - if (null == queryResponse.getPageToken()) { - return; - } - } - // This loop polls until results are present, then loops over result pages. - String pageToken = null; - while (true) { - GetQueryResultsResponse queryResults = - bigquery - .jobs() - .getQueryResults(projectId, queryResponse.getJobReference().getJobId()) - .setPageToken(pageToken) - .execute(); - if (queryResults.getJobComplete()) { - printRows(queryResults.getRows(), out); - pageToken = queryResults.getPageToken(); - if (null == pageToken) { - return; - } - } - Thread.sleep(500); - } - } - - /** - * Print the given rows. - * - * @param rows the rows to print. - * @param out the place to print them. - */ - private static void printRows(java.util.List rows, PrintStream out) { - if (rows != null) { - for (TableRow row : rows) { - for (TableCell cell : row.getF()) { - // Data.isNull() is the recommended way to check for the 'null object' in TableCell. - out.printf("%s, ", Data.isNull(cell.getV()) ? "null" : cell.getV().toString()); - } - out.println(); - } - } - } -} diff --git a/bigquery/src/main/java/com/google/cloud/bigquery/samples/LoadDataCsvSample.java b/bigquery/src/main/java/com/google/cloud/bigquery/samples/LoadDataCsvSample.java deleted file mode 100644 index b3ecb26c149..00000000000 --- a/bigquery/src/main/java/com/google/cloud/bigquery/samples/LoadDataCsvSample.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - Copyright 2015, 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.bigquery.samples; - -import com.google.api.services.bigquery.Bigquery; -import com.google.api.services.bigquery.model.Job; -import com.google.api.services.bigquery.model.JobConfiguration; -import com.google.api.services.bigquery.model.JobConfigurationLoad; -import com.google.api.services.bigquery.model.TableReference; -import com.google.api.services.bigquery.model.TableSchema; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; -import java.util.Collections; -import java.util.Scanner; - -/** - * Cli tool to load data from a CSV into Bigquery. - */ -public class LoadDataCsvSample { - - /** - * Protected constructor since this is a collection of static methods. - */ - protected LoadDataCsvSample() {} - - /** - * Cli tool to load data from a CSV into Bigquery. - * @param args Command line args, should be empty - * @throws IOException IOException - * @throws InterruptedException InterruptedException - */ - // [START main] - public static void main(final String[] args) throws IOException, InterruptedException { - Scanner scanner = new Scanner(System.in); - System.out.println("Enter your project id: "); - String projectId = scanner.nextLine(); - System.out.println("Enter your dataset id: "); - String datasetId = scanner.nextLine(); - System.out.println("Enter your table id: "); - String tableId = scanner.nextLine(); - System.out.println("Enter the Google Cloud Storage Path to the data " + "you'd like to load: "); - String cloudStoragePath = scanner.nextLine(); - System.out.println("Enter the filepath to your schema: "); - String sourceSchemaPath = scanner.nextLine(); - - System.out.println("Enter how often to check if your job is complete " + "(milliseconds): "); - long interval = scanner.nextLong(); - scanner.close(); - - run( - cloudStoragePath, - projectId, - datasetId, - tableId, - new FileReader(new File(sourceSchemaPath)), - interval); - } - // [END main] - - /** - * Run the bigquery ClI. - * @param cloudStoragePath The bucket we are using - * @param projectId Project id - * @param datasetId datasetid - * @param tableId tableid - * @param schemaSource Source of the schema - * @param interval interval to wait between polling in milliseconds - * @throws IOException Thrown if there is an error connecting to Bigquery. - * @throws InterruptedException Should never be thrown - */ - // [START run] - public static void run( - final String cloudStoragePath, - final String projectId, - final String datasetId, - final String tableId, - final Reader schemaSource, - final long interval) - throws IOException, InterruptedException { - - Bigquery bigquery = BigQueryServiceFactory.getService(); - - Job loadJob = - loadJob( - bigquery, - cloudStoragePath, - new TableReference() - .setProjectId(projectId) - .setDatasetId(datasetId) - .setTableId(tableId), - BigQueryUtils.loadSchema(schemaSource)); - - Bigquery.Jobs.Get getJob = - bigquery - .jobs() - .get(loadJob.getJobReference().getProjectId(), loadJob.getJobReference().getJobId()); - - BigQueryUtils.pollJob(getJob, interval); - - System.out.println("Load is Done!"); - } - // [END run] - - /** - * A job that extracts data from a table. - * @param bigquery Bigquery service to use - * @param cloudStoragePath Cloud storage bucket we are inserting into - * @param table Table to extract from - * @param schema The schema of the table we are loading into - * @return The job to extract data from the table - * @throws IOException Thrown if error connceting to Bigtable - */ - // [START load_job] - public static Job loadJob( - final Bigquery bigquery, - final String cloudStoragePath, - final TableReference table, - final TableSchema schema) - throws IOException { - - JobConfigurationLoad load = - new JobConfigurationLoad() - .setDestinationTable(table) - .setSchema(schema) - .setSourceUris(Collections.singletonList(cloudStoragePath)); - - return bigquery - .jobs() - .insert( - table.getProjectId(), new Job().setConfiguration(new JobConfiguration().setLoad(load))) - .execute(); - } - // [END load_job] -} diff --git a/bigquery/src/main/java/com/google/cloud/bigquery/samples/StreamingSample.java b/bigquery/src/main/java/com/google/cloud/bigquery/samples/StreamingSample.java deleted file mode 100644 index ef37f042aab..00000000000 --- a/bigquery/src/main/java/com/google/cloud/bigquery/samples/StreamingSample.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - Copyright 2015, 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.bigquery.samples; - -import com.google.api.services.bigquery.Bigquery; -import com.google.api.services.bigquery.model.TableDataInsertAllRequest; -import com.google.api.services.bigquery.model.TableDataInsertAllResponse; -import com.google.gson.Gson; -import com.google.gson.JsonSyntaxException; -import com.google.gson.stream.JsonReader; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Scanner; - -/** - * Example of Bigquery Streaming. - */ -public class StreamingSample { - - /** - * Empty constructor since this is just a collection of static methods. - */ - protected StreamingSample() {} - - /** - * Command line that demonstrates Bigquery streaming. - * - * @param args Command line args, should be empty - * @throws IOException IOexception - */ - // [START main] - public static void main(final String[] args) throws IOException { - final Scanner scanner = new Scanner(System.in); - System.out.println("Enter your project id: "); - String projectId = scanner.nextLine(); - System.out.println("Enter your dataset id: "); - String datasetId = scanner.nextLine(); - System.out.println("Enter your table id: "); - String tableId = scanner.nextLine(); - scanner.close(); - - System.out.println( - "Enter JSON to stream to BigQuery: \n" + "Press End-of-stream (CTRL-D) to stop"); - - JsonReader fromCli = new JsonReader(new InputStreamReader(System.in)); - - Iterator responses = run(projectId, datasetId, tableId, fromCli); - - while (responses.hasNext()) { - System.out.println(responses.next()); - } - - fromCli.close(); - } - // [END main] - - /** - * Run the bigquery ClI. - * - * @param projectId Project id - * @param datasetId datasetid - * @param tableId tableid - * @param rows The source of the JSON rows we are streaming in. - * @return Returns Iterates through the stream responses - * @throws IOException Thrown if there is an error connecting to Bigquery. - * @throws InterruptedException Should never be thrown - */ - // [START run] - public static Iterator run( - final String projectId, final String datasetId, final String tableId, final JsonReader rows) - throws IOException { - - final Bigquery bigquery = BigQueryServiceFactory.getService(); - final Gson gson = new Gson(); - rows.beginArray(); - - return new Iterator() { - - /** - * Check whether there is another row to stream. - * - * @return True if there is another row in the stream - */ - public boolean hasNext() { - try { - return rows.hasNext(); - } catch (IOException e) { - e.printStackTrace(); - } - return false; - } - - /** - * Insert the next row, and return the response. - * - * @return Next page of data - */ - public TableDataInsertAllResponse next() { - try { - Map rowData = - gson.>fromJson(rows, (new HashMap()).getClass()); - return streamRow( - bigquery, - projectId, - datasetId, - tableId, - new TableDataInsertAllRequest.Rows().setJson(rowData)); - } catch (JsonSyntaxException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - public void remove() { - this.next(); - } - }; - } - // [END run] - - /** - * Stream the given row into the given bigquery table. - * - * @param bigquery The bigquery service - * @param projectId project id from Google Developers console - * @param datasetId id of the dataset - * @param tableId id of the table we're streaming - * @param row the row we're inserting - * @return Response from the insert - * @throws IOException ioexception - */ - // [START streamRow] - public static TableDataInsertAllResponse streamRow( - final Bigquery bigquery, - final String projectId, - final String datasetId, - final String tableId, - final TableDataInsertAllRequest.Rows row) - throws IOException { - - return bigquery - .tabledata() - .insertAll( - projectId, - datasetId, - tableId, - new TableDataInsertAllRequest().setRows(Collections.singletonList(row))) - .execute(); - } - // [END streamRow] -} diff --git a/bigquery/src/main/java/com/google/cloud/bigquery/samples/SyncQuerySample.java b/bigquery/src/main/java/com/google/cloud/bigquery/samples/SyncQuerySample.java deleted file mode 100644 index bf3b0eb8bed..00000000000 --- a/bigquery/src/main/java/com/google/cloud/bigquery/samples/SyncQuerySample.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - Copyright 2015, 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.bigquery.samples; - -import com.google.api.services.bigquery.Bigquery; -import com.google.api.services.bigquery.Bigquery.Jobs.GetQueryResults; -import com.google.api.services.bigquery.model.GetQueryResultsResponse; -import com.google.api.services.bigquery.model.QueryRequest; -import com.google.api.services.bigquery.model.QueryResponse; - -import java.io.IOException; -import java.util.Iterator; - -/** - * Runs a synchronous query against Bigtable. - */ -public class SyncQuerySample { - private static final String DEFAULT_QUERY = - "SELECT corpus FROM `publicdata.samples.shakespeare` GROUP BY corpus;"; - private static final long TEN_SECONDS_MILLIS = 10000; - - /** - * Protected because this is a collection of static methods. - */ - protected SyncQuerySample() {} - - //[START main] - /** - * Prompts the user for the required parameters to perform a query. - * - * @param args args - * @throws IOException ioexceptino - */ - public static void main(final String[] args) throws IOException { - String projectId = System.getProperty("projectId"); - if (projectId == null || projectId.isEmpty()) { - System.err.println("The projectId property must be set."); - System.exit(1); - } - System.out.printf("projectId: %s\n", projectId); - - String queryString = System.getProperty("query"); - if (queryString == null || queryString.isEmpty()) { - System.out.println("The query property was not set, using default."); - queryString = DEFAULT_QUERY; - } - System.out.printf("query: %s\n", queryString); - - String waitTimeString = System.getProperty("waitTime"); - if (waitTimeString == null || waitTimeString.isEmpty()) { - waitTimeString = "1000"; - } - long waitTime = Long.parseLong(waitTimeString); - System.out.printf("waitTime: %d (milliseconds)\n", waitTime); - if (waitTime > TEN_SECONDS_MILLIS) { - System.out.println( - "WARNING: If the query is going to take longer than 10 seconds to complete, use an" - + " asynchronous query."); - } - - String useLegacySqlString = System.getProperty("useLegacySql"); - if (useLegacySqlString == null || useLegacySqlString.isEmpty()) { - useLegacySqlString = "false"; - } - boolean useLegacySql = Boolean.parseBoolean(useLegacySqlString); - - Iterator pages = run(projectId, queryString, waitTime, useLegacySql); - while (pages.hasNext()) { - BigQueryUtils.printRows(pages.next().getRows(), System.out); - } - } - // [END main] - - /** - * Perform the given query using the synchronous api. - * - * @param projectId project id from developer console - * @param queryString query to run - * @param waitTime Timeout in milliseconds before we abort - * @param useLegacySql Boolean that is false if using standard SQL syntax. - * @return Iterator that pages through the results of the query - * @throws IOException ioexception - */ - // [START run] - public static Iterator run( - final String projectId, - final String queryString, - final long waitTime, - final boolean useLegacySql) throws IOException { - Bigquery bigquery = BigQueryServiceFactory.getService(); - - // Wait until query is done with `waitTime` millisecond timeout, at most 5 retries on error. - QueryResponse query = - bigquery - .jobs() - .query( - projectId, - new QueryRequest() - .setTimeoutMs(waitTime) - .setQuery(queryString) - // Set the useLegacySql parameter to false to use standard SQL syntax. See: - // https://cloud.google.com/bigquery/sql-reference/enabling-standard-sql - .setUseLegacySql(useLegacySql)) - .execute(); - - // Make a request to get the results of the query. - GetQueryResults getRequest = - bigquery - .jobs() - .getQueryResults( - query.getJobReference().getProjectId(), query.getJobReference().getJobId()); - - return BigQueryUtils.getPages(getRequest); - } - // [END run] - -} diff --git a/bigquery/src/main/resources/schema.json b/bigquery/src/main/resources/schema.json deleted file mode 100644 index b61fd26be03..00000000000 --- a/bigquery/src/main/resources/schema.json +++ /dev/null @@ -1 +0,0 @@ -[{"type": "STRING", "name": "Name"}, {"type": "INTEGER", "name": "Age"}, {"type": "FLOAT", "name": "Weight"}, {"type": "BOOLEAN", "name": "IsMagic"}] diff --git a/bigquery/src/main/resources/streamrows.json b/bigquery/src/main/resources/streamrows.json deleted file mode 100644 index c65f6291054..00000000000 --- a/bigquery/src/main/resources/streamrows.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - {"Name": "test", "Age": 0, "Weight": 100.0, "IsMagic": false}, - {"Name": "test", "Age": 1, "Weight": 100.0, "IsMagic": false}, - {"Name": "test", "Age": 2, "Weight": 100.0, "IsMagic": false}, - {"Name": "test", "Age": 3, "Weight": 100.0, "IsMagic": false}, - {"Name": "test", "Age": 0, "Weight": 100.0, "IsMagic": false} -] diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/AsyncQuerySampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/AsyncQuerySampleTest.java deleted file mode 100644 index a71e472acdb..00000000000 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/AsyncQuerySampleTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2015 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.bigquery.samples.test; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.api.services.bigquery.model.GetQueryResultsResponse; -import com.google.cloud.bigquery.samples.AsyncQuerySample; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.io.IOException; -import java.util.Iterator; - -/** - * Tests for asynchronous query sample. - */ -@RunWith(JUnit4.class) -public class AsyncQuerySampleTest { - - @Test - public void testInteractive() throws IOException, InterruptedException { - Iterator pages = - AsyncQuerySample.run( - Constants.PROJECT_ID, - "SELECT corpus FROM `publicdata.samples.shakespeare` GROUP BY corpus;", - false /* useBatchMode */, - 5000, - false /* useLegacySql */); - while (pages.hasNext()) { - assertThat(pages.next().getRows()).isNotEmpty(); - } - } - - @Test - public void testInteractiveLegacySql() throws IOException, InterruptedException { - Iterator pages = - AsyncQuerySample.run( - Constants.PROJECT_ID, - Constants.QUERY, - false /* useBatchMode */, - 5000, - true /* useLegacySql */); - while (pages.hasNext()) { - assertThat(pages.next().getRows()).isNotEmpty(); - } - } - - @Test - @Ignore // Batches can take up to 3 hours to run, don't run during the system tests. - public void testBatch() throws IOException, InterruptedException { - Iterator pages = - AsyncQuerySample.run( - Constants.PROJECT_ID, - Constants.QUERY, - true /* useBatchMode */, - 5000, - true /* useLegacySql */); - while (pages.hasNext()) { - assertThat(pages.next().getRows()).isNotEmpty(); - } - } -} diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/Constants.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/Constants.java deleted file mode 100644 index 4bddbc34bd1..00000000000 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/Constants.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 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.google.cloud.bigquery.samples.test; - -public class Constants { - public static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - public static final String BUCKET = PROJECT_ID; - public static final String DATASET_ID = "test_dataset_java"; - public static final String CURRENT_TABLE_ID = "test_table_java"; - public static final String NEW_TABLE_ID = "test_table_java_2"; - public static final String CLOUD_STORAGE_INPUT_URI = "gs://" + BUCKET + "/data.csv"; - public static final String CLOUD_STORAGE_OUTPUT_URI = "gs://" + BUCKET + "/output.csv"; - public static final String QUERY = - "SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;"; -} diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ExportDataCloudStorageSampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ExportDataCloudStorageSampleTest.java deleted file mode 100644 index c05e6b17eb0..00000000000 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ExportDataCloudStorageSampleTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2015 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.bigquery.samples.test; - -import com.google.cloud.bigquery.samples.ExportDataCloudStorageSample; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.io.IOException; - -/** - * Tests for export data Cloud Storage sample. - */ -@RunWith(JUnit4.class) -public class ExportDataCloudStorageSampleTest { - - @Test - public void testExportData() throws IOException, InterruptedException { - ExportDataCloudStorageSample.run( - Constants.CLOUD_STORAGE_OUTPUT_URI, - Constants.PROJECT_ID, - Constants.DATASET_ID, - Constants.CURRENT_TABLE_ID, - 5000L); - } -} diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/GettingStartedTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/GettingStartedTest.java deleted file mode 100644 index 2a4babb4c1d..00000000000 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/GettingStartedTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2015 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.bigquery.samples.test; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.cloud.bigquery.samples.GettingStarted; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; - -/** - * Test for GettingStarted.java - */ -@RunWith(JUnit4.class) -public class GettingStartedTest { - private static final PrintStream REAL_OUT = System.out; - private static final PrintStream REAL_ERR = System.err; - - private final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); - private final ByteArrayOutputStream stderr = new ByteArrayOutputStream(); - - @Before - public void setUp() { - System.setOut(new PrintStream(stdout)); - System.setErr(new PrintStream(stderr)); - } - - @After - public void tearDown() { - System.setOut(REAL_OUT); - System.setErr(REAL_ERR); - } - - @Test - public void testSyncQuery() throws IOException { - GettingStarted.main(new String[] {Constants.PROJECT_ID}); - String out = stdout.toString(); - assertThat(out).named("stdout").containsMatch("Query Results:"); - assertThat(out).named("stdout").contains("hamlet"); - } -} diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java deleted file mode 100644 index 2bf05e7d3d0..00000000000 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2015 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.bigquery.samples.test; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.cloud.bigquery.samples.ListDatasetsProjects; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.lang.Exception; - -/** - * Unit tests for {@link ListDatasetsProjects}. - */ -@RunWith(JUnit4.class) -public class ListDatasetsProjectsTest { - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final PrintStream REAL_OUT = System.out; - private static final PrintStream REAL_ERR = System.err; - - private final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); - private final ByteArrayOutputStream stderr = new ByteArrayOutputStream(); - - @Before - public void setUp() { - System.setOut(new PrintStream(stdout)); - System.setErr(new PrintStream(stderr)); - } - - @After - public void tearDown() { - System.setOut(REAL_OUT); - System.setErr(REAL_ERR); - } - - @Test - public void testUsage() throws Exception { - ListDatasetsProjects.main(new String[] {}); - assertThat(stderr.toString()).named("stderr").isEqualTo("Usage: QuickStart \n"); - } - - @Test - public void testMain() throws Exception { - ListDatasetsProjects.main(new String[] {Constants.PROJECT_ID}); - String out = stdout.toString(); - assertThat(out).named("stdout").contains("Running the asynchronous query"); - assertThat(out).named("stdout").containsMatch("George W. Bush, [0-9]+"); - assertThat(out).named("stdout").containsMatch("Wikipedia, [0-9]+"); - - assertThat(out).named("stdout").contains("Listing all the Datasets"); - assertThat(out).named("stdout").contains("test_dataset"); - - assertThat(out).named("stdout").contains("Listing all the Projects"); - assertThat(out).named("stdout").contains("Project list:"); - assertThat(out).named("stdout").containsMatch("Bigquery Samples|" + PROJECT_ID); - } -} diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/LoadDataCsvSampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/LoadDataCsvSampleTest.java deleted file mode 100644 index c33201e71a4..00000000000 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/LoadDataCsvSampleTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2015 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.bigquery.samples.test; - -import com.google.cloud.bigquery.samples.LoadDataCsvSample; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.io.IOException; -import java.io.InputStreamReader; - -/** - * Tests for sample that loads data from CSV. - */ -@RunWith(JUnit4.class) -public class LoadDataCsvSampleTest { - - @Test - public void testLoadData() throws IOException, InterruptedException { - InputStreamReader is = - new InputStreamReader(LoadDataCsvSample.class.getResourceAsStream("/schema.json")); - LoadDataCsvSample.run( - Constants.CLOUD_STORAGE_INPUT_URI, - Constants.PROJECT_ID, - Constants.DATASET_ID, - Constants.NEW_TABLE_ID, - is, - 5000L); - } -} diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/StreamingSampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/StreamingSampleTest.java deleted file mode 100644 index 01a6bd8f42a..00000000000 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/StreamingSampleTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2015 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.bigquery.samples.test; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.api.services.bigquery.model.TableDataInsertAllResponse; -import com.google.cloud.bigquery.samples.StreamingSample; -import com.google.gson.stream.JsonReader; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Iterator; - -/** - * Tests for streaming sample. - */ -@RunWith(JUnit4.class) -public class StreamingSampleTest { - - @Test - public void testStream() throws IOException { - JsonReader json = - new JsonReader( - new InputStreamReader( - StreamingSampleTest.class.getResourceAsStream("/streamrows.json"))); - Iterator response = - StreamingSample.run( - Constants.PROJECT_ID, Constants.DATASET_ID, Constants.CURRENT_TABLE_ID, json); - - while (response.hasNext()) { - assertThat(response.next()).isNotEmpty(); - } - } -} diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/SyncQuerySampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/SyncQuerySampleTest.java deleted file mode 100644 index e40d02f30f5..00000000000 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/SyncQuerySampleTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2015 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.bigquery.samples.test; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.api.services.bigquery.model.GetQueryResultsResponse; -import com.google.cloud.bigquery.samples.SyncQuerySample; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.io.IOException; -import java.util.Iterator; - -/** - * Tests for synchronous query sample. - */ -@RunWith(JUnit4.class) -public class SyncQuerySampleTest { - - @Test - public void testSyncQuery() throws IOException { - Iterator pages = - SyncQuerySample.run( - Constants.PROJECT_ID, - "SELECT corpus FROM `publicdata.samples.shakespeare` GROUP BY corpus;", - 10000, - false /* useLegacySql */); - while (pages.hasNext()) { - assertThat(pages.next().getRows()).isNotEmpty(); - } - } - - @Test - public void testSyncQueryLegacySql() throws IOException { - Iterator pages = - SyncQuerySample.run(Constants.PROJECT_ID, Constants.QUERY, 10000, true /* useLegacySql */); - while (pages.hasNext()) { - assertThat(pages.next().getRows()).isNotEmpty(); - } - } -} diff --git a/compute/cmdline/pom.xml b/compute/cmdline/pom.xml index 39ff3628d90..32365aa38a9 100644 --- a/compute/cmdline/pom.xml +++ b/compute/cmdline/pom.xml @@ -1,5 +1,5 @@ diff --git a/datastore/pom.xml b/datastore/pom.xml index 359287bb690..4f52caadf2e 100644 --- a/datastore/pom.xml +++ b/datastore/pom.xml @@ -41,7 +41,7 @@ com.google.cloud google-cloud-datastore - 0.12.0-beta + 0.13.0-beta diff --git a/datastore/src/main/java/com/google/datastore/snippets/TaskList.java b/datastore/src/main/java/com/google/datastore/snippets/TaskList.java index 1482e0784ba..43af1c2e0d2 100644 --- a/datastore/src/main/java/com/google/datastore/snippets/TaskList.java +++ b/datastore/src/main/java/com/google/datastore/snippets/TaskList.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/datastore/src/test/java/com/google/datastore/snippets/ConceptsTest.java b/datastore/src/test/java/com/google/datastore/snippets/ConceptsTest.java index 8970e83e2ba..b388e657d26 100644 --- a/datastore/src/test/java/com/google/datastore/snippets/ConceptsTest.java +++ b/datastore/src/test/java/com/google/datastore/snippets/ConceptsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/endpoints/bookstore-grpc/api/build.gradle b/endpoints/bookstore-grpc/api/build.gradle index f8331ff246b..140900941b5 100644 --- a/endpoints/bookstore-grpc/api/build.gradle +++ b/endpoints/bookstore-grpc/api/build.gradle @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. All Rights Reserved. +// 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. diff --git a/endpoints/bookstore-grpc/api/src/main/proto/bookstore.proto b/endpoints/bookstore-grpc/api/src/main/proto/bookstore.proto index c3f685f1a0c..838c5302e81 100644 --- a/endpoints/bookstore-grpc/api/src/main/proto/bookstore.proto +++ b/endpoints/bookstore-grpc/api/src/main/proto/bookstore.proto @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. All Rights Reserved. +// 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. diff --git a/endpoints/bookstore-grpc/client/build.gradle b/endpoints/bookstore-grpc/client/build.gradle index 2bc4d2d74b2..fcedbceec5a 100644 --- a/endpoints/bookstore-grpc/client/build.gradle +++ b/endpoints/bookstore-grpc/client/build.gradle @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. All Rights Reserved. +// 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. diff --git a/endpoints/bookstore-grpc/client/src/main/java/com/google/endpoints/examples/bookstore/BookstoreClient.java b/endpoints/bookstore-grpc/client/src/main/java/com/google/endpoints/examples/bookstore/BookstoreClient.java index 1ff9cd7a0ed..39cf0c540ea 100644 --- a/endpoints/bookstore-grpc/client/src/main/java/com/google/endpoints/examples/bookstore/BookstoreClient.java +++ b/endpoints/bookstore-grpc/client/src/main/java/com/google/endpoints/examples/bookstore/BookstoreClient.java @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. All Rights Reserved. +// 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. diff --git a/endpoints/bookstore-grpc/server/build.gradle b/endpoints/bookstore-grpc/server/build.gradle index b1245eae51f..76eab5b6740 100644 --- a/endpoints/bookstore-grpc/server/build.gradle +++ b/endpoints/bookstore-grpc/server/build.gradle @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. All Rights Reserved. +// 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. diff --git a/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreData.java b/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreData.java index 95a04226a93..8f3c961260a 100644 --- a/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreData.java +++ b/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreData.java @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. All Rights Reserved. +// 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. diff --git a/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreServer.java b/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreServer.java index 6cd64a0f4ff..2a5c139df0a 100644 --- a/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreServer.java +++ b/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreServer.java @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. All Rights Reserved. +// 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. diff --git a/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreService.java b/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreService.java index f46cc87010c..97f666a3b8a 100644 --- a/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreService.java +++ b/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/BookstoreService.java @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. All Rights Reserved. +// 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. diff --git a/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/ShelfEntity.java b/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/ShelfEntity.java index 82ed11da7dd..f9764e311df 100644 --- a/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/ShelfEntity.java +++ b/endpoints/bookstore-grpc/server/src/main/java/com/google/endpoints/examples/bookstore/ShelfEntity.java @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. All Rights Reserved. +// 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. diff --git a/endpoints/getting-started/container-engine.yaml b/endpoints/getting-started/container-engine.yaml index bec789f3a26..718b8364648 100644 --- a/endpoints/getting-started/container-engine.yaml +++ b/endpoints/getting-started/container-engine.yaml @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. All Rights Reserved. +# Copyright 2015 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/endpoints/getting-started/openapi.yaml b/endpoints/getting-started/openapi.yaml index 634ef8b38dc..74c94107996 100644 --- a/endpoints/getting-started/openapi.yaml +++ b/endpoints/getting-started/openapi.yaml @@ -32,6 +32,8 @@ paths: required: true schema: $ref: "#/definitions/echoMessage" + security: + - api_key: [] "/auth/info/googlejwt": get: description: "Returns the requests' authentication information." @@ -43,12 +45,9 @@ paths: description: "Authenication info." schema: $ref: "#/definitions/authInfoResponse" - x-security: - - google_jwt: - audiences: - # This must match the "aud" field in the JWT. You can add multiple - # audiences to accept JWTs from multiple clients. - - "echo.endpoints.sample.google.com" + security: + - api_key: [] + - google_jwt: [] "/auth/info/googleidtoken": get: description: "Returns the requests' authentication information." @@ -60,12 +59,9 @@ paths: description: "Authenication info." schema: $ref: "#/definitions/authInfoResponse" - x-security: - - google_id_token: - audiences: - # Your OAuth2 client's Client ID must be added here. You can add - # multiple client IDs to accept tokens from multiple clients. - - "YOUR-CLIENT-ID" + security: + - api_key: [] + - google_id_token: [] definitions: echoMessage: properties: @@ -77,9 +73,6 @@ definitions: type: "string" email: type: "string" -# This section requires all requests to any path to require an API key. -security: -- api_key: [] securityDefinitions: # This section configures basic authentication with an API key. api_key: @@ -97,6 +90,9 @@ securityDefinitions: x-google-issuer: "jwt-client.endpoints.sample.google.com" # Update this with your service account's email address. x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/jwk/YOUR-SERVICE-ACCOUNT-EMAIL" + # This must match the "aud" field in the JWT. You can add multiple + # audiences to accept JWTs from multiple clients. + x-google-audiences: "echo.endpoints.sample.google.com" # This section configures authentication using Google OAuth2 ID Tokens. # ID Tokens can be obtained using OAuth2 clients, and can be used to access # your API on behalf of a particular user. @@ -104,5 +100,8 @@ securityDefinitions: authorizationUrl: "" flow: "implicit" type: "oauth2" - x-google-issuer: "accounts.google.com" - x-google-jwks_uri: "https://www.googleapis.com/oauth2/v1/certs" + x-google-issuer: "https://accounts.google.com" + x-google-jwks_uri: "https://www.googleapis.com/oauth2/v3/certs" + # Your OAuth2 client's Client ID must be added here. You can add + # multiple client IDs to accept tokens from multiple clients. + x-google-audiences: "YOUR-CLIENT-ID" 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 4ed7ba4a813..88cc789bf19 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,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 40e0f1f5038..729d14e7687 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 @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/endpoints/multiple-versions/README.md b/endpoints/multiple-versions/README.md new file mode 100644 index 00000000000..5ba505d5c4f --- /dev/null +++ b/endpoints/multiple-versions/README.md @@ -0,0 +1,25 @@ +# Google Cloud Endpoints & Java with Multiple Versions +This sample demonstrates how to use Google Cloud Endpoints using a Java backend +that supports multiple versions. + +For more information, see the Google Cloud Endpoints documentation on +[Running multiple API versions](https://cloud.google.com/endpoints/docs/multiple-api-versions). + +## Calling your API + +Please refer to the Google Cloud Endpoints +[documentation](https://cloud.google.com/endpoints/docs/app-engine/) for App +Engine Flexible Environment to learn about creating an API Key and calling your +API. + +## Viewing the Endpoints graphs + +By using Endpoints, you get access to several metrics that are displayed +graphically in the Cloud Console. + +To view the Endpoints graphs: + +1. Go to the [Endpoints section in Cloud Console](https://console.cloud.google.com/endpoints) + of the project you deployed your API to. +2. Click on your API to view more detailed information about the metrics + collected. diff --git a/endpoints/multiple-versions/container-engine.yaml b/endpoints/multiple-versions/container-engine.yaml new file mode 100644 index 00000000000..718b8364648 --- /dev/null +++ b/endpoints/multiple-versions/container-engine.yaml @@ -0,0 +1,56 @@ +# Copyright 2015 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. + +apiVersion: v1 +kind: Service +metadata: + name: esp-echo +spec: + ports: + - port: 80 + targetPort: 8081 + protocol: TCP + name: http + selector: + app: esp-echo + type: LoadBalancer +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: esp-echo +spec: + replicas: 1 + template: + metadata: + labels: + app: esp-echo + spec: + containers: + # [START esp] + - name: esp + image: gcr.io/endpoints-release/endpoints-runtime:1 + args: [ + "-p", "8081", + "-a", "127.0.0.1:8080", + "-s", "SERVICE_NAME", + "-v", "SERVICE_CONFIG_ID", + ] + # [END esp] + ports: + - containerPort: 8081 + - name: echo + image: gcr.io/google-samples/echo-java:1.0 + ports: + - containerPort: 8080 diff --git a/endpoints/multiple-versions/openapi-v2.yaml b/endpoints/multiple-versions/openapi-v2.yaml new file mode 100644 index 00000000000..d80ff233952 --- /dev/null +++ b/endpoints/multiple-versions/openapi-v2.yaml @@ -0,0 +1,125 @@ +# Copyright 2015 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. + +# [START swagger] +swagger: "2.0" +info: + description: "A simple Google Cloud Endpoints API example." + title: "Endpoints Example" + version: "2.0.0" +host: "echo-api.endpoints.YOUR-PROJECT-ID.cloud.goog" +# [END swagger] +basePath: "/v2" +consumes: + - "application/json" +produces: + - "application/json" +schemes: + - "https" +paths: + "/echo": + post: + description: "Echo back a given message." + operationId: "echo" + produces: + - "application/json" + responses: + 200: + description: "Echo" + schema: + $ref: "#/definitions/echoMessage" + parameters: + - + description: "Message to echo" + in: body + name: message + required: true + schema: + $ref: "#/definitions/echoMessage" + "/auth/info/googlejwt": + get: + description: "Returns the requests' authentication information." + operationId: "auth_info_google_jwt" + produces: + - "application/json" + responses: + 200: + description: "Authenication info." + schema: + $ref: "#/definitions/authInfoResponse" + x-security: + - + google_jwt: + audiences: + # This must match the "aud" field in the JWT. You can add multiple + # audiences to accept JWTs from multiple clients. + - "echo.endpoints.sample.google.com" + "/auth/info/googleidtoken": + get: + description: "Returns the requests' authentication information." + operationId: "authInfoGoogleIdToken" + produces: + - "application/json" + responses: + 200: + description: "Authenication info." + schema: + $ref: "#/definitions/authInfoResponse" + x-security: + - + google_id_token: + audiences: + # Your OAuth2 client's Client ID must be added here. You can add + # multiple client IDs to accept tokens from multiple clients. + - "YOUR-CLIENT-ID" +definitions: + echoMessage: + properties: + msg: + type: "string" + authInfoResponse: + properties: + id: + type: "string" + email: + type: "string" +# This section requires all requests to any path to require an API key. +security: + - api_key: [] +securityDefinitions: + # This section configures basic authentication with an API key. + api_key: + type: "apiKey" + name: "key" + in: "query" + # This section configures authentication using Google API Service Accounts + # to sign a json web token. This is mostly used for server-to-server + # communication. + google_jwt: + authorizationUrl: "" + flow: "implicit" + type: "oauth2" + # This must match the 'iss' field in the JWT. + x-google-issuer: "jwt-client.endpoints.sample.google.com" + # Update this with your service account's email address. + x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/jwk/YOUR-SERVICE-ACCOUNT-EMAIL" + # This section configures authentication using Google OAuth2 ID Tokens. + # ID Tokens can be obtained using OAuth2 clients, and can be used to access + # your API on behalf of a particular user. + google_id_token: + authorizationUrl: "" + flow: "implicit" + type: "oauth2" + x-google-issuer: "accounts.google.com" + x-google-jwks_uri: "https://www.googleapis.com/oauth2/v1/certs" diff --git a/endpoints/multiple-versions/openapi.yaml b/endpoints/multiple-versions/openapi.yaml new file mode 100644 index 00000000000..3a939f9cec6 --- /dev/null +++ b/endpoints/multiple-versions/openapi.yaml @@ -0,0 +1,125 @@ +# Copyright 2015 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. + +# [START swagger] +swagger: "2.0" +info: + description: "A simple Google Cloud Endpoints API example." + title: "Endpoints Example" + version: "1.0.0" +host: "echo-api.endpoints.YOUR-PROJECT-ID.cloud.goog" +# [END swagger] +basePath: "/v1" +consumes: + - "application/json" +produces: + - "application/json" +schemes: + - "https" +paths: + "/echo": + post: + description: "Echo back a given message." + operationId: "echo" + produces: + - "application/json" + responses: + 200: + description: "Echo" + schema: + $ref: "#/definitions/echoMessage" + parameters: + - + description: "Message to echo" + in: body + name: message + required: true + schema: + $ref: "#/definitions/echoMessage" + "/auth/info/googlejwt": + get: + description: "Returns the requests' authentication information." + operationId: "auth_info_google_jwt" + produces: + - "application/json" + responses: + 200: + description: "Authenication info." + schema: + $ref: "#/definitions/authInfoResponse" + x-security: + - + google_jwt: + audiences: + # This must match the "aud" field in the JWT. You can add multiple + # audiences to accept JWTs from multiple clients. + - "echo.endpoints.sample.google.com" + "/auth/info/googleidtoken": + get: + description: "Returns the requests' authentication information." + operationId: "authInfoGoogleIdToken" + produces: + - "application/json" + responses: + 200: + description: "Authenication info." + schema: + $ref: "#/definitions/authInfoResponse" + x-security: + - + google_id_token: + audiences: + # Your OAuth2 client's Client ID must be added here. You can add + # multiple client IDs to accept tokens from multiple clients. + - "YOUR-CLIENT-ID" +definitions: + echoMessage: + properties: + message: + type: "string" + authInfoResponse: + properties: + id: + type: "string" + email: + type: "string" +# This section requires all requests to any path to require an API key. +security: + - api_key: [] +securityDefinitions: + # This section configures basic authentication with an API key. + api_key: + type: "apiKey" + name: "key" + in: "query" + # This section configures authentication using Google API Service Accounts + # to sign a json web token. This is mostly used for server-to-server + # communication. + google_jwt: + authorizationUrl: "" + flow: "implicit" + type: "oauth2" + # This must match the 'iss' field in the JWT. + x-google-issuer: "jwt-client.endpoints.sample.google.com" + # Update this with your service account's email address. + x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/jwk/YOUR-SERVICE-ACCOUNT-EMAIL" + # This section configures authentication using Google OAuth2 ID Tokens. + # ID Tokens can be obtained using OAuth2 clients, and can be used to access + # your API on behalf of a particular user. + google_id_token: + authorizationUrl: "" + flow: "implicit" + type: "oauth2" + x-google-issuer: "accounts.google.com" + x-google-jwks_uri: "https://www.googleapis.com/oauth2/v1/certs" diff --git a/endpoints/multiple-versions/pom.xml b/endpoints/multiple-versions/pom.xml new file mode 100644 index 00000000000..c0329ef52f5 --- /dev/null +++ b/endpoints/multiple-versions/pom.xml @@ -0,0 +1,84 @@ + + + + 4.0.0 + war + 1.0-SNAPSHOT + com.example.endpoints + endpoints + + + doc-samples + com.google.cloud + 1.0.0 + ../.. + + + + 1.8 + 1.8 + + 2.6 + + 1.0.0 + 9.3.8.v20160314 + + false + + + + + javax.servlet + javax.servlet-api + 3.1.0 + jar + provided + + + + com.google.code.gson + gson + 2.6.2 + compile + + + com.google.collections + google-collections + 1.0-rc2 + + + + + + ${project.build.directory}/${project.build.finalName}/WEB-INF/classes + + + com.google.cloud.tools + appengine-maven-plugin + ${appengine.maven.plugin} + + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.maven.plugin} + + + + diff --git a/endpoints/multiple-versions/src/main/appengine/app.yaml b/endpoints/multiple-versions/src/main/appengine/app.yaml new file mode 100644 index 00000000000..8a74a8488ca --- /dev/null +++ b/endpoints/multiple-versions/src/main/appengine/app.yaml @@ -0,0 +1,28 @@ +#!/bin/bash +# Copyright 2015 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. + +runtime: custom +env: flex + +handlers: +- url: /.* + script: this field is required, but ignored + secure: always + +endpoints_api_service: + # The following values are to be replaced by information from the output of + # 'gcloud service-management deploy openapi.yaml openapi-v2.yaml' command. + name: ENDPOINTS SERVICE-NAME + config_id: ENDPOINTS CONFIG-ID diff --git a/speech/grpc/bin/speech-sample-sync.sh b/endpoints/multiple-versions/src/main/docker/Dockerfile old mode 100755 new mode 100644 similarity index 64% rename from speech/grpc/bin/speech-sample-sync.sh rename to endpoints/multiple-versions/src/main/docker/Dockerfile index 322d11af2cb..0d8a4c7f1e8 --- a/speech/grpc/bin/speech-sample-sync.sh +++ b/endpoints/multiple-versions/src/main/docker/Dockerfile @@ -1,11 +1,11 @@ #!/bin/bash -# Copyright 2016 Google Inc. All Rights Reserved. +# Copyright 2015 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 +# 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, @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -SRC_DIR="$( cd "$( dirname "$0" )/.." && pwd )" -java -cp "${SRC_DIR}/target/grpc-sample-1.0-jar-with-dependencies.jar" \ - com.examples.cloud.speech.SyncRecognizeClient "$@" +FROM gcr.io/google_appengine/jetty9 + +ADD endpoints-1.0-SNAPSHOT.war $JETTY_BASE/webapps/root.war +ADD . /app +RUN chown jetty:jetty $JETTY_BASE/webapps/root.war diff --git a/flexible/endpoints/src/main/java/com/example/endpoints/AuthInfoServlet.java b/endpoints/multiple-versions/src/main/java/com/example/endpoints/AuthInfoServlet.java similarity index 97% rename from flexible/endpoints/src/main/java/com/example/endpoints/AuthInfoServlet.java rename to endpoints/multiple-versions/src/main/java/com/example/endpoints/AuthInfoServlet.java index 4ed7ba4a813..88cc789bf19 100644 --- a/flexible/endpoints/src/main/java/com/example/endpoints/AuthInfoServlet.java +++ b/endpoints/multiple-versions/src/main/java/com/example/endpoints/AuthInfoServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/endpoints/multiple-versions/src/main/java/com/example/endpoints/Echo.java b/endpoints/multiple-versions/src/main/java/com/example/endpoints/Echo.java new file mode 100644 index 00000000000..d7ef4f0b962 --- /dev/null +++ b/endpoints/multiple-versions/src/main/java/com/example/endpoints/Echo.java @@ -0,0 +1,58 @@ +/** + * Copyright 2015 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.endpoints; + +import com.example.endpoints.message.Message; +import com.example.endpoints.message.MessageTranslator; + +import com.google.gson.Gson; +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.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** Version agnostic echo. */ +public class Echo { + + public static void echo( + MessageTranslator translator, HttpServletRequest req, HttpServletResponse resp) + throws IOException { + resp.addHeader("Content-Encoding", "application/json"); + + try { + JsonReader jsonReader = new JsonReader(req.getReader()); + Message message = + translator.fromExternalToInternal(new Gson().fromJson(jsonReader, Map.class)); + performTask(message); + new Gson().toJson(translator.fromInternalToExternal(message), resp.getWriter()); + } catch (JsonParseException je) { + resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); + JsonObject error = new JsonObject(); + error.addProperty("code", HttpServletResponse.SC_BAD_REQUEST); + error.addProperty("message", "Body was not valid JSON."); + new Gson().toJson(error, resp.getWriter()); + } + } + + private static void performTask(Message message) { + message.setMessage(message.getMessage().toUpperCase()); + } +} diff --git a/endpoints/multiple-versions/src/main/java/com/example/endpoints/EchoV1Servlet.java b/endpoints/multiple-versions/src/main/java/com/example/endpoints/EchoV1Servlet.java new file mode 100644 index 00000000000..40befeea433 --- /dev/null +++ b/endpoints/multiple-versions/src/main/java/com/example/endpoints/EchoV1Servlet.java @@ -0,0 +1,42 @@ +/** + * Copyright 2015 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.endpoints; + +import com.example.endpoints.message.MessageTranslator; +import com.example.endpoints.message.MessageV1Translator; + +import java.io.IOException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** A servlet for v1 that echoes JSON message bodies. */ +@WebServlet("/v1/echo") +public class EchoV1Servlet extends HttpServlet { + + private MessageTranslator translator; + + public EchoV1Servlet() { + this.translator = new MessageV1Translator(); + } + + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + Echo.echo(translator, req, resp); + } +} diff --git a/endpoints/multiple-versions/src/main/java/com/example/endpoints/EchoV2Servlet.java b/endpoints/multiple-versions/src/main/java/com/example/endpoints/EchoV2Servlet.java new file mode 100644 index 00000000000..096ecb4d5e1 --- /dev/null +++ b/endpoints/multiple-versions/src/main/java/com/example/endpoints/EchoV2Servlet.java @@ -0,0 +1,42 @@ +/** + * Copyright 2015 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.endpoints; + +import com.example.endpoints.message.MessageTranslator; +import com.example.endpoints.message.MessageV2Translator; + +import java.io.IOException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** A servlet for v2 that echoes JSON message bodies. */ +@WebServlet("/v2/echo") +public class EchoV2Servlet extends HttpServlet { + + private MessageTranslator translator; + + public EchoV2Servlet() { + this.translator = new MessageV2Translator(); + } + + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + Echo.echo(translator, req, resp); + } +} diff --git a/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/Message.java b/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/Message.java new file mode 100644 index 00000000000..29445235e8f --- /dev/null +++ b/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/Message.java @@ -0,0 +1,34 @@ +/** + * Copyright 2015 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.endpoints.message; + +/** Internal representation of a message. */ +public class Message { + private String message; + + public Message(String message) { + this.message = message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getMessage() { + return this.message; + } +} diff --git a/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/MessageTranslator.java b/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/MessageTranslator.java new file mode 100644 index 00000000000..35b2621a3b7 --- /dev/null +++ b/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/MessageTranslator.java @@ -0,0 +1,26 @@ +/** + * Copyright 2015 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.endpoints.message; + +import java.util.Map; + +/** Translates between external and internal representations of a message. */ +public interface MessageTranslator { + Message fromExternalToInternal(Map externalMessage); + + Map fromInternalToExternal(Message internalMessage); +} diff --git a/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/MessageV1Translator.java b/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/MessageV1Translator.java new file mode 100644 index 00000000000..f246d89ca17 --- /dev/null +++ b/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/MessageV1Translator.java @@ -0,0 +1,34 @@ +/** + * Copyright 2015 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.endpoints.message; + +import com.google.common.collect.ImmutableMap; + +import java.util.Map; + +/** Translates between v1 external and internal representations of a message. */ +public class MessageV1Translator implements MessageTranslator { + private static final String MESSAGE_KEY = "message"; + + public Message fromExternalToInternal(Map v1Message) { + return new Message(v1Message.get(MESSAGE_KEY)); + } + + public Map fromInternalToExternal(Message internalMessage) { + return ImmutableMap.of(MESSAGE_KEY, internalMessage.getMessage()); + } +} diff --git a/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/MessageV2Translator.java b/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/MessageV2Translator.java new file mode 100644 index 00000000000..e5e172113b0 --- /dev/null +++ b/endpoints/multiple-versions/src/main/java/com/example/endpoints/messsage/MessageV2Translator.java @@ -0,0 +1,34 @@ +/** + * Copyright 2015 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.endpoints.message; + +import com.google.common.collect.ImmutableMap; + +import java.util.Map; + +/** Translates between v2 external and internal representations of a message. */ +public class MessageV2Translator implements MessageTranslator { + private static final String MESSAGE_KEY = "msg"; + + public Message fromExternalToInternal(Map v2Message) { + return new Message(v2Message.get(MESSAGE_KEY)); + } + + public Map fromInternalToExternal(Message internalMessage) { + return ImmutableMap.of(MESSAGE_KEY, internalMessage.getMessage()); + } +} diff --git a/flexible/CONTRIBUTING.md b/flexible/CONTRIBUTING.md deleted file mode 100644 index d9365cc8f82..00000000000 --- a/flexible/CONTRIBUTING.md +++ /dev/null @@ -1,35 +0,0 @@ -# How to become a contributor and submit your own code - -## Contributor License Agreements - -We'd love to accept your patches! Before we can take them, we -have to jump a couple of legal hurdles. - -Please fill out either the individual or corporate Contributor License Agreement -(CLA). - - * If you are an individual writing original source code and you're sure you - own the intellectual property, then you'll need to sign an [individual CLA] - (https://developers.google.com/open-source/cla/individual). - * If you work for a company that wants to allow you to contribute your work, - then you'll need to sign a [corporate CLA] - (https://developers.google.com/open-source/cla/corporate). - -Follow either of the two links above to access the appropriate CLA and -instructions for how to sign and return it. Once we receive it, we'll be able to -accept your pull requests. - -## Contributing A Patch - -1. Submit an issue describing your proposed change to the repo in question. -1. The repo owner will respond to your issue promptly. -1. If your proposed change is accepted, and you haven't already done so, sign a - Contributor License Agreement (see details above). -1. Fork the desired repo, develop and test your code changes. -1. Ensure that your code adheres to the existing style in the sample to which - you are contributing. Refer to the - [Google Cloud Platform Samples Style Guide] - (https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the - recommended coding standards for this organization. -1. Ensure that your code has an appropriate set of unit tests which all pass. -1. Submit a pull request. diff --git a/flexible/LICENSE b/flexible/LICENSE deleted file mode 100644 index 57bc88a15a0..00000000000 --- a/flexible/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. - diff --git a/flexible/README.mdpp b/flexible/README.mdpp deleted file mode 100644 index 6a014ae9f07..00000000000 --- a/flexible/README.mdpp +++ /dev/null @@ -1,24 +0,0 @@ -# Google App Engine Flexible Environment Java Samples - -This is a repository that contains Java code samples for [Google App Engine -flexible environment][aeflex-docs]. - -See our other [Google Cloud Platform GitHub -repos](https://github.com/GoogleCloudPlatform) for sample applications and -scaffolding for other frameworks and use cases. - -[aeflex-docs]: https://cloud.google.com/appengine/docs/flexible/ - -!INCLUDE "../.github/templates/getting-sample-code.mdpp" - -!INCLUDE "../.github/templates/appengine-flexible-before-you-begin.mdpp" - -!INCLUDE "../.github/templates/appengine-flexible-deploy.mdpp" - -## Contributing changes - -* See [CONTRIBUTING.md](CONTRIBUTING.md) - -## Licensing - -* See [LICENSE](LICENSE) diff --git a/flexible/analytics/src/main/appengine/app.yaml b/flexible/analytics/src/main/appengine/app.yaml deleted file mode 100644 index 3273b02a0e8..00000000000 --- a/flexible/analytics/src/main/appengine/app.yaml +++ /dev/null @@ -1,11 +0,0 @@ -runtime: java -env: flex - -handlers: -- url: /.* - script: this field is required, but ignored - -# [START env_variables] -env_variables: - GA_TRACKING_ID: YOUR-GA-TRACKING-ID -# [END env_variables] diff --git a/flexible/async-rest/LICENSE b/flexible/async-rest/LICENSE deleted file mode 100644 index 04cb0d70775..00000000000 --- a/flexible/async-rest/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2013 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. diff --git a/flexible/cloudsql/.gitignore b/flexible/cloudsql/.gitignore deleted file mode 100644 index 83926cdbcaa..00000000000 --- a/flexible/cloudsql/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/bin/ -target diff --git a/flexible/cloudsql/README.md b/flexible/cloudsql/README.md deleted file mode 100644 index d2c3f3e6e67..00000000000 --- a/flexible/cloudsql/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Cloud SQL sample for Google App Engine Flexible -This sample demonstrates how to use [Cloud SQL](https://cloud.google.com/sql/) on Google App Engine -Flexible. - -## Setup -Before you can run or deploy the sample, you will need to create a [Cloud SQL instance)](https://cloud.google.com/sql/docs/create-instance) - -1. Create a new user and database for the application. The easiest way to do this is via the [Google -Developers Console](https://console.cloud.google.com/sql/instances). Alternatively, you can use -MySQL tools such as the command line client or workbench. -2. Change the root password (under Access Control) and / or create a new user / password. -3. Create a Database (under Databases) (or use MySQL with `gcloud sql connect --user=root`) -4. Note the **Instance connection name** under Overview > Properties -(It will look like project:region:zone for 2nd Generation) - -## Deploying - -```bash -$ mvn clean appengine:deploy -DINSTANCE_CONNECTION_NAME=instanceConnectionName -Duser=root --Dpassword=myPassword -Ddatabase=myDatabase -``` - -Or you can update the properties in `pom.xml` - -## Running locally - -```bash -$ mvn clean jetty:run -DINSTANCE_CONNECTION_NAME=instanceConnectionName -Duser=root -Dpassword=myPassowrd -Ddatabase=myDatabase -``` diff --git a/flexible/cloudstorage/README.md b/flexible/cloudstorage/README.md deleted file mode 100644 index 1d0ee071298..00000000000 --- a/flexible/cloudstorage/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Cloud Storage sample for Google Managed VMs -This sample demonstrates how to use [Cloud Storage](https://cloud.google.com/storage/) on Google Managed VMs. - -## Setup -Before you can run or deploy the sample, you will need to do the following: - -1. Enable the Cloud Storage API in the [Google Developers Console](https://console.developers.google.com/project/_/apiui/apiview/storage/overview). -2. Create a Cloud Storage Bucket. You can do this with the [Google Cloud SDK](https://cloud.google.com/sdk) using the following command: - - ``` - $ gsutil mb gs://[your-bucket-name] - ``` -3. Set the default ACL on your bucket to public read in order to serve files directly from Cloud Storage. You can do this with the [Google Cloud SDK](https://cloud.google.com/sdk) using the following command: - - ``` - $ gsutil defacl set public-read gs://[your-bucket-name] - ``` -4. Update the bucket name in `src/main/appengine/app.yaml`. This makes the bucket name an environment variable in deployment. You still need to set the environment variable when running locally, as shown below. - -## Running locally - $ export BUCKET_NAME=[your-bucket-name] - $ mvn clean jetty:run - -## Deploying - $ mvn clean appengine:deploy diff --git a/flexible/cloudstorage/src/main/appengine/app.yaml b/flexible/cloudstorage/src/main/appengine/app.yaml deleted file mode 100644 index da52dfa3ff2..00000000000 --- a/flexible/cloudstorage/src/main/appengine/app.yaml +++ /dev/null @@ -1,11 +0,0 @@ -runtime: java -env: flex - -handlers: -- url: /.* - script: this field is required, but ignored - -# [START env_variables] -env_variables: - BUCKET_NAME: YOUR-BUCKET-NAME -# [END env_variables] diff --git a/flexible/cron/README.md b/flexible/cron/README.md deleted file mode 100644 index 3535287907f..00000000000 --- a/flexible/cron/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# App Engine Cron Service sample for Google App Engine -This sample demonstrates how to deploy App Engine Cron Service to ping a servlet deployed in the app. - -## Running locally - $ mvn jetty:run - -## Deploying app - $ mvn gcloud:deploy - -## Deploying cron job - $ gcloud app deploy cron.yaml \ No newline at end of file diff --git a/flexible/cron/src/main/appengine/app.yaml b/flexible/cron/src/main/appengine/app.yaml deleted file mode 100644 index d7890aaff58..00000000000 --- a/flexible/cron/src/main/appengine/app.yaml +++ /dev/null @@ -1,6 +0,0 @@ -runtime: java -env: flex - -handlers: -- url: /.* - script: this field is required, but ignored diff --git a/flexible/cron/src/main/appengine/cron.yaml b/flexible/cron/src/main/appengine/cron.yaml deleted file mode 100644 index 989f1fe8b3f..00000000000 --- a/flexible/cron/src/main/appengine/cron.yaml +++ /dev/null @@ -1,4 +0,0 @@ -cron: - - description: sample cron job - url: /cron - schedule: every 1 mins \ No newline at end of file diff --git a/flexible/async-rest/README.md b/flexible/custom-runtime/async-rest/README.md similarity index 99% rename from flexible/async-rest/README.md rename to flexible/custom-runtime/async-rest/README.md index d88caad417e..7eff0ca6f1f 100644 --- a/flexible/async-rest/README.md +++ b/flexible/custom-runtime/async-rest/README.md @@ -45,4 +45,3 @@ To automatically stage and deploy the webapp to your project in the cloud do: mvn appengine:deploy See here for more information on the [GCloud Maven Plugin](https://github.com/GoogleCloudPlatform/gcloud-maven-plugin). - diff --git a/flexible/async-rest/pom.xml b/flexible/custom-runtime/async-rest/pom.xml similarity index 94% rename from flexible/async-rest/pom.xml rename to flexible/custom-runtime/async-rest/pom.xml index bc9c17834c8..b477f3138ca 100644 --- a/flexible/async-rest/pom.xml +++ b/flexible/custom-runtime/async-rest/pom.xml @@ -1,6 +1,6 @@ 4.0.0 - com.google.appengine.demos + com.example.flexible async-rest 1.0.0-SNAPSHOT war - doc-samples - com.google.cloud + com.example.flexible + flex-docs-samples 1.0.0 ../.. diff --git a/flexible/async-rest/src/main/appengine/app.yaml b/flexible/custom-runtime/async-rest/src/main/appengine/app.yaml similarity index 93% rename from flexible/async-rest/src/main/appengine/app.yaml rename to flexible/custom-runtime/async-rest/src/main/appengine/app.yaml index 378f5b9dbce..4206cff71b2 100644 --- a/flexible/async-rest/src/main/appengine/app.yaml +++ b/flexible/custom-runtime/async-rest/src/main/appengine/app.yaml @@ -1,4 +1,4 @@ -# Copyright 2016 Google Inc. All Rights Reserved. +# 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. diff --git a/flexible/async-rest/src/main/docker/Dockerfile b/flexible/custom-runtime/async-rest/src/main/docker/Dockerfile similarity index 100% rename from flexible/async-rest/src/main/docker/Dockerfile rename to flexible/custom-runtime/async-rest/src/main/docker/Dockerfile diff --git a/flexible/async-rest/src/main/docker/jetty-logging.properties b/flexible/custom-runtime/async-rest/src/main/docker/jetty-logging.properties similarity index 99% rename from flexible/async-rest/src/main/docker/jetty-logging.properties rename to flexible/custom-runtime/async-rest/src/main/docker/jetty-logging.properties index fd14a1d4c87..19ee58ff79f 100644 --- a/flexible/async-rest/src/main/docker/jetty-logging.properties +++ b/flexible/custom-runtime/async-rest/src/main/docker/jetty-logging.properties @@ -16,4 +16,3 @@ org.eclipse.jetty.STACKS=true ## If LONG is true, fully qualified package names are used rather than abbreviations org.eclipse.jetty.LONG=false - diff --git a/flexible/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AbstractRestServlet.java b/flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/AbstractRestServlet.java similarity index 98% rename from flexible/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AbstractRestServlet.java rename to flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/AbstractRestServlet.java index 51a3e49b096..101e511245b 100644 --- a/flexible/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AbstractRestServlet.java +++ b/flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/AbstractRestServlet.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/flexible/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AsyncRestServlet.java b/flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/AsyncRestServlet.java similarity index 99% rename from flexible/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AsyncRestServlet.java rename to flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/AsyncRestServlet.java index 571752ea08d..712e3587cd8 100644 --- a/flexible/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AsyncRestServlet.java +++ b/flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/AsyncRestServlet.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/flexible/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java b/flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/DumpServlet.java similarity index 97% rename from flexible/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java rename to flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/DumpServlet.java index 8f99971f8b3..eeb4d593dc5 100644 --- a/flexible/async-rest/src/main/java/com/google/appengine/demos/DumpServlet.java +++ b/flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/DumpServlet.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.appengine.demos; +package com.example.flexible.asyncrest; import java.io.IOException; import java.io.PrintWriter; diff --git a/flexible/async-rest/src/main/java/com/google/appengine/demos/asyncrest/SerialRestServlet.java b/flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/SerialRestServlet.java similarity index 98% rename from flexible/async-rest/src/main/java/com/google/appengine/demos/asyncrest/SerialRestServlet.java rename to flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/SerialRestServlet.java index 19d3bed254b..9717300e340 100644 --- a/flexible/async-rest/src/main/java/com/google/appengine/demos/asyncrest/SerialRestServlet.java +++ b/flexible/custom-runtime/async-rest/src/main/java/com/example/flexible/asyncrest/SerialRestServlet.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/flexible/async-rest/src/main/webapp/WEB-INF/jetty-web.xml b/flexible/custom-runtime/async-rest/src/main/webapp/WEB-INF/jetty-web.xml similarity index 100% rename from flexible/async-rest/src/main/webapp/WEB-INF/jetty-web.xml rename to flexible/custom-runtime/async-rest/src/main/webapp/WEB-INF/jetty-web.xml diff --git a/flexible/async-rest/src/main/webapp/WEB-INF/web.xml b/flexible/custom-runtime/async-rest/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from flexible/async-rest/src/main/webapp/WEB-INF/web.xml rename to flexible/custom-runtime/async-rest/src/main/webapp/WEB-INF/web.xml diff --git a/flexible/async-rest/src/main/webapp/asyncrest/green.png b/flexible/custom-runtime/async-rest/src/main/webapp/asyncrest/green.png similarity index 100% rename from flexible/async-rest/src/main/webapp/asyncrest/green.png rename to flexible/custom-runtime/async-rest/src/main/webapp/asyncrest/green.png diff --git a/flexible/async-rest/src/main/webapp/asyncrest/red.png b/flexible/custom-runtime/async-rest/src/main/webapp/asyncrest/red.png similarity index 100% rename from flexible/async-rest/src/main/webapp/asyncrest/red.png rename to flexible/custom-runtime/async-rest/src/main/webapp/asyncrest/red.png diff --git a/flexible/async-rest/src/main/webapp/index.html b/flexible/custom-runtime/async-rest/src/main/webapp/index.html similarity index 99% rename from flexible/async-rest/src/main/webapp/index.html rename to flexible/custom-runtime/async-rest/src/main/webapp/index.html index 1c4966e8185..f8ed1b5b2ae 100644 --- a/flexible/async-rest/src/main/webapp/index.html +++ b/flexible/custom-runtime/async-rest/src/main/webapp/index.html @@ -57,6 +57,5 @@

Blocking vs Asynchronous REST

- diff --git a/flexible/endpoints/README.md b/flexible/custom-runtime/endpoints/README.md similarity index 100% rename from flexible/endpoints/README.md rename to flexible/custom-runtime/endpoints/README.md diff --git a/flexible/endpoints/pom.xml b/flexible/custom-runtime/endpoints/pom.xml similarity index 77% rename from flexible/endpoints/pom.xml rename to flexible/custom-runtime/endpoints/pom.xml index 17a01909014..e566e464a24 100644 --- a/flexible/endpoints/pom.xml +++ b/flexible/custom-runtime/endpoints/pom.xml @@ -1,4 +1,19 @@ + @@ -9,8 +24,8 @@ flexible-endpoints - doc-samples - com.google.cloud + com.example.flexible + flex-docs-samples 1.0.0 ../.. diff --git a/flexible/endpoints/src/main/appengine/Dockerfile b/flexible/custom-runtime/endpoints/src/main/appengine/Dockerfile similarity index 100% rename from flexible/endpoints/src/main/appengine/Dockerfile rename to flexible/custom-runtime/endpoints/src/main/appengine/Dockerfile diff --git a/flexible/custom-runtime/endpoints/src/main/appengine/app.yaml b/flexible/custom-runtime/endpoints/src/main/appengine/app.yaml new file mode 100644 index 00000000000..4ff36f4f50c --- /dev/null +++ b/flexible/custom-runtime/endpoints/src/main/appengine/app.yaml @@ -0,0 +1,27 @@ +# Copyright 2015 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. +# [START appyaml] +runtime: custom +env: flex + +handlers: +- url: /.* + script: this field is required, but ignored + +beta_settings: + # Enable Google Cloud Endpoints API management. + use_endpoints_api_management: true + # Specify the Open API specification. + endpoints_swagger_spec_file: openapi.yaml +# [END appyaml] diff --git a/flexible/endpoints/src/main/appengine/openapi.yaml b/flexible/custom-runtime/endpoints/src/main/appengine/openapi.yaml similarity index 83% rename from flexible/endpoints/src/main/appengine/openapi.yaml rename to flexible/custom-runtime/endpoints/src/main/appengine/openapi.yaml index 71bac9ce62f..df9d42c65d3 100644 --- a/flexible/endpoints/src/main/appengine/openapi.yaml +++ b/flexible/custom-runtime/endpoints/src/main/appengine/openapi.yaml @@ -1,3 +1,17 @@ +# Copyright 2015 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. +# [START openapiyaml] swagger: "2.0" info: description: "A simple Google Cloud Endpoints API example." @@ -104,3 +118,4 @@ securityDefinitions: type: "oauth2" x-issuer: "accounts.google.com" x-jwks_uri: "https://www.googleapis.com/oauth2/v1/certs" +# [END openapiyaml] diff --git a/flexible/custom-runtime/endpoints/src/main/java/com/example/endpoints/AuthInfoServlet.java b/flexible/custom-runtime/endpoints/src/main/java/com/example/endpoints/AuthInfoServlet.java new file mode 100644 index 00000000000..88cc789bf19 --- /dev/null +++ b/flexible/custom-runtime/endpoints/src/main/java/com/example/endpoints/AuthInfoServlet.java @@ -0,0 +1,58 @@ +/** + * Copyright 2015 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.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; +import javax.servlet.http.HttpServletResponse; + +/** + * 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 { + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + String encodedInfo = req.getHeader("X-Endpoint-API-UserInfo"); + if (encodedInfo == null || encodedInfo == "") { + JsonObject anon = new JsonObject(); + anon.addProperty("id", "anonymous"); + new Gson().toJson(anon, resp.getWriter()); + return; + } + + try { + byte[] authInfo = Base64.getDecoder().decode(encodedInfo); + resp.getOutputStream().write(authInfo); + } catch (IllegalArgumentException iae) { + resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); + JsonObject error = new JsonObject(); + error.addProperty("code", HttpServletResponse.SC_BAD_REQUEST); + error.addProperty("message", "Could not decode auth info."); + new Gson().toJson(error, resp.getWriter()); + } + } +} diff --git a/flexible/endpoints/src/main/java/com/example/endpoints/EchoServlet.java b/flexible/custom-runtime/endpoints/src/main/java/com/example/endpoints/EchoServlet.java similarity index 97% rename from flexible/endpoints/src/main/java/com/example/endpoints/EchoServlet.java rename to flexible/custom-runtime/endpoints/src/main/java/com/example/endpoints/EchoServlet.java index 40e0f1f5038..729d14e7687 100644 --- a/flexible/endpoints/src/main/java/com/example/endpoints/EchoServlet.java +++ b/flexible/custom-runtime/endpoints/src/main/java/com/example/endpoints/EchoServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/flexible/extending-runtime/README.md b/flexible/custom-runtime/extending-runtime/README.md similarity index 88% rename from flexible/extending-runtime/README.md rename to flexible/custom-runtime/extending-runtime/README.md index a1c5801e06a..7f6c8389703 100644 --- a/flexible/extending-runtime/README.md +++ b/flexible/custom-runtime/extending-runtime/README.md @@ -1,6 +1,2 @@ # Java extending runtime sample for Google App Engine Flexible This sample demonstrates how to use custom runtime on Google App Engine Flexible - -## Setup - -... ?? diff --git a/flexible/extending-runtime/pom.xml b/flexible/custom-runtime/extending-runtime/pom.xml similarity index 94% rename from flexible/extending-runtime/pom.xml rename to flexible/custom-runtime/extending-runtime/pom.xml index 6a1fb31890d..3d6b6e3f673 100644 --- a/flexible/extending-runtime/pom.xml +++ b/flexible/custom-runtime/extending-runtime/pom.xml @@ -1,5 +1,5 @@ + 4.0.0 war @@ -21,10 +22,10 @@ flexible-analytics - doc-samples - com.google.cloud + com.example.flexible + flex-docs-samples 1.0.0 - ../.. + ../../.. @@ -33,10 +34,10 @@ 1.2.1 9.3.8.v20160314 - false + 3.3.9 diff --git a/flexible/java-runtime/samples/analytics/src/main/appengine/app.yaml b/flexible/java-runtime/samples/analytics/src/main/appengine/app.yaml new file mode 100644 index 00000000000..d6fe45ff48f --- /dev/null +++ b/flexible/java-runtime/samples/analytics/src/main/appengine/app.yaml @@ -0,0 +1,24 @@ +# Copyright 2015 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. + +runtime: java +env: flex + +handlers: +- url: /.* + script: this field is required, but ignored + +# [START env_variables] +env_variables: + GA_TRACKING_ID: YOUR-GA-TRACKING-ID +# [END env_variables] \ No newline at end of file diff --git a/flexible/analytics/src/main/java/com/example/analytics/AnalyticsServlet.java b/flexible/java-runtime/samples/analytics/src/main/java/com/example/flexible/analytics/AnalyticsServlet.java similarity index 93% rename from flexible/analytics/src/main/java/com/example/analytics/AnalyticsServlet.java rename to flexible/java-runtime/samples/analytics/src/main/java/com/example/flexible/analytics/AnalyticsServlet.java index d451a799629..4d41ebbe21f 100644 --- a/flexible/analytics/src/main/java/com/example/analytics/AnalyticsServlet.java +++ b/flexible/java-runtime/samples/analytics/src/main/java/com/example/flexible/analytics/AnalyticsServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 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,7 +14,7 @@ * limitations under the License. */ -package com.example.analytics; +package com.example.flexible.analytics; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; @@ -24,7 +24,6 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; - import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; @@ -33,7 +32,7 @@ // [START example] @SuppressWarnings("serial") -@WebServlet(name = "analytics", value = "") +@WebServlet(name = "Add Google Analytics event", value = {"/analytics.html"}) public class AnalyticsServlet extends HttpServlet { @Override diff --git a/flexible/cloudsql/pom.xml b/flexible/java-runtime/samples/cloudsql/pom.xml similarity index 78% rename from flexible/cloudsql/pom.xml rename to flexible/java-runtime/samples/cloudsql/pom.xml index 5794f3759cf..82dce7da66b 100644 --- a/flexible/cloudsql/pom.xml +++ b/flexible/java-runtime/samples/cloudsql/pom.xml @@ -21,14 +21,23 @@ flexible-cloudsql - doc-samples - com.google.cloud + com.example.flexible + flex-docs-samples 1.0.0 - ../.. + ../../.. - + 1.8 + 1.8 + + 1.2.1 + 9.3.8.v20160314 + + false + + + - 1.8 - 1.8 - - 1.2.1 - 9.3.8.v20160314 - - false - jdbc:mysql://google/${database}?cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=${user}&password=${password}&useSSL=false + - + + com.google.api-client + google-api-client + 1.21.0 + + + com.google.api-client + google-api-client-appengine + 1.21.0 + + + com.google.api-client + google-api-client-servlet + 1.21.0 + javax.servlet javax.servlet-api @@ -59,7 +74,7 @@ provided - + mysql mysql-connector-java 6.0.5 @@ -71,35 +86,11 @@ + - - - src/main/resources - true - - ${project.build.directory}/${project.build.finalName}/WEB-INF/classes - - - - com.google.cloud.tools appengine-maven-plugin @@ -112,5 +103,11 @@ ${jetty.maven.plugin} + + + src/main/resources + true + + diff --git a/flexible/cloudsql/src/main/appengine/app.yaml b/flexible/java-runtime/samples/cloudsql/src/main/appengine/app.yaml similarity index 96% rename from flexible/cloudsql/src/main/appengine/app.yaml rename to flexible/java-runtime/samples/cloudsql/src/main/appengine/app.yaml index ca251053293..68134485b6d 100644 --- a/flexible/cloudsql/src/main/appengine/app.yaml +++ b/flexible/java-runtime/samples/cloudsql/src/main/appengine/app.yaml @@ -1,5 +1,4 @@ # 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 @@ -21,4 +20,4 @@ handlers: automatic_scaling: min_num_instances: 1 - max_num_instances: 2 + max_num_instances: 2 \ No newline at end of file diff --git a/flexible/cloudsql/src/main/java/com/example/cloudsql/CloudSqlServlet.java b/flexible/java-runtime/samples/cloudsql/src/main/java/com/example/flexible/cloudsql/CloudSqlServlet.java similarity index 97% rename from flexible/cloudsql/src/main/java/com/example/cloudsql/CloudSqlServlet.java rename to flexible/java-runtime/samples/cloudsql/src/main/java/com/example/flexible/cloudsql/CloudSqlServlet.java index 45558bb24f8..00d34bd346e 100644 --- a/flexible/cloudsql/src/main/java/com/example/cloudsql/CloudSqlServlet.java +++ b/flexible/java-runtime/samples/cloudsql/src/main/java/com/example/flexible/cloudsql/CloudSqlServlet.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.cloudsql; +package com.example.flexible.cloudsql; import java.io.IOException; import java.io.PrintWriter; @@ -29,7 +29,6 @@ import java.sql.Timestamp; import java.util.Date; import java.util.Properties; - import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; @@ -38,7 +37,7 @@ // [START example] @SuppressWarnings("serial") -@WebServlet(name = "cloudsql", value = "") +@WebServlet(name = "CloudSQL Sample", value = {"/cloudsql.html"}) public class CloudSqlServlet extends HttpServlet { String url; diff --git a/flexible/cloudsql/src/main/resources/config.properties b/flexible/java-runtime/samples/cloudsql/src/main/resources/cloudsql/config.properties similarity index 100% rename from flexible/cloudsql/src/main/resources/config.properties rename to flexible/java-runtime/samples/cloudsql/src/main/resources/cloudsql/config.properties diff --git a/flexible/cloudstorage/pom.xml b/flexible/java-runtime/samples/cloudstorage/pom.xml similarity index 85% rename from flexible/cloudstorage/pom.xml rename to flexible/java-runtime/samples/cloudstorage/pom.xml index 61b7f266e7b..a2777c8a99c 100644 --- a/flexible/cloudstorage/pom.xml +++ b/flexible/java-runtime/samples/cloudstorage/pom.xml @@ -1,5 +1,5 @@ + + + junit + junit + 4.12 + test + diff --git a/flexible/java-runtime/samples/cloudstorage/src/main/appengine/app.yaml b/flexible/java-runtime/samples/cloudstorage/src/main/appengine/app.yaml new file mode 100644 index 00000000000..5aac05e790b --- /dev/null +++ b/flexible/java-runtime/samples/cloudstorage/src/main/appengine/app.yaml @@ -0,0 +1,24 @@ +# 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. + +runtime: java +env: flex + +handlers: +- url: /.* + script: this field is required, but ignored + +# [START env_variables] +env_variables: + BUCKET_NAME: YOUR-BUCKET-NAME +# [END env_variables] \ No newline at end of file diff --git a/flexible/cloudstorage/src/main/java/com/example/cloudstorage/UploadServlet.java b/flexible/java-runtime/samples/cloudstorage/src/main/java/com/example/flexible/UploadServlet.java similarity index 91% rename from flexible/cloudstorage/src/main/java/com/example/cloudstorage/UploadServlet.java rename to flexible/java-runtime/samples/cloudstorage/src/main/java/com/example/flexible/UploadServlet.java index 6223073be4e..afcce64d290 100644 --- a/flexible/cloudstorage/src/main/java/com/example/cloudstorage/UploadServlet.java +++ b/flexible/java-runtime/samples/cloudstorage/src/main/java/com/example/flexible/UploadServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 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,7 +14,7 @@ * limitations under the License. */ -package com.example.cloudstorage; +package com.example.flexible.cloudstorage; import com.google.cloud.storage.Acl; import com.google.cloud.storage.Blob; @@ -34,9 +34,9 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Part; -// [START example] +// [START cloudstorage] @SuppressWarnings("serial") -@WebServlet(name = "upload", value = "/upload") +@WebServlet(name = "Upload a file to a GCS bucket", value = "/cloudstorage/upload") @MultipartConfig() public class UploadServlet extends HttpServlet { @@ -67,4 +67,4 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOEx resp.getWriter().print(blob.getMediaLink()); } } -// [END example] +// [END cloudstorage] diff --git a/flexible/cloudstorage/src/main/webapp/index.html b/flexible/java-runtime/samples/cloudstorage/src/main/webapp/cloudstorage/upload.html similarity index 57% rename from flexible/cloudstorage/src/main/webapp/index.html rename to flexible/java-runtime/samples/cloudstorage/src/main/webapp/cloudstorage/upload.html index 78e9c675a9b..b8cf4082bef 100644 --- a/flexible/cloudstorage/src/main/webapp/index.html +++ b/flexible/java-runtime/samples/cloudstorage/src/main/webapp/cloudstorage/upload.html @@ -1,9 +1,10 @@ - Google Managed VMs Cloud Storage Sample + Cloud Storage Sample

Select a file to upload to your Google Cloud Storage bucket.

-
+
+ diff --git a/flexible/cron/pom.xml b/flexible/java-runtime/samples/cron/pom.xml similarity index 89% rename from flexible/cron/pom.xml rename to flexible/java-runtime/samples/cron/pom.xml index f66fcf2e908..d480951bc06 100644 --- a/flexible/cron/pom.xml +++ b/flexible/java-runtime/samples/cron/pom.xml @@ -1,5 +1,5 @@ - javax.servlet @@ -47,7 +46,6 @@ provided - diff --git a/flexible/java-runtime/samples/cron/src/main/appengine/cron.yaml b/flexible/java-runtime/samples/cron/src/main/appengine/cron.yaml new file mode 100644 index 00000000000..62bf2a137e6 --- /dev/null +++ b/flexible/java-runtime/samples/cron/src/main/appengine/cron.yaml @@ -0,0 +1,17 @@ +# 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. + +cron: + - description: sample cron job + url: /cron + schedule: every 1 mins \ No newline at end of file diff --git a/flexible/cron/src/main/java/com/example/cron/CronServlet.java b/flexible/java-runtime/samples/cron/src/main/java/com/example/flexible/cron/CronServlet.java similarity index 89% rename from flexible/cron/src/main/java/com/example/cron/CronServlet.java rename to flexible/java-runtime/samples/cron/src/main/java/com/example/flexible/cron/CronServlet.java index 998e013b2e2..54a0aa49161 100644 --- a/flexible/cron/src/main/java/com/example/cron/CronServlet.java +++ b/flexible/java-runtime/samples/cron/src/main/java/com/example/flexible/cron/CronServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. @@ -14,18 +14,17 @@ * limitations under the License. */ -package com.example.cron; +package com.example.flexible.cron; import java.io.IOException; import java.io.PrintWriter; - import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; // [START example] -@WebServlet(name = "cron", value = "/cron") +@WebServlet(name = "cron", value = {"/cron.html"}) @SuppressWarnings("serial") public class CronServlet extends HttpServlet { diff --git a/flexible/datastore/pom.xml b/flexible/java-runtime/samples/datastore/pom.xml similarity index 91% rename from flexible/datastore/pom.xml rename to flexible/java-runtime/samples/datastore/pom.xml index 2f715ad65a2..4bc455b131a 100644 --- a/flexible/datastore/pom.xml +++ b/flexible/java-runtime/samples/datastore/pom.xml @@ -1,5 +1,5 @@ diff --git a/speech/grpc/bin/speech-sample-async.sh b/flexible/java-runtime/samples/datastore/src/main/appengine/app.yaml old mode 100755 new mode 100644 similarity index 63% rename from speech/grpc/bin/speech-sample-async.sh rename to flexible/java-runtime/samples/datastore/src/main/appengine/app.yaml index be843b1b4e0..747f54080db --- a/speech/grpc/bin/speech-sample-async.sh +++ b/flexible/java-runtime/samples/datastore/src/main/appengine/app.yaml @@ -1,18 +1,20 @@ -#!/bin/bash -# Copyright 2016 Google Inc. All Rights Reserved. -# +# 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 +# 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. +# + +runtime: java +env: flex -SRC_DIR="$( cd "$( dirname "$0" )/.." && pwd )" -java -cp "${SRC_DIR}/target/grpc-sample-1.0-jar-with-dependencies.jar" \ - com.examples.cloud.speech.AsyncRecognizeClient "$@" +handlers: +- url: /.* + script: this field is required, but ignored \ No newline at end of file diff --git a/flexible/datastore/src/main/java/com/example/datastore/DatastoreServlet.java b/flexible/java-runtime/samples/datastore/src/main/java/com/example/flexible/datastore/DatastoreServlet.java similarity index 95% rename from flexible/datastore/src/main/java/com/example/datastore/DatastoreServlet.java rename to flexible/java-runtime/samples/datastore/src/main/java/com/example/flexible/datastore/DatastoreServlet.java index ef9822cd1f8..93d48803f54 100644 --- a/flexible/datastore/src/main/java/com/example/datastore/DatastoreServlet.java +++ b/flexible/java-runtime/samples/datastore/src/main/java/com/example/flexible/datastore/DatastoreServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 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,7 +14,7 @@ * limitations under the License. */ -package com.example.managedvms.datastore; +package com.example.flexible.datastore; import com.google.cloud.datastore.Datastore; import com.google.cloud.datastore.DatastoreOptions; @@ -32,16 +32,16 @@ import java.net.Inet4Address; import java.net.Inet6Address; import java.net.InetAddress; - import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + // [START example] @SuppressWarnings("serial") -@WebServlet(name = "datastore", value = "") +@WebServlet(name = "Datastore Sample", value = {"/datastore.html"}) public class DatastoreServlet extends HttpServlet { @Override diff --git a/flexible/disk/pom.xml b/flexible/java-runtime/samples/disk/pom.xml similarity index 92% rename from flexible/disk/pom.xml rename to flexible/java-runtime/samples/disk/pom.xml index 88dd81d9c3a..8e862f08876 100644 --- a/flexible/disk/pom.xml +++ b/flexible/java-runtime/samples/disk/pom.xml @@ -1,10 +1,9 @@ -
+ diff --git a/flexible/mailjet/pom.xml b/flexible/java-runtime/samples/mailjet/pom.xml similarity index 91% rename from flexible/mailjet/pom.xml rename to flexible/java-runtime/samples/mailjet/pom.xml index 75ff8a9a377..d480ac0bc65 100644 --- a/flexible/mailjet/pom.xml +++ b/flexible/java-runtime/samples/mailjet/pom.xml @@ -1,10 +1,9 @@ - + 4.0.5 + diff --git a/flexible/java-runtime/samples/mailjet/src/main/appengine/app.yaml b/flexible/java-runtime/samples/mailjet/src/main/appengine/app.yaml new file mode 100644 index 00000000000..62cc70ec004 --- /dev/null +++ b/flexible/java-runtime/samples/mailjet/src/main/appengine/app.yaml @@ -0,0 +1,25 @@ +# 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. + +runtime: java +env: flex + +handlers: +- url: /.* + script: this field is required, but ignored + +# [START env_variables] +env_variables: + MAILJET_API_KEY: YOUR-MAILJET-API-KEY + MAILJET_SECRET_KEY: YOUR-MAILJET-SECRET-KEY +# [END env_variables] \ No newline at end of file diff --git a/flexible/mailjet/src/main/java/com/example/mailjet/MailjetServlet.java b/flexible/java-runtime/samples/mailjet/src/main/java/com/example/flexible/mailjet/MailjetServlet.java similarity index 94% rename from flexible/mailjet/src/main/java/com/example/mailjet/MailjetServlet.java rename to flexible/java-runtime/samples/mailjet/src/main/java/com/example/flexible/mailjet/MailjetServlet.java index b8723834431..e43a11d4353 100644 --- a/flexible/mailjet/src/main/java/com/example/mailjet/MailjetServlet.java +++ b/flexible/java-runtime/samples/mailjet/src/main/java/com/example/flexible/mailjet/MailjetServlet.java @@ -1,5 +1,5 @@ /** - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. @@ -15,7 +15,7 @@ */ // [START mailjet_imports] -package com.example.mailjet; +package com.example.flexible.mailjet; import com.mailjet.client.MailjetClient; import com.mailjet.client.MailjetRequest; @@ -24,7 +24,6 @@ import com.mailjet.client.errors.MailjetSocketTimeoutException; import com.mailjet.client.resource.Email; // [END mailjet_imports] - import org.json.JSONArray; import org.json.JSONObject; @@ -38,7 +37,7 @@ // [START app] @SuppressWarnings("serial") -@WebServlet(name = "mailjet", value = "/send/email") +@WebServlet(name = "Send an email using MailJet", value = {"/mailjet/email/send"}) public class MailjetServlet extends HttpServlet { private static final String MAILJET_API_KEY = System.getenv("MAILJET_API_KEY"); private static final String MAILJET_SECRET_KEY = System.getenv("MAILJET_SECRET_KEY"); diff --git a/flexible/java-runtime/samples/mailjet/src/main/webapp/mailjet/email/send.html b/flexible/java-runtime/samples/mailjet/src/main/webapp/mailjet/email/send.html new file mode 100644 index 00000000000..3850f887931 --- /dev/null +++ b/flexible/java-runtime/samples/mailjet/src/main/webapp/mailjet/email/send.html @@ -0,0 +1,15 @@ + + + Mailgun on Google App Engine Flexible + + + + + + + + + + + + diff --git a/flexible/memcache/pom.xml b/flexible/java-runtime/samples/memcache/pom.xml similarity index 92% rename from flexible/memcache/pom.xml rename to flexible/java-runtime/samples/memcache/pom.xml index a1c13b42593..24cefc8492a 100644 --- a/flexible/memcache/pom.xml +++ b/flexible/java-runtime/samples/memcache/pom.xml @@ -1,10 +1,9 @@ + + 4.0.0 + jar + 1.0-SNAPSHOT + com.example + flex-java-runtime-samples + + + com.example.flexible + flex-java-runtime-samples-pom + 1.0-SNAPSHOT + .. + + + + 1.8 + 1.8 + false + + + + + + ${project.basedir}/../target/${project.build.finalName}/WEB-INF/classes + + + org.codehaus.mojo + build-helper-maven-plugin + 1.7 + + + add-source + generate-sources + + add-source + + + + + + + + + + add-test-source + generate-test-sources + + add-test-source + + + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-artifact + package + + copy + + + + + ${project.groupId} + ${project.artifactId} + ${project.version} + ${project.packaging} + + + ${project.parent.build.directory} + + + + + + + + src/main/resources + true + + + + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + javax.servlet + javax.servlet-api + 3.1.0 + jar + provided + + + + + + junit + junit + 4.12 + test + + + + diff --git a/flexible/java-runtime/samples/pom.xml b/flexible/java-runtime/samples/pom.xml new file mode 100644 index 00000000000..b9540baa6a6 --- /dev/null +++ b/flexible/java-runtime/samples/pom.xml @@ -0,0 +1,89 @@ + + + 4.0.0 + 1.0-SNAPSHOT + com.example.flexible + flex-java-runtime-samples-pom + pom + + + com.example.flexible + flex-docs-samples + 1.0.0 + ../.. + + + + 1.8 + 1.8 + 1.0.0 + 9.3.8.v20160314 + all + + + + samples-builder + + + + + + ${project.build.directory}/${project.build.finalName}/WEB-INF/classes + + + maven-clean-plugin + 3.0.0 + + false + + + ${basedir}/samples-runner + + + ${basedir}/src/main/appengine + + + ${basedir}/src/main/webapp + + + ${basedir}/src/main/resources + + + + + + com.google.cloud.tools + appengine-maven-plugin + ${appengine.maven.plugin} + + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.maven.plugin} + + + + + + junit + junit + 4.12 + test + + + \ No newline at end of file diff --git a/flexible/java-runtime/samples/pubsub/README.md b/flexible/java-runtime/samples/pubsub/README.md new file mode 100644 index 00000000000..2c03232b7f8 --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/README.md @@ -0,0 +1,59 @@ +# App Engine Flexible Environment - Pub/Sub Sample + +## Clone the sample app + +Copy the sample apps to your local machine, and cd to the pubsub directory: + +``` +git clone https://github.com/GoogleCloudPlatform/java-docs-samples +cd java-docs-samples/flexible/java-runtime/samples/pubsub +``` + +## Setup + +Make sure [`gcloud`](https://cloud.google.com/sdk/docs/) is installed and authenticated. + +Create a topic +``` +gcloud beta pubsub topics create +``` + +Create a push subscription, to send messages to a Google Cloud Project URL + such as https://.appspot.com/push. +``` +gcloud beta pubsub subscriptions create \ + --topic \ + --push-endpoint \ + https://.appspot.com/pubsub/push?token= \ + --ack-deadline 30 +``` +## Run + +Set the following environment variables and run using shown Maven command. You can then +direct your browser to `http://localhost:8080/pubsub` + +``` +export PUBSUB_TOPIC= +export PUBSUB_VERIFICATION_TOKEN= +mvn jetty:run +``` + + +### Send fake subscription push messages with: + +``` +curl -H "Content-Type: application/json" -i --data @sample_message.json +"localhost:8080/pubsub/push?token=" +``` + +## Deploy + +Update the environment variables `PUBSUB_TOPIC` and `PUBSUB_VERIFICATION_TOKEN` in [`app.yaml`](src/main/appengine/app.yaml), +then: + +``` +mvn appengine:deploy +``` + +The home page of this application provides a form to publish messages and also provides a view of the most recent messages +received over the push endpoint and persisted in storage. diff --git a/flexible/java-runtime/samples/pubsub/pom.xml b/flexible/java-runtime/samples/pubsub/pom.xml new file mode 100644 index 00000000000..d8944806337 --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/pom.xml @@ -0,0 +1,116 @@ + + + + 4.0.0 + war + 1.0-SNAPSHOT + com.example.flexible + flexible-pubsub + + + com.example.flexible + flex-docs-samples + 1.0.0 + ../../.. + + + + 1.3.0 + 1.8 + 1.8 + false + 9.3.8.v20160314 + + + + + javax.servlet + javax.servlet-api + 3.1.0 + jar + provided + + + + + com.google.cloud + google-cloud-pubsub + 0.13.0-alpha + + + com.google.cloud + google-cloud-datastore + 0.13.0-beta + + + + + + com.google.appengine + appengine-api-stubs + 1.9.38 + test + + + com.google.appengine + appengine-tools-sdk + 1.9.38 + test + + + org.eclipse.jetty + jetty-server + 9.4.3.v20170317 + + + junit + junit + test + + + org.mockito + mockito-all + 1.10.19 + test + + + org.eclipse.jetty + jetty-servlet + 9.3.14.v20161028 + + + + + ${project.build.directory}/${project.build.finalName}/WEB-INF/classes + + + com.google.cloud.tools + appengine-maven-plugin + ${appengine.maven.plugin} + + + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.maven.plugin} + + + + + diff --git a/flexible/java-runtime/samples/pubsub/sample_message.json b/flexible/java-runtime/samples/pubsub/sample_message.json new file mode 100644 index 00000000000..1c0e04caa1a --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/sample_message.json @@ -0,0 +1 @@ +{"message":{"data":"dGVzdA==","attributes":{},"messageId":"91010751788941","publishTime":"2017-04-05T23:16:42.302Z"}} diff --git a/flexible/java-runtime/samples/pubsub/src/main/appengine/app.yaml b/flexible/java-runtime/samples/pubsub/src/main/appengine/app.yaml new file mode 100644 index 00000000000..5233b58b21c --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/src/main/appengine/app.yaml @@ -0,0 +1,26 @@ +# 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. +# [START appyaml] +runtime: java +env: flex + +handlers: +- url: /.* + script: this field is required, but ignored + +# [START env_variables] +env_variables: + PUBSUB_TOPIC: + PUBSUB_VERIFICATION_TOKEN: +# [END env_variables] +# [END appyaml] diff --git a/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/Message.java b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/Message.java new file mode 100644 index 00000000000..de2c7e9d85a --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/Message.java @@ -0,0 +1,52 @@ +/** + * 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.flexible.pubsub; + +/** + * A message captures information from the Pubsub message received over the push endpoint and is + * persisted in storage. + */ +public class Message { + private String messageId; + private String publishTime; + private String data; + + public Message(String messageId) { + this.messageId = messageId; + } + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getPublishTime() { + return publishTime; + } + + public void setPublishTime(String publishTime) { + this.publishTime = publishTime; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/MessageRepository.java b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/MessageRepository.java new file mode 100644 index 00000000000..2ec79d71c9a --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/MessageRepository.java @@ -0,0 +1,29 @@ +/** + * 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.flexible.pubsub; + +import java.util.List; + +public interface MessageRepository { + + /** Save message to persistent storage. */ + void save(Message message); + + /** + * Retrieve most recent stored messages. + * @param limit number of messages + * @return list of messages + */ + List retrieve(int limit); +} diff --git a/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/MessageRepositoryImpl.java b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/MessageRepositoryImpl.java new file mode 100644 index 00000000000..ff6e7eab137 --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/MessageRepositoryImpl.java @@ -0,0 +1,98 @@ +/** + * 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.flexible.pubsub; + +import com.google.cloud.datastore.Datastore; +import com.google.cloud.datastore.DatastoreOptions; +import com.google.cloud.datastore.Entity; +import com.google.cloud.datastore.Key; +import com.google.cloud.datastore.KeyFactory; +import com.google.cloud.datastore.Query; +import com.google.cloud.datastore.QueryResults; +import com.google.cloud.datastore.StructuredQuery; + +import java.util.ArrayList; +import java.util.List; + +/** Storage for Message objects using Cloud Datastore. */ +public class MessageRepositoryImpl implements MessageRepository { + + private static MessageRepositoryImpl instance; + + private String messagesKind = "messages"; + private KeyFactory keyFactory = getDatastoreInstance().newKeyFactory().setKind(messagesKind); + + @Override + public void save(Message message) { + // Save message to "messages" + Datastore datastore = getDatastoreInstance(); + Key key = datastore.allocateId(keyFactory.newKey()); + + Entity.Builder messageEntityBuilder = Entity.newBuilder(key) + .set("messageId", message.getMessageId()); + + if (message.getData() != null) { + messageEntityBuilder = messageEntityBuilder.set("data", message.getData()); + } + + if (message.getPublishTime() != null) { + messageEntityBuilder = messageEntityBuilder.set("publishTime", message.getPublishTime()); + } + datastore.put(messageEntityBuilder.build()); + } + + @Override + public List retrieve(int limit) { + // Get Message saved in Datastore + Datastore datastore = getDatastoreInstance(); + Query query = + Query.newEntityQueryBuilder() + .setKind(messagesKind) + .setLimit(limit) + .addOrderBy(StructuredQuery.OrderBy.desc("publishTime")) + .build(); + QueryResults results = datastore.run(query); + + List messages = new ArrayList<>(); + while (results.hasNext()) { + Entity entity = results.next(); + Message message = new Message(entity.getString("messageId")); + String data = entity.getString("data"); + if (data != null) { + message.setData(data); + } + String publishTime = entity.getString("publishTime"); + if (publishTime != null) { + message.setPublishTime(publishTime); + } + messages.add(message); + } + return messages; + } + + private Datastore getDatastoreInstance() { + return DatastoreOptions.getDefaultInstance().getService(); + } + + private MessageRepositoryImpl() { + } + + // retrieve a singleton instance + public static synchronized MessageRepositoryImpl getInstance() { + if (instance == null) { + instance = new MessageRepositoryImpl(); + } + return instance; + } +} diff --git a/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/PubSubHome.java b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/PubSubHome.java new file mode 100644 index 00000000000..c65e3ed9e00 --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/PubSubHome.java @@ -0,0 +1,47 @@ +/** + * 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.flexible.pubsub; + +import java.util.List; + +public class PubSubHome { + + private static MessageRepository messageRepository = MessageRepositoryImpl.getInstance(); + private static int MAX_MESSAGES = 10; + + /** + * Retrieve received messages in html. + * + * @return html representation of messages (one per row) + */ + public static String getReceivedMessages() { + List messageList = messageRepository.retrieve(MAX_MESSAGES); + return convertToHtmlTable(messageList); + } + + private static String convertToHtmlTable(List messages) { + StringBuilder sb = new StringBuilder(); + for (Message message : messages) { + sb.append(""); + sb.append("" + message.getMessageId() + ""); + sb.append("" + message.getData() + ""); + sb.append("" + message.getPublishTime() + ""); + sb.append(""); + } + return sb.toString(); + } + + private PubSubHome() { } +} diff --git a/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/PubSubPublish.java b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/PubSubPublish.java new file mode 100644 index 00000000000..f4706faaf0e --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/PubSubPublish.java @@ -0,0 +1,68 @@ +/** + * 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.flexible.pubsub; + +import com.google.cloud.ServiceOptions; +import com.google.cloud.pubsub.spi.v1.Publisher; +import com.google.protobuf.ByteString; +import com.google.pubsub.v1.PubsubMessage; +import com.google.pubsub.v1.TopicName; +import org.apache.http.HttpStatus; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +// [START publish] +@WebServlet(name = "Publish with PubSub", value = "/pubsub/publish") +public class PubSubPublish extends HttpServlet { + + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) + throws IOException, ServletException { + Publisher publisher = this.publisher; + try { + String topicId = System.getenv("PUBSUB_TOPIC"); + // create a publisher on the topic + if (publisher == null) { + publisher = Publisher.defaultBuilder( + TopicName.create(ServiceOptions.getDefaultProjectId(), topicId)) + .build(); + } + // construct a pubsub message from the payload + final String payload = req.getParameter("payload"); + PubsubMessage pubsubMessage = + PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8(payload)).build(); + + publisher.publish(pubsubMessage); + // redirect to home page + resp.sendRedirect("/"); + // [END publish] + } catch (Exception e) { + resp.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage()); + } + } +// [END publish] + + private Publisher publisher; + + public PubSubPublish() { } + + PubSubPublish(Publisher publisher) { + this.publisher = publisher; + } +} diff --git a/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/PubSubPush.java b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/PubSubPush.java new file mode 100644 index 00000000000..ce47254e7aa --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/src/main/java/com/example/flexible/pubsub/PubSubPush.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.flexible.pubsub; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; + +import java.io.IOException; +import java.util.Base64; +import java.util.stream.Collectors; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +// [START push] +@WebServlet(value = "/pubsub/push") +public class PubSubPush extends HttpServlet { + + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) + throws IOException, ServletException { + String pubsubVerificationToken = System.getenv("PUBSUB_VERIFICATION_TOKEN"); + // Do not process message if request token does not match pubsubVerificationToken + if (req.getParameter("token").compareTo(pubsubVerificationToken) != 0) { + resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); + return; + } + // parse message object from "message" field in the request body json + // decode message data from base64 + Message message = getMessage(req); + try { + messageRepository.save(message); + // 200, 201, 204, 102 status codes are interpreted as success by the Pub/Sub system + resp.setStatus(HttpServletResponse.SC_OK); + } catch (Exception e) { + resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } +// [END push] + + private Message getMessage(HttpServletRequest request) throws IOException { + String requestBody = request.getReader().lines().collect(Collectors.joining("\n")); + JsonElement jsonRoot = jsonParser.parse(requestBody); + String messageStr = jsonRoot.getAsJsonObject().get("message").toString(); + Message message = gson.fromJson(messageStr, Message.class); + // decode from base64 + String decoded = decode(message.getData()); + message.setData(decoded); + return message; + } + + private String decode(String data) { + return new String(Base64.getDecoder().decode(data)); + } + + private final Gson gson = new Gson(); + private final JsonParser jsonParser = new JsonParser(); + private MessageRepository messageRepository; + + PubSubPush(MessageRepository messageRepository) { + this.messageRepository = messageRepository; + } + + public PubSubPush() { + this.messageRepository = MessageRepositoryImpl.getInstance(); + } +} diff --git a/flexible/java-runtime/samples/pubsub/src/main/test/com/example/flexible/pubsub/PubSubPublishTest.java b/flexible/java-runtime/samples/pubsub/src/main/test/com/example/flexible/pubsub/PubSubPublishTest.java new file mode 100644 index 00000000000..6b7f06016e9 --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/src/main/test/com/example/flexible/pubsub/PubSubPublishTest.java @@ -0,0 +1,50 @@ +/** + * 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.flexible.pubsub; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.api.gax.core.SettableApiFuture; +import com.google.cloud.pubsub.spi.v1.Publisher; +import com.google.protobuf.ByteString; +import com.google.pubsub.v1.PubsubMessage; +import org.junit.Test; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class PubSubPublishTest { + + @Test + public void servletPublishesPayloadMessage() throws Exception { + assertNotNull(System.getenv("PUBSUB_TOPIC")); + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getParameter("payload")).thenReturn("test-message"); + + HttpServletResponse response = mock(HttpServletResponse.class); + Publisher publisher = mock(Publisher.class); + PubsubMessage message = PubsubMessage.newBuilder() + .setData(ByteString.copyFromUtf8("test-message")).build(); + when(publisher.publish(eq(message))).thenReturn(SettableApiFuture.create()); + PubSubPublish pubSubPublish = new PubSubPublish(publisher); + // verify content of published test message + pubSubPublish.doPost(request, response); + verify(publisher, times(1)).publish(eq(message)); + } +} diff --git a/flexible/java-runtime/samples/pubsub/src/main/test/com/example/flexible/pubsub/PubSubPushTest.java b/flexible/java-runtime/samples/pubsub/src/main/test/com/example/flexible/pubsub/PubSubPushTest.java new file mode 100644 index 00000000000..ebb84c3156c --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/src/main/test/com/example/flexible/pubsub/PubSubPushTest.java @@ -0,0 +1,63 @@ +package com.example.flexible.pubsub; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; + +/** + * 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. + */ +import java.io.BufferedReader; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class PubSubPushTest { + + @Test + public void messageReceivedOverPushEndPointIsSaved() throws Exception { + MessageRepository messageRepository = mock(MessageRepository.class); + List messages = new ArrayList<>(); + doAnswer((invocation) -> { + messages.add((Message)invocation.getArguments()[0]); + return null; + } + ).when(messageRepository).save(any(Message.class)); + HttpServletRequest request = mock(HttpServletRequest.class); + assertNotNull(System.getenv("PUBSUB_VERIFICATION_TOKEN")); + when(request.getParameter("token")) + .thenReturn(System.getenv("PUBSUB_VERIFICATION_TOKEN")); + + HttpServletResponse response = mock(HttpServletResponse.class); + BufferedReader reader = mock(BufferedReader.class); + when (request.getReader()).thenReturn(reader); + Stream requestBody = Stream.of( + "{\"message\":{\"data\":\"dGVzdA==\",\"attributes\":{}," + + "\"messageId\":\"91010751788941\",\"publishTime\":\"2017-04-05T23:16:42.302Z\"}}"); + when(reader.lines()).thenReturn(requestBody); + PubSubPush servlet = new PubSubPush(messageRepository); + assertEquals(messages.size(), 0); + servlet.doPost(request, response); + assertEquals(messages.size(), 1); + } +} + diff --git a/flexible/java-runtime/samples/pubsub/src/main/webapp/pubsub/index.jsp b/flexible/java-runtime/samples/pubsub/src/main/webapp/pubsub/index.jsp new file mode 100644 index 00000000000..fa12f02a14d --- /dev/null +++ b/flexible/java-runtime/samples/pubsub/src/main/webapp/pubsub/index.jsp @@ -0,0 +1,24 @@ +<%@ page import="com.example.flexible.pubsub.PubSubHome" %> + + + + + An example of using PubSub on App Engine Flex + +

Publish a message

+
+ + + +
+

Last received messages

+ + + + + + + <%= PubSubHome.getReceivedMessages() %> +
IdDataPublishTime
+ + diff --git a/flexible/java-runtime/samples/samples-builder/README.md b/flexible/java-runtime/samples/samples-builder/README.md new file mode 100644 index 00000000000..73be2870ee0 --- /dev/null +++ b/flexible/java-runtime/samples/samples-builder/README.md @@ -0,0 +1,9 @@ +# Samples Builder + +Creates a single deployable Flex application from Flex sample applications under +[samples-source](../samples-source). + +# Run +`mvn package` creates the single Flex application under [samples](..). +Packages included in the application can be configured using `flexible.samples` property +in the parent [pom.xml](../pom.xml) diff --git a/flexible/java-runtime/samples/samples-builder/pom.xml b/flexible/java-runtime/samples/samples-builder/pom.xml new file mode 100644 index 00000000000..08350e04098 --- /dev/null +++ b/flexible/java-runtime/samples/samples-builder/pom.xml @@ -0,0 +1,111 @@ + + + 4.0.0 + flex-java-runtime-samples-builder + 1.0-SNAPSHOT + jar + + + com.example.flexible + flex-java-runtime-samples-pom + 1.0-SNAPSHOT + .. + + + + 1.8 + 1.8 + ${project.parent.basedir}/samples-runner + + + + + org.yaml + snakeyaml + 1.18 + + + commons-io + commons-io + 2.5 + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + build-samples + compile + + java + + false + + com.example.flexible.base.SamplesBuilder + + + ${project.basedir}/.. + + + ${flexible.samples} + + + + + + compile-samples + package + + exec + + false + + ${samples-output.dir} + mvn + + + package + + + + + + verify-samples + verify + + exec + + false + + ${samples-output.dir} + mvn + + + verify + + + + + + + + + diff --git a/flexible/java-runtime/samples/samples-builder/src/main/java/com/example/flexible/base/MergeYaml.java b/flexible/java-runtime/samples/samples-builder/src/main/java/com/example/flexible/base/MergeYaml.java new file mode 100644 index 00000000000..279fbca990c --- /dev/null +++ b/flexible/java-runtime/samples/samples-builder/src/main/java/com/example/flexible/base/MergeYaml.java @@ -0,0 +1,142 @@ +/** + * 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.flexible.base; + +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.nodes.Tag; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +class MergeYaml { + + Yaml yaml; + + MergeYaml() { + this.yaml = new Yaml(); + } + + @SuppressWarnings("unchecked") + public void merge(Map mergedResult, List files) throws IOException { + for (File file : files) { + if (file.isDirectory() && file.listFiles() != null) { + merge(mergedResult, Arrays.asList(file.listFiles())); + return; + } + InputStream in = null; + try { + in = new FileInputStream(file); + + final Map yamlContents = (Map) yaml.load(in); + + merge(mergedResult, yamlContents); + + } catch (IOException e) { + // ignore + } finally { + if (in != null) { + in.close(); + } + } + } + } + + @SuppressWarnings("unchecked") + private void merge(Map mergedResult, Map yamlContents) { + if (yamlContents == null) { + return; + } + + for (String key : yamlContents.keySet()) { + Object yamlValue = yamlContents.get(key); + if (yamlValue == null) { + addToMergedResult(mergedResult, key, yamlValue); + continue; + } + + Object existingValue = mergedResult.get(key); + if (existingValue != null) { + if (yamlValue instanceof Map) { + if (existingValue instanceof Map) { + merge((Map) existingValue, (Map) yamlValue); + } else if (existingValue instanceof String) { + throw new IllegalArgumentException( + "Cannot flexible.base complex element into a simple element: " + key); + } else { + throw unknownValueType(key, yamlValue); + } + } else if (yamlValue instanceof List) { + mergeLists(mergedResult, key, yamlValue); + + } else if (yamlValue instanceof String + || yamlValue instanceof Boolean + || yamlValue instanceof Double + || yamlValue instanceof Integer) { + addToMergedResult(mergedResult, key, yamlValue); + + } else { + throw unknownValueType(key, yamlValue); + } + + } else { + if (yamlValue instanceof Map + || yamlValue instanceof List + || yamlValue instanceof String + || yamlValue instanceof Boolean + || yamlValue instanceof Integer + || yamlValue instanceof Double) { + addToMergedResult(mergedResult, key, yamlValue); + } else { + throw unknownValueType(key, yamlValue); + } + } + } + } + + private IllegalArgumentException unknownValueType(String key, Object yamlValue) { + final String msg = + "Cannot flexible.base element of unknown type: " + key + ": " + yamlValue.getClass() + .getName(); + return new IllegalArgumentException(msg); + } + + private Object addToMergedResult(Map mergedResult, String key, Object yamlValue) { + return mergedResult.put(key, yamlValue); + } + + @SuppressWarnings("unchecked") + private void mergeLists(Map mergedResult, String key, Object yamlValue) { + if (!(yamlValue instanceof List && mergedResult.get(key) instanceof List)) { + throw new IllegalArgumentException("Cannot base a list with a non-list: " + key); + } + List originalList = (List) mergedResult.get(key); + originalList.addAll((List) yamlValue); + mergedResult.put(key, originalList.stream().distinct().collect(Collectors.toList())); + } + + public String getYaml(Map mergedResult) { + return yaml.dumpAs(mergedResult, Tag.MAP, DumperOptions.FlowStyle.BLOCK); + } +} + diff --git a/flexible/java-runtime/samples/samples-builder/src/main/java/com/example/flexible/base/SamplesBuilder.java b/flexible/java-runtime/samples/samples-builder/src/main/java/com/example/flexible/base/SamplesBuilder.java new file mode 100644 index 00000000000..8e7bc45949d --- /dev/null +++ b/flexible/java-runtime/samples/samples-builder/src/main/java/com/example/flexible/base/SamplesBuilder.java @@ -0,0 +1,232 @@ +/** + * 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.flexible.base; + +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +class SamplesBuilder { + + private final MergeYaml mergeYaml; + private final String sourcePath; + private final String destinationPath; + private final String basePath; + private final String[] packageNames; + private final String appYamlFile = "app.yaml"; + private final String cronYamlFile = "cron.yaml"; + + private SamplesBuilder(String basePath, String[] packageNames) + throws Exception { + this.mergeYaml = new MergeYaml(); + this.basePath = basePath; + this.sourcePath = basePath; + this.destinationPath = basePath + "/samples-runner"; + this.packageNames = packageNames; + } + + private void mergeAndWriteAppYaml() throws Exception { + List appEngineFiles = new ArrayList<>(); + List cronFiles = new ArrayList<>(); + for (String packageName : packageNames) { + appEngineFiles.add( + new File(sourcePath + "/" + packageName + "/src/main/appengine/" + appYamlFile)); + cronFiles.add( + new File(sourcePath + "/" + packageName + "/src/main/appengine/" + cronYamlFile)); + + } + Map mergedResult = new LinkedHashMap<>(); + mergeYaml.merge(mergedResult, appEngineFiles); + if (mergedResult.size() > 0) { + write(mergedResult, appYamlFile); + } + + mergedResult.clear(); + mergeYaml.merge(mergedResult, cronFiles); + if (mergedResult.size() > 0) { + write(mergedResult, cronYamlFile); + } + } + + private List read(String fileName) throws IOException { + return Files.readAllLines(Paths.get(fileName), StandardCharsets.UTF_8); + } + + private List extractBlock(String packageName, List lines, String blockName) + throws IllegalArgumentException { + boolean inBlock = false; + List block = new LinkedList<>(); + for (String line : lines) { + if (inBlock) { + if (line.contains("END " + blockName)) { + inBlock = false; + break; + } + block.add(line); + } + if (line.contains("START " + blockName)) { + inBlock = true; + } + } + + if (inBlock) { + throw new IllegalArgumentException(blockName + " not closed in " + packageName + " pom.xml"); + } + if (block.size() > 0) { + String indent = " "; + block.add(0, indent + ""); + block.add(indent + ""); + } + return block; + } + + private void parsePom(String packageName, List properties, List dependencies) + throws IllegalArgumentException, IOException { + List pom = read(sourcePath + "/" + packageName + "/pom.xml"); + properties.addAll(extractBlock(packageName, pom, "properties")); + dependencies.addAll(extractBlock(packageName, pom, "dependencies")); + } + + private void copyFile(String fileName) throws IOException { + FileUtils.copyFile(new File(sourcePath + "/" + fileName), + new File(basePath + "/" + fileName)); + } + + private void copyPackageFiles(String path) { + for (String packageName : packageNames) { + try { + FileUtils.copyDirectory( + new File(sourcePath + "/" + packageName + "/" + path + "/" + packageName), + new File(basePath + "/" + path + "/" + packageName)); + } catch (IOException e) { + // ignore if no directory exists + } + } + } + + private void addToPom(List pom, String blockTag, List lines) throws Exception { + int i; + String blockName = "[START " + blockTag + "]"; + for (i = 0; i < pom.size(); i++) { + if (pom.get(i).contains(blockName)) { + break; + } + } + if (i == pom.size()) { + throw new Exception(blockName + " block not found"); + } + + pom.addAll(i + 1, lines); + } + + private void generatePom() throws Exception { + List pom = read(sourcePath + "/pom-base.xml"); + List dependencies = new ArrayList<>(); + List properties = new ArrayList<>(); + List sourceDirs = new ArrayList<>(); + List testSourceDirs = new ArrayList<>(); + for (String packageName : packageNames) { + parsePom(packageName, properties, dependencies); + sourceDirs.add(" " + sourcePath + "/" + packageName + "/src/main/java" + ""); + testSourceDirs.add( + "" + sourcePath + "/" + packageName + "/src/main/test" + ""); + } + addToPom(pom, "properties", properties); + addToPom(pom, "dependencies", dependencies); + addToPom(pom, "source-dirs", sourceDirs); + addToPom(pom, "test-source-dirs", testSourceDirs); + write(pom, destinationPath + "/pom.xml"); + } + + private void write(List lines, String fileName) throws Exception { + File outputFile = new File(fileName); + outputFile.getParentFile().mkdirs(); + PrintWriter pw = new PrintWriter(new PrintWriter(fileName)); + for (String line : lines) { + pw.write(line); + pw.write("\n"); + } + pw.close(); + } + + private void write(Map mergedResult, String outputFileName) { + String yamlOutput = mergeYaml.getYaml(mergedResult); + PrintWriter writer = null; + File outputFile = new File( + basePath + "/src/main/appengine/" + outputFileName); + outputFile.getParentFile().mkdirs(); + try { + writer = new PrintWriter(outputFile, "UTF-8"); + writer.write(yamlOutput); + } catch (Exception e) { + System.err.println("Error writing to output file : " + e.getMessage()); + } finally { + if (writer != null) { + writer.close(); + } + } + } + + private static String[] getAllDirectories(String path) { + File[] files = new File(path).listFiles(); + List fileNamesList = Arrays.stream(files) + .filter(File::isDirectory) + .filter(x -> !x.getName().equals("samples-runner") + && !x.getName().equals("samples-builder") + && !x.getName().equals("src") + && !x.getName().equals("target")) + .map(File::getName) + .collect(Collectors.toList()); + String[] fileNames = new String[fileNamesList.size()]; + fileNamesList.toArray(fileNames); + return fileNames; + } + + public static void main(String[] args) throws Exception { + System.out.println(args[0]); + String baseDir = args[0]; + String[] packageNames; + if (args[1] == null || args[1].equals("all")) { + packageNames = getAllDirectories(args[0]); + } else { + packageNames = args[1].split(","); + } + SamplesBuilder samplesBuilder = new SamplesBuilder(baseDir, packageNames); + System.out.println("Merging app.yaml files"); + samplesBuilder.mergeAndWriteAppYaml(); + + System.out.println("Generating pom.xml"); + samplesBuilder.generatePom(); + + System.out.println("Copying source and webapp files"); + samplesBuilder.copyPackageFiles("src/main/webapp"); + samplesBuilder.copyPackageFiles("src/main/resources"); + } +} + diff --git a/flexible/sendgrid/pom.xml b/flexible/java-runtime/samples/sendgrid/pom.xml similarity index 92% rename from flexible/sendgrid/pom.xml rename to flexible/java-runtime/samples/sendgrid/pom.xml index 04ea5244c69..c1630c243bb 100644 --- a/flexible/sendgrid/pom.xml +++ b/flexible/java-runtime/samples/sendgrid/pom.xml @@ -1,12 +1,9 @@ - - - Mailgun on Google App Engine Flexible - - - -
- - - -
- - - diff --git a/flexible/memcache/README.md b/flexible/memcache/README.md deleted file mode 100644 index aab8ddf0d2e..00000000000 --- a/flexible/memcache/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# flexible/memcache - -How to use memcache on flexible. - -# NEEDS WORK - -This sample needs to be updated to use redis-memcache diff --git a/flexible/memcache/src/main/appengine/app.yaml b/flexible/memcache/src/main/appengine/app.yaml deleted file mode 100644 index 2bf46125d17..00000000000 --- a/flexible/memcache/src/main/appengine/app.yaml +++ /dev/null @@ -1,11 +0,0 @@ -runtime: java -env: flex - -handlers: -- url: /.* - script: this field is required, but ignored - -# [START config] -beta_settings: - use_memcache_proxy: true -# [END config] diff --git a/flexible/pom.xml b/flexible/pom.xml new file mode 100644 index 00000000000..4be447ed4b8 --- /dev/null +++ b/flexible/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + com.example.flexible + flex-docs-samples + 1.0.0 + pom + + + + doc-samples + com.google.cloud + 1.0.0 + .. + + + + + custom-runtime/async-rest + custom-runtime/endpoints + custom-runtime/extending-runtime + custom-runtime/sparkjava + java-runtime/samples + + diff --git a/flexible/sendgrid/README.md b/flexible/sendgrid/README.md deleted file mode 100644 index d7786659624..00000000000 --- a/flexible/sendgrid/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Java SendGrid Email Sample for Google App Engine Flexible Environment - -This sample demonstrates how to use [SendGrid](https://www.sendgrid.com) on -[Google App Engine flexible environment][aeflex-docs]. - -See the [sample application documentaion][sample-docs] for more detailed -instructions. - -For more information about SendGrid, see their -[documentation](https://sendgrid.com/docs/User_Guide/index.html). - -[aeflex-docs]: https://cloud.google.com/appengine/docs/flexible/ -[sample-docs]: https://cloud.google.com/appengine/docs/flexible/java/sending-emails-with-sendgrid - -## Setup - -Before you can run or deploy the sample, you will need to do the following: - -1. [Create a SendGrid Account](http://sendgrid.com/partner/google). As of - September 2015, Google users start with 25,000 free emails per month. -1. Configure your SendGrid settings in the environment variables section in - [`src/main/appengine/app.yaml`](src/main/appengine/app.yaml). - -## Running locally - -You can run the application locally and send emails from your local machine. You -will need to set environment variables before starting your application: - - $ export SENDGRID_API_KEY=[your-sendgrid-api-key] - $ export SENDGRID_SENDER=[your-sendgrid-sender-email-address] - $ mvn clean jetty:run diff --git a/flexible/sendgrid/src/main/appengine/app.yaml b/flexible/sendgrid/src/main/appengine/app.yaml deleted file mode 100644 index 0efc5d7b4d2..00000000000 --- a/flexible/sendgrid/src/main/appengine/app.yaml +++ /dev/null @@ -1,12 +0,0 @@ -runtime: java -env: flex - -handlers: -- url: /.* - script: this field is required, but ignored - -# [START env_variables] -env_variables: - SENDGRID_API_KEY: YOUR-SENDGRID-API-KEY - SENDGRID_SENDER: YOUR-SENDGRID-SENDER -# [END env_variables] diff --git a/flexible/sparkjava/src/main/appengine/app.yaml b/flexible/sparkjava/src/main/appengine/app.yaml deleted file mode 100644 index ce2a124359b..00000000000 --- a/flexible/sparkjava/src/main/appengine/app.yaml +++ /dev/null @@ -1,2 +0,0 @@ -runtime: custom -env: flex diff --git a/flexible/static-files/src/main/appengine/app.yaml b/flexible/static-files/src/main/appengine/app.yaml deleted file mode 100644 index d7890aaff58..00000000000 --- a/flexible/static-files/src/main/appengine/app.yaml +++ /dev/null @@ -1,6 +0,0 @@ -runtime: java -env: flex - -handlers: -- url: /.* - script: this field is required, but ignored diff --git a/flexible/static-files/src/main/webapp/index.html b/flexible/static-files/src/main/webapp/index.html deleted file mode 100644 index d1643e9a6b1..00000000000 --- a/flexible/static-files/src/main/webapp/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - -Static Files - - - -

This is a static file serving example.

- - diff --git a/flexible/twilio/README.md b/flexible/twilio/README.md deleted file mode 100644 index a1234c78af6..00000000000 --- a/flexible/twilio/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# Java Twilio Voice and SMS Sample for Google App Engine Flexible Environment - -This sample demonstrates how to use [Twilio](https://www.twilio.com) on [Google -App flexible environment][aeflex-docs]. - -See the [sample application documentaion][sample-docs] for more detailed -instructions. - -For more information about Twilio, see their [Java quickstart -tutorials](https://www.twilio.com/docs/quickstart/java). - -[aeflex-docs]: https://cloud.google.com/appengine/docs/flexible/ -[sample-docs]: https://cloud.google.com/appengine/docs/flexible/java/using-sms-and-voice-services-via-twilio - - -## Setup - -Before you can run or deploy the sample, you will need to do the following: - -1. [Create a Twilio Account](http://ahoy.twilio.com/googlecloudplatform). Google - App Engine customers receive a complimentary credit for SMS messages and - inbound messages. -1. Create a number on twilio, and configure the voice request URL to be - ``https://your-app-id.appspot.com/call/receive`` and the SMS request URL to - be ``https://your-app-id.appspot.com/sms/receive``. -1. Configure your Twilio settings in the environment variables section in - ``src/main/appengine/app.yaml``. - -## Running locally - -You can run the application locally to test the callbacks and SMS sending. You -will need to set environment variables before starting your application: - - $ export TWILIO_ACCOUNT_SID=[your-twilio-accoun-sid] - $ export TWILIO_AUTH_TOKEN=[your-twilio-auth-token] - $ export TWILIO_NUMBER=[your-twilio-number] - $ mvn clean jetty:run diff --git a/flexible/twilio/src/main/appengine/app.yaml b/flexible/twilio/src/main/appengine/app.yaml deleted file mode 100644 index 1ee3836bcef..00000000000 --- a/flexible/twilio/src/main/appengine/app.yaml +++ /dev/null @@ -1,13 +0,0 @@ -runtime: java -env: flex - -handlers: -- url: /.* - script: this field is required, but ignored - -# [START env_variables] -env_variables: - TWILIO_ACCOUNT_SID: YOUR-TWILIO-ACCOUNT-SID - TWILIO_AUTH_TOKEN: YOUR-TWILIO-AUTH-TOKEN - TWILIO_NUMBER: YOUR-TWILIO-NUMBER -# [END env_variables] diff --git a/kms/pom.xml b/kms/pom.xml index 8e0cbb6847e..4207d776c84 100644 --- a/kms/pom.xml +++ b/kms/pom.xml @@ -16,7 +16,7 @@ com.google.apis google-api-services-cloudkms - v1-rev5-1.22.0 + v1-rev6-1.22.0 com.google.guava diff --git a/language/analysis/README.md b/language/analysis/README.md index 14836f85f44..3d6c1f33ea5 100644 --- a/language/analysis/README.md +++ b/language/analysis/README.md @@ -68,6 +68,13 @@ java -cp target/language-entities-1.0-jar-with-dependencies.jar \ "The quick brown fox jumped over the lazy dog." ``` +Analyze sentiment Beta +``` +java -cp target/language-entities-1.0-jar-with-dependencies.jar \ + com.google.cloud.language.samples.AnalyzeBeta sentiment "Ich habe eine wundervolle Zeit." "DE" +``` + + Included with the sample are `demo.sh` and `demo.bat` which show additional examples of usage. diff --git a/language/analysis/demo-beta.sh b/language/analysis/demo-beta.sh new file mode 100644 index 00000000000..71d5116a142 --- /dev/null +++ b/language/analysis/demo-beta.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Demonstrates how to run the AnalyzeBeta sample. + +########################################################################## +# 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. +########################################################################## + + +####################################### +# Performs a language operation on the given text or GCS object. +# Globals: +# None +# Arguments: +# $1 The operation to perform, either entities, sentiment, or syntax. +# $2 The text or GCS object to operate on. +# Returns: +# None +####################################### +function run_nl() { + local main_class=com.google.cloud.language.samples.AnalyzeBeta + local jar_file=target/language-entities-1.0-jar-with-dependencies.jar + java -cp ${jar_file} ${main_class} "$1" "$2" +} + +####################################### +# Exercises the sample code on various example text and GCS objects. +# Globals: +# None +# Arguments: +# None +# Returns: +# None +####################################### +function run_nl_all() { + local quote_de="Bananen sind die köstlichsten Früchte, ich liebe sie zu + essen. Ich mag sie so sehr wie Ananas." + local quote="Larry Page, Google's co-founder, once described the 'perfect + search engine' as something that 'understands exactly what you mean and + gives you back exactly what you want.' Since he spoke those words Google + has grown to offer products beyond search, but the spirit of what he said + remains." + local gs_path="gs://cloud-samples-tests/natural-language/gettysburg.txt" + + run_nl entities-sentiment "${quote}" + run_nl entities-sentiment "${gs_path}" + run_nl sentiment "${quote_de}" "DE" +} + +run_nl_all diff --git a/language/analysis/demo.cmd b/language/analysis/demo.cmd index faf44778ba0..91b867d8477 100644 --- a/language/analysis/demo.cmd +++ b/language/analysis/demo.cmd @@ -1,8 +1,8 @@ : : Demonstrates how to run the Analyze sample. :######################################################################### - -: Copyright 2016 Google Inc. All Rights Reserved. + +: 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. @@ -14,7 +14,7 @@ : 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. -:######################################################################### +:######################################################################### :call:run_nl entities "The quick brown fox jumped over the lazy dog." @@ -40,7 +40,8 @@ EXIT /B :###################################### : Exercises the sample code on various example text and GCS objects. -: Globals: +: Globals: + : None : Arguments: : None diff --git a/language/analysis/demo.sh b/language/analysis/demo.sh index 043bee0e5ad..513c8e8ae04 100755 --- a/language/analysis/demo.sh +++ b/language/analysis/demo.sh @@ -3,7 +3,7 @@ # Demonstrates how to run the Analyze sample. ########################################################################## -# Copyright 2016 Google Inc. All Rights Reserved. +# 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. diff --git a/language/analysis/pom.xml b/language/analysis/pom.xml index a4f6c64fc78..75a689f1fc0 100644 --- a/language/analysis/pom.xml +++ b/language/analysis/pom.xml @@ -1,5 +1,5 @@ diff --git a/logging/cloud-client/pom.xml b/logging/cloud-client/pom.xml index 3e0ed57df54..91ed47a8ba6 100644 --- a/logging/cloud-client/pom.xml +++ b/logging/cloud-client/pom.xml @@ -1,5 +1,5 @@ diff --git a/logging/src/test/java/ListLogsTest.java b/logging/src/test/java/ListLogsTest.java index ee94330c394..45efec69444 100644 --- a/logging/src/test/java/ListLogsTest.java +++ b/logging/src/test/java/ListLogsTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/monitoring/cloud-client/pom.xml b/monitoring/cloud-client/pom.xml index d0bd0119b68..73133db2c1a 100644 --- a/monitoring/cloud-client/pom.xml +++ b/monitoring/cloud-client/pom.xml @@ -37,7 +37,7 @@ com.google.cloud google-cloud-monitoring - 0.12.0-alpha + 0.13.0-alpha diff --git a/monitoring/cloud-client/src/main/java/com/example/monitoring/Snippets.java b/monitoring/cloud-client/src/main/java/com/example/monitoring/Snippets.java index 07df8fe7391..b02aca0611b 100644 --- a/monitoring/cloud-client/src/main/java/com/example/monitoring/Snippets.java +++ b/monitoring/cloud-client/src/main/java/com/example/monitoring/Snippets.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. @@ -53,7 +53,7 @@ public class Snippets { /** * Exercises the methods defined in this class. - * + *

*

Assumes that you are authenticated using the Google Cloud SDK (using * {@code gcloud auth application-default-login}). */ @@ -81,8 +81,9 @@ public static void main(String[] args) throws Exception { /** * Creates a metric descriptor. - * + *

* See: https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors/create + * * @param type The metric type */ void createMetricDescriptor(String type) throws IOException { @@ -112,6 +113,7 @@ void createMetricDescriptor(String type) throws IOException { /** * Delete a metric descriptor. + * * @param name Name of metric descriptor to delete */ void deleteMetricDescriptor(String name) throws IOException { @@ -127,11 +129,10 @@ void deleteMetricDescriptor(String name) throws IOException { /** * Demonstrates writing a time series value for the metric type * 'custom.google.apis.com/my_metric'. - * + *

* This method assumes `my_metric` descriptor has already been created as a * DOUBLE value_type and GAUGE metric kind. If the metric descriptor * doesn't exist, it will be auto-created. - * */ void writeTimeSeries() throws IOException { // [START monitoring_write_timeseries] @@ -203,7 +204,6 @@ void listTimeSeriesHeaders() throws IOException { String projectId = System.getProperty("projectId"); ProjectName name = ProjectName.create(projectId); - // Restrict time to last 20 minutes long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000); TimeInterval interval = TimeInterval.newBuilder() @@ -217,33 +217,20 @@ void listTimeSeriesHeaders() throws IOException { .setInterval(interval) .setView(ListTimeSeriesRequest.TimeSeriesView.HEADERS); - String nextToken = ""; + ListTimeSeriesRequest request = requestBuilder.build(); - do { - if (nextToken != null) { - requestBuilder.setPageToken(nextToken); - } - ListTimeSeriesRequest request = requestBuilder.build(); + PagedResponseWrappers.ListTimeSeriesPagedResponse response = metricServiceClient + .listTimeSeries(request); - PagedResponseWrappers.ListTimeSeriesPagedResponse response = metricServiceClient - .listTimeSeries(request); - List timeseries = response.getPage() - .getResponseObject() - .getTimeSeriesList(); - - System.out.println("Got timeseries headers: "); - for (TimeSeries ts : timeseries) { - System.out.println(ts); - } - Object nextObjectToken = response.getNextPageToken(); - nextToken = (String)nextObjectToken; - } while (nextToken != ""); + System.out.println("Got timeseries headers: "); + for (TimeSeries ts : response.iterateAll()) { + System.out.println(ts); + } // [END monitoring_read_timeseries_fields] } /** * Demonstrates listing time series using a filter. - * */ void listTimeSeries(String filter) throws IOException { // [START monitoring_read_timeseries_simple] @@ -251,7 +238,6 @@ void listTimeSeries(String filter) throws IOException { String projectId = System.getProperty("projectId"); ProjectName name = ProjectName.create(projectId); - // Restrict time to last 20 minutes long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000); TimeInterval interval = TimeInterval.newBuilder() @@ -264,33 +250,20 @@ void listTimeSeries(String filter) throws IOException { .setFilter(filter) .setInterval(interval); - String nextToken = ""; - - do { - if (nextToken != null) { - requestBuilder.setPageToken(nextToken); - } - ListTimeSeriesRequest request = requestBuilder.build(); + ListTimeSeriesRequest request = requestBuilder.build(); - PagedResponseWrappers.ListTimeSeriesPagedResponse response = metricServiceClient - .listTimeSeries(request); - List timeseries = response.getPage() - .getResponseObject() - .getTimeSeriesList(); + PagedResponseWrappers.ListTimeSeriesPagedResponse response = metricServiceClient + .listTimeSeries(request); - System.out.println("Got timeseries: "); - for (TimeSeries ts : timeseries) { - System.out.println(ts); - } - Object nextObjectToken = response.getNextPageToken(); - nextToken = (String)nextObjectToken; - } while (nextToken != ""); + System.out.println("Got timeseries: "); + for (TimeSeries ts : response.iterateAll()) { + System.out.println(ts); + } // [END monitoring_read_timeseries_simple] } /** * Demonstrates listing time series and aggregating them. - * */ void listTimeSeriesAggregrate() throws IOException { // [START monitoring_read_timeseries_align] @@ -298,7 +271,6 @@ void listTimeSeriesAggregrate() throws IOException { String projectId = System.getProperty("projectId"); ProjectName name = ProjectName.create(projectId); - // Restrict time to last 20 minutes long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000); TimeInterval interval = TimeInterval.newBuilder() @@ -317,32 +289,20 @@ void listTimeSeriesAggregrate() throws IOException { .setInterval(interval) .setAggregation(aggregation); - String nextToken = ""; - do { - if (nextToken != null) { - requestBuilder.setPageToken(nextToken); - } - ListTimeSeriesRequest request = requestBuilder.build(); + ListTimeSeriesRequest request = requestBuilder.build(); - PagedResponseWrappers.ListTimeSeriesPagedResponse response = metricServiceClient - .listTimeSeries(request); - List timeseries = response.getPage() - .getResponseObject() - .getTimeSeriesList(); + PagedResponseWrappers.ListTimeSeriesPagedResponse response = metricServiceClient + .listTimeSeries(request); - System.out.println("Got timeseries: "); - for (TimeSeries ts : timeseries) { - System.out.println(ts); - } - Object nextObjectToken = response.getNextPageToken(); - nextToken = (String)nextObjectToken; - } while (nextToken != ""); + System.out.println("Got timeseries: "); + for (TimeSeries ts : response.iterateAll()) { + System.out.println(ts); + } // [END monitoring_read_timeseries_align] } /** * Demonstrates listing time series and aggregating and reducing them. - * */ void listTimeSeriesReduce() throws IOException { // [START monitoring_read_timeseries_reduce] @@ -350,7 +310,6 @@ void listTimeSeriesReduce() throws IOException { String projectId = System.getProperty("projectId"); ProjectName name = ProjectName.create(projectId); - // Restrict time to last 20 minutes long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000); TimeInterval interval = TimeInterval.newBuilder() @@ -370,27 +329,15 @@ void listTimeSeriesReduce() throws IOException { .setInterval(interval) .setAggregation(aggregation); - String nextToken = ""; - - do { - if (nextToken != null) { - requestBuilder.setPageToken(nextToken); - } - ListTimeSeriesRequest request = requestBuilder.build(); + ListTimeSeriesRequest request = requestBuilder.build(); - PagedResponseWrappers.ListTimeSeriesPagedResponse response = metricServiceClient - .listTimeSeries(request); - List timeseries = response.getPage() - .getResponseObject() - .getTimeSeriesList(); + PagedResponseWrappers.ListTimeSeriesPagedResponse response = metricServiceClient + .listTimeSeries(request); - System.out.println("Got timeseries: "); - for (TimeSeries ts : timeseries) { - System.out.println(ts); - } - Object nextObjectToken = response.getNextPageToken(); - nextToken = (String)nextObjectToken; - } while (nextToken != ""); + System.out.println("Got timeseries: "); + for (TimeSeries ts : response.iterateAll()) { + System.out.println(ts); + } // [END monitoring_read_timeseries_reduce] } @@ -414,9 +361,7 @@ void listMetricDescriptors() throws IOException { System.out.println("Listing descriptors: "); - List descriptors = response.getPage() - .getResponseObject().getMetricDescriptorsList(); - for (MetricDescriptor d : descriptors) { + for (MetricDescriptor d : response.iterateAll()) { System.out.println(d.getName() + " " + d.getDisplayName()); } // [END monitoring_list_descriptors] @@ -443,10 +388,7 @@ void listMonitoredResources() throws IOException { PagedResponseWrappers.ListMonitoredResourceDescriptorsPagedResponse response = client .listMonitoredResourceDescriptors(request); - List descriptors = response.getPage() - .getResponseObject().getResourceDescriptorsList(); - - for (MonitoredResourceDescriptor d : descriptors) { + for (MonitoredResourceDescriptor d : response.iterateAll()) { System.out.println(d.getType()); } // [END monitoring_list_resources] @@ -454,7 +396,8 @@ void listMonitoredResources() throws IOException { /** * Gets full information for a monitored resource. - * @param The resource type + * + * @param type The resource type */ void describeMonitoredResources(String type) throws IOException { // [START monitoring_get_descriptor] diff --git a/monitoring/v2/src/test/java/CloudMonitoringAuthSampleTest.java b/monitoring/v2/src/test/java/CloudMonitoringAuthSampleTest.java index 4af0e1c0a1f..c1bdadc4d55 100644 --- a/monitoring/v2/src/test/java/CloudMonitoringAuthSampleTest.java +++ b/monitoring/v2/src/test/java/CloudMonitoringAuthSampleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/monitoring/v3/pom.xml b/monitoring/v3/pom.xml index d9aec58e27b..81812561607 100644 --- a/monitoring/v3/pom.xml +++ b/monitoring/v3/pom.xml @@ -81,7 +81,7 @@ com.google.apis google-api-services-monitoring - v3-rev395-1.22.0 + v3-rev397-1.22.0 com.google.code.gson diff --git a/monitoring/v3/src/main/java/CreateCustomMetric.java b/monitoring/v3/src/main/java/CreateCustomMetric.java index 5b0def17b8f..fa7dfd2bfb7 100644 --- a/monitoring/v3/src/main/java/CreateCustomMetric.java +++ b/monitoring/v3/src/main/java/CreateCustomMetric.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/monitoring/v3/src/main/java/ListResources.java b/monitoring/v3/src/main/java/ListResources.java index 859e635f7c9..818b95a9a24 100644 --- a/monitoring/v3/src/main/java/ListResources.java +++ b/monitoring/v3/src/main/java/ListResources.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/monitoring/v3/src/test/java/CreateCustomMetricTest.java b/monitoring/v3/src/test/java/CreateCustomMetricTest.java index 301d08ed741..26dc57e5b97 100644 --- a/monitoring/v3/src/test/java/CreateCustomMetricTest.java +++ b/monitoring/v3/src/test/java/CreateCustomMetricTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/monitoring/v3/src/test/java/ListResourcesTest.java b/monitoring/v3/src/test/java/ListResourcesTest.java index 7a03548b08c..211dbd80837 100644 --- a/monitoring/v3/src/test/java/ListResourcesTest.java +++ b/monitoring/v3/src/test/java/ListResourcesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/pom.xml b/pom.xml index 840a22a62fa..5cc07f821d9 100644 --- a/pom.xml +++ b/pom.xml @@ -49,24 +49,8 @@ appengine - flexible/analytics - flexible/async-rest - flexible/cloudsql - flexible/cloudstorage - flexible/cron - flexible/datastore - flexible/disk - flexible/extending-runtime - flexible/helloworld - flexible/mailgun - flexible/mailjet - flexible/memcache - flexible/sendgrid - flexible/sparkjava - flexible/static-files - flexible/twilio - - bigquery + flexible + bigquery/cloud-client bigquery/rest compute/cmdline @@ -75,6 +59,7 @@ compute/sendgrid datastore datastore/cloud-client + kms language/analysis language/cloud-client @@ -85,7 +70,7 @@ monitoring/v3 pubsub/cloud-client spanner/cloud-client - speech/grpc + speech/cloud-client storage/cloud-client storage/json-api storage/storage-transfer diff --git a/pubsub/cloud-client/pom.xml b/pubsub/cloud-client/pom.xml index 0088599b1f2..b0717ceda42 100644 --- a/pubsub/cloud-client/pom.xml +++ b/pubsub/cloud-client/pom.xml @@ -1,5 +1,5 @@ com.google.guava diff --git a/speech/README.md b/speech/README.md index e6e4b640430..9d54a590b10 100644 --- a/speech/README.md +++ b/speech/README.md @@ -3,6 +3,6 @@ This directory contains several samples for the [Cloud Speech API](https://cloud.google.com/speech/) with Java. -- [grpc](grpc) +- [Cloud Client](cloud-client) - A sample for accessing Cloud Speech streaming and non streaming apis with [gRPC](http://www.grpc.io/). + A sample for accessing Cloud Speech streaming and non streaming apis using the [Cloud Client Library for Java](https://github.com/GoogleCloudPlatform/google-cloud-java). diff --git a/speech/cloud-client/README.md b/speech/cloud-client/README.md index c0397107edb..c9d1bae43b5 100644 --- a/speech/cloud-client/README.md +++ b/speech/cloud-client/README.md @@ -31,8 +31,20 @@ You can then run a given `ClassName` via: -Dexec.args="syncrecognize ./resources/audio.raw" ``` +### Asynchronously transcribe a local audio file (using the recognize sample) +``` + mvn exec:java -Dexec.mainClass=com.example.speech.Recognize \ + -Dexec.args="asyncrecognize ./resources/audio.raw" +``` + ### Transcribe a remote audio file (using the recognize sample) ``` mvn exec:java -Dexec.mainClass=com.example.speech.Recognize \ -Dexec.args="syncrecognize 'gs://cloud-samples-tests/speech/brooklyn.flac'" ``` + +### Asynchronously transcribe a remote audio file (using the recognize sample) +``` + mvn exec:java -Dexec.mainClass=com.example.speech.Recognize \ + -Dexec.args="asyncrecognize 'gs://cloud-samples-tests/speech/vr.flac'" +``` diff --git a/speech/cloud-client/pom.xml b/speech/cloud-client/pom.xml index 1d5009b0cac..6ccbf48580a 100644 --- a/speech/cloud-client/pom.xml +++ b/speech/cloud-client/pom.xml @@ -38,7 +38,7 @@ com.google.cloud google-cloud - 0.11.2-alpha + 0.13.0-alpha @@ -52,7 +52,7 @@ com.google.truth truth - 0.31 + 0.32 test diff --git a/speech/cloud-client/src/main/java/com/example/speech/Recognize.java b/speech/cloud-client/src/main/java/com/example/speech/Recognize.java index 55f7a63f2ef..71659e7d396 100644 --- a/speech/cloud-client/src/main/java/com/example/speech/Recognize.java +++ b/speech/cloud-client/src/main/java/com/example/speech/Recognize.java @@ -172,7 +172,7 @@ public static void asyncRecognizeFile(String fileName) throws Exception, IOExcep speech.longRunningRecognizeAsync(config, audio); while (!response.isDone()) { System.out.println("Waiting for response..."); - Thread.sleep(200); + Thread.sleep(10000); } List results = response.get().getResultsList(); @@ -211,7 +211,7 @@ public static void asyncRecognizeGcs(String gcsUri) throws Exception, IOExceptio speech.longRunningRecognizeAsync(config, audio); while (!response.isDone()) { System.out.println("Waiting for response..."); - Thread.sleep(200); + Thread.sleep(10000); } List results = response.get().getResultsList(); diff --git a/speech/grpc/README.md b/speech/grpc/README.md deleted file mode 100644 index b4407df50ef..00000000000 --- a/speech/grpc/README.md +++ /dev/null @@ -1,101 +0,0 @@ -# Cloud Speech API gRPC samples for Java - -This is a sample repo for accessing the [Google Cloud Speech API](http://cloud.google.com/speech) with -[gRPC](http://www.grpc.io/) client library. Note that these samples are for `advanced users` and is in -BETA. Please see [Google Cloud Platform Launch Stages](https://cloud.google.com/terms/launch-stages). - -## Prerequisites - -### Enable the Speech API - -If you have not already done so, [enable the Google Cloud Speech API for your project](https://console.developers.google.com/apis/api/speech.googleapis.com/overview). -You must be whitelisted to do this. - - -### Download and install Java and Maven - -Install [Java7 or -higher](http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html). - -This sample uses the [Apache Maven][maven] build system. Before getting started, be -sure to [download][maven-download] and [install][maven-install] it. When you use -Maven as described here, it will automatically download the needed client -libraries. - -[maven]: https://maven.apache.org -[maven-download]: https://maven.apache.org/download.cgi -[maven-install]: https://maven.apache.org/install.html - - -### Set Up to Authenticate With Your Project's Credentials - -The example uses a service account for OAuth2 authentication. -So next, set up to authenticate with the Speech API using your project's -service account credentials. - -Visit the [Cloud Console](https://console.developers.google.com), and navigate to: -`API Manager > Credentials > Create credentials > -Service account key > New service account`. -Create a new service account, and download the json credentials file. - -Then, set -the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to point to your -downloaded service account credentials before running this example: - - export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials-key.json - -If you do not do this, you will see an error that looks something like this when -you run the example scripts: -`WARNING: RPC failed: Status{code=PERMISSION_DENIED, description=Request had insufficient authentication scopes., cause=null}`. -See the -[Cloud Platform Auth Guide](https://cloud.google.com/docs/authentication#developer_workflow) -for more information. - -## Build the application - -Then, build the program: - -```sh -$ mvn package -``` - -or - -```sh -$ mvn compile -$ mvn assembly:single -``` - -## Run the clients - -These programs return the transcription of the audio file you provided. Please -note that the audio file must be in RAW format. You can use `sox` -(available, e.g. via [http://sox.sourceforge.net/](http://sox.sourceforge.net/) -or [homebrew](http://brew.sh/)) to convert audio files to raw format. - -### Run the sync client - -To use the sync method to transcribe a 16,000Hz sample audio file, run the following: - -```sh -$ bin/speech-sample-sync.sh --host=speech.googleapis.com --port=443 \ ---uri=resources/audio.raw --sampling=16000 -``` - -### Run the async client - -To use the async method to transcribe a 16,000Hz sample audio file, run the following: - -```sh -$ bin/speech-sample-async.sh --host=speech.googleapis.com --port=443 \ ---uri=resources/audio.raw --sampling=16000 -``` - -### Run the streaming client - -To use the streaming method to transcribe a 16,000Hz sample audio file, run the following: - -```sh -$ bin/speech-sample-streaming.sh --host=speech.googleapis.com --port=443 \ ---sampling=16000 -``` diff --git a/speech/grpc/pom.xml b/speech/grpc/pom.xml deleted file mode 100644 index f42b2f22b28..00000000000 --- a/speech/grpc/pom.xml +++ /dev/null @@ -1,166 +0,0 @@ - - - 4.0.0 - - com.google.cloud.speech - grpc-sample - 1.0 - jar - - speech-grpc-sample - https://cloud.google.com/speech/ - 2016 - - - - com.google.cloud - doc-samples - 1.0.0 - ../.. - - - - - Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - Google - http://www.google.com - - - - UTF-8 - 2.3 - 1.0.3 - 3.6.0 - 0.5.0 - - 1.8 - 1.8 - - - - - - com.google.cloud - google-cloud-speech - 0.12.0-alpha - - - junit - junit - 4.12 - test - - - commons-cli - commons-cli - 1.3.1 - - - com.google.auth - google-auth-library-credentials - 0.6.1 - - - com.google.auth - google-auth-library-oauth2-http - 0.6.1 - - - - com.google.guava - guava-jdk5 - - - - - com.google.guava - guava - 20.0 - - - com.google.truth - truth - 0.32 - test - - - org.mockito - mockito-all - 1.10.19 - test - - - io.grpc - grpc-auth - ${grpc-version} - - - io.grpc - grpc-netty - ${grpc-version} - - - io.grpc - grpc-protobuf - ${grpc-version} - - - io.grpc - grpc-stub - ${grpc-version} - - - log4j - log4j - 1.2.17 - - - - - - - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - - simple-command - package - - attached - - - - - - - - - diff --git a/speech/grpc/resources/audio.raw b/speech/grpc/resources/audio.raw deleted file mode 100644 index 5ebf79d3c9c..00000000000 Binary files a/speech/grpc/resources/audio.raw and /dev/null differ diff --git a/speech/grpc/resources/audio32KHz.raw b/speech/grpc/resources/audio32KHz.raw deleted file mode 100644 index 6b52fc326f8..00000000000 Binary files a/speech/grpc/resources/audio32KHz.raw and /dev/null differ diff --git a/speech/grpc/src/main/java/com/examples/cloud/speech/AsyncRecognizeClient.java b/speech/grpc/src/main/java/com/examples/cloud/speech/AsyncRecognizeClient.java deleted file mode 100644 index 9d9d5899a4b..00000000000 --- a/speech/grpc/src/main/java/com/examples/cloud/speech/AsyncRecognizeClient.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * 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.examples.cloud.speech; - -import com.google.auth.oauth2.GoogleCredentials; -import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest; -import com.google.cloud.speech.v1beta1.AsyncRecognizeResponse; -import com.google.cloud.speech.v1beta1.RecognitionAudio; -import com.google.cloud.speech.v1beta1.RecognitionConfig; -import com.google.cloud.speech.v1beta1.RecognitionConfig.AudioEncoding; -import com.google.cloud.speech.v1beta1.SpeechGrpc; -import com.google.longrunning.GetOperationRequest; -import com.google.longrunning.Operation; -import com.google.longrunning.OperationsGrpc; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import io.grpc.StatusRuntimeException; -import io.grpc.auth.ClientAuthInterceptor; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; - -import java.io.IOException; -import java.net.URI; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Client that sends audio to Speech.AsyncRecognize and returns transcript. - */ -public class AsyncRecognizeClient { - - private static final Logger logger = Logger.getLogger(AsyncRecognizeClient.class.getName()); - - private static final List OAUTH2_SCOPES = - Arrays.asList("https://www.googleapis.com/auth/cloud-platform"); - - private final URI input; - private final int samplingRate; - - private final ManagedChannel channel; - private final SpeechGrpc.SpeechBlockingStub speechClient; - private final OperationsGrpc.OperationsBlockingStub statusClient; - - /** - * Construct client connecting to Cloud Speech server at {@code host:port}. - */ - public AsyncRecognizeClient(ManagedChannel channel, URI input, int samplingRate) - throws IOException { - this.input = input; - this.samplingRate = samplingRate; - this.channel = channel; - - speechClient = SpeechGrpc.newBlockingStub(channel); - statusClient = OperationsGrpc.newBlockingStub(channel); - } - - public void shutdown() throws InterruptedException { - channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - - public static ManagedChannel createChannel(String host, int port) throws IOException { - GoogleCredentials creds = GoogleCredentials.getApplicationDefault(); - creds = creds.createScoped(OAUTH2_SCOPES); - ManagedChannel channel = - ManagedChannelBuilder.forAddress(host, port) - .intercept(new ClientAuthInterceptor(creds, Executors.newSingleThreadExecutor())) - .build(); - - return channel; - } - - /** - * Sends a request to the speech API and returns an Operation handle. - */ - public void recognize() { - RecognitionAudio audio; - try { - audio = RecognitionAudioFactory.createRecognitionAudio(this.input); - } catch (IOException e) { - logger.log(Level.WARNING, "Failed to read audio uri input: " + input); - return; - } - logger.info("Sending " + audio.getContent().size() + " bytes from audio uri input: " + input); - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setEncoding(AudioEncoding.LINEAR16) - .setSampleRate(samplingRate) - .build(); - AsyncRecognizeRequest request = - AsyncRecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - - Operation operation; - Operation status; - try { - operation = speechClient.asyncRecognize(request); - - // Print the long running operation handle - logger.log( - Level.INFO, - String.format("Operation handle: %s, URI: %s", operation.getName(), input.toString())); - } catch (StatusRuntimeException e) { - logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus()); - return; - } - - while (true) { - try { - logger.log(Level.INFO, "Waiting 2s for operation, {0} processing...", operation.getName()); - Thread.sleep(2000); - GetOperationRequest operationReq = - GetOperationRequest.newBuilder().setName(operation.getName()).build(); - status = - statusClient.getOperation( - GetOperationRequest.newBuilder().setName(operation.getName()).build()); - - if (status.getDone()) { - break; - } - } catch (Exception ex) { - logger.log(Level.WARNING, ex.getMessage()); - } - } - - try { - AsyncRecognizeResponse asyncRes = status.getResponse().unpack(AsyncRecognizeResponse.class); - - logger.info("Received response: " + asyncRes); - } catch (com.google.protobuf.InvalidProtocolBufferException ex) { - logger.log(Level.WARNING, "Unpack error, {0}", ex.getMessage()); - } - } - - public static void main(String[] args) throws Exception { - - String audioFile = ""; - String host = "speech.googleapis.com"; - Integer port = 443; - Integer sampling = 16000; - - CommandLineParser parser = new DefaultParser(); - - Options options = new Options(); - options.addOption( - Option.builder() - .longOpt("uri") - .desc("path to audio uri") - .hasArg() - .argName("FILE_PATH") - .build()); - options.addOption( - Option.builder() - .longOpt("host") - .desc("endpoint for api, e.g. speech.googleapis.com") - .hasArg() - .argName("ENDPOINT") - .build()); - options.addOption( - Option.builder() - .longOpt("port") - .desc("SSL port, usually 443") - .hasArg() - .argName("PORT") - .build()); - options.addOption( - Option.builder() - .longOpt("sampling") - .desc("Sampling Rate, i.e. 16000") - .hasArg() - .argName("RATE") - .build()); - - try { - CommandLine line = parser.parse(options, args); - if (line.hasOption("uri")) { - audioFile = line.getOptionValue("uri"); - } else { - System.err.println("An Audio uri must be specified (e.g. file:///foo/baz.raw)."); - System.exit(1); - } - - if (line.hasOption("host")) { - host = line.getOptionValue("host"); - } else { - System.err.println("An API enpoint must be specified (typically speech.googleapis.com)."); - System.exit(1); - } - - if (line.hasOption("port")) { - port = Integer.parseInt(line.getOptionValue("port")); - } else { - System.err.println("An SSL port must be specified (typically 443)."); - System.exit(1); - } - - if (line.hasOption("sampling")) { - sampling = Integer.parseInt(line.getOptionValue("sampling")); - } else { - System.err.println("An Audio sampling rate must be specified."); - System.exit(1); - } - } catch (ParseException exp) { - System.err.println("Unexpected exception:" + exp.getMessage()); - System.exit(1); - } - - ManagedChannel channel = AsyncRecognizeClient.createChannel(host, port); - - AsyncRecognizeClient client = - new AsyncRecognizeClient(channel, URI.create(audioFile), sampling); - try { - client.recognize(); - } finally { - client.shutdown(); - } - } -} diff --git a/speech/grpc/src/main/java/com/examples/cloud/speech/RecognitionAudioFactory.java b/speech/grpc/src/main/java/com/examples/cloud/speech/RecognitionAudioFactory.java deleted file mode 100644 index 2f340b94fb4..00000000000 --- a/speech/grpc/src/main/java/com/examples/cloud/speech/RecognitionAudioFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * 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.examples.cloud.speech; - -import com.google.cloud.speech.v1beta1.RecognitionAudio; -import com.google.protobuf.ByteString; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -/* - * RecognitionAudioFactory takes a URI as an input and creates a RecognitionAudio. - * The URI can point to a local file or a file on Google Cloud Storage. - */ -public class RecognitionAudioFactory { - - private static final String FILE_SCHEME = "file"; - private static final String GS_SCHEME = "gs"; - - /** - * Takes an input URI of form $scheme:// and converts to audio request. - * - * @param uri input uri - * @return RecognitionAudio recognition audio - */ - public static RecognitionAudio createRecognitionAudio(URI uri) throws IOException { - if (uri.getScheme() == null) { - uri = new File(uri.toString()).toURI(); - Path path = Paths.get(uri); - return audioFromBytes(Files.readAllBytes(path)); - } else if (uri.getScheme().equals(FILE_SCHEME)) { - Path path = Paths.get(uri); - return audioFromBytes(Files.readAllBytes(path)); - } else if (uri.getScheme().equals(GS_SCHEME)) { - return RecognitionAudio.newBuilder().setUri(uri.toString()).build(); - } - throw new RuntimeException("scheme not supported " + uri.getScheme()); - } - - /** - * Convert bytes to RecognitionAudio. - * - * @param bytes input bytes - * @return RecognitionAudio recognition audio - */ - private static RecognitionAudio audioFromBytes(byte[] bytes) { - return RecognitionAudio.newBuilder().setContent(ByteString.copyFrom(bytes)).build(); - } -} diff --git a/speech/grpc/src/main/java/com/examples/cloud/speech/StreamingRecognizeClient.java b/speech/grpc/src/main/java/com/examples/cloud/speech/StreamingRecognizeClient.java deleted file mode 100644 index 7a70b0359fb..00000000000 --- a/speech/grpc/src/main/java/com/examples/cloud/speech/StreamingRecognizeClient.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * 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.examples.cloud.speech; - -import static org.apache.log4j.ConsoleAppender.SYSTEM_OUT; - -import com.google.auth.oauth2.GoogleCredentials; -import com.google.cloud.speech.v1beta1.RecognitionConfig; -import com.google.cloud.speech.v1beta1.RecognitionConfig.AudioEncoding; -import com.google.cloud.speech.v1beta1.SpeechGrpc; -import com.google.cloud.speech.v1beta1.StreamingRecognitionConfig; -import com.google.cloud.speech.v1beta1.StreamingRecognitionResult; -import com.google.cloud.speech.v1beta1.StreamingRecognizeRequest; -import com.google.cloud.speech.v1beta1.StreamingRecognizeResponse; -import com.google.protobuf.ByteString; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import io.grpc.auth.ClientAuthInterceptor; -import io.grpc.stub.StreamObserver; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import javax.sound.sampled.AudioFormat; -import javax.sound.sampled.AudioSystem; -import javax.sound.sampled.DataLine; -import javax.sound.sampled.LineUnavailableException; -import javax.sound.sampled.TargetDataLine; - - -/** - * Client that sends streaming audio to Speech.Recognize and returns streaming transcript. - */ -public class StreamingRecognizeClient { - - private static final Logger logger = Logger.getLogger(StreamingRecognizeClient.class.getName()); - - private final ManagedChannel channel; - private final SpeechGrpc.SpeechStub speechClient; - private static final List OAUTH2_SCOPES = - Arrays.asList("https://www.googleapis.com/auth/cloud-platform"); - - static final int BYTES_PER_SAMPLE = 2; // bytes per sample for LINEAR16 - - private final int samplingRate; - final int bytesPerBuffer; // buffer size in bytes - - // Used for testing - protected TargetDataLine mockDataLine = null; - - /** - * Construct client connecting to Cloud Speech server at {@code host:port}. - */ - public StreamingRecognizeClient(ManagedChannel channel, int samplingRate) - throws IOException { - this.samplingRate = samplingRate; - this.channel = channel; - this.bytesPerBuffer = samplingRate * BYTES_PER_SAMPLE / 10; // 100 ms - - speechClient = SpeechGrpc.newStub(channel); - - // Send log4j logs to Console - // If you are going to run this on GCE, you might wish to integrate with - // google-cloud-java logging. See: - // https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/README.md#stackdriver-logging-alpha - ConsoleAppender appender = new ConsoleAppender(new SimpleLayout(), SYSTEM_OUT); - logger.addAppender(appender); - } - - public void shutdown() throws InterruptedException { - channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - - static ManagedChannel createChannel(String host, int port) throws IOException { - GoogleCredentials creds = GoogleCredentials.getApplicationDefault(); - creds = creds.createScoped(OAUTH2_SCOPES); - ManagedChannel channel = - ManagedChannelBuilder.forAddress(host, port) - .intercept(new ClientAuthInterceptor(creds, Executors.newSingleThreadExecutor())) - .build(); - - return channel; - } - - /** - * Return a Line to the audio input device. - */ - private TargetDataLine getAudioInputLine() { - // For testing - if (null != mockDataLine) { - return mockDataLine; - } - - AudioFormat format = new AudioFormat(samplingRate, BYTES_PER_SAMPLE * 8, 1, true, false); - DataLine.Info info = new DataLine.Info(TargetDataLine.class, format); - if (!AudioSystem.isLineSupported(info)) { - throw new RuntimeException(String.format( - "Device doesn't support LINEAR16 mono raw audio format at {%d}Hz", samplingRate)); - } - try { - TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info); - // Make sure the line buffer doesn't overflow while we're filling this thread's buffer. - line.open(format, bytesPerBuffer * 5); - return line; - } catch (LineUnavailableException e) { - throw new RuntimeException(e); - } - } - - /** Send streaming recognize requests to server. */ - public void recognize() throws InterruptedException, IOException { - final CountDownLatch finishLatch = new CountDownLatch(1); - StreamObserver responseObserver = - new StreamObserver() { - private int sentenceLength = 1; - /** - * Prints the transcription results. Interim results are overwritten by subsequent - * results, until a final one is returned, at which point we start a new line. - * - * Flags the program to exit when it hears "exit". - */ - @Override - public void onNext(StreamingRecognizeResponse response) { - List results = response.getResultsList(); - if (results.size() < 1) { - return; - } - - StreamingRecognitionResult result = results.get(0); - String transcript = result.getAlternatives(0).getTranscript(); - - // Print interim results with a line feed, so subsequent transcriptions will overwrite - // it. Final result will print a newline. - String format = "%-" + this.sentenceLength + 's'; - if (result.getIsFinal()) { - format += '\n'; - this.sentenceLength = 1; - - if (transcript.toLowerCase().indexOf("exit") >= 0) { - finishLatch.countDown(); - } - } else { - format += '\r'; - this.sentenceLength = transcript.length(); - } - System.out.print(String.format(format, transcript)); - } - - @Override - public void onError(Throwable error) { - logger.log(Level.ERROR, "recognize failed: {0}", error); - finishLatch.countDown(); - } - - @Override - public void onCompleted() { - logger.info("recognize completed."); - finishLatch.countDown(); - } - }; - - StreamObserver requestObserver = - speechClient.streamingRecognize(responseObserver); - try { - // Build and send a StreamingRecognizeRequest containing the parameters for - // processing the audio. - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setEncoding(AudioEncoding.LINEAR16) - .setSampleRate(samplingRate) - .build(); - StreamingRecognitionConfig streamingConfig = - StreamingRecognitionConfig.newBuilder() - .setConfig(config) - .setInterimResults(true) - .setSingleUtterance(false) - .build(); - - StreamingRecognizeRequest initial = - StreamingRecognizeRequest.newBuilder().setStreamingConfig(streamingConfig).build(); - requestObserver.onNext(initial); - - // Get a Line to the audio input device. - TargetDataLine in = getAudioInputLine(); - byte[] buffer = new byte[bytesPerBuffer]; - int bytesRead; - - in.start(); - // Read and send sequential buffers of audio as additional RecognizeRequests. - while (finishLatch.getCount() > 0 - && (bytesRead = in.read(buffer, 0, buffer.length)) != -1) { - StreamingRecognizeRequest request = - StreamingRecognizeRequest.newBuilder() - .setAudioContent(ByteString.copyFrom(buffer, 0, bytesRead)) - .build(); - requestObserver.onNext(request); - } - } catch (RuntimeException e) { - // Cancel RPC. - requestObserver.onError(e); - throw e; - } - // Mark the end of requests. - requestObserver.onCompleted(); - - // Receiving happens asynchronously. - finishLatch.await(1, TimeUnit.MINUTES); - } - - public static void main(String[] args) throws Exception { - - String host = null; - Integer port = null; - Integer sampling = null; - - CommandLineParser parser = new DefaultParser(); - - Options options = new Options(); - options.addOption( - Option.builder() - .longOpt("host") - .desc("endpoint for api, e.g. speech.googleapis.com") - .hasArg() - .argName("ENDPOINT") - .build()); - options.addOption( - Option.builder() - .longOpt("port") - .desc("SSL port, usually 443") - .hasArg() - .argName("PORT") - .build()); - options.addOption( - Option.builder() - .longOpt("sampling") - .desc("Sampling Rate, i.e. 16000") - .hasArg() - .argName("RATE") - .build()); - - try { - CommandLine line = parser.parse(options, args); - - host = line.getOptionValue("host", "speech.googleapis.com"); - port = Integer.parseInt(line.getOptionValue("port", "443")); - - if (line.hasOption("sampling")) { - sampling = Integer.parseInt(line.getOptionValue("sampling")); - } else { - System.err.println("An Audio sampling rate (--sampling) must be specified. (e.g. 16000)"); - System.exit(1); - } - } catch (ParseException exp) { - System.err.println("Unexpected exception:" + exp.getMessage()); - System.exit(1); - } - - ManagedChannel channel = createChannel(host, port); - StreamingRecognizeClient client = new StreamingRecognizeClient(channel, sampling); - try { - client.recognize(); - } finally { - client.shutdown(); - } - } -} diff --git a/speech/grpc/src/main/java/com/examples/cloud/speech/SyncRecognizeClient.java b/speech/grpc/src/main/java/com/examples/cloud/speech/SyncRecognizeClient.java deleted file mode 100644 index 9b8e68efb17..00000000000 --- a/speech/grpc/src/main/java/com/examples/cloud/speech/SyncRecognizeClient.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * 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.examples.cloud.speech; - -import com.google.auth.oauth2.GoogleCredentials; -import com.google.cloud.speech.v1beta1.RecognitionAudio; -import com.google.cloud.speech.v1beta1.RecognitionConfig; -import com.google.cloud.speech.v1beta1.RecognitionConfig.AudioEncoding; -import com.google.cloud.speech.v1beta1.SpeechGrpc; -import com.google.cloud.speech.v1beta1.SyncRecognizeRequest; -import com.google.cloud.speech.v1beta1.SyncRecognizeResponse; -import com.google.protobuf.TextFormat; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import io.grpc.StatusRuntimeException; -import io.grpc.auth.ClientAuthInterceptor; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; - -import java.io.IOException; -import java.net.URI; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Client that sends audio to Speech.SyncRecognize and returns transcript. - */ -public class SyncRecognizeClient { - - private static final Logger logger = Logger.getLogger(SyncRecognizeClient.class.getName()); - - private final URI input; - private final int samplingRate; - - private final ManagedChannel channel; - private final SpeechGrpc.SpeechBlockingStub speechClient; - - private static final List OAUTH2_SCOPES = - Arrays.asList("https://www.googleapis.com/auth/cloud-platform"); - - /** - * Construct client connecting to Cloud Speech server at {@code host:port}. - */ - public SyncRecognizeClient(ManagedChannel channel, URI input, int samplingRate) - throws IOException { - this.input = input; - this.samplingRate = samplingRate; - this.channel = channel; - - speechClient = SpeechGrpc.newBlockingStub(channel); - } - - private RecognitionAudio createRecognitionAudio() throws IOException { - return RecognitionAudioFactory.createRecognitionAudio(this.input); - } - - public void shutdown() throws InterruptedException { - channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - - static ManagedChannel createChannel(String host, int port) throws IOException { - GoogleCredentials creds = GoogleCredentials.getApplicationDefault(); - creds = creds.createScoped(OAUTH2_SCOPES); - ManagedChannel channel = - ManagedChannelBuilder.forAddress(host, port) - .intercept(new ClientAuthInterceptor(creds, Executors.newSingleThreadExecutor())) - .build(); - - return channel; - } - - /** Send a non-streaming-recognize request to server. */ - public void recognize() { - RecognitionAudio audio; - try { - audio = createRecognitionAudio(); - } catch (IOException e) { - logger.log(Level.WARNING, "Failed to read audio uri input: " + input); - return; - } - logger.info("Sending " + audio.getContent().size() + " bytes from audio uri input: " + input); - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setEncoding(AudioEncoding.LINEAR16) - .setSampleRate(samplingRate) - .build(); - SyncRecognizeRequest request = - SyncRecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - - SyncRecognizeResponse response; - try { - response = speechClient.syncRecognize(request); - } catch (StatusRuntimeException e) { - logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus()); - return; - } - logger.info("Received response: " + TextFormat.printToString(response)); - } - - public static void main(String[] args) throws Exception { - - String audioFile = ""; - String host = "speech.googleapis.com"; - Integer port = 443; - Integer sampling = 16000; - - CommandLineParser parser = new DefaultParser(); - - Options options = new Options(); - options.addOption( - Option.builder() - .longOpt("uri") - .desc("path to audio uri") - .hasArg() - .argName("FILE_PATH") - .build()); - options.addOption( - Option.builder() - .longOpt("host") - .desc("endpoint for api, e.g. speech.googleapis.com") - .hasArg() - .argName("ENDPOINT") - .build()); - options.addOption( - Option.builder() - .longOpt("port") - .desc("SSL port, usually 443") - .hasArg() - .argName("PORT") - .build()); - options.addOption( - Option.builder() - .longOpt("sampling") - .desc("Sampling Rate, i.e. 16000") - .hasArg() - .argName("RATE") - .build()); - - try { - CommandLine line = parser.parse(options, args); - if (line.hasOption("uri")) { - audioFile = line.getOptionValue("uri"); - } else { - System.err.println("An Audio uri must be specified (e.g. file:///foo/baz.raw)."); - System.exit(1); - } - - if (line.hasOption("host")) { - host = line.getOptionValue("host"); - } else { - System.err.println("An API enpoint must be specified (typically speech.googleapis.com)."); - System.exit(1); - } - - if (line.hasOption("port")) { - port = Integer.parseInt(line.getOptionValue("port")); - } else { - System.err.println("An SSL port must be specified (typically 443)."); - System.exit(1); - } - - if (line.hasOption("sampling")) { - sampling = Integer.parseInt(line.getOptionValue("sampling")); - } else { - System.err.println("An Audio sampling rate must be specified."); - System.exit(1); - } - } catch (ParseException exp) { - System.err.println("Unexpected exception:" + exp.getMessage()); - System.exit(1); - } - - ManagedChannel channel = createChannel(host, port); - SyncRecognizeClient client = new SyncRecognizeClient(channel, URI.create(audioFile), sampling); - try { - client.recognize(); - } finally { - client.shutdown(); - } - } -} diff --git a/speech/grpc/src/test/java/com/examples/cloud/speech/RecognitionAudioFactoryTest.java b/speech/grpc/src/test/java/com/examples/cloud/speech/RecognitionAudioFactoryTest.java deleted file mode 100644 index 0f1e01b24c4..00000000000 --- a/speech/grpc/src/test/java/com/examples/cloud/speech/RecognitionAudioFactoryTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * 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.examples.cloud.speech; - -import static org.junit.Assert.assertEquals; - -import com.google.cloud.speech.v1beta1.RecognitionAudio; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.io.File; -import java.io.IOException; -import java.net.URI; - -/** - * Unit tests for {@link RecognitionAudioFactory}. - */ -@RunWith(JUnit4.class) -public class RecognitionAudioFactoryTest { - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String BUCKET = PROJECT_ID; - - @Test - public void verifyBytesInSizeFromLocalFile() throws IOException { - URI uri = new File("resources/audio.raw").toURI(); - RecognitionAudio audio = RecognitionAudioFactory.createRecognitionAudio(uri); - - int numBytes = audio.getContent().toByteArray().length; - - //assert the number of bytes in the audio as 57958 - assertEquals(57958, numBytes); - } - - @Test - public void verifyBytesInSizeFromGoogleStorageFile() throws IOException { - String audioUri = "gs://" + BUCKET + "/speech/audio.raw"; - - URI uri = URI.create(audioUri); - RecognitionAudio audio = RecognitionAudioFactory.createRecognitionAudio(uri); - - int numBytes = audio.getContent().toByteArray().length; - - //assert the number of bytes in the audio as 0 - assertEquals(0, numBytes); - - //assert the uri - assertEquals(audioUri, audio.getUri()); - } -} diff --git a/speech/grpc/src/test/java/com/examples/cloud/speech/StreamingRecognizeClientTest.java b/speech/grpc/src/test/java/com/examples/cloud/speech/StreamingRecognizeClientTest.java deleted file mode 100644 index 7ed15a0fe9e..00000000000 --- a/speech/grpc/src/test/java/com/examples/cloud/speech/StreamingRecognizeClientTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * 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.examples.cloud.speech; - -import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.when; - -import io.grpc.ManagedChannel; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.PrintStream; -import javax.sound.sampled.TargetDataLine; - - -/** - * Unit tests for {@link StreamingRecognizeClient }. - */ -@RunWith(JUnit4.class) -public class StreamingRecognizeClientTest { - private final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); - private static final PrintStream REAL_OUT = System.out; - - @Mock private TargetDataLine mockDataLine; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - System.setOut(new PrintStream(stdout)); - } - - @After - public void tearDown() { - System.setOut(REAL_OUT); - } - - @Test - public void test16KHzAudio() throws InterruptedException, IOException { - String host = "speech.googleapis.com"; - int port = 443; - ManagedChannel channel = StreamingRecognizeClient.createChannel(host, port); - - final FileInputStream in = new FileInputStream("resources/audio.raw"); - - final int samplingRate = 16000; - final StreamingRecognizeClient client = new StreamingRecognizeClient(channel, samplingRate); - - // When audio data is requested from the mock, get it from the file - when(mockDataLine.read(any(byte[].class), anyInt(), anyInt())).thenAnswer(new Answer() { - public Object answer(InvocationOnMock invocation) { - Object[] args = invocation.getArguments(); - byte[] buffer = (byte[])args[0]; - int offset = (int)args[1]; - int len = (int)args[2]; - assertThat(buffer.length).isEqualTo(len); - - try { - // Sleep, to simulate realtime - int samplesPerBuffer = client.bytesPerBuffer / StreamingRecognizeClient.BYTES_PER_SAMPLE; - int samplesPerMillis = samplingRate / 1000; - Thread.sleep(samplesPerBuffer / samplesPerMillis); - - // Provide the audio bytes from the file - return in.read(buffer, offset, len); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); - client.mockDataLine = mockDataLine; - - client.recognize(); - - assertThat(stdout.toString()).contains("how old is the Brooklyn Bridge"); - } - - @Test - public void test32KHzAudio() throws InterruptedException, IOException { - String host = "speech.googleapis.com"; - int port = 443; - ManagedChannel channel = StreamingRecognizeClient.createChannel(host, port); - - final FileInputStream in = new FileInputStream("resources/audio32KHz.raw"); - - final int samplingRate = 32000; - final StreamingRecognizeClient client = new StreamingRecognizeClient(channel, samplingRate); - - // When audio data is requested from the mock, get it from the file - when(mockDataLine.read(any(byte[].class), anyInt(), anyInt())).thenAnswer(new Answer() { - public Object answer(InvocationOnMock invocation) { - Object[] args = invocation.getArguments(); - byte[] buffer = (byte[])args[0]; - int offset = (int)args[1]; - int len = (int)args[2]; - assertThat(buffer.length).isEqualTo(len); - - try { - // Sleep, to simulate realtime - int samplesPerBuffer = client.bytesPerBuffer / StreamingRecognizeClient.BYTES_PER_SAMPLE; - int samplesPerMillis = samplingRate / 1000; - Thread.sleep(samplesPerBuffer / samplesPerMillis); - - // Provide the audio bytes from the file - return in.read(buffer, offset, len); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); - client.mockDataLine = mockDataLine; - - client.recognize(); - - assertThat(stdout.toString()).contains("how old is the Brooklyn Bridge"); - } -} diff --git a/storage/cloud-client/pom.xml b/storage/cloud-client/pom.xml index 0de63bad6a8..6722813d5a0 100644 --- a/storage/cloud-client/pom.xml +++ b/storage/cloud-client/pom.xml @@ -1,5 +1,5 @@ diff --git a/storage/json-api/pom.xml b/storage/json-api/pom.xml index e9c61d63469..7f9315478f3 100644 --- a/storage/json-api/pom.xml +++ b/storage/json-api/pom.xml @@ -1,5 +1,5 @@ com.google.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 e49c5fd324f..6feefa79662 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 @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 c2f4be1c79a..b7d89640732 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 @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 826fef4b97e..6de18a12aa5 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 @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 c035e4a808e..6d202c5e095 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 @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 320d3a37a06..769fdb6b962 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 @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 5210f43193f..0fdd94d7d02 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 @@ -1,5 +1,5 @@ /** - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/AwsRequesterTest.java b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/AwsRequesterTest.java index 395687d54c8..911af55ba25 100644 --- a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/AwsRequesterTest.java +++ b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/AwsRequesterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/NearlineRequesterTest.java b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/NearlineRequesterTest.java index 21118e80df9..7fb9bc05428 100644 --- a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/NearlineRequesterTest.java +++ b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/NearlineRequesterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/RequestCheckerTest.java b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/RequestCheckerTest.java index 0404962885d..6f48ae2ff3a 100644 --- a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/RequestCheckerTest.java +++ b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/RequestCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/TransferJobUtilsTest.java b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/TransferJobUtilsTest.java index bdb4197c92f..9306545c387 100644 --- a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/TransferJobUtilsTest.java +++ b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/TransferJobUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/storage/xml-api/cmdline-sample/pom.xml b/storage/xml-api/cmdline-sample/pom.xml index 29cc30c4af5..04bccd40609 100644 --- a/storage/xml-api/cmdline-sample/pom.xml +++ b/storage/xml-api/cmdline-sample/pom.xml @@ -1,5 +1,5 @@ diff --git a/translate/pom.xml b/translate/pom.xml index a4b5b86cf72..00cfbd5794d 100644 --- a/translate/pom.xml +++ b/translate/pom.xml @@ -38,7 +38,7 @@ limitations under the License. com.google.cloud google-cloud-translate - 0.12.0-beta + 0.13.0-beta junit diff --git a/translate/src/main/java/com/example/cloud/translate/samples/TranslateText.java b/translate/src/main/java/com/example/cloud/translate/samples/TranslateText.java index 9870793a2aa..b5454b0687d 100644 --- a/translate/src/main/java/com/example/cloud/translate/samples/TranslateText.java +++ b/translate/src/main/java/com/example/cloud/translate/samples/TranslateText.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/translate/src/test/java/com/example/cloud/translate/samples/TranslateTextTest.java b/translate/src/test/java/com/example/cloud/translate/samples/TranslateTextTest.java index c0f6edb4afc..4d943a59fd8 100644 --- a/translate/src/test/java/com/example/cloud/translate/samples/TranslateTextTest.java +++ b/translate/src/test/java/com/example/cloud/translate/samples/TranslateTextTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/travis.sh b/travis.sh index dcadb947760..713c32a8493 100755 --- a/travis.sh +++ b/travis.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 2016 Google Inc. All Rights Reserved. +# 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. diff --git a/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java b/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java index 5ef8f133693..c300702fb20 100644 --- a/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java b/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java index d96bd974fe2..3477305210e 100644 --- a/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java b/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java index 59246c5341b..ef889c7579e 100644 --- a/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java b/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java index 6e2e0185090..2b451c8d65b 100644 --- a/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java b/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java index 62f6bd05883..8d696ad21d4 100644 --- a/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java b/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java index 8950dc67a92..39186086cc2 100644 --- a/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/unittests/src/test/java/com/google/appengine/samples/LocalUrlFetchTest.java b/unittests/src/test/java/com/google/appengine/samples/LocalUrlFetchTest.java index a2f1eba6c67..b0e616f721e 100644 --- a/unittests/src/test/java/com/google/appengine/samples/LocalUrlFetchTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/LocalUrlFetchTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. All Rights Reserved. + * 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. diff --git a/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java b/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java index 25aa98c6728..f60eed48e1c 100644 --- a/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/unittests/src/test/java/com/google/appengine/samples/ShortTest.java b/unittests/src/test/java/com/google/appengine/samples/ShortTest.java index 071b004db4e..a024c08bcd3 100644 --- a/unittests/src/test/java/com/google/appengine/samples/ShortTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/ShortTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java b/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java index a3ac7a3d6e4..84e5d91b15f 100644 --- a/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java b/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java index cd03d1fb6c4..3616fb035e2 100644 --- a/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Google Inc. All Rights Reserved. + * Copyright 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/vision/cloud-client/pom.xml b/vision/cloud-client/pom.xml index 62006df1f4f..3f744ea2f34 100644 --- a/vision/cloud-client/pom.xml +++ b/vision/cloud-client/pom.xml @@ -1,5 +1,5 @@ diff --git a/vision/face-detection/pom.xml b/vision/face-detection/pom.xml index 658630d62e6..46eec9371fe 100644 --- a/vision/face-detection/pom.xml +++ b/vision/face-detection/pom.xml @@ -1,6 +1,6 @@