Skip to content

Commit b466427

Browse files
authored
Merge pull request #316 from GoogleCloudPlatform/endpoints-frameworks-v2-management
Updates Endpoints Frameworks v2 sample with service management.
2 parents bbc8d5c + 613fefb commit b466427

File tree

5 files changed

+99
-12
lines changed

5 files changed

+99
-12
lines changed

appengine/endpoints-frameworks-v2/backend/README.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,7 @@ To build the project:
2727

2828
To generate the required configuration file `swagger.json`:
2929

30-
0. Download and unzip the [Endpoints Framework tools
31-
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).
32-
33-
0. Invoke the Endpoints Tool using this command:
34-
35-
path/to/endpoints-framework-tools-2.0.0-beta.7/bin/endpoints-framework-tools get-swagger-doc \
36-
-h <PROJECT_ID>.appspot.com \
37-
-w target/echo-1.0-SNAPSHOT com.example.echo.Echo
38-
39-
Replace`<PROJECT_ID>` with your project ID.
30+
mvn exec:java -DGetSwaggerDoc
4031

4132
## Deploying the sample API to App Engine
4233

appengine/endpoints-frameworks-v2/backend/pom.xml

+56-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<properties>
3232
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3333

34+
<endpoints.framework.version>2.0.0-beta.7</endpoints.framework.version>
35+
<endpoints.management.version>1.0.0-beta.7</endpoints.management.version>
36+
3437
<endpoints.project.id>YOUR_PROJECT_ID</endpoints.project.id>
3538
</properties>
3639

@@ -45,10 +48,62 @@
4548
<dependency>
4649
<groupId>com.google.endpoints</groupId>
4750
<artifactId>endpoints-framework</artifactId>
48-
<version>2.0.0-beta.7</version>
51+
<version>${endpoints.framework.version}</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.google.endpoints</groupId>
55+
<artifactId>endpoints-management-control-appengine</artifactId>
56+
<version>${endpoints.management.version}</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.google.endpoints</groupId>
60+
<artifactId>endpoints-framework-auth</artifactId>
61+
<version>${endpoints.management.version}</version>
4962
</dependency>
5063
</dependencies>
5164

65+
<profiles>
66+
<profile>
67+
<id>GetSwaggerDoc</id>
68+
<activation>
69+
<property>
70+
<name>GetSwaggerDoc</name>
71+
</property>
72+
</activation>
73+
<build>
74+
<plugins>
75+
<plugin>
76+
<groupId>org.codehaus.mojo</groupId>
77+
<artifactId>exec-maven-plugin</artifactId>
78+
<version>1.4.0</version>
79+
<configuration>
80+
<includePluginDependencies>true</includePluginDependencies>
81+
<mainClass>com.google.api.server.spi.tools.EndpointsTool</mainClass>
82+
<arguments>
83+
<argument>get-swagger-doc</argument>
84+
<argument>--hostname=${endpoints.project.id}.appspot.com</argument>
85+
<argument>--war=target/echo-1.0-SNAPSHOT</argument>
86+
<argument>com.example.echo.Echo</argument>
87+
</arguments>
88+
</configuration>
89+
<dependencies>
90+
<dependency>
91+
<groupId>com.google.endpoints</groupId>
92+
<artifactId>endpoints-framework-tools</artifactId>
93+
<version>${endpoints.framework.version}</version>
94+
</dependency>
95+
<dependency>
96+
<groupId>com.google.appengine</groupId>
97+
<artifactId>appengine-api-1.0-sdk</artifactId>
98+
<version>1.9.30</version>
99+
</dependency>
100+
</dependencies>
101+
</plugin>
102+
</plugins>
103+
</build>
104+
</profile>
105+
</profiles>
106+
52107
<build>
53108
<!-- for hot reload of the web application-->
54109
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>

appengine/endpoints-frameworks-v2/backend/src/main/java/com/example/echo/Echo.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
package com.example.echo;
1818

19+
import com.google.api.server.spi.auth.EspAuthenticator;
1920
import com.google.api.server.spi.auth.common.User;
2021
import com.google.api.server.spi.config.Api;
2122
import com.google.api.server.spi.config.ApiMethod;
2223
import com.google.api.server.spi.config.ApiNamespace;
24+
import com.google.api.server.spi.config.AuthLevel;
2325

2426
/** The Echo API which Endpoints will be exposing. */
2527
@Api(
@@ -57,7 +59,12 @@ public Message echo(Message message) {
5759
* Note that httpMethod is not required here. Without httpMethod, this will default to GET due
5860
* to the API method name. httpMethod is added here for example purposes.
5961
*/
60-
@ApiMethod(httpMethod = ApiMethod.HttpMethod.GET)
62+
@ApiMethod(
63+
httpMethod = ApiMethod.HttpMethod.GET,
64+
authenticators = {EspAuthenticator.class},
65+
audiences = {"YOUR_OAUTH_CLIENT_ID"},
66+
authLevel = AuthLevel.REQUIRED
67+
)
6168
public Email getUserEmail(User user) throws UnauthorizedException {
6269
if (user == null) {
6370
throw new UnauthorizedException();

appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/appengine-web.xml

+4
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@
2626
<system-properties>
2727
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
2828
</system-properties>
29+
30+
<env-variables>
31+
<env-var name="ENDPOINTS_SERVICE_NAME" value="${endpoints.project.id}.appspot.com" />
32+
</env-variables>
2933
</appengine-web-app>

appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/web.xml

+30
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,34 @@
3232
<welcome-file-list>
3333
<welcome-file>index.html</welcome-file>
3434
</welcome-file-list>
35+
36+
<!-- Add a filter that fetches the service config from service management. -->
37+
<filter>
38+
<filter-name>endpoints-api-configuration</filter-name>
39+
<filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
40+
</filter>
41+
42+
<!-- Add a filter that performs Endpoints logging and monitoring. -->
43+
<filter>
44+
<filter-name>endpoints-api-controller</filter-name>
45+
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
46+
<init-param>
47+
<param-name>endpoints.projectId</param-name>
48+
<param-value>${endpoints.project.id}</param-value>
49+
</init-param>
50+
<init-param>
51+
<param-name>endpoints.serviceName</param-name>
52+
<param-value>${endpoints.project.id}.appspot.com</param-value>
53+
</init-param>
54+
</filter>
55+
56+
<filter-mapping>
57+
<filter-name>endpoints-api-configuration</filter-name>
58+
<servlet-name>EndpointsServlet</servlet-name>
59+
</filter-mapping>
60+
61+
<filter-mapping>
62+
<filter-name>endpoints-api-controller</filter-name>
63+
<servlet-name>EndpointsServlet</servlet-name>
64+
</filter-mapping>
3565
</web-app>

0 commit comments

Comments
 (0)