Skip to content

Commit 60f17a2

Browse files
Annie29lesv
authored andcommitted
Move Push Taskqueue sample program to Github (GoogleCloudPlatform#209)
* Move Push Taskqueue sample program to Github Some minor corrections to Requests testing and configuration. * Added licenses
1 parent f2212b5 commit 60f17a2

File tree

11 files changed

+387
-9
lines changed

11 files changed

+387
-9
lines changed

appengine/requests/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ Copyright 2016 Google Inc. All Rights Reserved.
9393
<!-- for hot reload of the web application -->
9494
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
9595
<plugins>
96-
9796
<plugin>
9897
<groupId>com.google.appengine</groupId>
9998
<artifactId>appengine-maven-plugin</artifactId>

appengine/requests/src/test/java/com/example/appengine/requests/LoggingServletTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ public void testListLogs() throws Exception {
8080
assertThat(out).contains("An informational message.");
8181
assertThat(out).contains("A warning message.");
8282
assertThat(out).contains("An error message.");
83-
84-
// We expect three log messages to be created
85-
// with the following severities.
86-
// Since there's no guarantee of case, use lowercase
87-
String lcOut = out.toLowerCase();
88-
assertThat(lcOut).contains("info");
89-
assertThat(lcOut).contains("warning");
90-
assertThat(lcOut).contains("severe");
9183
}
9284

9385
}

