From 77a83b9749fe981dab5220ecc6364a812aa5ff51 Mon Sep 17 00:00:00 2001 From: Wesley Wong Date: Mon, 29 Aug 2016 12:37:27 -0500 Subject: [PATCH 1/3] Updates Endpoints Frameworks v2 sample with service management. Adds service management and auth dependencies and filters. Uses exec-maven-plugin to generate the swagger spec. Updates README for swagger generation. --- .../endpoints-frameworks-v2/backend/README.md | 11 +--- .../endpoints-frameworks-v2/backend/pom.xml | 66 ++++++++++++++++++- .../src/main/java/com/example/echo/Echo.java | 9 ++- .../src/main/webapp/WEB-INF/appengine-web.xml | 4 ++ 4 files changed, 78 insertions(+), 12 deletions(-) diff --git a/appengine/endpoints-frameworks-v2/backend/README.md b/appengine/endpoints-frameworks-v2/backend/README.md index 18322cab66e..d7b23ec6bdd 100644 --- a/appengine/endpoints-frameworks-v2/backend/README.md +++ b/appengine/endpoints-frameworks-v2/backend/README.md @@ -27,16 +27,7 @@ To build the project: To generate the required configuration file `swagger.json`: -0. Download and unzip the [Endpoints Framework tools -package](http://search.maven.org/remotecontent?filepath=com/google/endpoints/endpoints-framework-tools/2.0.0-beta.7/endpoints-framework-tools-2.0.0-beta.7.zip). - -0. Invoke the Endpoints Tool using this command: - - path/to/endpoints-framework-tools-2.0.0-beta.7/bin/endpoints-framework-tools get-swagger-doc \ - -h .appspot.com \ - -w target/echo-1.0-SNAPSHOT com.example.echo.Echo - - Replace`` with your project ID. + mvn exec:java -DGetSwaggerDoc ## Deploying the sample API to App Engine diff --git a/appengine/endpoints-frameworks-v2/backend/pom.xml b/appengine/endpoints-frameworks-v2/backend/pom.xml index 3c4796f3294..ac799f82599 100644 --- a/appengine/endpoints-frameworks-v2/backend/pom.xml +++ b/appengine/endpoints-frameworks-v2/backend/pom.xml @@ -31,9 +31,21 @@ UTF-8 + 2.0.0-beta.7 + 0.0.20-SNAPSHOT + YOUR_PROJECT_ID + + + + internal-endpoints-testing + Internal Endpoints Testing + http://104.197.230.53:8081/nexus/content/repositories/snapshots/ + + + @@ -45,10 +57,62 @@ com.google.endpoints endpoints-framework - 2.0.0-beta.7 + ${endpoints.framework.version} + + + com.google.endpoints + endpoints-management-control-appengine + ${endpoints.management.version} + + + com.google.endpoints + endpoints-framework-auth + ${endpoints.management.version} + + + GetSwaggerDoc + + + GetSwaggerDoc + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.4.0 + + true + com.google.api.server.spi.tools.EndpointsTool + + get-swagger-doc + --hostname=${endpoints.project.id}.appspot.com + --war=target/echo-1.0-SNAPSHOT + com.example.echo.Echo + + + + + com.google.endpoints + endpoints-framework-tools + ${endpoints.framework.version} + + + com.google.appengine + appengine-api-1.0-sdk + 1.9.30 + + + + + + + + ${project.build.directory}/${project.build.finalName}/WEB-INF/classes diff --git a/appengine/endpoints-frameworks-v2/backend/src/main/java/com/example/echo/Echo.java b/appengine/endpoints-frameworks-v2/backend/src/main/java/com/example/echo/Echo.java index 8a7d050051a..977f5b94c65 100644 --- a/appengine/endpoints-frameworks-v2/backend/src/main/java/com/example/echo/Echo.java +++ b/appengine/endpoints-frameworks-v2/backend/src/main/java/com/example/echo/Echo.java @@ -16,10 +16,12 @@ package com.example.echo; +import com.google.api.server.spi.auth.EspAuthenticator; import com.google.api.server.spi.auth.common.User; import com.google.api.server.spi.config.Api; import com.google.api.server.spi.config.ApiMethod; import com.google.api.server.spi.config.ApiNamespace; +import com.google.api.server.spi.config.AuthLevel; /** The Echo API which Endpoints will be exposing. */ @Api( @@ -57,7 +59,12 @@ public Message echo(Message message) { * Note that httpMethod is not required here. Without httpMethod, this will default to GET due * to the API method name. httpMethod is added here for example purposes. */ - @ApiMethod(httpMethod = ApiMethod.HttpMethod.GET) + @ApiMethod( + httpMethod = ApiMethod.HttpMethod.GET, + authenticators = {EspAuthenticator.class}, + audiences = {"YOUR_OAUTH_CLIENT_ID"}, + authLevel = AuthLevel.REQUIRED + ) public Email getUserEmail(User user) throws UnauthorizedException { if (user == null) { throw new UnauthorizedException(); diff --git a/appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/appengine-web.xml b/appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/appengine-web.xml index 274894e136b..8f249f751a1 100644 --- a/appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/appengine-web.xml +++ b/appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/appengine-web.xml @@ -26,4 +26,8 @@ + + + + From d7962d8d89d19c9fc58f07f55758d594ad60fe70 Mon Sep 17 00:00:00 2001 From: Wesley Wong Date: Tue, 30 Aug 2016 11:42:36 -0500 Subject: [PATCH 2/3] Fix checkstyle error. --- .../backend/src/main/java/com/example/echo/Echo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine/endpoints-frameworks-v2/backend/src/main/java/com/example/echo/Echo.java b/appengine/endpoints-frameworks-v2/backend/src/main/java/com/example/echo/Echo.java index 977f5b94c65..f8bc0590748 100644 --- a/appengine/endpoints-frameworks-v2/backend/src/main/java/com/example/echo/Echo.java +++ b/appengine/endpoints-frameworks-v2/backend/src/main/java/com/example/echo/Echo.java @@ -59,7 +59,7 @@ public Message echo(Message message) { * Note that httpMethod is not required here. Without httpMethod, this will default to GET due * to the API method name. httpMethod is added here for example purposes. */ - @ApiMethod( + @ApiMethod( httpMethod = ApiMethod.HttpMethod.GET, authenticators = {EspAuthenticator.class}, audiences = {"YOUR_OAUTH_CLIENT_ID"}, From 613fefb2512371e323b2c37d032aae9faaee883f Mon Sep 17 00:00:00 2001 From: Wesley Wong Date: Wed, 31 Aug 2016 16:13:51 -0500 Subject: [PATCH 3/3] Adds filters for management and uses public repo. --- .../endpoints-frameworks-v2/backend/pom.xml | 11 +------ .../backend/src/main/webapp/WEB-INF/web.xml | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/appengine/endpoints-frameworks-v2/backend/pom.xml b/appengine/endpoints-frameworks-v2/backend/pom.xml index ac799f82599..a0cabc5964b 100644 --- a/appengine/endpoints-frameworks-v2/backend/pom.xml +++ b/appengine/endpoints-frameworks-v2/backend/pom.xml @@ -32,20 +32,11 @@ UTF-8 2.0.0-beta.7 - 0.0.20-SNAPSHOT + 1.0.0-beta.7 YOUR_PROJECT_ID - - - - internal-endpoints-testing - Internal Endpoints Testing - http://104.197.230.53:8081/nexus/content/repositories/snapshots/ - - - diff --git a/appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/web.xml b/appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/web.xml index 53beffe8208..66db1fda503 100644 --- a/appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/web.xml +++ b/appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/web.xml @@ -32,4 +32,34 @@ index.html + + + + endpoints-api-configuration + com.google.api.control.ServiceManagementConfigFilter + + + + + endpoints-api-controller + com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter + + endpoints.projectId + ${endpoints.project.id} + + + endpoints.serviceName + ${endpoints.project.id}.appspot.com + + + + + endpoints-api-configuration + EndpointsServlet + + + + endpoints-api-controller + EndpointsServlet +