Here is a quick way to determine if your code is executing in the GAE/J environment:
boolean onGoogleAppEngine = getServletContext().getServerInfo().startsWith("Google App Engine");getServerInfo() currently returns "Google App Engine/1.2.0" when running in the live GAE/J environment. When running in local development mode it returns "Google App Engine Development/1.2.0".
Please comment if you know of any better/cleaner way to determine if your code is executing in the GAE/J sandbox.
4 comments:
Wow, I hope people use this as a temporary ugly hack or GAE/j is really breaking WORA.
Alexis: The check is meant to be used for debugging GAE/J compatibility issues. If possible using such a check should be avoided.
I think there's a small typo in your code example. You're missing a "/" at the end of "Google App Engine". As written, your function will always return true.
It should read:
getServletContext().getServerInfo().startsWith("Google App Engine/");
Much better..
//GET this printed once!
static final String YOUR_HOME_DIR ="/home/username/grails......../stage";
String userDir = System.getProperty("user.dir");
if(YOUR_HOME_DIR.equals(userDir)){
//DEv Env
}else{
//Live Env
}
Post a Comment