diff --git a/appengine-java8/gaeinfo/README.md b/appengine-java8/gaeinfo/README.md new file mode 100644 index 00000000000..a43199924eb --- /dev/null +++ b/appengine-java8/gaeinfo/README.md @@ -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`. + + diff --git a/appengine-java8/gaeinfo/pom.xml b/appengine-java8/gaeinfo/pom.xml new file mode 100644 index 00000000000..a0bb6f78bba --- /dev/null +++ b/appengine-java8/gaeinfo/pom.xml @@ -0,0 +1,88 @@ + + + + 4.0.0 + war + 1.0-SNAPSHOT + com.example.appengine + gaeinfo-j8 + + + appengine-java8-samples + com.google.cloud + 1.0.0 + .. + + + + + 1.8 + 1.8 + + + + + + com.google.appengine + appengine-api-1.0-sdk + ${appengine.sdk.version} + + + + javax.servlet + javax.servlet-api + 3.1.0 + jar + provided + + + + + + + ${project.build.directory}/${project.build.finalName}/WEB-INF/classes + + + org.apache.maven.plugins + maven-war-plugin + 3.0.0 + + + + + ${basedir}/src/main/webapp/WEB-INF + true + WEB-INF + + + + + + + com.google.cloud.tools + appengine-maven-plugin + 1.3.1 + + true + true + + + + + + + diff --git a/appengine-java8/gaeinfo/src/main/java/com/example/appengine/standard/GAEInfoServlet.java b/appengine-java8/gaeinfo/src/main/java/com/example/appengine/standard/GAEInfoServlet.java new file mode 100644 index 00000000000..cd5fff0f4de --- /dev/null +++ b/appengine-java8/gaeinfo/src/main/java/com/example/appengine/standard/GAEInfoServlet.java @@ -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("

" + title + "

"); + p.print(""); + p.print(c); + p.print("
"); + } + + public String tr(String c) { + return "" + c + ""; + } + + public String td(String s) { + return "" + s + ""; + } + + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + resp.setContentType("text/html"); + PrintWriter p = resp.getWriter(); + + + p.print(""); + + 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 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 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 envVar = System.getenv(); + c = ""; + for(String key : envVar.keySet()) { + c += tr(td(key)+td(envVar.get(key))); + } + table(p, "Envirionment Variables", c); + p.print(""); + p.close(); + + } +} +// [END example] diff --git a/appengine-java8/gaeinfo/src/main/webapp/WEB-INF/appengine-web.xml b/appengine-java8/gaeinfo/src/main/webapp/WEB-INF/appengine-web.xml new file mode 100644 index 00000000000..dd2cb3e09be --- /dev/null +++ b/appengine-java8/gaeinfo/src/main/webapp/WEB-INF/appengine-web.xml @@ -0,0 +1,23 @@ + + + + + true + true + java8 + + diff --git a/appengine-java8/gaeinfo/src/main/webapp/WEB-INF/web.xml b/appengine-java8/gaeinfo/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000000..e31839a606f --- /dev/null +++ b/appengine-java8/gaeinfo/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,27 @@ + + + + + gaeinfo + + diff --git a/appengine-java8/pom.xml b/appengine-java8/pom.xml index 02ccbef5d98..1337c87abd4 100644 --- a/appengine-java8/pom.xml +++ b/appengine-java8/pom.xml @@ -51,6 +51,8 @@ firebase-tictactoe + gaeinfo + guestbook-cloud-datastore guestbook-objectify