Skip to content

Commit

Permalink
Updates Endpoints Frameworks v2 sample with service management.
Browse files Browse the repository at this point in the history
Adds service management and auth dependencies and filters.
Uses exec-maven-plugin to generate the swagger spec.
Updates README for swagger generation.
  • Loading branch information
wmwong committed Aug 29, 2016
1 parent 63895f8 commit 77a83b9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 12 deletions.
11 changes: 1 addition & 10 deletions appengine/endpoints-frameworks-v2/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,7 @@ To build the project:

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

0. Download and unzip the [Endpoints Framework tools
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).

0. Invoke the Endpoints Tool using this command:

path/to/endpoints-framework-tools-2.0.0-beta.7/bin/endpoints-framework-tools get-swagger-doc \
-h <PROJECT_ID>.appspot.com \
-w target/echo-1.0-SNAPSHOT com.example.echo.Echo

Replace`<PROJECT_ID>` with your project ID.
mvn exec:java -DGetSwaggerDoc

## Deploying the sample API to App Engine

Expand Down
66 changes: 65 additions & 1 deletion appengine/endpoints-frameworks-v2/backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<endpoints.framework.version>2.0.0-beta.7</endpoints.framework.version>
<endpoints.management.version>0.0.20-SNAPSHOT</endpoints.management.version>

<endpoints.project.id>YOUR_PROJECT_ID</endpoints.project.id>
</properties>

<!-- TODO(wmwong): Remove this repo before merging. -->
<repositories>
<repository>
<id>internal-endpoints-testing</id>
<name>Internal Endpoints Testing</name>
<url>http://104.197.230.53:8081/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
<!-- Compile/runtime dependencies -->
<dependency>
Expand All @@ -45,10 +57,62 @@
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework</artifactId>
<version>2.0.0-beta.7</version>
<version>${endpoints.framework.version}</version>
</dependency>
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-management-control-appengine</artifactId>
<version>${endpoints.management.version}</version>
</dependency>
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework-auth</artifactId>
<version>${endpoints.management.version}</version>
</dependency>
</dependencies>

<profiles>
<profile>
<id>GetSwaggerDoc</id>
<activation>
<property>
<name>GetSwaggerDoc</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>com.google.api.server.spi.tools.EndpointsTool</mainClass>
<arguments>
<argument>get-swagger-doc</argument>
<argument>--hostname=${endpoints.project.id}.appspot.com</argument>
<argument>--war=target/echo-1.0-SNAPSHOT</argument>
<argument>com.example.echo.Echo</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework-tools</artifactId>
<version>${endpoints.framework.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.30</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
<!-- for hot reload of the web application-->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.example.echo;

import com.google.api.server.spi.auth.EspAuthenticator;
import com.google.api.server.spi.auth.common.User;
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.api.server.spi.config.AuthLevel;

/** The Echo API which Endpoints will be exposing. */
@Api(
Expand Down Expand Up @@ -57,7 +59,12 @@ public Message echo(Message message) {
* Note that httpMethod is not required here. Without httpMethod, this will default to GET due
* to the API method name. httpMethod is added here for example purposes.
*/
@ApiMethod(httpMethod = ApiMethod.HttpMethod.GET)
@ApiMethod(
httpMethod = ApiMethod.HttpMethod.GET,
authenticators = {EspAuthenticator.class},
audiences = {"YOUR_OAUTH_CLIENT_ID"},
authLevel = AuthLevel.REQUIRED
)
public Email getUserEmail(User user) throws UnauthorizedException {
if (user == null) {
throw new UnauthorizedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>

<env-variables>
<env-var name="ENDPOINTS_SERVICE_NAME" value="${endpoints.project.id}.appspot.com" />
</env-variables>
</appengine-web-app>

0 comments on commit 77a83b9

Please sign in to comment.