Skip to content

Commit 77a83b9

Browse files
committed
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.
1 parent 63895f8 commit 77a83b9

File tree

4 files changed

+78
-12
lines changed

4 files changed

+78
-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

+65-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,21 @@
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>0.0.20-SNAPSHOT</endpoints.management.version>
36+
3437
<endpoints.project.id>YOUR_PROJECT_ID</endpoints.project.id>
3538
</properties>
3639

40+
<!-- TODO(wmwong): Remove this repo before merging. -->
41+
<repositories>
42+
<repository>
43+
<id>internal-endpoints-testing</id>
44+
<name>Internal Endpoints Testing</name>
45+
<url>http://104.197.230.53:8081/nexus/content/repositories/snapshots/</url>
46+
</repository>
47+
</repositories>
48+
3749
<dependencies>
3850
<!-- Compile/runtime dependencies -->
3951
<dependency>
@@ -45,10 +57,62 @@
4557
<dependency>
4658
<groupId>com.google.endpoints</groupId>
4759
<artifactId>endpoints-framework</artifactId>
48-
<version>2.0.0-beta.7</version>
60+
<version>${endpoints.framework.version}</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>com.google.endpoints</groupId>
64+
<artifactId>endpoints-management-control-appengine</artifactId>
65+
<version>${endpoints.management.version}</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>com.google.endpoints</groupId>
69+
<artifactId>endpoints-framework-auth</artifactId>
70+
<version>${endpoints.management.version}</version>
4971
</dependency>
5072
</dependencies>
5173

74+
<profiles>
75+
<profile>
76+
<id>GetSwaggerDoc</id>
77+
<activation>
78+
<property>
79+
<name>GetSwaggerDoc</name>
80+
</property>
81+
</activation>
82+
<build>
83+
<plugins>
84+
<plugin>
85+
<groupId>org.codehaus.mojo</groupId>
86+
<artifactId>exec-maven-plugin</artifactId>
87+
<version>1.4.0</version>
88+
<configuration>
89+
<includePluginDependencies>true</includePluginDependencies>
90+
<mainClass>com.google.api.server.spi.tools.EndpointsTool</mainClass>
91+
<arguments>
92+
<argument>get-swagger-doc</argument>
93+
<argument>--hostname=${endpoints.project.id}.appspot.com</argument>
94+
<argument>--war=target/echo-1.0-SNAPSHOT</argument>
95+
<argument>com.example.echo.Echo</argument>
96+
</arguments>
97+
</configuration>
98+
<dependencies>
99+
<dependency>
100+
<groupId>com.google.endpoints</groupId>
101+
<artifactId>endpoints-framework-tools</artifactId>
102+
<version>${endpoints.framework.version}</version>
103+
</dependency>
104+
<dependency>
105+
<groupId>com.google.appengine</groupId>
106+
<artifactId>appengine-api-1.0-sdk</artifactId>
107+
<version>1.9.30</version>
108+
</dependency>
109+
</dependencies>
110+
</plugin>
111+
</plugins>
112+
</build>
113+
</profile>
114+
</profiles>
115+
52116
<build>
53117
<!-- for hot reload of the web application-->
54118
<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>

0 commit comments

Comments
 (0)