How to check environment is Production or local in Google Cloud SDK Java 11 -

225 views
Skip to first unread message

Harwinder Singh

unread,
Jul 8, 2022, 11:10:31 AM7/8/22
to Google Cloud Developers
I'm migrating my app from GAE Java 8 to Google Cloud SDK Java 11. 

I used to check whether my environment was Production using the following code:

if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
  isProd = true;
}
else {
  isProd = false;
}

How do I go about doing the same with Google Cloud SDK for Java 11?

Thanks!

Jose Perez Sanchez

unread,
Jul 13, 2022, 1:55:21 PM7/13/22
to Google Cloud Developers

It is recommended that you configure your web server with an environment variable. Following the next code example will help you to confirm if it is in production or local.


// You could use this in your scenario with your own variable.

// PORT environment variable when present, otherwise on 8080.

    int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));

    HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);


But also, reviewing this GitHub repository, you can actually use your current code in Java 8 for Java 11.


Here is the direct link to the current code you can follow using SystemProperty.

Harwinder Singh

unread,
Jul 19, 2022, 5:00:03 PM7/19/22
to Google Cloud Developers
Hi,

Thanks for your response.

I'm not using appengine API SDK and removed it as a dependency. So, SystemProperty doesn't work for me anymore. 

I'll try the approach in your first example and post an update here.
Reply all
Reply to author
Forward
0 new messages