-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* gaeinfo Simple Servlet that displays most info * Fix ReadMe
- Loading branch information
Showing
6 changed files
with
337 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Google App Engine Information | ||
|
||
This sample displays what's going on in your app. It dumps the environment and lots more. | ||
|
||
See the [Google App Engine standard environment documentation][ae-docs] for more | ||
detailed instructions. | ||
|
||
[ae-docs]: https://cloud.google.com/appengine/docs/java/ | ||
|
||
## Setup | ||
|
||
Use either: | ||
|
||
* `gcloud init` | ||
* `gcloud auth application-default login` | ||
|
||
## Maven | ||
### Running locally | ||
|
||
$ mvn appengine:run | ||
|
||
### Deploying | ||
|
||
$ mvn appengine:deploy | ||
|
||
## Gradle | ||
### Running locally | ||
|
||
$ gradle appengineRun | ||
|
||
If you do not have gradle installed, you can run using `./gradlew appengineRun`. | ||
|
||
### Deploying | ||
|
||
$ gradle appengineDeploy | ||
|
||
If you do not have gradle installed, you can deploy using `./gradlew appengineDeploy`. | ||
|
||
<!-- | ||
## Intelij Idea | ||
Limitations - Appengine Standard support in the Intellij plugin is only available for the Ultimate Edition of Idea. | ||
### Install and Set Up Cloud Tools for IntelliJ | ||
To use Cloud Tools for IntelliJ, you must first install IntelliJ IDEA Ultimate edition. | ||
Next, install the plugins from the IntelliJ IDEA Plugin Repository. | ||
To install the plugins: | ||
1. From inside IDEA, open File > Settings (on Mac OS X, open IntelliJ IDEA > Preferences). | ||
1. In the left-hand pane, select Plugins. | ||
1. Click Browse repositories. | ||
1. In the dialog that opens, select Google Cloud Tools. | ||
1. Click Install. | ||
1. Click Close. | ||
1. Click OK in the Settings dialog. | ||
1. Click Restart (or you can click Postpone, but the plugins will not be available until you do restart IDEA.) | ||
### Running locally | ||
### Deploying | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<!-- | ||
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. | ||
--> | ||
<!-- [START pom] --> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>war</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<groupId>com.example.appengine</groupId> | ||
<artifactId>gaeinfo-j8</artifactId> | ||
|
||
<parent> | ||
<artifactId>appengine-java8-samples</artifactId> | ||
<groupId>com.google.cloud</groupId> | ||
<version>1.0.0</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
|
||
<!-- [START compiler] --> | ||
<properties> <!-- App Engine Standard currently requires Java 7 --> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
</properties> | ||
<!-- [END compiler] --> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.appengine</groupId> | ||
<artifactId>appengine-api-1.0-sdk</artifactId> | ||
<version>${appengine.sdk.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</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> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>3.0.0</version> | ||
<configuration> | ||
<webResources> | ||
<!-- in order to interpolate version from pom into appengine-web.xml --> | ||
<resource> | ||
<directory>${basedir}/src/main/webapp/WEB-INF</directory> | ||
<filtering>true</filtering> | ||
<targetPath>WEB-INF</targetPath> | ||
</resource> | ||
</webResources> | ||
</configuration> | ||
</plugin> | ||
|
||
<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> | ||
<!-- [END pom] --> |
134 changes: 134 additions & 0 deletions
134
appengine-java8/gaeinfo/src/main/java/com/example/appengine/standard/GAEInfoServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
package com.example.appengine.standard; | ||
|
||
import com.google.appengine.api.appidentity.AppIdentityService; | ||
import com.google.appengine.api.appidentity.AppIdentityServiceFactory; | ||
import com.google.appengine.api.utils.SystemProperty; | ||
import com.google.apphosting.api.ApiProxy; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.Enumeration; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
// [START example] | ||
@SuppressWarnings({"serial"}) | ||
@WebServlet(name = "GAEInfo", description = "GAEInfo: Write info about GAE Standard", | ||
urlPatterns = "/gaeinfo") | ||
//CHECKSTYLE:OFF | ||
public class GAEInfoServlet extends HttpServlet { | ||
|
||
public void table(PrintWriter p, String title, String c) { | ||
p.print("<h3>" + title + "</h3>"); | ||
p.print("<table>"); | ||
p.print(c); | ||
p.print("</table>"); | ||
} | ||
|
||
public String tr(String c) { | ||
return "<tr>" + c + "</tr>"; | ||
} | ||
|
||
public String td(String s) { | ||
return "<td>" + s + "</td>"; | ||
} | ||
|
||
|
||
@Override | ||
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
resp.setContentType("text/html"); | ||
PrintWriter p = resp.getWriter(); | ||
|
||
|
||
p.print("<html><body>"); | ||
|
||
final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService(); | ||
table(p, "AppIdentity", | ||
tr(td("ServiceAccountName") + td(appIdentity.getServiceAccountName()) ) + | ||
tr(td("GCS Bucket") + td( appIdentity.getDefaultGcsBucketName())) | ||
); | ||
|
||
table(p, "SystemProperties", | ||
tr( td( "appId") + td(SystemProperty.applicationId.get()) ) + | ||
tr(td("appVer") + td( SystemProperty.applicationVersion.get()) ) + | ||
tr(td("version") + td(SystemProperty.version.get()) ) + | ||
tr(td("environment") + td(SystemProperty.environment.get()) ) | ||
); | ||
|
||
|
||
// Environment Atributes | ||
ApiProxy.Environment env = ApiProxy.getCurrentEnvironment(); | ||
Map<String,Object> attr = env.getAttributes(); | ||
|
||
String c = ""; | ||
for(String key : attr.keySet()) { | ||
Object o = attr.get(key); | ||
|
||
if(o.getClass().getCanonicalName().equals("java.lang.String")) { | ||
c += tr(td(key) + td((String) o)); | ||
} else | ||
c += tr(td(key) + td(o.getClass().getCanonicalName())); | ||
} | ||
table(p, "Environment Attributes", c); | ||
|
||
c = ""; | ||
for (Enumeration<String> e = req.getHeaderNames(); e.hasMoreElements();) { | ||
String key = e.nextElement(); | ||
String val = req.getHeader(key); | ||
c += tr(td(key) + td(val) );; | ||
} | ||
table(p, "Headers", c); | ||
|
||
|
||
Cookie[] cookies = req.getCookies(); | ||
if(cookies != null && cookies.length != 0) { | ||
c = ""; | ||
for (Cookie co : cookies) { | ||
c += tr( td(co.getName()) + td(co.getValue()) + td(co.getComment()) + | ||
td(co.getPath()) + td(Integer.toString(co.getMaxAge())) ); | ||
} | ||
table(p, "Cookies", c); | ||
} | ||
|
||
Properties properties = System.getProperties(); | ||
c = ""; | ||
for(Enumeration e = properties.propertyNames(); e.hasMoreElements();) { | ||
String key = (String) e.nextElement(); | ||
c += tr( td(key) + td((String)properties.get(key))); | ||
} | ||
table(p, "Java SystemProperties", c); | ||
|
||
Map<String, String> envVar = System.getenv(); | ||
c = ""; | ||
for(String key : envVar.keySet()) { | ||
c += tr(td(key)+td(envVar.get(key))); | ||
} | ||
table(p, "Envirionment Variables", c); | ||
p.print("</body></html>"); | ||
p.close(); | ||
|
||
} | ||
} | ||
// [END example] |
23 changes: 23 additions & 0 deletions
23
appengine-java8/gaeinfo/src/main/webapp/WEB-INF/appengine-web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<!-- [START config] --> | ||
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> | ||
<threadsafe>true</threadsafe> | ||
<ssl-enabled>true</ssl-enabled> | ||
<runtime>java8</runtime> | ||
</appengine-web-app> | ||
<!-- [END config] --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee | ||
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | ||
version="3.1"> | ||
<welcome-file-list> | ||
<welcome-file>gaeinfo</welcome-file> | ||
</welcome-file-list> | ||
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters