Skip to content

Commit 48b8f12

Browse files
frankyndpebot
authored andcommitted
Move and update appengine-endpoints-helloendpoints-java-maven sample (GoogleCloudPlatform#488)
* Adding endpoints v1 using endpoints frameworks v2 samples * Removing CONTRIB and LICENSE from within a sample * Moved endpoints-v1-using-endpoints-frameworks-v2 * Removed nbactions.xml and eclipse-launch-profiles. * Removed 'All Rights Reserved' * Added project id to expected test output in Jenkins.sh * Removed unnecessary plugins * Added README to explain the endpoints directories for Standard * Updated discovery doc sample for EP standard * Updating PROJECT_ID to VERSION_ID in Jenkins.sh test * Making Endpoints E2E tests version specific. * Typo... in which argument being used. * Adding Gradle tests to Jenkins.sh * Changed README text for endpoints-frameworks-v2/ * Updating endpoints-frameworks-v2/discovery/Jenkins.sh to be version specific. * Added parent pom to pom.xml and updated sample based on stylecheck. * fix typo. setting java compiler source and target * Adding space between region tags * Modified verbage for cost related to endpoints in README * Updated endpionts README to give more information about user authentication * Double quotes for environment variables Jenkins.sh
1 parent 5440235 commit 48b8f12

File tree

19 files changed

+8532
-0
lines changed

19 files changed

+8532
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Google Cloud Endpoints Frameworks for App Engine Standard
2+
3+
This directory contains Google Cloud Endpoints Frameworks for App Engine for
4+
App Engine Standard samples. The [`backend/`](backend/) directory contains the
5+
sample code for the [quickstart][4] for Cloud Endpoints Frameworks on App Engine
6+
using an OpenAPI development process. The [`discovery/`](discovery/) directory
7+
contains the sample code for [migrated][2] prior version of [Cloud Endpoints
8+
Frameworks][1] project to the new [Cloud Endpoints Frameworks for App Engine][8]
9+
using a discovery document development process.
10+
11+
The new Google Cloud Endpoints Frameworks for App Engine provides
12+
[additional functionality][3] using OpenAPI which may require payment.
13+
It's recommended that you migrate projects using the prior version of [Cloud Endpoints Frameworks][1].
14+
15+
16+
[1]: https://cloud.google.com/appengine/docs/java/endpoints/
17+
[2]: https://cloud.google.com/appengine/docs/java/endpoints/migrating
18+
[3]: https://cloud.google.com/endpoints/docs/frameworks/java/about-cloud-endpoints-frameworks
19+
[4]: https://cloud.google.com/endpoints/docs/frameworks/java/quickstart-frameworks-java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 Google Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Fail on non-zero return and print command to stdout
18+
set -xe
19+
20+
# Jenkins Test Script
21+
function TestEndpoints () {
22+
# Test getGreeting Endpoint (hello world!)
23+
curl -X GET \
24+
"https://${2}-dot-${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting/0" | \
25+
grep "hello version-${2}"
26+
27+
# Test getGreeting Endpoint (goodbye world!)
28+
curl -X GET \
29+
"https://${2}-dot-${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting/1" | \
30+
grep "goodbye world!"
31+
32+
# Test listGreeting Endpoint (hello world! and goodbye world!)
33+
curl -X GET \
34+
"https://${2}-dot-${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting" | \
35+
grep "hello world!\|goodbye world!"
36+
37+
# Test multiply Endpoint (This is a greeting.)
38+
curl -X POST \
39+
-H "Content-Type: application/json" \
40+
--data "{'message':'This is a greeting from instance ${2}'}." \
41+
"https://${2}-dot-${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting/1" | \
42+
grep "This is a greeting from instance ${2}."
43+
}
44+
45+
# Jenkins provides values for GOOGLE_PROJECT_ID and GOOGLE_VERSION_ID
46+
# Update Greetings.java
47+
sed -i'.bak' -e "s/hello world!/hello version-${GOOGLE_VERSION_ID}!/g" src/main/java/com/example/helloendpoints/Greetings.java
48+
49+
# Test with Maven
50+
mvn clean appengine:deploy \
51+
-Dapp.deploy.version="${GOOGLE_VERSION_ID}"
52+
53+
# End-2-End tests
54+
TestEndpoints "${GOOGLE_PROJECT_ID}" "${GOOGLE_VERSION_ID}"
55+
56+
# Clean
57+
mvn clean
58+
59+
# Test with Gradle
60+
# Update build.gradle
61+
sed -i'.bak' -e "s/deploy {/deploy {\n version='${GOOGLE_VERSION_ID}'/g" build.gradle
62+
63+
# Modify Greetings.java for Gradle
64+
sed -i'.bak' -e "s/hello version-${GOOGLE_VERSION_ID}!/hello version-gradle-${GOOGLE_VERSION_ID}!/g" src/main/java/com/example/helloendpoints/Greetings.java
65+
66+
# Deploy Gradle
67+
gradle appengineDeploy
68+
69+
# End-2-End tests
70+
TestEndpoints "${GOOGLE_PROJECT_ID}" "gradle-${GOOGLE_VERSION_ID}"
71+
72+
# Clean
73+
gradle clean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Hello World Google Cloud Endpoints for App Engine with a discovery document
2+
3+
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]
5+
while still using a discovery document. This sample contains comments of how to
6+
use the prior Endpoints Frameworks as well. For clarity, the prior Endpoints
7+
Frameworks and the new Endpoints Frameworks are denoted as Endpoints Frameworks v1.0
8+
and Endpoints Frameworks v2.0 respectively.
9+
10+
Google Cloud Endpoints Frameworks v2.0 provides new functionality which may
11+
require payment and uses an OpenAPI specification instead of the discovery document.
12+
The OpenAPI development process is explained [here][8] and a quickstart is
13+
provided [here][9].
14+
15+
## Products
16+
- [Google App Engine Standard][1]
17+
18+
## Language
19+
- [Java][2]
20+
21+
## APIs
22+
- [Google Cloud Endpoints Frameworks v2.0][8]
23+
- [Google Cloud Endpoints Frameworks v1.0][3]
24+
25+
## Build and Deployment Plugins
26+
- [Google Cloud Endpoints Frameworks Maven Plugin][10]
27+
- [Google Cloud Endpoints Frameworks Gradle Plugin][11]
28+
29+
## Setup
30+
1. [Optional]: User Authenticating with Google Accounts in Web Clients
31+
32+
1. Update the `WEB_CLIENT_ID` in [Constants.java](src/main/java/com/example/helloendpoints/Constants.java)
33+
to reflect the web client ID you have registered in the [Credentials on Developers Console for OAuth 2.0 client IDs][6].
34+
35+
1. Update the value of `google.devrel.samples.helloendpoints.CLIENT_ID` in [base.js](src/main/webapp/js/base.js)
36+
to reflect the web client ID you have registered in the [Credentials on Developers Console for OAuth 2.0 client IDs][6].
37+
38+
1. [Optional]: User Authenticating with Google Accounts in other Applications Types
39+
40+
- Inside [Constants.java](src/main/java/com/example/helloendpoints/Constants.java) you will find placeholders for Android
41+
and iOS applications using Google Accounts client IDs registered in the
42+
[Credentials on Developers Console for OAuth 2.0 client IDs][6].
43+
44+
- These client IDs are used when defining annotation for this sample API found in [Greetings.java](src/main/java/com/example/helloendpoints/Greetings.java).
45+
46+
- You can read more about different user authentication supported [here][12].
47+
48+
49+
1. [Optional]: Use Cloud Endpoints Frameworks v2.0 Maven and Gradle discovery and
50+
client library generation plugins with Cloud Endpoints Frameworks v1.0.
51+
52+
- Uncomment `Endpoints Frameworks v1.0` sections and comment
53+
`Endpoints Frameworks v2.0` sections in the following files.
54+
55+
```
56+
pom.xml
57+
build.gradle
58+
src/main/webapp/WEB-INF/web.xml
59+
```
60+
61+
## Build and Deployment
62+
63+
### Maven
64+
65+
1. Build a fresh binary with
66+
67+
`mvn clean compile`
68+
69+
1. Run the application locally at [localhost:8080][5] with
70+
71+
`mvn appengine:run`
72+
73+
1. Generate the client library in a zip file named `helloworld-v1-java.zip` with
74+
75+
`mvn endpoints-framework:clientLibs`
76+
77+
1. Deploy your application to Google App Engine with
78+
79+
`mvn appengine:deploy`
80+
81+
### Gradle
82+
83+
1. Build a fresh binary with
84+
85+
`gradle clean compileJava`
86+
87+
1. Run the application locally at [localhost:8080][5] with
88+
89+
`gradle appengineRun`
90+
91+
1. Generate the client library in a zip file named `helloworld-v1-java.zip` with
92+
93+
`gradle endpointsClientLibs`
94+
95+
1. Deploy your application to Google App Engine with
96+
97+
`gradle appengineDeploy`
98+
99+
[1]: https://cloud.google.com/appengine/docs/java/
100+
[2]: http://java.com/en/
101+
[3]: https://cloud.google.com/appengine/docs/java/endpoints/
102+
[4]: https://cloud.google.com/appengine/docs/java/tools/maven
103+
[5]: https://localhost:8080/
104+
[6]: https://console.developers.google.com/project/_/apiui/credential
105+
[7]: https://cloud.google.com/appengine/docs/java/endpoints/migrating
106+
[8]: https://cloud.google.com/endpoints/docs/frameworks/java/about-cloud-endpoints-frameworks
107+
[9]: https://cloud.google.com/endpoints/docs/frameworks/java/quickstart-frameworks-java
108+
[10]: https://github.com/GoogleCloudPlatform/endpoints-framework-maven-plugin
109+
[11]: https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin
110+
[12]: https://cloud.google.com/endpoints/docs/authenticating-users-frameworks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2017 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
buildscript { // Configuration for building
16+
repositories {
17+
mavenCentral()
18+
jcenter() // Bintray's repository - a fast Maven Central mirror & more
19+
}
20+
dependencies {
21+
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' // latest App Engine Gradle tasks
22+
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:+'
23+
}
24+
}
25+
26+
repositories { // repositories for Jar's you access in your code
27+
maven {
28+
url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT Repository (if needed)
29+
}
30+
mavenCentral()
31+
jcenter()
32+
}
33+
34+
apply plugin: 'java' // standard Java tasks
35+
apply plugin: 'war' // standard Web Archive plugin
36+
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
37+
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
38+
39+
dependencies {
40+
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
41+
compile 'jstl:jstl:1.2'
42+
compile group: 'javax.inject', name: 'javax.inject', version: '1'
43+
44+
// Uncomment to use Endpoints Frameworks v1.0
45+
// compile group: 'com.google.appengine', name: 'appengine-endpoints', version: '1.9.48'
46+
// End of Endpoints Frameworks v1.0
47+
48+
// Endpoints Frameworks v2.0
49+
compile "com.google.endpoints:endpoints-framework:+"
50+
// End of Endpoints Frameworks v2.0
51+
}
52+
53+
appengine { // App Engine tasks configuration
54+
run { // local (dev_appserver) configuration (standard environments only)
55+
56+
}
57+
58+
deploy { // deploy configuration
59+
60+
}
61+
}
62+
63+
group = "com.example.helloendpoints" // Generated output GroupId
64+
version = "1" // Version in generated output
65+
66+
sourceCompatibility = 1.7 // App Engine Standard uses Java 7
67+
targetCompatibility = 1.7 // App Engine Standard uses Java 7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Mon Jan 16 22:18:59 PST 2017
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip

0 commit comments

Comments
 (0)