Getting the Server Name from the session

2019-09-09 00:57发布

问题:

In a managed bean that resides in a Database on the server Development I have this code:

s = ExtLibUtil.getCurrentSession();
theMap.put("Server Name", s.getServerName());

when I look at theMap after this has run I see Server Name and the value is blank. After this I get a datbase RepID and then try to open the database by RepID with

appDB = s.getDbDirectory(null).openDatabaseByReplicaID(repID);
                if (appDB.isOpen()){
                    theMap.put(thisKey, repID); 
                }else{
                    theMap.put("DB " + thisKey, "Is Not Open");
                }

if I have a rep copy of the database locally it opens it, if I remove the local Replica the open fails. If I change the line to:

appDB = s.getDbDirectory("Development").openDatabaseByReplicaID(repID);

the proper appDB opens. So it looks like the session thinks it is running locally because it return null for the server name. This is really strange, am I missing something? For the moment i have just hard coded the server name in the getDbDirectory but that wont work in the real world.

回答1:

Is this XPiNC? That would consider the database to be running locally unless you've set the application property "Run server-based XPages on server"



回答2:

String serverName = s.getEnvironmentString("ServerName", true);
or
String serverName = s.getEnvironmentString("ServerKeyFileName_Owner", true);