diff --git a/bosh/src/main/java/org/jivesoftware/smack/BOSHConfiguration.java b/bosh/src/main/java/org/jivesoftware/smack/BOSHConfiguration.java index 386c3b082..6adcd0331 100644 --- a/bosh/src/main/java/org/jivesoftware/smack/BOSHConfiguration.java +++ b/bosh/src/main/java/org/jivesoftware/smack/BOSHConfiguration.java @@ -22,6 +22,7 @@ import java.net.URISyntaxException; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.proxy.ProxyInfo; +import org.jivesoftware.smack.util.dns.HostAddress; /** * Configuration to use while establishing the connection to the XMPP server via @@ -112,6 +113,9 @@ public class BOSHConfiguration extends ConnectionConfiguration { if (file.charAt(0) != '/') { file = '/' + file; } - return new URI((ssl ? "https://" : "http://") + getHost() + ":" + getPort() + file); + HostAddress hostAddress = hostAddresses.get(0); + String host = hostAddress.getFQDN(); + int port = hostAddress.getPort(); + return new URI((ssl ? "https://" : "http://") + host + ":" + port + file); } } diff --git a/core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java b/core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java index 56bcd1ca1..858c751fa 100644 --- a/core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java +++ b/core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java @@ -48,8 +48,6 @@ public class ConnectionConfiguration implements Cloneable { */ private String serviceName; - private String host; - private int port; protected List hostAddresses; private String keystorePath; @@ -218,32 +216,6 @@ public class ConnectionConfiguration implements Cloneable { return serviceName; } - /** - * Returns the host to use when establishing the connection. The host and port to use - * might have been resolved by a DNS lookup as specified by the XMPP spec (and therefore - * may not match the {@link #getServiceName service name}. - * - * @return the host to use when establishing the connection. - */ - public String getHost() { - return host; - } - - /** - * Returns the port to use when establishing the connection. The host and port to use - * might have been resolved by a DNS lookup as specified by the XMPP spec. - * - * @return the port to use when establishing the connection. - */ - public int getPort() { - return port; - } - - public void setUsedHostAddress(HostAddress hostAddress) { - this.host = hostAddress.getFQDN(); - this.port = hostAddress.getPort(); - } - /** * Returns the TLS security mode used when making the connection. By default, * the mode is {@link SecurityMode#enabled}. diff --git a/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java index 3024e080d..d4fcca44f 100644 --- a/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java +++ b/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java @@ -216,6 +216,16 @@ public abstract class XMPPConnection { private Roster roster; + /** + * The used host to establish the connection to + */ + private String host; + + /** + * The used port to establish the connection to + */ + private int port; + /** * Create an executor to deliver incoming packets to listeners. We'll use a single thread with an unbounded queue. */ @@ -262,20 +272,20 @@ public abstract class XMPPConnection { * Returns the host name of the server where the XMPP server is running. This would be the * IP address of the server or a name that may be resolved by a DNS server. * - * @return the host name of the server where the XMPP server is running. + * @return the host name of the server where the XMPP server is running or null if not yet connected. */ public String getHost() { - return config.getHost(); + return host; } /** * Returns the port number of the XMPP server for this connection. The default port - * for normal connections is 5222. The default port for SSL connections is 5223. + * for normal connections is 5222. * - * @return the port number of the XMPP server. + * @return the port number of the XMPP server or 0 if not yet connected. */ public int getPort() { - return config.getPort(); + return port; } /** diff --git a/tcp/src/main/java/org/jivesoftware/smack/TCPConnection.java b/tcp/src/main/java/org/jivesoftware/smack/TCPConnection.java index 9f9827cf2..d2f4e74ee 100644 --- a/tcp/src/main/java/org/jivesoftware/smack/TCPConnection.java +++ b/tcp/src/main/java/org/jivesoftware/smack/TCPConnection.java @@ -439,7 +439,8 @@ public class TCPConnection extends XMPPConnection { } if (exception == null) { // We found a host to connect to, break here - config.setUsedHostAddress(hostAddress); + host = hostAddress.getFQDN(); + port = hostAddress.getPort(); break; } hostAddress.setException(exception);