Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Endpoints] Update Endpoints + Guice sample #850

Merged
merged 3 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions appengine-java8/endpoints-v2-guice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ To add the project ID:
0. For `<endpoints.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.

Expand Down Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> apiController = new HashMap<String, String>();
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));
}
Expand Down
34 changes: 5 additions & 29 deletions appengine-java8/endpoints-v2-guice/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<!--
URL Pattern /_ah/api/* instead of /* because a legacy v1 servlet uses
the route /_ah/api/ and using /* will erronously use the legacy v1
servlet instead of routing to your API.
-->
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/_ah/api/*</url-pattern>
Expand All @@ -35,33 +40,4 @@
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<!-- Add a filter that fetches the service config from service management. -->
<filter>
<filter-name>endpoints-api-configuration</filter-name>
<filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
</filter>

<!-- Add a filter that performs Endpoints logging and monitoring. -->
<filter>
<filter-name>endpoints-api-controller</filter-name>
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
<init-param>
<param-name>endpoints.projectId</param-name>
<param-value>${endpoints.project.id}</param-value>
</init-param>
<init-param>
<param-name>endpoints.serviceName</param-name>
<param-value>${endpoints.project.id}.appspot.com</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>endpoints-api-configuration</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>

<filter-mapping>
<filter-name>endpoints-api-controller</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
</web-app>
6 changes: 4 additions & 2 deletions appengine/endpoints-frameworks-v2/guice-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ To add the project ID:
0. For `<endpoints.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.

Expand Down Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,34 @@

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<String, String> apiController = new HashMap<String, String>();
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]

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<!--
URL Pattern /_ah/api/* instead of /* because a legacy v1 servlet uses
the route /_ah/api/ and using /* will erronously use the legacy v1
servlet instead of routing to your API.
-->
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/_ah/api/*</url-pattern>
Expand All @@ -35,33 +40,4 @@
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<!-- Add a filter that fetches the service config from service management. -->
<filter>
<filter-name>endpoints-api-configuration</filter-name>
<filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
</filter>

<!-- Add a filter that performs Endpoints logging and monitoring. -->
<filter>
<filter-name>endpoints-api-controller</filter-name>
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
<init-param>
<param-name>endpoints.projectId</param-name>
<param-value>${endpoints.project.id}</param-value>
</init-param>
<init-param>
<param-name>endpoints.serviceName</param-name>
<param-value>${endpoints.project.id}.appspot.com</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>endpoints-api-configuration</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>

<filter-mapping>
<filter-name>endpoints-api-controller</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
</web-app>