appengine/taskqueue-push/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# A Java Task Queue example for Google App Engine
2+
3+
This sample demonstrates how to use the [TaskQueue API][taskqueue-api] on [Google App
4+
Engine][ae-docs].
5+
6+
[taskqueue-api]: https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/taskqueue/package-summary
7+
[ae-docs]: https://cloud.google.com/appengine/docs/java/
8+
9+
## Running locally
10+
This example uses the
11+
[Maven gcloud plugin](https://cloud.google.com/appengine/docs/java/managed-vms/maven).
12+
To run this sample locally:
13+
14+
$ mvn appengine:devserver
15+
16+
Go to the site `localhost:8080` to add elements to the queue. They will appear in the log as the result of the Enqueue servlet transmitting the data to the Worker servlet.
17+
18+
## Deploying
19+
In the following command, replace YOUR-PROJECT-ID with your
20+
[Google Cloud Project ID](https://support.google.com/cloud/answer/6158840).
21+
22+
$ mvn appengine:update -Dappengine.appId=YOUR-PROJECT-ID -Dappengine.version=SOME-VERSION
23+
24+
## Setup
25+
To save your project settings so that you don't need to enter the
26+
parameters, you can:
27+
28+
1. Update the `<application>` tag in src/main/webapp/WEB-INF/appengine-web.xml
29+
with your project name.
30+
31+
2. Update the `<version>` tag in src/main/webapp/WEB-INF/appengine-web.xml
32+
with a valid version number.
33+
34+
35+
You will now be able to run
36+
37+
$ mvn appengine:update
38+
39+
without the need for any additional parameters.

appengine/taskqueue-push/pom.xml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2016 Google Inc. All Rights Reserved.
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+
<project>
18+
<modelVersion>4.0.0</modelVersion>
19+
<packaging>war</packaging>
20+
<version>1.0-SNAPSHOT</version>
21+
<groupId>com.example.appengine</groupId>
22+
<artifactId>taskqueue-push</artifactId>
23+
<!-- Parent POM defines ${appengine.sdk.version} (updates frequently). -->
24+
<parent>
25+
<groupId>com.google.cloud</groupId>
26+
<artifactId>doc-samples</artifactId>
27+
<version>1.0.0</version>
28+
<relativePath>../..</relativePath>
29+
</parent>
30+
<dependencies>
31+
<dependency>
32+
<groupId>com.google.appengine</groupId>
33+
<artifactId>appengine-maven-plugin</artifactId>
34+
<version>${appengine.sdk.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>javax.servlet</groupId>
38+
<artifactId>servlet-api</artifactId>
39+
<version>2.5</version>
40+
<type>jar</type>
41+
<scope>provided</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.json</groupId>
45+
<artifactId>json</artifactId>
46+
<version>20151123</version>
47+
</dependency>
48+
<!-- Test Dependencies -->
49+
<dependency>
50+
<groupId>junit</groupId>
51+
<artifactId>junit</artifactId>
52+
<version>4.10</version>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.mockito</groupId>
57+
<artifactId>mockito-all</artifactId>
58+
<version>1.10.19</version>
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>com.google.appengine</groupId>
63+
<artifactId>appengine-testing</artifactId>
64+
<version>${appengine.sdk.version}</version>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>com.google.appengine</groupId>
69+
<artifactId>appengine-api-stubs</artifactId>
70+
<version>${appengine.sdk.version}</version>
71+
<scope>test</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>com.google.appengine</groupId>
75+
<artifactId>appengine-tools-sdk</artifactId>
76+
<version>${appengine.sdk.version}</version>
77+
<scope>test</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>com.google.truth</groupId>
81+
<artifactId>truth</artifactId>
82+
<version>0.28</version>
83+
<scope>test</scope>
84+
</dependency>
85+
86+
</dependencies>
87+
<build>
88+
<!-- for hot reload of the web application -->
89+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
90+
<plugins>
91+
<plugin>
92+
<groupId>com.google.appengine</groupId>
93+
<artifactId>appengine-maven-plugin</artifactId>
94+
<version>${appengine.sdk.version}</version>
95+
</plugin>
96+
</plugins>
97+
</build>
98+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright 2016 Google Inc. All Rights Reserved.
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+
package com.example.appengine.taskqueue.push;
16+
17+
import com.google.appengine.api.taskqueue.Queue;
18+
import com.google.appengine.api.taskqueue.QueueFactory;
19+
import com.google.appengine.api.taskqueue.TaskOptions;
20+
21+
import java.io.IOException;
22+
23+
import javax.servlet.ServletException;
24+
import javax.servlet.http.HttpServlet;
25+
import javax.servlet.http.HttpServletRequest;
26+
import javax.servlet.http.HttpServletResponse;
27+
28+
// [START enqueue]
29+
// The Enqueue servlet should be mapped to the "/enqueue" URL.
30+
public class Enqueue extends HttpServlet {
31+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
32+
throws ServletException, IOException {
33+
String key = request.getParameter("key");
34+
35+
// Add the task to the default queue.
36+
Queue queue = QueueFactory.getDefaultQueue();
37+
queue.add(TaskOptions.Builder.withUrl("/worker").param("key", key));
38+
39+
response.sendRedirect("/");
40+
}
41+
}
42+
// [END enqueue]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Copyright 2016 Google Inc. All Rights Reserved.
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+
package com.example.appengine.taskqueue.push;
16+
17+
import java.io.IOException;
18+
import java.util.logging.Logger;
19+
20+
import javax.servlet.ServletException;
21+
import javax.servlet.http.HttpServlet;
22+
import javax.servlet.http.HttpServletRequest;
23+
import javax.servlet.http.HttpServletResponse;
24+
25+
// [START worker]
26+
// The Worker servlet should be mapped to the "/worker" URL.
27+
public class Worker extends HttpServlet {
28+
private static final Logger log = Logger.getLogger(Worker.class.getName());
29+
30+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
31+
throws ServletException, IOException {
32+
String key = request.getParameter("key");
33+
34+
// Do something with key.
35+
// [START_EXCLUDE]
36+
log.info("Worker is processing " + key);
37+
// [END_EXCLUDE]
38+
}
39+
}
40+
// [END worker]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2016 Google Inc. All Rights Reserved.
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+
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
18+
<application>YOUR-PROJECT-ID</application>
19+
<version>YOUR-VERSION-ID</version>
20+
<threadsafe>true</threadsafe>
21+
</appengine-web-app>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2016 Google Inc. All Rights Reserved.
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+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
18+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
19+
version="2.5">
20+
<welcome-file-list>
21+
<welcome-file>index.html</welcome-file>
22+
</welcome-file-list>
23+
<servlet>
24+
<servlet-name>enqueue</servlet-name>
25+
<servlet-class>com.example.appengine.taskqueue.push.Enqueue</servlet-class>
26+
</servlet>
27+
<servlet>
28+
<servlet-name>worker</servlet-name>
29+
<servlet-class>com.example.appengine.taskqueue.push.Worker</servlet-class>
30+
</servlet>
31+
<servlet-mapping>
32+
<servlet-name>enqueue</servlet-name>
33+
<url-pattern>/enqueue</url-pattern>
34+
</servlet-mapping>
35+
<servlet-mapping>
36+
<servlet-name>worker</servlet-name>
37+
<url-pattern>/worker</url-pattern>
38+
</servlet-mapping>
39+
</web-app>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright 2016 Google Inc. All Rights Reserved.
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+
<!--[START index_file] -->
18+
<!-- A basic index.html file served from the "/" URL. -->
19+
<html>
20+
<body>
21+
<p>Enqueue a value, to be processed by a worker.</p>
22+
<form action="/enqueue" method="post">
23+
<input type="text" name="key">
24+
<input type="submit">
25+
</form>
26+
</body>
27+
</html>
28+
<!--[END index_file] -->

0 commit comments

Comments
 (0)