Sunday, April 12, 2009

Determining if your code is executing in the GAE/J environment/sandbox

When moving your apps to the GAE/J platform you might be required to do some tweaking to make your application comply with the restricted sandbox environment of the Google App Engine (no write access to disk, read access limited to "user.dir", no thread creation, etc.).

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.

9 comments:

  1. Wow, I hope people use this as a temporary ugly hack or GAE/j is really breaking WORA.

    ReplyDelete
  2. Alexis: The check is meant to be used for debugging GAE/J compatibility issues. If possible using such a check should be avoided.

    ReplyDelete
  3. 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/");

    ReplyDelete
  4. 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
    }

    ReplyDelete
  5. Really good site thank you so much for your time in writing the posts for all of us to learn about. It will be very useful for me.
    share market
    stock market
    Indian Stock Market Tips

    ReplyDelete
  6. This is a great post ! it was very informative. I look forward in reading more of your work.
    Intraday Nifty Future Tips
    Share market tips
    Share and Earn

    ReplyDelete
  7. I was very encouraged to find this site. I wanted to thank you for this special read.
    Commodity tips
    Stock Market
    Share Market
    Nse Tips
    Bse Tips

    ReplyDelete
  8. Hi there! I just would like to give a huge thumbs up for the nice info you will have right here on this post. I will likely be coming again to your weblog for extra soon.
    Buy Property
    Sell Property
    Invest in Property
    Find real estate agent

    ReplyDelete
  9. I am very much pleased with the contents you have mentioned. I enjoyed every little bit part of it. It contains truly information. I want to thank you for this informative read.
    Intraday Calls || Nifty Trading || Nifty Intraday Tips.

    ReplyDelete