Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current server URL of appengine app?

I'm trying to get the server URL of a currently running appengine java app from code. That is, if the app is running on my local dev machine I would like to somehow get returned "http://localhost:8080" but if it is running in prod I'd like to be returned "http://myappid.appspot.com". Are there any java or appengine API's that can do this? I'd like to not have a to manually change and read from a config file or a constant.

Thanks.

  • Aleem
like image 640
aloo Avatar asked Jun 18 '09 22:06

aloo


1 Answers

This is working for me in Java on appengine:

String hostUrl; 
String environment = System.getProperty("com.google.appengine.runtime.environment");
if (StringUtils.equals("Production", environment)) {
    String applicationId = System.getProperty("com.google.appengine.application.id");
    String version = System.getProperty("com.google.appengine.application.version");
    hostUrl = "http://"+version+"."+applicationId+".appspot.com/";
} else {
    hostUrl = "http://localhost:8888";
}
like image 51
Sandokan Avatar answered Sep 24 '22 18:09

Sandokan