Skip to content

Commit

Permalink
Initial Java8-master
Browse files Browse the repository at this point in the history
  • Loading branch information
Les Vogel committed Jan 26, 2017
1 parent 34a1592 commit 120d40c
Show file tree
Hide file tree
Showing 318 changed files with 20,937 additions and 0 deletions.
44 changes: 44 additions & 0 deletions java8-appengine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2015 Google Inc. All Rights Reserved.
# 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.

# Google App Engine generated folder
appengine-generated/

# Java
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties

service-account.json

#eclipse
.classpath
.settings
.project
101 changes: 101 additions & 0 deletions java8-appengine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Google App Engine Standard Environment Java Samples

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).

66 changes: 66 additions & 0 deletions java8-appengine/analytics/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!--
Copyright 2015 Google Inc. All Rights Reserved.
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</artifactId>

<parent>
<artifactId>doc-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.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
</properties>

<dependencies>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<!-- for hot reload of the web application -->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<!-- Parent POM defines ${appengine.sdk.version} (updates frequently). -->
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.sdk.version}</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* 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,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- [START_EXCLUDE] -->
<!--
Copyright 2015 Google Inc. All Rights Reserved.
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">
<application>YOUR-PROJECT-ID</application>
<version>YOUR-VERSION-ID</version>
<threadsafe>true</threadsafe>
<env-variables>
<env-var name="GA_TRACKING_ID" value="YOUR-GA-TRACKING-ID" />
</env-variables>
</appengine-web-app>

29 changes: 29 additions & 0 deletions java8-appengine/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. All Rights Reserved.
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>

7 changes: 7 additions & 0 deletions java8-appengine/appidentity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Eclipse files
.project
.classpath
.settings

# Target folders
target/
33 changes: 33 additions & 0 deletions java8-appengine/appidentity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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 gcloud plugin](https://cloud.google.com/appengine/docs/java/managed-vms/maven).
To run this sample locally:

$ mvn gcloud:run

## Deploying
In the following command, replace YOUR-PROJECT-ID with your
[Google Cloud Project ID](https://developers.google.com/console/help/new/#projectnumber).

$ mvn gcloud:deploy -Dgcloud.gcloud_project=YOUR-PROJECT-ID

## Setup
To save your project settings so that you don't need to enter the
`-Dgcloud.gcloud_project=YOUR-CLOUD-PROJECT-ID` parameters, you can:

1. Update the <application> tag in src/main/webapp/WEB-INF/appengine-web.xml
with your project name.

You will now be able to run

$ mvn gcloud:deploy

without the need for any additional parameters.
Loading

0 comments on commit 120d40c

Please sign in to comment.