Move host/port from ConnectionConfiguration to XMPPConnection

There semantic is that they now report the host used to establish the
connection. Therefore BOSHConfiguration needs to hostAddresses for
getURI().
This commit is contained in:
Florian Schmaus 2014-03-18 09:27:45 +01:00
parent 81d49d2f60
commit 44a5408bc0
4 changed files with 22 additions and 35 deletions

View File

@ -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);
}
}

View File

@ -48,8 +48,6 @@ public class ConnectionConfiguration implements Cloneable {
*/
private String serviceName;
private String host;
private int port;
protected List<HostAddress> 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}.

View File

@ -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;
}
/**

View File

@ -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);