Environment Detection

Please check out sample code in SVN: https://sfee.ucsd.edu/svn/repos/env-poc/trunk

Package includes:

  • /src
    • edu.ucsd.act.aim.jlinkcompat
      • JLinkJndi.java
    • edu.ucsd.act.aim.web.util
      • AimJndi.java
      • AimJndiFactory.java
      • Environment.java
      • JndiEnvBean.java
      • JndiStringValueFactory.java
  • /doc
  • server_env.bat
  • server_env.sh

In a desktop development environment, the code in either server_env.bat or server_env.sh (as appropriate) should be added to your Tomcat startup scripts.

Once the appropriate environment variables are available in your app server, you can get environment information from the static methods in either the JLinkJndi compatibility class or the newer AimJndi class.

The following static methods in both AimJndi the JLinkJndi compatibility class are similar to those in classic JLinkJndi, though the internal implementation differs. See the Javadoc for more details:

  • isDesktop()
  • isEnvDev()
  • isEnvProd()
  • isEnvQA()
  • isEnvStaging()
  • isEnvTraining()
  • isMainframe()

If you prefer to use a standard Java JNDI binding you can set up JndiStringValueFactory as an object factory. This will return the raw string values ENV_DEV, ENV_QA, ENV_STAGE, ENV_PROD, ENV_TRAIN.

There is no particular functional difference between the various methods. The choice is a matter of personal preference / theology.

JNDI object factory example:

<Context path="sample" crossContext="true">

<Resource name="aim/env.name" auth="Container"
InitialContext ic = new InitialContext();

Context ctx = (Context)ic.lookup("java:comp/env");

String env = (String)ctx.lookup("aim/env.name");

Middleware (Integration Layer)