in appengine-java8/gaeinfo/src/main/java/com/example/appengine/standard/GaeInfoServlet.java [136:225]
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String key = "";
final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
WebContext ctx = new WebContext(application.buildExchange(req, resp));
ctx.setLocale(req.getLocale());
resp.setContentType("text/html");
ctx.setVariable("production", SystemProperty.environment.value().name());
ctx.setVariable("ServiceAccountName", appIdentity.getServiceAccountName());
ctx.setVariable("gcs", appIdentity.getDefaultGcsBucketName());
ctx.setVariable("appId", SystemProperty.applicationId.get());
ctx.setVariable("appVer", SystemProperty.applicationVersion.get());
ctx.setVariable("version", SystemProperty.version.get());
ctx.setVariable("environment", SystemProperty.environment.get());
// Environment Atributes
ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
Map<String, Object> attr = env.getAttributes();
TreeMap<String, String> m = new TreeMap<>();
for (String k : attr.keySet()) {
Object o = attr.get(k);
if (o.getClass().getCanonicalName().equals("java.lang.String")) {
m.put(k, (String) o);
} else if (o.getClass().getCanonicalName().equals("java.lang.Boolean")) {
m.put(k, ((Boolean) o).toString());
} else {
m.put(k, "a " + o.getClass().getCanonicalName());
}
}
ctx.setVariable("attribs", m);
m = new TreeMap<>();
for (Enumeration<String> e = req.getHeaderNames(); e.hasMoreElements(); ) {
key = e.nextElement();
m.put(key, req.getHeader(key));
}
ctx.setVariable("headers", m);
Cookie[] cookies = req.getCookies();
m = new TreeMap<>();
if (cookies != null && cookies.length != 0) {
for (Cookie co : cookies) {
m.put(co.getName(), co.getValue());
}
}
ctx.setVariable("cookies", m);
Properties properties = System.getProperties();
m = new TreeMap<>();
for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements(); ) {
key = (String) e.nextElement();
m.put(key, (String) properties.get(key));
}
ctx.setVariable("systemprops", m);
Map<String, String> envVar = System.getenv();
m = new TreeMap<>(envVar);
ctx.setVariable("envvar", m);
// The metadata server is only on a production system
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
m = new TreeMap<>();
for (String k : metaPath) {
m.put(k, fetchMetadata(k));
}
ctx.setVariable("Metadata", m.descendingMap());
m = new TreeMap<>();
for (String k : metaServiceAcct) {
// substitute a service account for {account}
k = k.replace("{account}", appIdentity.getServiceAccountName());
m.put(k, fetchMetadata(k));
}
ctx.setVariable("sam", m.descendingMap());
// Recursively get all info about service accounts -- Note tokens are leftout by default.
ctx.setVariable(
"rsa",
fetchJsonMetadata("/computeMetadata/v1/instance/service-accounts/?recursive=true"));
// Recursively get all data on Metadata server.
ctx.setVariable("ram", fetchJsonMetadata("/?recursive=true"));
}
templateEngine.process("index", ctx, resp.getWriter());
}