Skip to content

Commit caf31ce

Browse files
author
Frank Natividad
committed
Applying changes to Java 8 migration example (endpoints)
1 parent 83658a5 commit caf31ce

File tree

8 files changed

+72
-41
lines changed

8 files changed

+72
-41
lines changed

appengine-java8/endpoints-v2-migration/README.md

+51-26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Hello World Google Cloud Endpoints for App Engine
22

33
This sample provides an example of a [migration][7] from the prior version of
4-
[Google Cloud Endpoints Frameworks][3] to new [Google Cloud Endpoints Frameworks for App Engine][8].
4+
[Google Cloud Endpoints Frameworks][3] to new
5+
[Google Cloud Endpoints Frameworks for App Engine][8] using a
6+
**Discovery Document**. Additionally, this sample provides an example of using
7+
the new App Engine Maven and Gradle plugins for deploying your Google App Engine
8+
Standard applications.
9+
510
This sample contains comments of how to use the prior Endpoints Frameworks as
611
well. For clarity, the prior Endpoints Frameworks and the new Endpoints
712
Frameworks are denoted as Endpoints Frameworks v1.0 and Endpoints Frameworks
@@ -22,10 +27,21 @@ process is explained [here][8] and a quickstart is provided [here][9].
2227
- [Google Cloud Endpoints Frameworks v1.0][3]
2328

2429
## Build and Deployment Plugins
30+
- [Google App Engine Maven plugin][14]
31+
- [Google App Engine Gradle plugin][15]
32+
33+
## Discovery Document and Client Library Generation Plugins
2534
- [Google Cloud Endpoints Frameworks Maven Plugin][10]
2635
- [Google Cloud Endpoints Frameworks Gradle Plugin][11]
2736

2837
## Setup
38+
1. Change `YOUR-PROJECT-ID` with your project id in the hostname parameter
39+
defined in either the Maven or Gradle build script. Hostname is used when a
40+
discovery document is generated.
41+
42+
- Maven - pom.xml
43+
- Gradle - build.gradle
44+
2945
1. [Optional]: User Authenticating with Google Accounts in Web Clients
3046

3147
1. Update the `WEB_CLIENT_ID` in [Constants.java](src/main/java/com/example/helloendpoints/Constants.java)
@@ -37,12 +53,16 @@ process is explained [here][8] and a quickstart is provided [here][9].
3753
have registered in the
3854
[Credentials on Developers Console for OAuth 2.0 client IDs][6].
3955

40-
1. [Optional]: User Authenticating with Google Accounts in other Applications Types
56+
1. [Optional]: User Authenticating with Google Accounts in other Applications
57+
Types
4158

42-
- Inside [Constants.java](src/main/java/com/example/helloendpoints/Constants.java) you will find placeholders for Android
43-
applications using Google Accounts client IDs registered in the
59+
- Inside [Constants.java](src/main/java/com/example/helloendpoints/Constants.java)
60+
you will find placeholders for Android applications using Google Accounts
61+
client IDs registered in the
4462
[Credentials on Developers Console for OAuth 2.0 client IDs][6].
4563

64+
- Note: iOS support should work but has not been fully tested.
65+
4666
- These client IDs are used when defining annotation for this sample API
4767
found in [Greetings.java](src/main/java/com/example/helloendpoints/Greetings.java).
4868

