Getting system properties

In this Topic

Accessing Other Properties

Related Topics ...

Overview: Working with Java

Javadoc for SystemProperties Class

We can get the values of the Factory properties stored in the cluster.properties and bowstreet.properties files by accessing the com.bowstreet.util.SystemProperties object returned by a call to webAppAccess.getSystemProperties().

Using the SystemProperties object, we can access information such as the directory path to the document root, the URL to the server, and other information by calling the following methods:

  • Directory path to document root  -- webAppAccess.getSystemProperties().getDocumentRoot();

Returns a String specifying the directory path to the Factory's servable content root directory, such as: <AppServerDeployDir>\MyApp.ear\MyApp.war

  • Directory path to the Factory's WEB-INF directory  -- webAppAccess.getSystemProperties().getWebInfDir();

Returns a String specifying the directory path to the Factory's non-servable content root directory, such as: <AppServerDeployDir>\MyApp.ear\MyApp.war\WEB-INF

  • URL to Factory server -- webAppAccess.getRequestData().getContextURL();

Returns a String specifying the URL to the Factory, such as: http://127.0.0.1:9080/MyApp

  • URL to Factory servlet -- webAppAccess.getRequestData().getServletURL();

Returns a String specifying the URL to the current Factory servlet, such as: http://127.0.0.1:9080/MyApp/webengine

 

Accessing other Properties

We can access values stored in other properties files using Java conventions for loading properties files. For example, if you have created your own properties file or want to access other Factory properties files, we can use code similar to the following to access those property values. This code gets the value of the application context property in the Factory's install.properties file. Adapt this code to suit your needs:

{

   String propertyValue = null;

   FileInputStream propertiesStream = null;

 

   String webInfDir = webAppAccess.getSystemProperties().getWebInfDir();

   try {

      propertiesStream = new FileInputStream(webInfDir + "\\config\\install.properties");

   }

   catch (SecurityException se) {

      webAppAccess.getVariables().setString("SecurityExceptionVar", se.toString());

      webAppAccess.processPage("ErrorPage");

   }

   catch (FileNotFoundException fnfe) {

      webAppAccess.getVariables().setString("FNFExceptionVar", fnfe.toString());

      webAppAccess.processPage("ErrorPage");   

   }

   try {

       PropertyResourceBundle propertiesFile = new PropertyResourceBundle(propertiesStream);

       String propertyKey = "install.webSphere.webModule.context";

       propertyValue = propertiesFile.getString(propertyKey);

   }

   catch (IOException ioe) {

      webAppAccess.getVariables().setString("IOExceptionVar", ioe.toString());

      webAppAccess.processPage("ErrorPage");   

   }

   webAppAccess.getVariables().setString("PropertyValue", propertyValue);

}