Environment recognition
The environment recognition makes it possible to modify the behavior of a solution, depending on the environment to which it is published.
For example, it is possible to get the solution to use different URLs for external services depending on the environment (e.g. some mock service URLs for a testing environment, different URLs for the production environment, etc.).
How does it work?
- In order to recognize the environment where the solution has been published, an environment-specific Java System Property must be set on the environment (in the application server on that environment);
- then, the following method can be used in the solution to pick the system property from the Solution:
_.getProperty(<property name>)
.
The system property name and the values of the property must be fixed for all the environments to which the solutions using this functionality are deployed. The system property is then set once by the administrator of the environments, according to the decided name and values.
Use case example
In a solution using external services, it is possible to use the environment recognition to automatically select different service URLs, depending on the publication environment. This way, the same solution can be deployed to different environments without the need to change the service URL manually before publishing. To do this, a Begin Dialogue script such as the following could be used:
groovy
1def env = _.getProperty("systemProperties.environment.id");
2if (env==”test”) {
3 service_url = “…”
4} else if (env==”prod”) {
5 service_url = “…”
6}
7