Skip to content

Commit 9045d25

Browse files
committed
Fixed behavior related to getHostName
- it is not guaranteed that the local host name is resolvable by DNS - but it should be in nearly all cases we use it Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
1 parent 2cc331e commit 9045d25

14 files changed

Lines changed: 359 additions & 239 deletions

File tree

appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/CreateIiopListenerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
@ExtendWith(OrbJunitExtension.class)
5555
public class CreateIiopListenerTest {
5656

57-
private static final String LOCALHOST = NetUtils.getHostName();
57+
private static final String LOCALHOST = NetUtils.getCanonicalHostName();
5858

5959
@Inject
6060
private ServiceLocator services;

appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/DeleteIiopListenerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void tearDown() throws TransactionFailure {
100100
*/
101101
@Test
102102
public void testExecuteSuccessDefaultTarget() {
103-
parameters.set("listeneraddress", NetUtils.getHostName());
103+
parameters.set("listeneraddress", NetUtils.getCanonicalHostName());
104104
parameters.set("iiopport", "4440");
105105
parameters.set("listener_id", "iiop_1");
106106
CreateIiopListener createCommand = services.getService(CreateIiopListener.class);

appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/ListIiopListenersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void testExecuteSuccessValidTargetOperand() {
114114
*/
115115
@Test
116116
public void testExecuteSuccessListListener() {
117-
parameters.set("listeneraddress", NetUtils.getHostName());
117+
parameters.set("listeneraddress", NetUtils.getCanonicalHostName());
118118
parameters.set("iiopport", "4440");
119119
parameters.set("listener_id", "listener");
120120
CreateIiopListener createCommand = services.getService(CreateIiopListener.class);

appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IiopFolbGmsClient.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ boolean isGMSAvailable() {
138138
return gmsAdapter != null ;
139139
}
140140

141-
////////////////////////////////////////////////////
142-
//
143-
// Action
144-
//
145-
146141
@Override
147142
public void processNotification(final Signal signal) {
148143
try {
@@ -250,18 +245,7 @@ private ClusterInstanceInfo getClusterInstanceInfo(Server server, Config config,
250245
final int weight = Integer.parseInt(server.getLbWeight());
251246
LOG.log(DEBUG, "getClusterInstanceInfo: weight {0}", weight);
252247

253-
final String nodeName = server.getNodeRef();
254-
String hostName = nodeName;
255-
if (nodes != null) {
256-
Node node = nodes.getNode(nodeName);
257-
if (node != null) {
258-
if (node.isLocal()) {
259-
hostName = NetUtils.getHostName();
260-
} else {
261-
hostName = node.getNodeHost();
262-
}
263-
}
264-
}
248+
final String hostName = getHostName(server.getNodeRef());
265249

266250
LOG.log(DEBUG, "getClusterInstanceInfo: host {0}", hostName);
267251

@@ -273,8 +257,7 @@ private ClusterInstanceInfo getClusterInstanceInfo(Server server, Config config,
273257

274258
final List<SocketInfo> sinfos = new ArrayList<>();
275259
for (IiopListener il : listeners) {
276-
SocketInfo sinfo = new SocketInfo(il.getId(), hostName, resolvePort(server, il));
277-
sinfos.add(sinfo);
260+
sinfos.add(new SocketInfo(il.getId(), hostName, resolvePort(server, il)));
278261
}
279262
LOG.log(DEBUG, "getClusterInstanceInfo: sinfos {0}", sinfos);
280263

@@ -284,6 +267,17 @@ private ClusterInstanceInfo getClusterInstanceInfo(Server server, Config config,
284267
return result;
285268
}
286269

270+
private String getHostName(final String nodeName) {
271+
if (nodes == null) {
272+
return nodeName;
273+
}
274+
Node node = nodes.getNode(nodeName);
275+
if (node == null) {
276+
return nodeName;
277+
}
278+
return node.isLocal() ? NetUtils.getCanonicalHostName() : node.getNodeHost();
279+
}
280+
287281

288282
private Config getConfigForServer(Server server) {
289283
LOG.log(DEBUG, "getConfigForServer: server {0}", server);

appserver/security/webintegration/src/main/java/com/sun/web/security/RealmAdapter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,6 @@ private List<String> getHostAndPort(HttpRequest request) throws IOException {
10761076
for (NetworkListener nwListener : networkListeners.getNetworkListener()) {
10771077
// Loop through the network listeners
10781078
String nwAddress = nwListener.getAddress();
1079-
InetAddress[] localHostAdresses;
10801079
if (nwAddress == null || nwAddress.equals("0.0.0.0")) {
10811080
nwAddress = NetUtils.getCanonicalHostName();
10821081
if (nwAddress.equals(hostPort[0])) {
@@ -1095,8 +1094,8 @@ private List<String> getHostAndPort(HttpRequest request) throws IOException {
10951094
// only if the hostname in the header
10961095
// does not match with the hostname in the
10971096
// listener-To avoid performance overhead
1098-
localHostAdresses = NetUtils.getHostAddresses();
1099-
if (localHostAdresses.length == 0) {
1097+
List<InetAddress> localHostAdresses = NetUtils.getHostAddresses();
1098+
if (localHostAdresses.isEmpty()) {
11001099
break;
11011100
}
11021101
InetAddress hostAddress = InetAddress.getByName(hostPort[0]);

appserver/transaction/jts/src/main/java/com/sun/jts/CosTransactions/DefaultTransactionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static void setServerName(Properties properties) {
221221
}
222222
final String serverName;
223223
if (properties.getProperty(JTS_XA_SERVER_NAME) == null) {
224-
serverName = NetUtils.getHostName();
224+
serverName = NetUtils.getCanonicalHostName();
225225
} else {
226226
serverName = properties.getProperty(JTS_XA_SERVER_NAME);
227227
LOG.log(DEBUG, "DTR: Got serverName from JTS_XA_SERVER_NAME");

nucleus/admin/config-api/src/main/java/com/sun/enterprise/config/util/PortManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private Map<String, Integer> reassignPorts() throws TransactionFailure {
220220

221221
private Integer reassignPort(int num) throws TransactionFailure {
222222
int max = num + 100;
223-
final String hostName = NetUtils.getHostName();
223+
final String hostName = NetUtils.getCanonicalHostName();
224224
while (num < max) {
225225
num = getNextUnassignedPort(num);
226226
if (NetUtils.isPortFree(hostName, num)) {

nucleus/admin/config-api/src/main/java/com/sun/enterprise/config/util/ServerHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public final String getAdminHost() throws RuntimeException {
9393
// We are the DAS. Return our hostname
9494
return System.getProperty(HOST_NAME.getSystemPropertyName());
9595
}
96-
return NetUtils.getHostName();
96+
return NetUtils.getCanonicalHostName();
9797
}
9898

9999
String hostName = null;
@@ -107,7 +107,7 @@ public final String getAdminHost() throws RuntimeException {
107107
}
108108
// Hack to get around the fact that the default localhost node entry is malformed
109109
if (hostName == null && nodeName.equals("localhost-" + domain.getName())) {
110-
return NetUtils.getHostName();
110+
return NetUtils.getCanonicalHostName();
111111
}
112112
}
113113

nucleus/admin/util/src/main/java/com/sun/enterprise/admin/util/GenericAdminAuthenticator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public Subject authenticate(Object credentials) {
522522
}
523523
}
524524
} else {
525-
host = NetUtils.getHostName();
525+
host = NetUtils.getCanonicalHostName();
526526
}
527527

528528
String realm = as.getSystemJmxConnector().getAuthRealmName(); //yes, for backward compatibility;

0 commit comments

Comments
 (0)