Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0dd5abc

Browse files
author
Frank Natividad
committedSep 2, 2017
Update endpoints samples and add sample using Guice
1 parent 9f1c2e8 commit 0dd5abc

35 files changed

+2238
-172
lines changed
 

‎appengine-java8/endpoints-v2-backend/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ To build the project:
3333

3434
To generate the required configuration file `openapi.json`:
3535

36-
mvn exec:java -DGetSwaggerDoc
36+
mvn endpoints-framework:openApiDocs
3737

3838
### Deploying the sample API to App Engine
3939

‎appengine-java8/endpoints-v2-backend/pom.xml

Lines changed: 99 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -14,120 +14,112 @@
1414
limitations under the License.
1515
-->
1616
<project>
17-
<modelVersion>4.0.0</modelVersion>
18-
<packaging>war</packaging>
19-
<version>1.0-SNAPSHOT</version>
17+
<modelVersion>4.0.0</modelVersion>
18+
<packaging>war</packaging>
19+
<version>1.0-SNAPSHOT</version>
2020

21-
<groupId>com.example.echo</groupId>
22-
<artifactId>echo-j8</artifactId>
21+
<groupId>com.example.echo</groupId>
22+
<artifactId>echo</artifactId>
2323

24-
<parent>
25-
<artifactId>appengine-java8-samples</artifactId>
26-
<groupId>com.google.cloud</groupId>
27-
<version>1.0.0</version>
28-
<relativePath>..</relativePath>
29-
</parent>
24+
<parent>
25+
<artifactId>appengine-java8-samples</artifactId>
26+
<groupId>com.google.cloud</groupId>
27+
<version>1.0.0</version>
28+
<relativePath>..</relativePath>
29+
</parent>
3030

31-
<properties>
32-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
<properties>
32+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3333

34-
<endpoints.framework.version>2.0.7</endpoints.framework.version>
35-
<endpoints.management.version>1.0.4</endpoints.management.version>
34+
<endpoints.framework.version>2.0.7</endpoints.framework.version>
35+
<endpoints.management.version>1.0.4</endpoints.management.version>
3636

37-
<endpoints.project.id>YOUR_PROJECT_ID</endpoints.project.id>
38-
<maven.compiler.target>1.8</maven.compiler.target>
39-
<maven.compiler.source>1.8</maven.compiler.source>
40-
<appengine.maven.plugin>1.3.1</appengine.maven.plugin>
41-
</properties>
37+
<endpoints.project.id>YOUR-PROJECT-ID</endpoints.project.id>
38+
<maven.compiler.target>1.8</maven.compiler.target>
39+
<maven.compiler.source>1.8</maven.compiler.source>
40+
<appengine.maven.plugin.version>1.3.1</appengine.maven.plugin.version>
41+
</properties>
4242

43-
<dependencies>
44-
<!-- Compile/runtime dependencies -->
45-
<dependency>
46-
<groupId>javax.servlet</groupId>
47-
<artifactId>javax.servlet-api</artifactId>
48-
<version>3.1.0</version>
49-
<type>jar</type>
50-
<scope>provided</scope>
51-
</dependency>
43+
<dependencies>
44+
<!-- Compile/runtime dependencies -->
45+
<dependency>
46+
<groupId>com.google.endpoints</groupId>
47+
<artifactId>endpoints-framework</artifactId>
48+
<version>${endpoints.framework.version}</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.google.endpoints</groupId>
52+
<artifactId>endpoints-management-control-appengine-all</artifactId>
53+
<version>1.0.4</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>com.google.appengine</groupId>
57+
<artifactId>appengine-api-1.0-sdk</artifactId>
58+
<version>1.9.54</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>javax.servlet</groupId>
62+
<artifactId>javax.servlet-api</artifactId>
63+
<version>3.1.0</version>
64+
<type>jar</type>
65+
<scope>provided</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>javax.inject</groupId>
69+
<artifactId>javax.inject</artifactId>
70+
<version>1</version>
71+
</dependency>
72+
</dependencies>
5273

