Skip to content

Commit f3bfff5

Browse files
authored
J8 samples (#665)
* j8-samples Some bugs * minor tweaks... 1. Fix guestbook-datastore to release API’s 2. Fix the rest to have 1.3.1 & runtime: java8 * add j8 suffix to artifactId * Fix import order * CheckStyle magic.
1 parent 783a454 commit f3bfff5

File tree

346 files changed

+29175
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

346 files changed

+29175
-68
lines changed

.mvn/wrapper/maven-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
1+
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip

appengine-java8/README.md

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Google App Engine Standard Environment Samples for Java 8
2+
3+
This is a repository that contains Java code samples for [Google App Engine
4+
standard environment][ae-docs].
5+
6+
[ae-docs]: https://cloud.google.com/appengine/docs/java/
7+
8+
## Prerequisites
9+
10+
### Download Maven
11+
12+
These samples use the [Apache Maven][maven] build system. Before getting
13+
started, be sure to [download][maven-download] and [install][maven-install] it.
14+
When you use Maven as described here, it will automatically download the needed
15+
client libraries.
16+
17+
[maven]: https://maven.apache.org
18+
[maven-download]: https://maven.apache.org/download.cgi
19+
[maven-install]: https://maven.apache.org/install.html
20+
21+
### Create a Project in the Google Cloud Platform Console
22+
23+
If you haven't already created a project, create one now. Projects enable you to
24+
manage all Google Cloud Platform resources for your app, including deployment,
25+
access control, billing, and services.
26+
27+
1. Open the [Cloud Platform Console][cloud-console].
28+
1. In the drop-down menu at the top, select **Create a project**.
29+
1. Give your project a name.
30+
1. Make a note of the project ID, which might be different from the project
31+
name. The project ID is used in commands and in configurations.
32+
33+
[cloud-console]: https://console.cloud.google.com/
34+
35+
36+
## Samples
37+
38+
### Hello World
39+
40+
This sample demonstrates how to deploy an application on Google App Engine.
41+
42+
- [Documentation][ae-docs]
43+
- [Code](helloworld)
44+
45+
### Sending Email
46+
47+
#### Sending Email with Mailgun
48+
49+
This sample demonstrates how to send email using the [Mailgun API][mailgun-api].
50+
51+
- [Documentation][mailgun-sample-docs]
52+
- [Code](mailgun)
53+
54+
[mailgun-api]: https://documentation.mailgun.com/
55+
[mailgun-sample-docs]: https://cloud.google.com/appengine/docs/java/mail/mailgun
56+
57+
#### Sending Email with SendGrid
58+
59+
This sample demonstrates how to send email using the [SendGrid][sendgrid].
60+
61+
- [Documentation][sendgrid-sample-docs]
62+
- [Code](sendgrid)
63+
64+
[sendgrid]: https://sendgrid.com/docs/User_Guide/index.html
65+
[sendgrid-sample-docs]: https://cloud.google.com/appengine/docs/java/mail/sendgrid
66+
67+
### Sending SMS with Twilio
68+
69+
This sample demonstrates how to use [Twilio](https://www.twilio.com) on [Google
70+
App Engine standard environment][ae-docs].
71+
72+
- [Documentation][twilio-sample-docs]
73+
- [Code](twilio)
74+
75+
[twilio-sample-docs]: https://cloud.google.com/appengine/docs/java/sms/twilio
76+
77+
### App Identity
78+
79+
This sample demonstrates how to use the [App Identity API][appid] to discover
80+
the application's ID and assert identity to Google and third-party APIs.
81+
82+
- [Documentation][appid]
83+
- [Code](appidentity)
84+
85+
[appid]: https://cloud.google.com/appengine/docs/java/appidentity/
86+
87+
### Other Samples
88+
89+
- [Sample Applications][sample-apps]
90+
91+
[sample-apps]: https://cloud.google.com/appengine/docs/java/samples
92+
93+
94+
## Contributing changes
95+
96+
See [CONTRIBUTING.md](../CONTRIBUTING.md).
97+
98+
## Licensing
99+
100+
See [LICENSE](../LICENSE).
101+

appengine-java8/analytics/pom.xml

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<!--
2+
Copyright 2017 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<project>
17+
<modelVersion>4.0.0</modelVersion>
18+
<packaging>war</packaging>
19+
<version>1.0-SNAPSHOT</version>
20+
<groupId>com.example.appengine</groupId>
21+
<artifactId>appengine-analytics-j8</artifactId>
22+
23+
<parent>
24+
<artifactId>appengine-java8-samples</artifactId>
25+
<groupId>com.google.cloud</groupId>
26+
<version>1.0.0</version>
27+
<relativePath>..</relativePath>
28+
</parent>
29+
<!-- Parent POM defines ${appengine.sdk.version} (updates frequently). -->
30+
31+
<properties>
32+
<maven.compiler.target>1.8</maven.compiler.target>
33+
<maven.compiler.source>1.8</maven.compiler.source>
34+
<appengine.sdk.version>1.9.52</appengine.sdk.version>
35+
</properties>
36+
37+
<dependencies>
38+
<!-- Compile/runtime dependencies -->
39+
<dependency>
40+
<groupId>com.google.appengine</groupId>
41+
<artifactId>appengine-api-1.0-sdk</artifactId>
42+
<version>${appengine.sdk.version}</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>jstl</groupId>
47+
<artifactId>jstl</artifactId>
48+
<version>1.2</version>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.apache.httpcomponents</groupId>
53+
<artifactId>httpclient</artifactId>
54+
<version>4.5.3</version>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>javax.servlet</groupId>
59+
<artifactId>javax.servlet-api</artifactId>
60+
<version>3.1.0</version>
61+
<type>jar</type>
62+
<scope>provided</scope>
63+
</dependency>
64+
65+
<!-- Test Dependencies -->
66+
<dependency>
67+
<groupId>com.google.appengine</groupId>
68+
<artifactId>appengine-testing</artifactId>
69+
<version>${appengine.sdk.version}</version>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>com.google.appengine</groupId>
74+
<artifactId>appengine-api-stubs</artifactId>
75+
<version>${appengine.sdk.version}</version>
76+
<scope>test</scope>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>junit</groupId>
81+
<artifactId>junit</artifactId>
82+
<version>4.12</version>
83+
<scope>test</scope>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.mockito</groupId>
87+
<artifactId>mockito-core</artifactId>
88+
<version>2.7.22</version>
89+
<scope>test</scope>
90+
</dependency>
91+
<dependency>
92+
<groupId>com.jcabi</groupId>
93+
<artifactId>jcabi-matchers</artifactId>
94+
<version>1.4</version>
95+
</dependency>
96+
<dependency>
97+
<groupId>com.google.truth</groupId>
98+
<artifactId>truth</artifactId>
99+
<version>0.32</version>
100+
<scope>test</scope>
101+
</dependency>
102+
</dependencies>
103+
104+
<build>
105+
<!-- for hot reload of the web application -->
106+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
107+
<plugins>
108+
<plugin>
109+
<groupId>com.google.cloud.tools</groupId>
110+
<artifactId>appengine-maven-plugin</artifactId>
111+
<version>1.3.1</version>
112+
<configuration>
113+
<deploy.promote>true</deploy.promote>
114+
<deploy.stopPreviousVersion>true</deploy.stopPreviousVersion>
115+
</configuration>
116+
</plugin>
117+
</plugins>
118+
</build>
119+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright 2015 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.appengine.analytics;
18+
19+
import com.google.appengine.api.urlfetch.URLFetchService;
20+
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
21+
22+
import org.apache.http.client.utils.URIBuilder;
23+
24+
import java.io.IOException;
25+
import java.net.URI;
26+
import java.net.URISyntaxException;
27+
import java.net.URL;
28+
29+
import javax.servlet.ServletException;
30+
import javax.servlet.http.HttpServlet;
31+
import javax.servlet.http.HttpServletRequest;
32+
import javax.servlet.http.HttpServletResponse;
33+
34+
// [START example]
35+
@SuppressWarnings("serial")
36+
public class AnalyticsServlet extends HttpServlet {
37+
38+
@Override
39+
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
40+
ServletException {
41+
String trackingId = System.getenv("GA_TRACKING_ID");
42+
URIBuilder builder = new URIBuilder();
43+
builder.setScheme("http").setHost("www.google-analytics.com").setPath("/collect")
44+
.addParameter("v", "1") // API Version.
45+
.addParameter("tid", trackingId) // Tracking ID / Property ID.
46+
// Anonymous Client Identifier. Ideally, this should be a UUID that
47+
// is associated with particular user, device, or browser instance.
48+
.addParameter("cid", "555")
49+
.addParameter("t", "event") // Event hit type.
50+
.addParameter("ec", "example") // Event category.
51+
.addParameter("ea", "test action"); // Event action.
52+
URI uri = null;
53+
try {
54+
uri = builder.build();
55+
} catch (URISyntaxException e) {
56+
throw new ServletException("Problem building URI", e);
57+
}
58+
URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
59+
URL url = uri.toURL();
60+
fetcher.fetch(url);
61+
resp.getWriter().println("Event tracked.");
62+
}
63+
}
64+
// [END example]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- [START_EXCLUDE] -->
3+
<!--
4+
Copyright 2015 Google Inc.
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+
http://www.apache.org/licenses/LICENSE-2.0
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+
<!-- [END_EXCLUDE] -->
16+
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
17+
<threadsafe>true</threadsafe>
18+
<runtime>java8</runtime>
19+
<env-variables>
20+
<env-var name="GA_TRACKING_ID" value="YOUR-GA-TRACKING-ID" />
21+
</env-variables>
22+
</appengine-web-app>
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- [START_EXCLUDE] -->
3+
<!--
4+
Copyright 2015 Google Inc.
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+
http://www.apache.org/licenses/LICENSE-2.0
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+
<!-- [END_EXCLUDE] -->
16+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
17+
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
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+
<servlet>
21+
<servlet-name>analytics</servlet-name>
22+
<servlet-class>com.example.appengine.analytics.AnalyticsServlet</servlet-class>
23+
</servlet>
24+
<servlet-mapping>
25+
<servlet-name>analytics</servlet-name>
26+
<url-pattern>/</url-pattern>
27+
</servlet-mapping>
28+
</web-app>
29+

appengine-java8/appidentity/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# App Identity sample for Google App Engine
2+
3+
This sample demonstrates how to use the [App Identity API][appid] on [Google App
4+
Engine][ae-docs].
5+
6+
[appid]: https://cloud.google.com/appengine/docs/java/appidentity/
7+
[ae-docs]: https://cloud.google.com/appengine/docs/java/
8+
9+
## Running locally
10+
This example uses the
11+
[Maven Cloud SDK based plugin](https://cloud.google.com/appengine/docs/java/tools/using-maven).
12+
To run this sample locally:
13+
14+
$ mvn appengine:run
15+
16+
## Deploying
17+
18+
$ mvn appengine:deploy

0 commit comments

Comments
 (0)