@@ -65,61 +85,66 @@ process is explained [here][8] and a quickstart is provided [here][9].
6585
6686
### Maven
6787
68-
1. Build a fresh binary by using:
69-
70-
`mvn clean compile`
71-
72-
1. Run the application locally at [http://localhost:8080][5] by using:
88+
1. Build and Run the application locally at [http://localhost:8080][5] by using:
7389
74-
`mvn appengine:run`
90+
`mvn clean appengine:run`
7591
7692
1. Explore local server's API explorer by browsing to:
7793
7894
[http://localhost:8080/_ah/api/explorer][13]
7995
80-
1. Generate the client library located at `target/client-libs/helloworld-v1-java.zip`
81-
by using:
96+
1. Generate the discovery document located at
97+
`target/discovery-docs/helloworld-v1-rest.discovery` by using:
98+
99+
`mvn endpoints-framework:discoveryDocs`
100+
101+
1. Generate the client library located at
102+
`target/client-libs/helloworld-v1-java.zip` by using:
82103
83104
`mvn endpoints-framework:clientLibs`
84105
85-
1. Deploy your application to Google App Engine by using:
106+
1. Build and Deploy your application to Google App Engine by using:
86107
87-
`mvn appengine:deploy`
108+
`mvn clean appengine:deploy`
88109
89110
### Gradle
90111
91-
1. Build a fresh binary by using:
92-
93-
`gradle clean compileJava`
112+
1. Build and Run the application locally at [http://localhost:8080][5] by using:
94113
95-
1. Run the application locally at [http://localhost:8080][5] by using:
114+
`./gradlew clean appengineRun`
96115
97-
`gradle appengineRun`
116+
Windows users: Use `gradlew.bat` instead of `./gradlew`
98117
99118
1. Explore local server's API explorer by browsing to:
100119
101120
[http://localhost:8080/_ah/api/explorer][13]
102121
103-
1. Generate the client library located at `build/endpointsClientLibs/helloworld-v1-java.zip`
104-
by using:
122+
1. Generate the discovery document located at
123+
`build/endpointsDiscoveryDocs/helloworld-v1-rest.discovery` by using:
105124
106-
`gradle endpointsClientLibs`
125+
`./gradlew endpointsDiscoveryDocs`
107126
108-
1. Deploy your application to Google App Engine by using:
127+
1. Generate the client library located at
128+
`build/endpointsClientLibs/helloworld-v1-java.zip` by using:
129+
130+
`./gradlew endpointsClientLibs`
109131
110-
`gradle appengineDeploy`
132+
1. Deploy your application to Google App Engine by using:
111133
134+
`./gradlew appengineDeploy`
112135
113136
[1]: https://cloud.google.com/appengine/docs/java/
114137
[2]: http://java.com/en/
115-
[3]: https://cloud.google.com/appengine/docs/java/endpoints/
138+
[3]: https://cloud.google.com/endpoints/docs/frameworks/legacy/v1/java
116139
[4]: https://cloud.google.com/appengine/docs/java/tools/maven
117140
[5]: http://localhost:8080/
118141
[6]: https://console.developers.google.com/project/_/apiui/credential
119-
[7]: https://cloud.google.com/appengine/docs/java/endpoints/migrating
142+
[7]: https://cloud.google.com/endpoints/docs/frameworks/legacy/v1/java/migrating
120143
[8]: https://cloud.google.com/endpoints/docs/frameworks/java/about-cloud-endpoints-frameworks
121144
[9]: https://cloud.google.com/endpoints/docs/frameworks/java/quickstart-frameworks-java
122145
[10]: https://github.com/GoogleCloudPlatform/endpoints-framework-maven-plugin
123146
[11]: https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin
124147
[12]: https://cloud.google.com/endpoints/docs/authenticating-users-frameworks
125148
[13]: http://localhost:8080/_ah/api/explorer
149+
[14]: https://github.com/GoogleCloudPlatform/app-maven-plugin
150+
[15]: https://github.com/GoogleCloudPlatform/app-gradle-plugin

appengine-java8/endpoints-v2-migration/build.gradle

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ buildscript { // Configuration for building
2020
}
2121
dependencies {
2222
// App Engine Gradle plugin
23-
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.1.1'
23+
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+'
2424

2525
// Endpoints Frameworks Gradle plugin
26-
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.0-beta6'
26+
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:+'
2727
}
2828
}
2929
// [END buildscript]
@@ -49,13 +49,13 @@ dependencies {
4949
compile 'jstl:jstl:1.2'
5050
compile group: 'javax.inject', name: 'javax.inject', version: '1'
5151

52-
// Uncomment to use Endpoints Frameworks v1.0
53-
// compile group: 'com.google.appengine', name: 'appengine-endpoints', version: '1.9.48'
52+
// Uncomment to use Endpoints Frameworks v1.0 and comment the v2.0 section
53+
// compile group: 'com.google.appengine', name: 'appengine-endpoints', version: '+'
5454
// End of Endpoints Frameworks v1.0
5555

5656
// Endpoints Frameworks v2.0
5757
// [START endpoints-tools]
58-
compile group: 'com.google.endpoints', name: 'endpoints-framework-tools', version: '2.0.4'
58+
compile group: 'com.google.endpoints', name: 'endpoints-framework-tools', version: '+'
5959
// [END endpoints-tools]
6060
// End of Endpoints Frameworks v2.0
6161
}
@@ -74,6 +74,7 @@ appengine { // App Engine tasks configuration
7474
/* [START endpoints-server]
7575
endpointsServer {
7676
// Endpoints Framework Plugin server-side configuration
77+
hostname = 'YOUR-PROJECT-ID.appspot.com'
7778
}
7879
[END endpoints-server] */
7980

Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Jan 16 22:18:59 PST 2017
1+
#Thu Jun 01 13:22:47 PDT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip

appengine-java8/endpoints-v2-migration/pom.xml

+9-6
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ limitations under the License.
3030
</parent>
3131

3232
<properties>
33-
<javax.inject.version>1</javax.inject.version>
3433
<maven.compiler.source>1.8</maven.compiler.source>
3534
<maven.compiler.target>1.8</maven.compiler.target>
36-
<mojo.versions.maven.version>2.1</mojo.versions.maven.version>
3735
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3836
</properties>
3937

4038
<dependencies>
4139
<!-- Compile/runtime dependencies -->
42-
<!-- Uncomment to use Endpoints Frameworks v1.0 -->
40+
<!-- Uncomment to use Endpoints Frameworks v1.0 and comment the v2.0 section-->
4341
<!--
4442
[START appengine-endpoints]
4543
<dependency>
@@ -55,10 +53,15 @@ limitations under the License.
5553
<dependency>
5654
<groupId>com.google.endpoints</groupId>
5755
<artifactId>endpoints-framework</artifactId>
58-
<version>2.0.4</version>
56+
<version>2.0.7</version>
5957
</dependency>
6058
<!-- [END endpoints-frameworks] -->
6159
<!-- End of Endpoints Frameworks v2.0 -->
60+
<dependency>
61+
<groupId>com.google.appengine</groupId>
62+
<artifactId>appengine-api-1.0-sdk</artifactId>
63+
<version>1.9.53</version>
64+
</dependency>
6265
<dependency>
6366
<groupId>javax.servlet</groupId>
6467
<artifactId>javax.servlet-api</artifactId>
@@ -69,7 +72,7 @@ limitations under the License.
6972
<dependency>
7073
<groupId>javax.inject</groupId>
7174
<artifactId>javax.inject</artifactId>
72-
<version>${javax.inject.version}</version>
75+
<version>1</version>
7376
</dependency>
7477
</dependencies>
7578

@@ -100,7 +103,7 @@ limitations under the License.
100103
<plugin>
101104
<groupId>org.codehaus.mojo</groupId>
102105
<artifactId>versions-maven-plugin</artifactId>
103-
<version>${mojo.versions.maven.version}</version>
106+
<version>2.3</version>
104107
<executions>
105108
<execution>
106109
<phase>compile</phase>

appengine-java8/endpoints-v2-migration/src/main/java/com/example/helloendpoints/Constants.java

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
public class Constants {
2323
public static final String WEB_CLIENT_ID = "replace this with your web client ID";
2424
public static final String ANDROID_CLIENT_ID = "replace this with your Android client ID";
25+
public static final String IOS_CLIENT_ID = "replace this with your iOS client ID";
2526
public static final String ANDROID_AUDIENCE = WEB_CLIENT_ID;
2627

2728
public static final String EMAIL_SCOPE = "https://www.googleapis.com/auth/userinfo.email";

appengine-java8/endpoints-v2-migration/src/main/java/com/example/helloendpoints/Greetings.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
*/
3535
@Api(name = "helloworld",
3636
version = "v1",
37+
// You can add additional SCOPES as a comma separated list of values
3738
scopes = {Constants.EMAIL_SCOPE},
38-
clientIds = {Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID},
39+
clientIds = {Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID, Constants.IOS_CLIENT_ID},
3940
audiences = {Constants.ANDROID_AUDIENCE}
4041
)
4142
public class Greetings {

appengine-java8/endpoints-v2-migration/src/main/webapp/WEB-INF/web.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
2020
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
2121
version="3.1">
22-
<!-- Uncomment to use Endpoints Frameworks v1.0 -->
22+
<!-- Uncomment to use Endpoints Frameworks v1.0 and comment the v2.0 section -->
2323
<!--
2424
[START appengine-endpoints]
2525
<servlet>

0 commit comments

Comments
 (0)