Skip to content

Commit ca74223

Browse files
committed
added gradle build configuration to appengine endpoints-frameworks-v2 backend
1 parent c90a83d commit ca74223

5 files changed

Lines changed: 397 additions & 5 deletions

File tree

appengine/endpoints-frameworks-v2/backend/README.md

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
This sample demonstrates how to use Google Cloud Endpoints Frameworks using
44
Java on App Engine Standard.
55

6-
## Adding the project ID to the sample API code
6+
## Build with Maven
7+
8+
### Adding the project ID to the sample API code
79

810
You must add the project ID obtained when you created your project to the
911
sample's `pom.xml` before you can deploy the code.
@@ -21,19 +23,19 @@ your project ID.
2123

2224
0. Save your changes.
2325

24-
## Building the sample project
26+
### Building the sample project
2527

2628
To build the project:
2729

2830
mvn clean package
2931

30-
## Generating the openapi.json file
32+
### Generating the openapi.json file
3133

3234
To generate the required configuration file `openapi.json`:
3335

3436
mvn exec:java -DGetSwaggerDoc
3537

36-
## Deploying the sample API to App Engine
38+
### Deploying the sample API to App Engine
3739

3840
To deploy the sample API:
3941

@@ -51,7 +53,92 @@ To deploy the sample API:
5153

5254
0. Wait for the upload to finish.
5355

54-
## Sending a request to the sample API
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` with
83+
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+
Note for windows user: 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+
[endpoints-framework-gradle-plugin](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin "endpoints-framework-gradle-plugin") for the endpoint related tasks and
103+
[appengine-gradle-plugin](https://github.com/GoogleCloudPlatform/app-gradle-plugin "appengine-gradle-plugin") for the appengine standard related tasks.
104+
</details>
105+
106+
### Generating the openapi.json file
107+
108+
To generate the required configuration file `openapi.json`:
109+
110+
./gradlew endpointsOpenApiDocs
111+
112+
This results in a file in build/endpointsOpenApiDocs/openapi.json
113+
114+
### Deploying the sample API to App Engine
115+
116+
To deploy the sample API:
117+
118+
0. Invoke the `gcloud` command to deploy the API configuration file:
119+
120+
gcloud service-management deploy build/endpointsOpenApiDocs/openapi.json
121+
122+
0. Deploy the API implementation code by invoking:
123+
124+
./gradlew appengineDeploy
125+
126+
The first time you upload a sample app, you may be prompted to authorize the
127+
deployment. Follow the prompts: when you are presented with a browser window
128+
containing a code, copy it to the terminal window.
129+
130+
<details>
131+
<summary>ERROR: (gcloud.app.deploy) The current Google Cloud project [...] does not contain an App Engine application.</summary>
132+
If you create a fresh cloud project that doesn't contain a appengine application you may receive this Error:
133+
134+
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.
135+
136+
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.
137+
</details>
138+
139+
0. Wait for the upload to finish.
140+
141+
### Sending a request to the sample API
55142

56143
After you deploy the API and its configuration file, you can send requests
57144
to the API.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import org.apache.tools.ant.filters.ReplaceTokens
2+
3+
buildscript {
4+
repositories {
5+
mavenCentral()
6+
}
7+
8+
dependencies {
9+
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.0'
10+
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.2'
11+
}
12+
}
13+
14+
repositories {
15+
maven {
16+
url 'https://maven-central.storage.googleapis.com'
17+
}
18+
jcenter()
19+
mavenCentral()
20+
}
21+
22+
task wrapper(type: Wrapper) {
23+
gradleVersion = '3.5'
24+
}
25+
26+
def projectId = 'endpointstest2'
27+
28+
apply plugin: 'java'
29+
apply plugin: 'war'
30+
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
31+
apply plugin: 'com.google.cloud.tools.appengine'
32+
33+
dependencies {
34+
compile 'com.google.endpoints:endpoints-framework:2.0.7'
35+
compile 'com.google.endpoints:endpoints-management-control-appengine:1.0.3'
36+
compile 'com.google.endpoints:endpoints-framework-auth:1.0.3'
37+
}
38+
39+
endpointsServer {
40+
// Endpoints Framework Plugin server-side configuration
41+
hostname = "echo-api.endpoints.${projectId}.cloud.goog"
42+
}
43+
44+
sourceCompatibility = 1.7 // App Engine Standard uses Java 7
45+
targetCompatibility = 1.7 // App Engine Standard uses Java 7
46+
47+
// this replaces the ${endpoints.project.id} in appengine-web.xml and web.xml
48+
task replaceProjectId(type: Copy) {
49+
from 'src/main/webapp/WEB-INF/'
50+
include '*.xml'
51+
into 'build/exploded-backend/WEB-INF'
52+
expand(endpoints:[project:[id:projectId]])
53+
filteringCharset = 'UTF-8'
54+
}
55+
assemble.dependsOn replaceProjectId
Binary file not shown.

appengine/endpoints-frameworks-v2/backend/gradlew

Lines changed: 160 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)