Skip to content

Commit ce0f1e7

Browse files
authored
Merge branch 'master' into update-migration-sample
2 parents ef80c83 + 377462f commit ce0f1e7

File tree

35 files changed

+465
-91
lines changed

35 files changed

+465
-91
lines changed

appengine-java8/analytics/src/main/java/com/example/appengine/analytics/AnalyticsServlet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
// [START example]
3636
@SuppressWarnings("serial")
37+
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
3738
@WebServlet(name = "analytics", description = "Analytics: Send Analytics Event to Google Analytics",
3839
urlPatterns = "/analytics")
3940
public class AnalyticsServlet extends HttpServlet {

appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/IdentityServlet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javax.servlet.http.HttpServletResponse;
2727

2828
@SuppressWarnings("serial")
29+
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
2930
@WebServlet(name = "appidentity", description = "AppIdentity: Get the Host Name",
3031
urlPatterns = "/appidentity/identity")
3132
public class IdentityServlet extends HttpServlet {

appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/SignForAppServlet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import javax.servlet.http.HttpServletResponse;
4343

4444
@SuppressWarnings("serial")
45+
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
4546
@WebServlet(name = "signforapp", description = "AppIdentity: Sign 'abcdefg'",
4647
urlPatterns = "/appidentity/sign")
4748
public class SignForAppServlet extends HttpServlet {

appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortenerServlet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.servlet.http.HttpServletResponse;
2626

2727
@SuppressWarnings("serial")
28+
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
2829
@WebServlet(name = "UrlShortener", description = "AppIdentity: Url Shortener",
2930
urlPatterns = "/appidentity/shorten")
3031
public class UrlShortenerServlet extends HttpServlet {

appengine-java8/cloudsql/pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
<database>sqldemo</database>
4141

4242
<!-- [START_EXCLUDE] -->
43-
<appengine.maven.plugin>1.3.1</appengine.maven.plugin>
4443
<maven.compiler.target>1.8</maven.compiler.target>
4544
<maven.compiler.source>1.8</maven.compiler.source>
4645
<!-- [END_EXCLUDE] -->
@@ -51,7 +50,7 @@
5150
<dependency>
5251
<groupId>com.google.appengine</groupId>
5352
<artifactId>appengine-api-1.0-sdk</artifactId>
54-
<version>${appengine.sdk.version}</version>
53+
<version>1.9.53</version>
5554
</dependency>
5655

5756
<dependency>
@@ -72,7 +71,7 @@
7271
<dependency>
7372
<groupId>mysql</groupId>
7473
<artifactId>mysql-connector-java</artifactId>
75-
<version>5.1.40</version> <!-- v5.x.x is for production, v6.x.x EAP X DevAPI and Java 8 -->
74+
<version>5.1.40</version> <!-- v5.x.x is for production, v6.x.x EAP X DevAPI -->
7675
<!--<version>6.0.6</version>-->
7776
</dependency>
7877
<dependency>
@@ -105,7 +104,7 @@
105104
<plugin>
106105
<groupId>com.google.cloud.tools</groupId>
107106
<artifactId>appengine-maven-plugin</artifactId>
108-
<version>${appengine.maven.plugin}</version>
107+
<version>1.3.1</version>
109108
<configuration>
110109
<deploy.promote>true</deploy.promote>
111110
<deploy.stopPreviousVersion>true</deploy.stopPreviousVersion>

appengine-java8/cloudsql/src/main/java/com/example/appengine/cloudsql/CloudSqlServlet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
// [START example]
3939
@SuppressWarnings("serial")
40+
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
4041
@WebServlet(name = "CloudSQL", description = "CloudSQL: Write low order IP address to Cloud SQL",
4142
urlPatterns = "/cloudsql")
4243
public class CloudSqlServlet extends HttpServlet {

appengine-java8/gaeinfo/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Google App Engine Information
2+
3+
This sample displays what's going on in your app. It dumps the environment and lots more.
4+
5+
See the [Google App Engine standard environment documentation][ae-docs] for more
6+
detailed instructions.
7+
8+
[ae-docs]: https://cloud.google.com/appengine/docs/java/
9+
10+
## Setup
11+
12+
Use either:
13+
14+
* `gcloud init`
15+
* `gcloud auth application-default login`
16+
17+
## Maven
18+
### Running locally
19+
20+
$ mvn appengine:run
21+
22+
### Deploying
23+
24+
$ mvn appengine:deploy
25+
26+
## Gradle
27+
### Running locally
28+
29+
$ gradle appengineRun
30+
31+
If you do not have gradle installed, you can run using `./gradlew appengineRun`.
32+
33+
### Deploying
34+
35+
$ gradle appengineDeploy
36+
37+
If you do not have gradle installed, you can deploy using `./gradlew appengineDeploy`.
38+
39+
<!--
40+
## Intelij Idea
41+
Limitations - Appengine Standard support in the Intellij plugin is only available for the Ultimate Edition of Idea.
42+
43+
### Install and Set Up Cloud Tools for IntelliJ
44+
45+
To use Cloud Tools for IntelliJ, you must first install IntelliJ IDEA Ultimate edition.
46+
47+
Next, install the plugins from the IntelliJ IDEA Plugin Repository.
48+
49+
To install the plugins:
50+
51+
1. From inside IDEA, open File > Settings (on Mac OS X, open IntelliJ IDEA > Preferences).
52+
1. In the left-hand pane, select Plugins.
53+
1. Click Browse repositories.
54+
1. In the dialog that opens, select Google Cloud Tools.
55+
1. Click Install.
56+
1. Click Close.
57+
1. Click OK in the Settings dialog.
58+
1. Click Restart (or you can click Postpone, but the plugins will not be available until you do restart IDEA.)
59+
60+
### Running locally
61+
62+
### Deploying
63+
-->

appengine-java8/gaeinfo/pom.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
<!-- [START pom] -->
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>gaeinfo-j8</artifactId>
23+
24+
<parent>
25+
<artifactId>appengine-java8-samples</artifactId>
26+
<groupId>com.google.cloud</groupId>
27+
<version>1.0.0</version>
28+
<relativePath>..</relativePath>
29+
</parent>
30+
31+
<!-- [START compiler] -->
32+
<properties> <!-- App Engine Standard currently requires Java 7 -->
33+
<maven.compiler.target>1.8</maven.compiler.target>
34+
<maven.compiler.source>1.8</maven.compiler.source>
35+
</properties>
36+
<!-- [END compiler] -->
37+
38+
<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>javax.servlet</groupId>
47+
<artifactId>javax.servlet-api</artifactId>
48+
<version>3.1.0</version>
49+
<type>jar</type>
50+
<scope>provided</scope>
51+
</dependency>
52+
53+
</dependencies>
54+
55+
<build>
56+
<!-- for hot reload of the web application -->
57+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-war-plugin</artifactId>
62+
<version>3.0.0</version>
63+
<configuration>
64+
<webResources>
65+
<!-- in order to interpolate version from pom into appengine-web.xml -->
66+
<resource>
67+
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
68+
<filtering>true</filtering>
69+
<targetPath>WEB-INF</targetPath>
70+
</resource>
71+
</webResources>
72+
</configuration>
73+
</plugin>
74+
75+
<plugin>
76+
<groupId>com.google.cloud.tools</groupId>
77+
<artifactId>appengine-maven-plugin</artifactId>
78+
<version>1.3.1</version>
79+
<configuration>
80+
<deploy.promote>true</deploy.promote>
81+
<deploy.stopPreviousVersion>true</deploy.stopPreviousVersion>
82+
</configuration>
83+
</plugin>
84+
85+
</plugins>
86+
</build>
87+
</project>
88+
<!-- [END pom] -->
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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+
17+
package com.example.appengine.standard;
18+
19+
import com.google.appengine.api.appidentity.AppIdentityService;
20+
import com.google.appengine.api.appidentity.AppIdentityServiceFactory;
21+
import com.google.appengine.api.utils.SystemProperty;
22+
import com.google.apphosting.api.ApiProxy;
23+
24+
import java.io.IOException;
25+
import java.io.PrintWriter;
26+
import java.util.Enumeration;
27+
import java.util.Map;
28+
import java.util.Properties;
29+
30+
import javax.servlet.annotation.WebServlet;
31+
import javax.servlet.http.Cookie;
32+
import javax.servlet.http.HttpServlet;
33+
import javax.servlet.http.HttpServletRequest;
34+
import javax.servlet.http.HttpServletResponse;
35+
36+
// [START example]
37+
@SuppressWarnings({"serial"})
38+
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
39+
@WebServlet(name = "GAEInfo", description = "GAEInfo: Write info about GAE Standard",
40+
urlPatterns = "/gaeinfo")
41+
//CHECKSTYLE:OFF
42+
public class GAEInfoServlet extends HttpServlet {
43+
44+
public void table(PrintWriter p, String title, String c) {
45+
p.print("<h3>" + title + "</h3>");
46+
p.print("<table>");
47+
p.print(c);
48+
p.print("</table>");
49+
}
50+
51+
public String tr(String c) {
52+
return "<tr>" + c + "</tr>";
53+
}
54+
55+
public String td(String s) {
56+
return "<td>" + s + "</td>";
57+
}
58+
59+
60+
@Override
61+
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
62+
resp.setContentType("text/html");
63+
PrintWriter p = resp.getWriter();
64+
65+
66+
p.print("<html><body>");
67+
68+
final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
69+
table(p, "AppIdentity",
70+
tr(td("ServiceAccountName") + td(appIdentity.getServiceAccountName()) ) +
71+
tr(td("GCS Bucket") + td( appIdentity.getDefaultGcsBucketName()))
72+
);
73+
74+
table(p, "SystemProperties",
75+
tr( td( "appId") + td(SystemProperty.applicationId.get()) ) +
76+
tr(td("appVer") + td( SystemProperty.applicationVersion.get()) ) +
77+
tr(td("version") + td(SystemProperty.version.get()) ) +
78+
tr(td("environment") + td(SystemProperty.environment.get()) )
79+
);
80+
81+
82+
// Environment Atributes
83+
ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
84+
Map<String,Object> attr = env.getAttributes();
85+
86+
String c = "";
87+
for(String key : attr.keySet()) {
88+
Object o = attr.get(key);
89+
90+
if(o.getClass().getCanonicalName().equals("java.lang.String")) {
91+
c += tr(td(key) + td((String) o));
92+
} else
93+
c += tr(td(key) + td(o.getClass().getCanonicalName()));
94+
}
95+
table(p, "Environment Attributes", c);
96+
97+
c = "";
98+
for (Enumeration<String> e = req.getHeaderNames(); e.hasMoreElements();) {
99+
String key = e.nextElement();
100+
String val = req.getHeader(key);
101+
c += tr(td(key) + td(val) );;
102+
}
103+
table(p, "Headers", c);
104+
105+
106+
Cookie[] cookies = req.getCookies();
107+
if(cookies != null && cookies.length != 0) {
108+
c = "";
109+
for (Cookie co : cookies) {
110+
c += tr( td(co.getName()) + td(co.getValue()) + td(co.getComment()) +
111+
td(co.getPath()) + td(Integer.toString(co.getMaxAge())) );
112+
}
113+
table(p, "Cookies", c);
114+
}
115+
116+
Properties properties = System.getProperties();
117+
c = "";
118+
for(Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
119+
String key = (String) e.nextElement();
120+
c += tr( td(key) + td((String)properties.get(key)));
121+
}
122+
table(p, "Java SystemProperties", c);
123+
124+
Map<String, String> envVar = System.getenv();
125+
c = "";
126+
for(String key : envVar.keySet()) {
127+
c += tr(td(key)+td(envVar.get(key)));
128+
}
129+
table(p, "Envirionment Variables", c);
130+
p.print("</body></html>");
131+
p.close();
132+
133+
}
134+
}
135+
// [END example]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2017 Google Inc.
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 config] -->
18+
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
19+
<threadsafe>true</threadsafe>
20+
<ssl-enabled>true</ssl-enabled>
21+
<runtime>java8</runtime>
22+
</appengine-web-app>
23+
<!-- [END config] -->

0 commit comments

Comments
 (0)