Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

J8 samples #665

Merged
merged 6 commits into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
101 changes: 101 additions & 0 deletions appengine-java8/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Google App Engine Standard Environment Samples for Java 8

This is a repository that contains Java code samples for [Google App Engine
standard environment][ae-docs].

[ae-docs]: https://cloud.google.com/appengine/docs/java/

## Prerequisites

### Download Maven

These samples use the [Apache Maven][maven] build system. Before getting
started, be sure to [download][maven-download] and [install][maven-install] it.
When you use Maven as described here, it will automatically download the needed
client libraries.

[maven]: https://maven.apache.org
[maven-download]: https://maven.apache.org/download.cgi
[maven-install]: https://maven.apache.org/install.html

### Create a Project in the Google Cloud Platform Console

If you haven't already created a project, create one now. Projects enable you to
manage all Google Cloud Platform resources for your app, including deployment,
access control, billing, and services.

1. Open the [Cloud Platform Console][cloud-console].
1. In the drop-down menu at the top, select **Create a project**.
1. Give your project a name.
1. Make a note of the project ID, which might be different from the project
name. The project ID is used in commands and in configurations.

[cloud-console]: https://console.cloud.google.com/


## Samples

### Hello World

This sample demonstrates how to deploy an application on Google App Engine.

- [Documentation][ae-docs]
- [Code](helloworld)

### Sending Email

#### Sending Email with Mailgun

This sample demonstrates how to send email using the [Mailgun API][mailgun-api].

- [Documentation][mailgun-sample-docs]
- [Code](mailgun)

[mailgun-api]: https://documentation.mailgun.com/
[mailgun-sample-docs]: https://cloud.google.com/appengine/docs/java/mail/mailgun

#### Sending Email with SendGrid

This sample demonstrates how to send email using the [SendGrid][sendgrid].

- [Documentation][sendgrid-sample-docs]
- [Code](sendgrid)

[sendgrid]: https://sendgrid.com/docs/User_Guide/index.html
[sendgrid-sample-docs]: https://cloud.google.com/appengine/docs/java/mail/sendgrid

### Sending SMS with Twilio

This sample demonstrates how to use [Twilio](https://www.twilio.com) on [Google
App Engine standard environment][ae-docs].

- [Documentation][twilio-sample-docs]
- [Code](twilio)

[twilio-sample-docs]: https://cloud.google.com/appengine/docs/java/sms/twilio

### App Identity

This sample demonstrates how to use the [App Identity API][appid] to discover
the application's ID and assert identity to Google and third-party APIs.

- [Documentation][appid]
- [Code](appidentity)

[appid]: https://cloud.google.com/appengine/docs/java/appidentity/

### Other Samples

- [Sample Applications][sample-apps]

[sample-apps]: https://cloud.google.com/appengine/docs/java/samples


## Contributing changes

See [CONTRIBUTING.md](../CONTRIBUTING.md).

## Licensing

See [LICENSE](../LICENSE).

119 changes: 119 additions & 0 deletions appengine-java8/analytics/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<!--
Copyright 2017 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<groupId>com.example.appengine</groupId>
<artifactId>appengine-analytics-j8</artifactId>

<parent>
<artifactId>appengine-java8-samples</artifactId>
<groupId>com.google.cloud</groupId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<!-- Parent POM defines ${appengine.sdk.version} (updates frequently). -->

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<appengine.sdk.version>1.9.52</appengine.sdk.version>
</properties>

<dependencies>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>${appengine.sdk.version}</version>
</dependency>

<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${appengine.sdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${appengine.sdk.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.7.22</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-matchers</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>0.32</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<!-- for hot reload of the web application -->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<deploy.promote>true</deploy.promote>
<deploy.stopPreviousVersion>true</deploy.stopPreviousVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.appengine.analytics;

import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;

import org.apache.http.client.utils.URIBuilder;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// [START example]
@SuppressWarnings("serial")
public class AnalyticsServlet extends HttpServlet {

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
String trackingId = System.getenv("GA_TRACKING_ID");
URIBuilder builder = new URIBuilder();
builder.setScheme("http").setHost("www.google-analytics.com").setPath("/collect")
.addParameter("v", "1") // API Version.
.addParameter("tid", trackingId) // Tracking ID / Property ID.
// Anonymous Client Identifier. Ideally, this should be a UUID that
// is associated with particular user, device, or browser instance.
.addParameter("cid", "555")
.addParameter("t", "event") // Event hit type.
.addParameter("ec", "example") // Event category.
.addParameter("ea", "test action"); // Event action.
URI uri = null;
try {
uri = builder.build();
} catch (URISyntaxException e) {
throw new ServletException("Problem building URI", e);
}
URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
URL url = uri.toURL();
fetcher.fetch(url);
resp.getWriter().println("Event tracked.");
}
}
// [END example]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- [START_EXCLUDE] -->
<!--
Copyright 2015 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- [END_EXCLUDE] -->
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
<env-variables>
<env-var name="GA_TRACKING_ID" value="YOUR-GA-TRACKING-ID" />
</env-variables>
</appengine-web-app>

29 changes: 29 additions & 0 deletions appengine-java8/analytics/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- [START_EXCLUDE] -->
<!--
Copyright 2015 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- [END_EXCLUDE] -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>analytics</servlet-name>
<servlet-class>com.example.appengine.analytics.AnalyticsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>analytics</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

18 changes: 18 additions & 0 deletions appengine-java8/appidentity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# App Identity sample for Google App Engine

This sample demonstrates how to use the [App Identity API][appid] on [Google App
Engine][ae-docs].

[appid]: https://cloud.google.com/appengine/docs/java/appidentity/
[ae-docs]: https://cloud.google.com/appengine/docs/java/

## Running locally
This example uses the
[Maven Cloud SDK based plugin](https://cloud.google.com/appengine/docs/java/tools/using-maven).
To run this sample locally:

$ mvn appengine:run

## Deploying

$ mvn appengine:deploy
Loading