Skip to content

Commit 6007d3d

Browse files
authored
gaeinfo (#689)
* gaeinfo Simple Servlet that displays most info * Fix ReadMe
1 parent 588be0f commit 6007d3d

File tree

6 files changed

+337
-0
lines changed

6 files changed

+337
-0
lines changed

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: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
@WebServlet(name = "GAEInfo", description = "GAEInfo: Write info about GAE Standard",
39+
urlPatterns = "/gaeinfo")
40+
//CHECKSTYLE:OFF
41+
public class GAEInfoServlet extends HttpServlet {
42+
43+
public void table(PrintWriter p, String title, String c) {
44+
p.print("<h3>" + title + "</h3>");
45+
p.print("<table>");
46+
p.print(c);
47+
p.print("</table>");
48+
}
49+
50+
public String tr(String c) {
51+
return "<tr>" + c + "</tr>";
52+
}
53+
54+
public String td(String s) {
55+
return "<td>" + s + "</td>";
56+
}
57+
58+
59+
@Override
60+
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
61+
resp.setContentType("text/html");
62+
PrintWriter p = resp.getWriter();
63+
64+
65+
p.print("<html><body>");
66+
67+
final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
68+
table(p, "AppIdentity",
69+
tr(td("ServiceAccountName") + td(appIdentity.getServiceAccountName()) ) +
70+
tr(td("GCS Bucket") + td( appIdentity.getDefaultGcsBucketName()))
71+
);
72+
73+
table(p, "SystemProperties",
74+
tr( td( "appId") + td(SystemProperty.applicationId.get()) ) +
75+
tr(td("appVer") + td( SystemProperty.applicationVersion.get()) ) +
76+
tr(td("version") + td(SystemProperty.version.get()) ) +
77+
tr(td("environment") + td(SystemProperty.environment.get()) )
78+
);
79+
80+
81+
// Environment Atributes
82+
ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
83+
Map<String,Object> attr = env.getAttributes();
84+
85+
String c = "";
86+
for(String key : attr.keySet()) {
87+
Object o = attr.get(key);
88+
89+
if(o.getClass().getCanonicalName().equals("java.lang.String")) {
90+
c += tr(td(key) + td((String) o));
91+
} else
92+
c += tr(td(key) + td(o.getClass().getCanonicalName()));
93+
}
94+
table(p, "Environment Attributes", c);
95+
96+
c = "";
97+
for (Enumeration<String> e = req.getHeaderNames(); e.hasMoreElements();) {
98+
String key = e.nextElement();
99+
String val = req.getHeader(key);
100+
c += tr(td(key) + td(val) );;
101+
}
102+
table(p, "Headers", c);
103+
104+
105+
Cookie[] cookies = req.getCookies();
106+
if(cookies != null && cookies.length != 0) {
107+
c = "";
108+
for (Cookie co : cookies) {
109+
c += tr( td(co.getName()) + td(co.getValue()) + td(co.getComment()) +
110+
td(co.getPath()) + td(Integer.toString(co.getMaxAge())) );
111+
}
112+
table(p, "Cookies", c);
113+
}
114+
115+
Properties properties = System.getProperties();
116+
c = "";
117+
for(Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
118+
String key = (String) e.nextElement();
119+
c += tr( td(key) + td((String)properties.get(key)));
120+
}
121+
table(p, "Java SystemProperties", c);
122+
123+
Map<String, String> envVar = System.getenv();
124+
c = "";
125+
for(String key : envVar.keySet()) {
126+
c += tr(td(key)+td(envVar.get(key)));
127+
}
128+
table(p, "Envirionment Variables", c);
129+
p.print("</body></html>");
130+
p.close();
131+
132+
}
133+
}
134+
// [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] -->
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
4+
Copyright 2017 Google Inc.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
22+
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
23+
version="3.1">
24+
<welcome-file-list>
25+
<welcome-file>gaeinfo</welcome-file>
26+
</welcome-file-list>
27+
</web-app>

appengine-java8/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151

5252
<module>firebase-tictactoe</module>
5353

54+
<module>gaeinfo</module>
55+
5456
<module>guestbook-cloud-datastore</module>
5557
<module>guestbook-objectify</module>
5658

0 commit comments

Comments
 (0)