Object socketRef = tc.getParams().remove(SOCKET_REF);
if (socketRef != null) {
String name = socketRef.toString();
String host;
int port;
OutboundSocketBinding binding = outboundSocketBindings.get(name);
if (binding == null) {
final SocketBinding socketBinding = socketBindings.get(name);
if (socketBinding == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
}
InetSocketAddress sa = socketBinding.getSocketAddress();
port = sa.getPort();
// resolve the host name of the address only if a loopback address has been set
if (sa.getAddress().isLoopbackAddress()) {
host = NetworkUtils.canonize(sa.getAddress().getHostName());
} else {
host = NetworkUtils.canonize(sa.getAddress().getHostAddress());
}
} else {
port = binding.getDestinationPort();
host = NetworkUtils.canonize(binding.getUnresolvedDestinationAddress());
if (binding.getSourceAddress() != null) {
tc.getParams().put(TransportConstants.LOCAL_ADDRESS_PROP_NAME,
NetworkUtils.canonize(binding.getSourceAddress().getHostAddress()));
}
if (binding.getSourcePort() != null) {
// Use absolute port to account for source port offset/fixation
tc.getParams().put(TransportConstants.LOCAL_PORT_PROP_NAME, binding.getAbsoluteSourcePort());
}
}
tc.getParams().put(HOST, host);
tc.getParams().put(PORT, String.valueOf(port));
}
}
}
if (acceptors != null) {
for (TransportConfiguration tc : acceptors) {
// If there is a socket binding set the HOST/PORT values
Object socketRef = tc.getParams().remove(SOCKET_REF);
if (socketRef != null) {
String name = socketRef.toString();
SocketBinding binding = socketBindings.get(name);
if (binding == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
}
InetSocketAddress socketAddress = binding.getSocketAddress();
tc.getParams().put(HOST, socketAddress.getAddress().getHostAddress());
tc.getParams().put(PORT, "" + socketAddress.getPort());
}
}
}