Code sometimes needs to determine the identifier of the application in which it is executing. This may be to generate a URL or email address, or possibly to make some run-time decision. App Engine includes an Application Identity service for this purpose.
- Identifying itself
- Asserting identity to other App Engine apps
- Asserting identity to Google APIs
- Asserting identity to other systems
Identifying itself
Application ID
The application ID can be found using the
ApiProxy.Environment.getAppId()
method.
Versioned hostnames
A related operation is the need to get the hostname part of a URL to the application. You can use the
com.google.appengine.runtime.default_version_hostname
attribute of the
CurrentEnvironment
for this purpose. This is useful in certain scenarios when the application is not available at
http://your_app_id.appspot.com
.
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
Environment env = ApiProxy.getCurrentEnvironment();
resp.getWriter().println("default_version_hostname: "
+ env.getAttributes().get("com.google.appengine.runtime.default_version_hostname"));
}