how to get the primary port number of the server in the runtime

Hi All,

Can any one help me to get primary port number of the server,here in java service i tried with int intCurrentPort = com.wm.app.b2b.server.ServerAPI.getCurrentPort(); with single code line in java service,this is giving as a “-1” in runtime,if i run the java service from developer it is giving correct port number,but it is not giving correct port number at runtime giving as a -1 in the output.

can any one help me to get the primary port number at runtime.

Regards,
anil kumar elelndula

Write a service to read the port number from server.cnf (watt.server.port=5565) and use the information retrieved from this service.

Hai,

Thanx for reply,yes server.cnf file in config folder ,it contains watt.server.port=55555,can you help how get the value of this filed.

sending me the code great help to me.

regards,
anil kumar ellendula

Try something like:

      Properties prop = new Properties();
      prop.load(new FileInputStream(ServerAPI.getServerConfigDir() + "/server.cnf"));
      String port = prop.getProperty("watt.server.port");

with the import of java.util.* and com.wm.app.b2b.server.*

or you can use system properties like

String IShostName = System.getProperty(“watt.net.localhost”);

String ISHTTPlistener = System.getProperty(“watt.net.primaryListener”);

you can also read all system properties by

Properties props = System.getProperties(); //import java.util.*

//and put the values on pipeline
IDataCursor pipelineCursor= pipeline.getCursor();
Enumeration enum = props.propertyNames();
for (; enum.hasMoreElements(); ) {
// Get property name
String propName = (String)enum.nextElement();

// Get property value
String propValue = (String)props.get(propName);
IDataUtil.put( pipelineCursor, propName, propValue);
}

IDataCursor pipelineCursor = pipeline.getCursor();
ServerAPI API;
String hostname;
String port;
{
API = new ServerAPI();
hostname = API.getServerName();
int temp_port = API.getCurrentPort();

temp_port = API.getCurrentPort();

port = (new Integer(temp_port)).toString();

IDataUtil.put( pipelineCursor, “IShostname”, hostname );
IDataUtil.put( pipelineCursor, “ISport”, port);

pipelineCursor.destroy();
}

Cheers!

in flow service, call wm.server.ports:listListeners
it will generate a list : listeners
under it, if listeners/primary=true
it’s primary port

Hai All,

Thax for solution for every one.

Regards,
anil