From 8ccc6a404d9fab877df4cebae583c79fef6941dd Mon Sep 17 00:00:00 2001 From: Frank Natividad Date: Mon, 11 Sep 2017 14:13:41 -0700 Subject: [PATCH 1/3] Saving current progress --- .../com/example/echo/EchoEndpointModule.java | 17 ++++++++++++++ .../guice-example/src/main/main74.iml | 12 ---------- .../src/main/webapp/WEB-INF/web.xml | 22 ++++++++++++------- 3 files changed, 31 insertions(+), 20 deletions(-) delete mode 100644 appengine/endpoints-frameworks-v2/guice-example/src/main/main74.iml diff --git a/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java b/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java index ed40f5b1117..b97e0959425 100644 --- a/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java +++ b/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java @@ -16,13 +16,30 @@ package com.example.echo; +import com.google.api.control.ServiceManagementConfigFilter; +import com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter; +import com.google.api.server.spi.EndpointsServlet; import com.google.api.server.spi.guice.EndpointsModule; import com.google.common.collect.ImmutableList; +import com.google.inject.servlet.GuiceFilter; +import java.util.HashMap; +import java.util.Map; // [START endpoints_module] public class EchoEndpointModule extends EndpointsModule { @Override public void configureServlets() { + filter("/_ah/api/*").through(GuiceFilter.class); + + Map apiController = new HashMap(); + apiController.put("endpoints.projectId", "YOUR_PROJECT_ID"); + apiController.put("endpoints.serviceName", "YOUR_PROJECT_ID.appspot.com"); + + filter("/_ah/api/*").through(ServiceManagementConfigFilter.class); + filter("/_ah/api/*").through(GoogleAppEngineControlFilter.class, apiController); + + serve("/_ah/api/*").with(EndpointsServlet.class); + bind(Echo.class).toInstance(new Echo()); configureEndpoints("/_ah/api/*", ImmutableList.of(Echo.class)); super.configureServlets(); diff --git a/appengine/endpoints-frameworks-v2/guice-example/src/main/main74.iml b/appengine/endpoints-frameworks-v2/guice-example/src/main/main74.iml deleted file mode 100644 index e44df5c20e5..00000000000 --- a/appengine/endpoints-frameworks-v2/guice-example/src/main/main74.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/appengine/endpoints-frameworks-v2/guice-example/src/main/webapp/WEB-INF/web.xml b/appengine/endpoints-frameworks-v2/guice-example/src/main/webapp/WEB-INF/web.xml index c37b4290300..8585142bebc 100644 --- a/appengine/endpoints-frameworks-v2/guice-example/src/main/webapp/WEB-INF/web.xml +++ b/appengine/endpoints-frameworks-v2/guice-example/src/main/webapp/WEB-INF/web.xml @@ -17,15 +17,20 @@ - + - + + com.example.echo.EchoGuiceListener @@ -35,13 +40,14 @@ index.html - + + --> + From b77cdcb8acdd6f9880098981874b4c6662205321 Mon Sep 17 00:00:00 2001 From: Frank Natividad Date: Mon, 11 Sep 2017 15:55:55 -0700 Subject: [PATCH 2/3] Moving filters --- .../com/example/echo/EchoEndpointModule.java | 8 ++-- .../src/main/webapp/WEB-INF/web.xml | 38 ++----------------- 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java b/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java index b97e0959425..7ca2d708b99 100644 --- a/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java +++ b/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java @@ -24,21 +24,21 @@ import com.google.inject.servlet.GuiceFilter; import java.util.HashMap; import java.util.Map; +import javax.inject.Singleton; // [START endpoints_module] public class EchoEndpointModule extends EndpointsModule { @Override public void configureServlets() { - filter("/_ah/api/*").through(GuiceFilter.class); - Map apiController = new HashMap(); apiController.put("endpoints.projectId", "YOUR_PROJECT_ID"); apiController.put("endpoints.serviceName", "YOUR_PROJECT_ID.appspot.com"); + bind(ServiceManagementConfigFilter.class).in(Singleton.class); filter("/_ah/api/*").through(ServiceManagementConfigFilter.class); - filter("/_ah/api/*").through(GoogleAppEngineControlFilter.class, apiController); - serve("/_ah/api/*").with(EndpointsServlet.class); + bind(GoogleAppEngineControlFilter.class).in(Singleton.class); + filter("/_ah/api/*").through(GoogleAppEngineControlFilter.class, apiController); bind(Echo.class).toInstance(new Echo()); configureEndpoints("/_ah/api/*", ImmutableList.of(Echo.class)); diff --git a/appengine/endpoints-frameworks-v2/guice-example/src/main/webapp/WEB-INF/web.xml b/appengine/endpoints-frameworks-v2/guice-example/src/main/webapp/WEB-INF/web.xml index 8585142bebc..7d126e19349 100644 --- a/appengine/endpoints-frameworks-v2/guice-example/src/main/webapp/WEB-INF/web.xml +++ b/appengine/endpoints-frameworks-v2/guice-example/src/main/webapp/WEB-INF/web.xml @@ -17,20 +17,20 @@ - + - + com.example.echo.EchoGuiceListener @@ -40,34 +40,4 @@ index.html - - From 52bb096857c4a6c55cd696a1c48b010d452b5f9e Mon Sep 17 00:00:00 2001 From: Frank Natividad Date: Mon, 11 Sep 2017 17:05:12 -0700 Subject: [PATCH 3/3] Updating endpoints guice sample based on comments --- appengine-java8/endpoints-v2-guice/README.md | 6 ++-- .../com/example/echo/EchoEndpointModule.java | 19 +++++++++++ .../src/main/webapp/WEB-INF/web.xml | 34 +++---------------- .../guice-example/README.md | 6 ++-- .../com/example/echo/EchoEndpointModule.java | 9 ++--- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/appengine-java8/endpoints-v2-guice/README.md b/appengine-java8/endpoints-v2-guice/README.md index 3209a5539a0..e90c17bde58 100644 --- a/appengine-java8/endpoints-v2-guice/README.md +++ b/appengine-java8/endpoints-v2-guice/README.md @@ -17,7 +17,8 @@ To add the project ID: 0. For ``, replace the value `YOUR_PROJECT_ID` with your project ID. -0. Edit the file `src/main/java/com/example/echo/Echo.java`. +0. Edit the file `src/main/java/com/example/echo/Echo.java` and + `src/main/java/com/example/echo/EchoEndpointModule.java`. 0. Replace the value `YOUR-PROJECT-ID` with your project ID. @@ -82,7 +83,8 @@ You will get a 200 response with the following data: 0. For `def projectId = 'YOUR_PROJECT_ID'`, replace the value `YOUR_PROJECT_ID` with your project ID. -0. Edit the file `src/main/java/com/example/echo/Echo.java +0. Edit the file `src/main/java/com/example/echo/Echo.java` and + `src/main/java/com/example/echo/EchoEndpointModule.java`. 0. Replace the value `YOUR-PROJECT-ID` with your project ID. diff --git a/appengine-java8/endpoints-v2-guice/src/main/java/com/example/echo/EchoEndpointModule.java b/appengine-java8/endpoints-v2-guice/src/main/java/com/example/echo/EchoEndpointModule.java index 798648a1781..a0b2cf7f005 100644 --- a/appengine-java8/endpoints-v2-guice/src/main/java/com/example/echo/EchoEndpointModule.java +++ b/appengine-java8/endpoints-v2-guice/src/main/java/com/example/echo/EchoEndpointModule.java @@ -16,13 +16,32 @@ package com.example.echo; +import com.google.api.control.ServiceManagementConfigFilter; +import com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter; +import com.google.api.server.spi.EndpointsServlet; import com.google.api.server.spi.guice.EndpointsModule; import com.google.common.collect.ImmutableList; +import com.google.inject.servlet.GuiceFilter; +import java.util.HashMap; +import java.util.Map; +import javax.inject.Singleton; // [START endpoints_module] public class EchoEndpointModule extends EndpointsModule { @Override public void configureServlets() { + super.configureServlets(); + + bind(ServiceManagementConfigFilter.class).in(Singleton.class); + filter("/_ah/api/*").through(ServiceManagementConfigFilter.class); + + Map apiController = new HashMap(); + apiController.put("endpoints.projectId", "YOUR-PROJECT-ID"); + apiController.put("endpoints.serviceName", "YOUR-PROJECT-ID.appspot.com"); + + bind(GoogleAppEngineControlFilter.class).in(Singleton.class); + filter("/_ah/api/*").through(GoogleAppEngineControlFilter.class, apiController); + bind(Echo.class).toInstance(new Echo()); configureEndpoints("/_ah/api/*", ImmutableList.of(Echo.class)); } diff --git a/appengine-java8/endpoints-v2-guice/src/main/webapp/WEB-INF/web.xml b/appengine-java8/endpoints-v2-guice/src/main/webapp/WEB-INF/web.xml index c37b4290300..7d126e19349 100644 --- a/appengine-java8/endpoints-v2-guice/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/endpoints-v2-guice/src/main/webapp/WEB-INF/web.xml @@ -22,6 +22,11 @@ com.google.inject.servlet.GuiceFilter + guiceFilter /_ah/api/* @@ -35,33 +40,4 @@ 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 - diff --git a/appengine/endpoints-frameworks-v2/guice-example/README.md b/appengine/endpoints-frameworks-v2/guice-example/README.md index c4b4701c390..478872879c6 100644 --- a/appengine/endpoints-frameworks-v2/guice-example/README.md +++ b/appengine/endpoints-frameworks-v2/guice-example/README.md @@ -17,7 +17,8 @@ To add the project ID: 0. For ``, replace the value `YOUR_PROJECT_ID` with your project ID. -0. Edit the file `src/main/java/com/example/echo/Echo.java`. +0. Edit the file `src/main/java/com/example/echo/Echo.java` and + `src/main/java/com/example/echo/EchoEndpointModule.java`. 0. Replace the value `YOUR-PROJECT-ID` with your project ID. @@ -82,7 +83,8 @@ You will get a 200 response with the following data: 0. For `def projectId = 'YOUR_PROJECT_ID'`, replace the value `YOUR_PROJECT_ID` with your project ID. -0. Edit the file `src/main/java/com/example/echo/Echo.java +0. Edit the file `src/main/java/com/example/echo/Echo.java` and + `src/main/java/com/example/echo/EchoEndpointModule.java` 0. Replace the value `YOUR-PROJECT-ID` with your project ID. diff --git a/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java b/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java index 7ca2d708b99..a0b2cf7f005 100644 --- a/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java +++ b/appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java @@ -30,19 +30,20 @@ public class EchoEndpointModule extends EndpointsModule { @Override public void configureServlets() { - Map apiController = new HashMap(); - apiController.put("endpoints.projectId", "YOUR_PROJECT_ID"); - apiController.put("endpoints.serviceName", "YOUR_PROJECT_ID.appspot.com"); + super.configureServlets(); bind(ServiceManagementConfigFilter.class).in(Singleton.class); filter("/_ah/api/*").through(ServiceManagementConfigFilter.class); + Map apiController = new HashMap(); + apiController.put("endpoints.projectId", "YOUR-PROJECT-ID"); + apiController.put("endpoints.serviceName", "YOUR-PROJECT-ID.appspot.com"); + bind(GoogleAppEngineControlFilter.class).in(Singleton.class); filter("/_ah/api/*").through(GoogleAppEngineControlFilter.class, apiController); bind(Echo.class).toInstance(new Echo()); configureEndpoints("/_ah/api/*", ImmutableList.of(Echo.class)); - super.configureServlets(); } } // [END endpoints_module]