From ca9868767580b2affb2a419786ea5898fe926972 Mon Sep 17 00:00:00 2001 From: Brad Friedman Date: Wed, 2 Nov 2016 16:41:57 -0700 Subject: [PATCH 1/9] Add Java quickstart for Endpoints --- endpoints/getting-started/README.md | 66 +++++++++++ endpoints/getting-started/gke.yaml | 54 +++++++++ endpoints/getting-started/pom.xml | 71 ++++++++++++ .../src/main/appengine/Dockerfile | 4 + .../src/main/appengine/app.yaml | 13 +++ .../src/main/appengine/swagger.yaml | 106 ++++++++++++++++++ .../managedvms/endpoints/AuthInfoServlet.java | 59 ++++++++++ .../managedvms/endpoints/EchoServlet.java | 58 ++++++++++ 8 files changed, 431 insertions(+) create mode 100644 endpoints/getting-started/README.md create mode 100644 endpoints/getting-started/gke.yaml create mode 100644 endpoints/getting-started/pom.xml create mode 100644 endpoints/getting-started/src/main/appengine/Dockerfile create mode 100644 endpoints/getting-started/src/main/appengine/app.yaml create mode 100644 endpoints/getting-started/src/main/appengine/swagger.yaml create mode 100644 endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/AuthInfoServlet.java create mode 100644 endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/EchoServlet.java diff --git a/endpoints/getting-started/README.md b/endpoints/getting-started/README.md new file mode 100644 index 00000000000..b15e7658129 --- /dev/null +++ b/endpoints/getting-started/README.md @@ -0,0 +1,66 @@ +# Google Cloud Endpoints +This sample demonstrates how to use Google Cloud Endpoints using Java. + +## Deploying to Google App Engine Flexible Environment + +### Edit the Swagger API specification + +Open the [src/main/appengine/swagger.yaml](src/main/appengine/swagger.yaml) file in your favorite editor, and replace the YOUR-PROJECT-ID `host` line with your actual Google Cloud Platform project Id. + +### Running locally + $ mvn jetty:run + +### Deploying + $ mvn gcloud:deploy + +### 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. + +## Deploying to Google Container Engine + +### Deploy the sample API to the GKE cluster + +To deploy to a cluster: + +For instructions on how to create a GKE cluster, please refer to the GKE [documentation](https://cloud.google.com/container-engine/docs/quickstart). + +1. Edit the Kubernetes configuration file called gke.yaml in this directory, replacing SERVICE_NAME and SERVICE_VERSION shown in the snippet below with the values returned when you deployed the API: + + ``` + containers: + - name: esp + image: b.gcr.io/endpoints/endpoints-runtime:0.3 + args: [ + "-p", "8080", # the port ESP listens on + "-a", "127.0.0.1:8081", # the backend address + "-s", "SERVICE_NAME", + "-v", "SERVICE_VERSION", + ] + ``` + +2. Start the service using the kubectl create command: + + ``` + kubectl create -f gke.yaml + ``` + +3. Get the service's external IP address (it can take a few minutes after you start your service in the container before the external IP address is ready): + + ``` + kubectl get service + ``` + +4. [Create an API key](https://console.cloud.google.com/apis/credentials) in the API credentials page. + * Click Create credentials, then select API key > Server key, then click Create. + * Copy the key, then paste it into the following export statement: + + ``` + export ENDPOINTS_KEY=AIza... + ``` + +5. Test the app by making a call to the EXTERNAL-IP returned in the previous step, at port 8080. For example, this curl will test the app: + + ``` + curl -d '{"message":"hello world"}' -H "content-type:application/json" http://[EXTERNAL-IP]/echo?key=${ENDPOINTS_KEY} + ``` diff --git a/endpoints/getting-started/gke.yaml b/endpoints/getting-started/gke.yaml new file mode 100644 index 00000000000..0d67ca406ef --- /dev/null +++ b/endpoints/getting-started/gke.yaml @@ -0,0 +1,54 @@ +# Copyright 2015 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. + +apiVersion: v1 +kind: Service +metadata: + name: esp-echo +spec: + ports: + - port: 80 + targetPort: 8080 + 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: + - name: esp + image: b.gcr.io/endpoints/endpoints-runtime:0.3 + args: [ + "-p", "8080", + "-a", "127.0.0.1:8081", + "-s", "SERVICE_NAME", + "-v", "SERVICE_VERSION", + ] + ports: + - containerPort: 8080 + - name: echo + image: b.gcr.io/endpoints/echo:latest + ports: + - containerPort: 8081 diff --git a/endpoints/getting-started/pom.xml b/endpoints/getting-started/pom.xml new file mode 100644 index 00000000000..fefb3acde20 --- /dev/null +++ b/endpoints/getting-started/pom.xml @@ -0,0 +1,71 @@ + + + + 4.0.0 + war + 1.0-SNAPSHOT + com.example.managedvms + managed-vms-endpoints + + + doc-samples + com.google.cloud + 1.0.0 + ../.. + + + + + javax.servlet + javax.servlet-api + 3.1.0 + jar + provided + + + + com.google.code.gson + gson + 2.6.2 + compile + + + + + + ${project.build.directory}/${project.build.finalName}/WEB-INF/classes + + + com.google.appengine + gcloud-maven-plugin + 2.0.9.121.v20160815 + + beta + + + + org.apache.maven.plugins + maven-war-plugin + 2.6 + + false + + + + org.apache.maven.plugins + 3.3 + maven-compiler-plugin + + 1.7 + 1.7 + + + + org.eclipse.jetty + jetty-maven-plugin + 9.3.8.v20160314 + + + + diff --git a/endpoints/getting-started/src/main/appengine/Dockerfile b/endpoints/getting-started/src/main/appengine/Dockerfile new file mode 100644 index 00000000000..49864ba44c8 --- /dev/null +++ b/endpoints/getting-started/src/main/appengine/Dockerfile @@ -0,0 +1,4 @@ +FROM gcr.io/google_appengine/jetty9 + +ADD managed-vms-endpoints-1.0-SNAPSHOT.war $JETTY_BASE/webapps/root.war +ADD . /app diff --git a/endpoints/getting-started/src/main/appengine/app.yaml b/endpoints/getting-started/src/main/appengine/app.yaml new file mode 100644 index 00000000000..6d375d8db22 --- /dev/null +++ b/endpoints/getting-started/src/main/appengine/app.yaml @@ -0,0 +1,13 @@ +runtime: custom +vm: true + +handlers: +- url: /.* + script: this field is required, but ignored + secure: always + +beta_settings: + # Enable Google Cloud Endpoints API management. + use_endpoints_api_management: true + # Specify the Swagger API specification. + endpoints_swagger_spec_file: swagger.yaml diff --git a/endpoints/getting-started/src/main/appengine/swagger.yaml b/endpoints/getting-started/src/main/appengine/swagger.yaml new file mode 100644 index 00000000000..71bac9ce62f --- /dev/null +++ b/endpoints/getting-started/src/main/appengine/swagger.yaml @@ -0,0 +1,106 @@ +swagger: "2.0" +info: + description: "A simple Google Cloud Endpoints API example." + title: "Endpoints Example" + version: "1.0.0" +host: "YOUR-PROJECT-ID.appspot.com" +basePath: "/" +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-issuer: "jwt-client.endpoints.sample.google.com" + # Update this with your service account's email address. + x-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-issuer: "accounts.google.com" + x-jwks_uri: "https://www.googleapis.com/oauth2/v1/certs" diff --git a/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/AuthInfoServlet.java b/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/AuthInfoServlet.java new file mode 100644 index 00000000000..c5bc081040c --- /dev/null +++ b/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/AuthInfoServlet.java @@ -0,0 +1,59 @@ +/** + * Copyright 2015 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.example.managedvms.endpoints; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Base64; + +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; + +/** + * A servlet that returns authentication information. + * See swagger.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/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/EchoServlet.java b/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/EchoServlet.java new file mode 100644 index 00000000000..e54da65bd43 --- /dev/null +++ b/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/EchoServlet.java @@ -0,0 +1,58 @@ +/** + * Copyright 2015 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.example.managedvms.endpoints; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Map; + +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.stream.JsonReader; + +/** + * A servlet that echoes JSON message bodies. + */ +@WebServlet("/echo") +public class EchoServlet extends HttpServlet { + + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + resp.addHeader("Content-Encoding", "application/json"); + + Object responseBody; + try { + JsonReader jsonReader = new JsonReader(req.getReader()); + responseBody = new Gson().fromJson(jsonReader, Map.class); + } 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."); + responseBody = error; + } + + new Gson().toJson(responseBody, resp.getWriter()); + } +} From a94e91205b8c578852d57f516d99c6bab3fd585d Mon Sep 17 00:00:00 2001 From: Brad Friedman Date: Thu, 3 Nov 2016 11:51:26 -0700 Subject: [PATCH 2/9] Tweaks to Endpoints README --- endpoints/getting-started/README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/endpoints/getting-started/README.md b/endpoints/getting-started/README.md index b15e7658129..a938bbb98e6 100644 --- a/endpoints/getting-started/README.md +++ b/endpoints/getting-started/README.md @@ -1,11 +1,15 @@ # Google Cloud Endpoints This sample demonstrates how to use Google Cloud Endpoints using Java. -## Deploying to Google App Engine Flexible Environment +## Pre-deployment steps + +### Edit and deploy the OpenAPI specification -### Edit the Swagger API specification +1. Open the [src/main/appengine/swagger.yaml](src/main/appengine/swagger.yaml) file in your favorite editor, and replace the YOUR-PROJECT-ID `host` line with your actual Google Cloud Platform project id. -Open the [src/main/appengine/swagger.yaml](src/main/appengine/swagger.yaml) file in your favorite editor, and replace the YOUR-PROJECT-ID `host` line with your actual Google Cloud Platform project Id. +2. Deploy the service configuration. For information on how to do this, see the Configuring Endpoints and Deploying the Sample API sections [here](https://cloud.google.com/endpoints/docs/quickstart-container-engine). + +## Deploying to Google App Engine Flexible Environment ### Running locally $ mvn jetty:run From 1e7b7b27c60a74608e8690dc7bc6a7eb8f5d6df9 Mon Sep 17 00:00:00 2001 From: Brad Friedman Date: Thu, 3 Nov 2016 15:13:28 -0700 Subject: [PATCH 3/9] Change name of gke.yaml to container-engine.yaml --- endpoints/getting-started/{gke.yaml => container-engine.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename endpoints/getting-started/{gke.yaml => container-engine.yaml} (100%) diff --git a/endpoints/getting-started/gke.yaml b/endpoints/getting-started/container-engine.yaml similarity index 100% rename from endpoints/getting-started/gke.yaml rename to endpoints/getting-started/container-engine.yaml From 04f00a3dd78d31051e8e605e988d89186f0de82e Mon Sep 17 00:00:00 2001 From: Brad Friedman Date: Thu, 3 Nov 2016 15:18:21 -0700 Subject: [PATCH 4/9] Add tags to container-engine.yaml --- endpoints/getting-started/container-engine.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/endpoints/getting-started/container-engine.yaml b/endpoints/getting-started/container-engine.yaml index 0d67ca406ef..b3910bf7026 100644 --- a/endpoints/getting-started/container-engine.yaml +++ b/endpoints/getting-started/container-engine.yaml @@ -38,6 +38,7 @@ spec: app: esp-echo spec: containers: + # [START esp] - name: esp image: b.gcr.io/endpoints/endpoints-runtime:0.3 args: [ @@ -46,6 +47,7 @@ spec: "-s", "SERVICE_NAME", "-v", "SERVICE_VERSION", ] + # [END esp] ports: - containerPort: 8080 - name: echo From 08bad86b6eaf0a801ba7c4aebc08ba824ae2add5 Mon Sep 17 00:00:00 2001 From: Brad Friedman Date: Fri, 4 Nov 2016 15:23:24 -0700 Subject: [PATCH 5/9] Simplify the README --- endpoints/getting-started/README.md | 66 ++--------------------------- 1 file changed, 4 insertions(+), 62 deletions(-) diff --git a/endpoints/getting-started/README.md b/endpoints/getting-started/README.md index a938bbb98e6..81cba25045e 100644 --- a/endpoints/getting-started/README.md +++ b/endpoints/getting-started/README.md @@ -1,70 +1,12 @@ # Google Cloud Endpoints This sample demonstrates how to use Google Cloud Endpoints using Java. -## Pre-deployment steps +For a complete walkthrough showing how to run this sample in different environments, see the [Google Cloud Endpoints Quickstarts](https://cloud.google.com/endpoints/docs/quickstarts). -### Edit and deploy the OpenAPI specification +## Deploying to Production -1. Open the [src/main/appengine/swagger.yaml](src/main/appengine/swagger.yaml) file in your favorite editor, and replace the YOUR-PROJECT-ID `host` line with your actual Google Cloud Platform project id. +See the [Google Cloud Endpoints Quickstarts](https://cloud.google.com/endpoints/docs/quickstarts). -2. Deploy the service configuration. For information on how to do this, see the Configuring Endpoints and Deploying the Sample API sections [here](https://cloud.google.com/endpoints/docs/quickstart-container-engine). - -## Deploying to Google App Engine Flexible Environment - -### Running locally - $ mvn jetty:run - -### Deploying - $ mvn gcloud:deploy - -### Calling your API +## 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. - -## Deploying to Google Container Engine - -### Deploy the sample API to the GKE cluster - -To deploy to a cluster: - -For instructions on how to create a GKE cluster, please refer to the GKE [documentation](https://cloud.google.com/container-engine/docs/quickstart). - -1. Edit the Kubernetes configuration file called gke.yaml in this directory, replacing SERVICE_NAME and SERVICE_VERSION shown in the snippet below with the values returned when you deployed the API: - - ``` - containers: - - name: esp - image: b.gcr.io/endpoints/endpoints-runtime:0.3 - args: [ - "-p", "8080", # the port ESP listens on - "-a", "127.0.0.1:8081", # the backend address - "-s", "SERVICE_NAME", - "-v", "SERVICE_VERSION", - ] - ``` - -2. Start the service using the kubectl create command: - - ``` - kubectl create -f gke.yaml - ``` - -3. Get the service's external IP address (it can take a few minutes after you start your service in the container before the external IP address is ready): - - ``` - kubectl get service - ``` - -4. [Create an API key](https://console.cloud.google.com/apis/credentials) in the API credentials page. - * Click Create credentials, then select API key > Server key, then click Create. - * Copy the key, then paste it into the following export statement: - - ``` - export ENDPOINTS_KEY=AIza... - ``` - -5. Test the app by making a call to the EXTERNAL-IP returned in the previous step, at port 8080. For example, this curl will test the app: - - ``` - curl -d '{"message":"hello world"}' -H "content-type:application/json" http://[EXTERNAL-IP]/echo?key=${ENDPOINTS_KEY} - ``` From bfa605077b3d53e43914a43ef190712a8cb41850 Mon Sep 17 00:00:00 2001 From: Brad Friedman Date: Mon, 14 Nov 2016 11:06:24 -0800 Subject: [PATCH 6/9] Update Endpoints getting started to reflect new docker image --- endpoints/getting-started/container-engine.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/endpoints/getting-started/container-engine.yaml b/endpoints/getting-started/container-engine.yaml index b3910bf7026..6374d012aac 100644 --- a/endpoints/getting-started/container-engine.yaml +++ b/endpoints/getting-started/container-engine.yaml @@ -19,7 +19,7 @@ metadata: spec: ports: - port: 80 - targetPort: 8080 + targetPort: 8081 protocol: TCP name: http selector: @@ -42,15 +42,15 @@ spec: - name: esp image: b.gcr.io/endpoints/endpoints-runtime:0.3 args: [ - "-p", "8080", - "-a", "127.0.0.1:8081", + "-p", "8081", + "-a", "127.0.0.1:8080", "-s", "SERVICE_NAME", "-v", "SERVICE_VERSION", ] # [END esp] ports: - - containerPort: 8080 + - containerPort: 8081 - name: echo - image: b.gcr.io/endpoints/echo:latest + image: gcr.io/google-samples/echo-java:1.0 ports: - - containerPort: 8081 + - containerPort: 8080 From d7f2998906c67e15200e5803b53a3f7796693116 Mon Sep 17 00:00:00 2001 From: Brad Friedman Date: Wed, 16 Nov 2016 12:46:13 -0800 Subject: [PATCH 7/9] Fix groupId in pom.xml --- endpoints/getting-started/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/endpoints/getting-started/pom.xml b/endpoints/getting-started/pom.xml index fefb3acde20..9fdc7a70da5 100644 --- a/endpoints/getting-started/pom.xml +++ b/endpoints/getting-started/pom.xml @@ -5,7 +5,7 @@ 4.0.0 war 1.0-SNAPSHOT - com.example.managedvms + com.example.flexible.endpoints managed-vms-endpoints @@ -37,9 +37,9 @@ ${project.build.directory}/${project.build.finalName}/WEB-INF/classes - com.google.appengine - gcloud-maven-plugin - 2.0.9.121.v20160815 + com.google.cloud.tools + appengine-maven-plugin + 0.1.2 beta From b8bcacaf105c0041882e1e8c172aab856ee01487 Mon Sep 17 00:00:00 2001 From: Brad Friedman Date: Wed, 16 Nov 2016 13:40:38 -0800 Subject: [PATCH 8/9] More updates to the quickstart, following the example set in the appengine/flexible quickstart --- endpoints/getting-started/pom.xml | 26 +++++++++---------- .../src/main/appengine/Dockerfile | 2 +- .../src/main/appengine/app.yaml | 2 +- .../managedvms/endpoints/AuthInfoServlet.java | 9 +++---- .../managedvms/endpoints/EchoServlet.java | 14 +++++----- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/endpoints/getting-started/pom.xml b/endpoints/getting-started/pom.xml index 9fdc7a70da5..9d79c4078b2 100644 --- a/endpoints/getting-started/pom.xml +++ b/endpoints/getting-started/pom.xml @@ -6,7 +6,7 @@ war 1.0-SNAPSHOT com.example.flexible.endpoints - managed-vms-endpoints + flexible-endpoints doc-samples @@ -15,6 +15,16 @@ ../.. + + 1.8 + 1.8 + + 1.0.0 + 9.3.8.v20160314 + + false + + javax.servlet @@ -39,9 +49,8 @@ com.google.cloud.tools appengine-maven-plugin - 0.1.2 + ${appengine.maven.plugin} - beta @@ -52,19 +61,10 @@ false - - org.apache.maven.plugins - 3.3 - maven-compiler-plugin - - 1.7 - 1.7 - - org.eclipse.jetty jetty-maven-plugin - 9.3.8.v20160314 + ${jetty.maven.plugin} diff --git a/endpoints/getting-started/src/main/appengine/Dockerfile b/endpoints/getting-started/src/main/appengine/Dockerfile index 49864ba44c8..063636ed556 100644 --- a/endpoints/getting-started/src/main/appengine/Dockerfile +++ b/endpoints/getting-started/src/main/appengine/Dockerfile @@ -1,4 +1,4 @@ FROM gcr.io/google_appengine/jetty9 -ADD managed-vms-endpoints-1.0-SNAPSHOT.war $JETTY_BASE/webapps/root.war +ADD endpoints-1.0-SNAPSHOT.war $JETTY_BASE/webapps/root.war ADD . /app diff --git a/endpoints/getting-started/src/main/appengine/app.yaml b/endpoints/getting-started/src/main/appengine/app.yaml index 6d375d8db22..5882f5a8952 100644 --- a/endpoints/getting-started/src/main/appengine/app.yaml +++ b/endpoints/getting-started/src/main/appengine/app.yaml @@ -1,5 +1,5 @@ runtime: custom -vm: true +env: flex handlers: - url: /.* diff --git a/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/AuthInfoServlet.java b/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/AuthInfoServlet.java index c5bc081040c..233ea414239 100644 --- a/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/AuthInfoServlet.java +++ b/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/AuthInfoServlet.java @@ -14,10 +14,12 @@ * limitations under the License. */ -package com.example.managedvms.endpoints; +package com.example.endpoints; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; import java.io.IOException; -import java.io.PrintWriter; import java.util.Base64; import javax.servlet.annotation.WebServlet; @@ -25,9 +27,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import com.google.gson.Gson; -import com.google.gson.JsonObject; - /** * A servlet that returns authentication information. * See swagger.yaml for authentication mechanisms (e.g. JWT tokens, Google ID token). diff --git a/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/EchoServlet.java b/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/EchoServlet.java index e54da65bd43..40e0f1f5038 100644 --- a/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/EchoServlet.java +++ b/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/EchoServlet.java @@ -14,11 +14,14 @@ * limitations under the License. */ -package com.example.managedvms.endpoints; +package com.example.endpoints; + +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.io.InputStream; -import java.io.OutputStream; import java.util.Map; import javax.servlet.annotation.WebServlet; @@ -26,11 +29,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.stream.JsonReader; - /** * A servlet that echoes JSON message bodies. */ From 5d07f6f1fbf69aa61ef245a357688f7afe35de3d Mon Sep 17 00:00:00 2001 From: Brad Friedman Date: Wed, 16 Nov 2016 15:52:49 -0800 Subject: [PATCH 9/9] More changes to match the flexible/endpoints code changes --- endpoints/getting-started/README.md | 13 +++++++++++-- endpoints/getting-started/pom.xml | 16 +++++++++++++--- .../endpoints/AuthInfoServlet.java | 0 .../{managedvms => }/endpoints/EchoServlet.java | 0 4 files changed, 24 insertions(+), 5 deletions(-) rename endpoints/getting-started/src/main/java/com/example/{managedvms => }/endpoints/AuthInfoServlet.java (100%) rename endpoints/getting-started/src/main/java/com/example/{managedvms => }/endpoints/EchoServlet.java (100%) diff --git a/endpoints/getting-started/README.md b/endpoints/getting-started/README.md index 81cba25045e..12b5579fd9a 100644 --- a/endpoints/getting-started/README.md +++ b/endpoints/getting-started/README.md @@ -1,5 +1,5 @@ -# Google Cloud Endpoints -This sample demonstrates how to use Google Cloud Endpoints using Java. +# Google Cloud Endpoints & Java +This sample demonstrates how to use Google Cloud Endpoints using a Java backend. For a complete walkthrough showing how to run this sample in different environments, see the [Google Cloud Endpoints Quickstarts](https://cloud.google.com/endpoints/docs/quickstarts). @@ -10,3 +10,12 @@ See the [Google Cloud Endpoints Quickstarts](https://cloud.google.com/endpoints/ ## 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/getting-started/pom.xml b/endpoints/getting-started/pom.xml index 9d79c4078b2..1bee4f5e64d 100644 --- a/endpoints/getting-started/pom.xml +++ b/endpoints/getting-started/pom.xml @@ -5,8 +5,8 @@ 4.0.0 war 1.0-SNAPSHOT - com.example.flexible.endpoints - flexible-endpoints + com.example.endpoints + endpoints doc-samples @@ -19,6 +19,8 @@ 1.8 1.8 + 2.6 + 1.0.0 9.3.8.v20160314 @@ -46,6 +48,14 @@ ${project.build.directory}/${project.build.finalName}/WEB-INF/classes + + com.google.appengine + gcloud-maven-plugin + 2.0.9.121.v20160815 + + beta + + com.google.cloud.tools appengine-maven-plugin @@ -56,7 +66,7 @@ org.apache.maven.plugins maven-war-plugin - 2.6 + ${maven.war.plugin} false diff --git a/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/AuthInfoServlet.java b/endpoints/getting-started/src/main/java/com/example/endpoints/AuthInfoServlet.java similarity index 100% rename from endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/AuthInfoServlet.java rename to endpoints/getting-started/src/main/java/com/example/endpoints/AuthInfoServlet.java diff --git a/endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/EchoServlet.java b/endpoints/getting-started/src/main/java/com/example/endpoints/EchoServlet.java similarity index 100% rename from endpoints/getting-started/src/main/java/com/example/managedvms/endpoints/EchoServlet.java rename to endpoints/getting-started/src/main/java/com/example/endpoints/EchoServlet.java