53-
<dependency>
54-
<groupId>com.google.endpoints</groupId>
55-
<artifactId>endpoints-framework</artifactId>
56-
<version>${endpoints.framework.version}</version>
57-
</dependency>
58-
<dependency>
59-
<groupId>com.google.endpoints</groupId>
60-
<artifactId>endpoints-management-control-appengine-all</artifactId>
61-
<version>${endpoints.management.version}</version>
62-
</dependency>
63-
</dependencies>
64-
65-
<profiles>
66-
<profile>
67-
<id>GetSwaggerDoc</id>
68-
<activation>
69-
<property>
70-
<name>GetSwaggerDoc</name>
71-
</property>
72-
</activation>
73-
<build>
74+
<build>
75+
<!-- for hot reload of the web application-->
76+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
7477
<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.52</version>
99-
</dependency>
100-
</dependencies>
101-
</plugin>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-war-plugin</artifactId>
81+
<version>2.6</version>
82+
<configuration>
83+
<webResources>
84+
<resources>
85+
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
86+
<filtering>true</filtering>
87+
<targetPath>WEB-INF</targetPath>
88+
</resources>
89+
</webResources>
90+
</configuration>
91+
</plugin>
92+
<plugin>
93+
<groupId>com.google.cloud.tools</groupId>
94+
<artifactId>appengine-maven-plugin</artifactId>
95+
<version>${appengine.maven.plugin.version}</version>
96+
<configuration>
97+
<!-- deploy configuration -->
98+
</configuration>
99+
</plugin>
100+
<plugin>
101+
<groupId>com.google.cloud.tools</groupId>
102+
<artifactId>endpoints-framework-maven-plugin</artifactId>
103+
<version>1.0.0</version>
104+
<configuration>
105+
<!-- plugin configuration -->
106+
<hostname>${endpoints.project.id}.appspot.com</hostname>
107+
</configuration>
108+
</plugin>
109+
<plugin>
110+
<groupId>org.codehaus.mojo</groupId>
111+
<artifactId>versions-maven-plugin</artifactId>
112+
<version>2.3</version>
113+
<executions>
114+
<execution>
115+
<phase>compile</phase>
116+
<goals>
117+
<goal>display-dependency-updates</goal>
118+
<goal>display-plugin-updates</goal>
119+
</goals>
120+
</execution>
121+
</executions>
122+
</plugin>
102123
</plugins>
103-
</build>
104-
</profile>
105-
</profiles>
106-
107-
<build>
108-
<!-- for hot reload of the web application-->
109-
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
110-
<plugins>
111-
<plugin>
112-
<groupId>org.apache.maven.plugins</groupId>
113-
<artifactId>maven-war-plugin</artifactId>
114-
<version>2.6</version>
115-
<configuration>
116-
<webResources>
117-
<resource>
118-
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
119-
<filtering>true</filtering>
120-
<targetPath>WEB-INF</targetPath>
121-
</resource>
122-
</webResources>
123-
</configuration>
124-
</plugin>
125-
126-
<plugin>
127-
<groupId>com.google.cloud.tools</groupId>
128-
<artifactId>appengine-maven-plugin</artifactId>
129-
<version>${appengine.maven.plugin}</version>
130-
</plugin>
131-
</plugins>
132-
</build>
124+
</build>
133125
</project>
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# App Engine Standard & Google Cloud Endpoints Frameworks
2+
3+
This sample demonstrates how to use Google Cloud Endpoints Frameworks with Guice
4+
on App Engine Standard.
5+
6+
## Build with Maven
7+
8+
### Adding the project ID to the sample API code
9+
10+
You must add the project ID obtained when you created your project to the
11+
sample's `pom.xml` before you can deploy the code.
12+
13+
To add the project ID:
14+
15+
0. Edit the file `pom.xml`.
16+
17+
0. For `<endpoints.project.id>`, replace the value `YOUR_PROJECT_ID` with
18+
your project ID.
19+
20+
0. Edit the file `src/main/java/com/example/echo/Echo.java`.
21+
22+
0. Replace the value `YOUR-PROJECT-ID` with your project ID.
23+
24+
0. Save your changes.
25+
26+
### Building the sample project
27+
28+
To build the project:
29+
30+
mvn clean package
31+
32+
### Generating the openapi.json file
33+
34+
To generate the required configuration file `openapi.json`:
35+
36+
mvn endpoints-framework:openApiDoc
37+
38+
### Deploying the sample API to App Engine
39+
40+
To deploy the sample API:
41+
42+
0. Invoke the `gcloud` command to deploy the API configuration file:
43+
44+
gcloud service-management deploy openapi.json
45+
46+
0. Deploy the API implementation code by invoking:
47+
48+
mvn appengine:deploy
49+
50+
The first time you upload a sample app, you may be prompted to authorize the
51+
deployment. Follow the prompts: when you are presented with a browser window
52+
containing a code, copy it to the terminal window.
53+
54+
0. Wait for the upload to finish.
55+
56+
### Sending a request to the sample API
57+
58+
After you deploy the API and its configuration file, you can send requests
59+
to the API.
60+
61+
To send a request to the API, from a command line, invoke the following `cURL`
62+
command:
63+
64+
curl \
65+
-H "Content-Type: application/json" \
66+
-X POST \
67+
-d '{"message":"echo"}' \
68+
https://$PROJECT_ID.appspot.com/_ah/api/echo/v1/echo
69+
70+
You will get a 200 response with the following data:
71+
72+
{
73+
"message": "echo"
74+
}
75+
76+
## Build with gradle
77+
78+
### Adding the project ID to the sample API code
79+
80+
0. Edit the file `build.gradle`.
81+
82+
0. For `def projectId = 'YOUR_PROJECT_ID'`, replace the value `YOUR_PROJECT_ID`
83+
with your project ID.
84+
85+
0. Edit the file `src/main/java/com/example/echo/Echo.java
86+
87+
0. Replace the value `YOUR-PROJECT-ID` with your project ID.
88+
89+
0. Save your changes.
90+
91+
### Building the sample project
92+
93+
To build the project on unix-based systems:
94+
95+
./gradlew build
96+
97+
Windows users: Use `gradlew.bat` instead of `./gradlew`
98+
99+
<details>
100+
<summary>more details</summary>
101+
The project contains the standard java and war plugins and in addition to that it contains the following plugins:
102+
https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin for the endpoint related tasks and
103+
https://github.com/GoogleCloudPlatform/app-gradle-plugin for the appengine standard related tasks.
104+
105+
Check the links for details about the available Plugin Goals and Parameters.
106+
</details>
107+
108+
### Generating the openapi.json file
109+
110+
To generate the required configuration file `openapi.json`:
111+
112+
./gradlew endpointsOpenApiDocs
113+
114+
This results in a file in build/endpointsOpenApiDocs/openapi.json
115+
116+
### Deploying the sample API to App Engine
117+
118+
To deploy the sample API:
119+
120+
0. Invoke the `gcloud` command to deploy the API configuration file:
121+
122+
gcloud service-management deploy build/endpointsOpenApiDocs/openapi.json
123+
124+
0. Deploy the API implementation code by invoking:
125+
126+
./gradlew appengineDeploy
127+
128+
The first time you upload a sample app, you may be prompted to authorize the
129+
deployment. Follow the prompts: when you are presented with a browser window
130+
containing a code, copy it to the terminal window.
131+
132+
<details>
133+
<summary>ERROR: (gcloud.app.deploy) The current Google Cloud project [...] does not contain an App Engine application.</summary>
134+
If you create a fresh cloud project that doesn't contain a appengine application you may receive this Error:
135+
136+
ERROR: (gcloud.app.deploy) The current Google Cloud project [...] does not contain an App Engine application. Use `gcloud app create` to initialize an App Engine application within the project.
137+
138+
In that case just execute `gcloud app create`, you will be asked to select a region and the app will be created. Then run gradle appengineDeploy again.
139+
</details>
140+
141+
0. Wait for the upload to finish.
142+
143+
### Sending a request to the sample API
144+
145+
After you deploy the API and its configuration file, you can send requests
146+
to the API.
147+
148+
To send a request to the API, from a command line, invoke the following `cURL`
149+
command:
150+
151+
curl \
152+
-H "Content-Type: application/json" \
153+
-X POST \
154+
-d '{"message":"echo"}' \
155+
https://$PROJECT_ID.appspot.com/_ah/api/echo/v1/echo
156+
157+
You will get a 200 response with the following data:
158+
159+
{
160+
"message": "echo"
161+
}

0 commit comments

Comments
 (0)