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

Updates Endpoints Frameworks v2 sample with service management. #316

Merged
merged 3 commits into from
Sep 1, 2016
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
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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mention what files to edit to make things work somewhere here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Up above, there is a section to replace the endpoints.project.id property.

## Deploying the sample API to App Engine

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

<endpoints.framework.version>2.0.0-beta.7</endpoints.framework.version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would hope this changes, but ok.

<endpoints.management.version>1.0.0-beta.7</endpoints.management.version>

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

Expand All @@ -45,10 +48,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>
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,34 @@
<welcome-file-list>
<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>