Finding install and configuration information

I’m trying to get install information (i.e. directory, OS, ports, server name, etc) from within a service. Is there any way I can do this? I need to do different things based on “environmental” information and I’d rather not have multiple versions of packages depending on environment.

My approach to this is to give each installation a unique name. This name is stored in a small java class that is saved to $IS_HOME/lib/classes/au/com/yourCompany/webMethods:

package au.com.yourCompany.webMethods;

public class InstanceConstants
{
        public static String getInstanceName() {
                return "unique instance name";
        }
}

Make the return string different for each webMethods environment.

Compile it with this command:

javac InstanceConstants.java

Inside Developer, create a wrapper java service like this:

IDataCursor idc = pipeline.getCursor();

try {
	IDataUtil.put(idc, "instanceName", InstanceConstants.getInstanceName());
} 
catch (Exception e) {
	throw new ServiceException("Exception in service " + getServiceEntry().toString() + "\n" + e);
}
finally {
	idc.destroy();
}

Add this to the Extends field on the shared tab:

com.wm.app.b2b.server.Service

And this to the Imports list:

au.com.yourCompany.webMethods.InstanceConstants

This instance name can be accessed by flow services or by java code directly.

Now here’s the clever part.

Inside your package, in the config folder, create one folder for each of your environments, using the different instance names you have assigned. Inside these folders put properties files with configuration required by your applications. Now write another java service that will read these properties files, constructing the path to the file like this:

String applicationHomePath = ServerAPI.getPackageConfigDir(packageName).getCanonicalPath();
String instanceName = InstanceConstants.getInstanceName();
String propertiesPath = applicationHomePath + File.separator + instanceName + File.separator + “the name of your properties file.properties”;

properties = new Properties();
if (new File(propertiesPath.trim()).exists() == true) {
	try {
		InputStream input = new BufferedInputStream(new FileInputStream(propertiesPath));
		properties.load(input);
		input.close();
	}
	catch (Exception e) {
		throw new Exception("Exception reading properties file: " + propsFiles[i] + "\n" + e);
	}
}

The values of the properties can then be retrieved with calls like this:
String value = properties.getProperty(“property name”);

In this way, your packages will automatically read in different configuration depending on which installation of webMethods they are running on.

I hope that makes some kind of sense.

This thread has several ways it can go.

From what you originally asked, there are a few options. Several of those values you can get from internal services. If they are not available that way, you should make use of System.getProperty(“property”) function to query the java ‘property’.