File tree Expand file tree Collapse file tree 5 files changed +37
-37
lines changed
appengine-java8/endpoints-v2-guice
appengine/endpoints-frameworks-v2/guice-example
src/main/java/com/example/echo Expand file tree Collapse file tree 5 files changed +37
-37
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ To add the project ID:
17170 . For ` <endpoints.project.id> ` , replace the value ` YOUR_PROJECT_ID ` with
1818your project ID.
1919
20- 0 . Edit the file ` src/main/java/com/example/echo/Echo.java ` .
20+ 0 . Edit the file ` src/main/java/com/example/echo/Echo.java ` and
21+ ` src/main/java/com/example/echo/EchoEndpointModule.java ` .
2122
22230 . Replace the value ` YOUR-PROJECT-ID ` with your project ID.
2324
@@ -82,7 +83,8 @@ You will get a 200 response with the following data:
82830 . For ` def projectId = 'YOUR_PROJECT_ID' ` , replace the value ` YOUR_PROJECT_ID `
8384with your project ID.
8485
85- 0 . Edit the file `src/main/java/com/example/echo/Echo.java
86+ 0 . Edit the file ` src/main/java/com/example/echo/Echo.java ` and
87+ ` src/main/java/com/example/echo/EchoEndpointModule.java ` .
8688
87890 . Replace the value ` YOUR-PROJECT-ID ` with your project ID.
8890
Original file line number Diff line number Diff line change 1616
1717package com .example .echo ;
1818
19+ import com .google .api .control .ServiceManagementConfigFilter ;
20+ import com .google .api .control .extensions .appengine .GoogleAppEngineControlFilter ;
21+ import com .google .api .server .spi .EndpointsServlet ;
1922import com .google .api .server .spi .guice .EndpointsModule ;
2023import com .google .common .collect .ImmutableList ;
24+ import com .google .inject .servlet .GuiceFilter ;
25+ import java .util .HashMap ;
26+ import java .util .Map ;
27+ import javax .inject .Singleton ;
2128
2229// [START endpoints_module]
2330public class EchoEndpointModule extends EndpointsModule {
2431 @ Override
2532 public void configureServlets () {
33+ super .configureServlets ();
34+
35+ bind (ServiceManagementConfigFilter .class ).in (Singleton .class );
36+ filter ("/_ah/api/*" ).through (ServiceManagementConfigFilter .class );
37+
38+ Map <String , String > apiController = new HashMap <String , String >();
39+ apiController .put ("endpoints.projectId" , "YOUR-PROJECT-ID" );
40+ apiController .put ("endpoints.serviceName" , "YOUR-PROJECT-ID.appspot.com" );
41+
42+ bind (GoogleAppEngineControlFilter .class ).in (Singleton .class );
43+ filter ("/_ah/api/*" ).through (GoogleAppEngineControlFilter .class , apiController );
44+
2645 bind (Echo .class ).toInstance (new Echo ());
2746 configureEndpoints ("/_ah/api/*" , ImmutableList .of (Echo .class ));
2847 }
Original file line number Diff line number Diff line change 2222 <filter-class >com.google.inject.servlet.GuiceFilter</filter-class >
2323 </filter >
2424
25+ <!--
26+ URL Pattern /_ah/api/* instead of /* because a legacy v1 servlet uses
27+ the route /_ah/api/ and using /* will erronously use the legacy v1
28+ servlet instead of routing to your API.
29+ -->
2530 <filter-mapping >
2631 <filter-name >guiceFilter</filter-name >
2732 <url-pattern >/_ah/api/*</url-pattern >
3540 <welcome-file >index.html</welcome-file >
3641 </welcome-file-list >
3742
38- <!-- Add a filter that fetches the service config from service management. -->
39- <filter >
40- <filter-name >endpoints-api-configuration</filter-name >
41- <filter-class >com.google.api.control.ServiceManagementConfigFilter</filter-class >
42- </filter >
43-
44- <!-- Add a filter that performs Endpoints logging and monitoring. -->
45- <filter >
46- <filter-name >endpoints-api-controller</filter-name >
47- <filter-class >com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class >
48- <init-param >
49- <param-name >endpoints.projectId</param-name >
50- <param-value >${endpoints.project.id}</param-value >
51- </init-param >
52- <init-param >
53- <param-name >endpoints.serviceName</param-name >
54- <param-value >${endpoints.project.id}.appspot.com</param-value >
55- </init-param >
56- </filter >
57-
58- <filter-mapping >
59- <filter-name >endpoints-api-configuration</filter-name >
60- <servlet-name >EndpointsServlet</servlet-name >
61- </filter-mapping >
62-
63- <filter-mapping >
64- <filter-name >endpoints-api-controller</filter-name >
65- <servlet-name >EndpointsServlet</servlet-name >
66- </filter-mapping >
6743</web-app >
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ To add the project ID:
17170 . For ` <endpoints.project.id> ` , replace the value ` YOUR_PROJECT_ID ` with
1818your project ID.
1919
20- 0 . Edit the file ` src/main/java/com/example/echo/Echo.java ` .
20+ 0 . Edit the file ` src/main/java/com/example/echo/Echo.java ` and
21+ ` src/main/java/com/example/echo/EchoEndpointModule.java ` .
2122
22230 . Replace the value ` YOUR-PROJECT-ID ` with your project ID.
2324
@@ -82,7 +83,8 @@ You will get a 200 response with the following data:
82830 . For ` def projectId = 'YOUR_PROJECT_ID' ` , replace the value ` YOUR_PROJECT_ID `
8384with your project ID.
8485
85- 0 . Edit the file `src/main/java/com/example/echo/Echo.java
86+ 0 . Edit the file ` src/main/java/com/example/echo/Echo.java ` and
87+ ` src/main/java/com/example/echo/EchoEndpointModule.java `
8688
87890 . Replace the value ` YOUR-PROJECT-ID ` with your project ID.
8890
Original file line number Diff line number Diff line change 3030public class EchoEndpointModule extends EndpointsModule {
3131 @ Override
3232 public void configureServlets () {
33- Map <String , String > apiController = new HashMap <String , String >();
34- apiController .put ("endpoints.projectId" , "YOUR_PROJECT_ID" );
35- apiController .put ("endpoints.serviceName" , "YOUR_PROJECT_ID.appspot.com" );
33+ super .configureServlets ();
3634
3735 bind (ServiceManagementConfigFilter .class ).in (Singleton .class );
3836 filter ("/_ah/api/*" ).through (ServiceManagementConfigFilter .class );
3937
38+ Map <String , String > apiController = new HashMap <String , String >();
39+ apiController .put ("endpoints.projectId" , "YOUR-PROJECT-ID" );
40+ apiController .put ("endpoints.serviceName" , "YOUR-PROJECT-ID.appspot.com" );
41+
4042 bind (GoogleAppEngineControlFilter .class ).in (Singleton .class );
4143 filter ("/_ah/api/*" ).through (GoogleAppEngineControlFilter .class , apiController );
4244
4345 bind (Echo .class ).toInstance (new Echo ());
4446 configureEndpoints ("/_ah/api/*" , ImmutableList .of (Echo .class ));
45- super .configureServlets ();
4647 }
4748}
4849// [END endpoints_module]
You can’t perform that action at this time.
0 commit comments