Tuesday, December 22, 2015

IBM BPM - How to get the Server HostName and Port in different Environments

In this Post, let us look at how to retrieve the Server host name and port in different environments. The general practice is to use an environment variable for host name and port which can be used to hold these constants and change these values when you promote the code to higher environments.
I found a way  to retrieve these values programmatically using  the apis that comes with IBM BPM, just thought of sharing that with you all. Below is script which will fetch these values dynamically.

Packages.com.lombardisoftware.core.config.TWConfiguration.getInstance().getServer();
Above statement gives the instance of the server.

server.getServerHost() - This gives the Host Name of the BPM server.
server.getServerPort() -  This gives the port of the BPM server

Packages.com.lombardisoftware.core.config.TWConfiguration.getInstance().getCommon().getPortalPrefix(); 
Above statement gives the portal prefix



you can put the below script in a js file and attach it as a server in the file section and get the server name readily
var  serverURL = "";
var server = Packages.com.lombardisoftware.core.config.TWConfiguration.getInstance().getServer();

var portalPrefix = Packages.com.lombardisoftware.core.config.TWConfiguration.getInstance().getCommon().getPortalPrefix();
portalPrefix = portalPrefix.substr(0, portalPrefix.lastIndexOf("/"));
if(portalPrefix.substr(0, 4).indexOf("http")==0){
    serverURL = portalPrefix;
} else {
    serverURL = "https://" + server.getServerHost() + ":" + server.getServerPort() + portalPrefix;
}




No comments:

Post a Comment