mirror of https://github.com/apache/activemq.git
AMQ-2094. fix break of org.apache.activemq.transport.tcp.SslContextNBrokerServiceTest where localhost and host name resolve to different interfaces as now the broker just listens on one interface unless ip:0.0.0.0 is used. The connectorUri did nore reflect the socket
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@750532 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
212a7904a9
commit
b56cb8f3e2
|
@ -138,7 +138,7 @@ public class TcpTransportServer extends TransportServerThreadSupport implements
|
||||||
throw IOExceptionSupport.create("Failed to bind to server socket: " + bind + " due to: " + e, e);
|
throw IOExceptionSupport.create("Failed to bind to server socket: " + bind + " due to: " + e, e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
setConnectURI(new URI(bind.getScheme(), bind.getUserInfo(), resolveHostName(bind.getHost()), serverSocket.getLocalPort(), bind.getPath(), bind.getQuery(), bind
|
setConnectURI(new URI(bind.getScheme(), bind.getUserInfo(), resolveHostName(serverSocket, addr), serverSocket.getLocalPort(), bind.getPath(), bind.getQuery(), bind
|
||||||
.getFragment()));
|
.getFragment()));
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
|
|
||||||
|
@ -314,15 +314,22 @@ public class TcpTransportServer extends TransportServerThreadSupport implements
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param hostName
|
* @param socket
|
||||||
|
* @param inetAddress
|
||||||
* @return real hostName
|
* @return real hostName
|
||||||
* @throws UnknownHostException
|
* @throws UnknownHostException
|
||||||
*/
|
*/
|
||||||
protected String resolveHostName(String hostName) throws UnknownHostException {
|
protected String resolveHostName(ServerSocket socket, InetAddress bindAddress) throws UnknownHostException {
|
||||||
String result = hostName;
|
String result = null;
|
||||||
// hostname can be null for vm:// protocol ...
|
if (socket.isBound()) {
|
||||||
if (hostName != null && (hostName.equalsIgnoreCase("localhost") || hostName.equals("127.0.0.1"))) {
|
if (socket.getInetAddress().isAnyLocalAddress()) {
|
||||||
|
// make it more human readable and useful, an alternative to 0.0.0.0
|
||||||
result = InetAddress.getLocalHost().getHostName();
|
result = InetAddress.getLocalHost().getHostName();
|
||||||
|
} else {
|
||||||
|
result = socket.getInetAddress().getCanonicalHostName();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = bindAddress.getCanonicalHostName();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,8 @@ public class SslContextNBrokerServiceTest extends TestCase {
|
||||||
context.init(null, new TrustManager[] {catcher}, null);
|
context.init(null, new TrustManager[] {catcher}, null);
|
||||||
|
|
||||||
SSLSocketFactory factory = context.getSocketFactory();
|
SSLSocketFactory factory = context.getSocketFactory();
|
||||||
|
LOG.info("Connecting to broker: " + broker.getBrokerName()
|
||||||
|
+ " on: " + brokerUri.getHost() + ":" + brokerUri.getPort());
|
||||||
SSLSocket socket = (SSLSocket)factory.createSocket(brokerUri.getHost(), brokerUri.getPort());
|
SSLSocket socket = (SSLSocket)factory.createSocket(brokerUri.getHost(), brokerUri.getPort());
|
||||||
socket.setSoTimeout(5000);
|
socket.setSoTimeout(5000);
|
||||||
socket.startHandshake();
|
socket.startHandshake();
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
</amq:sslContext>
|
</amq:sslContext>
|
||||||
|
|
||||||
<amq:transportConnectors>
|
<amq:transportConnectors>
|
||||||
<amq:transportConnector uri="ssl://localhost:62616" />
|
<amq:transportConnector uri="ssl://0.0.0.0:62616" />
|
||||||
</amq:transportConnectors>
|
</amq:transportConnectors>
|
||||||
|
|
||||||
</amq:broker>
|
</amq:broker>
|
||||||
|
|
Loading…
Reference in New Issue