mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 14:02:06 +01:00
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:
parent
81d49d2f60
commit
44a5408bc0
4 changed files with 22 additions and 35 deletions
|
@ -22,6 +22,7 @@ import java.net.URISyntaxException;
|
||||||
|
|
||||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||||
import org.jivesoftware.smack.proxy.ProxyInfo;
|
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
|
* 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) != '/') {
|
if (file.charAt(0) != '/') {
|
||||||
file = '/' + file;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,6 @@ public class ConnectionConfiguration implements Cloneable {
|
||||||
*/
|
*/
|
||||||
private String serviceName;
|
private String serviceName;
|
||||||
|
|
||||||
private String host;
|
|
||||||
private int port;
|
|
||||||
protected List<HostAddress> hostAddresses;
|
protected List<HostAddress> hostAddresses;
|
||||||
|
|
||||||
private String keystorePath;
|
private String keystorePath;
|
||||||
|
@ -218,32 +216,6 @@ public class ConnectionConfiguration implements Cloneable {
|
||||||
return serviceName;
|
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,
|
* Returns the TLS security mode used when making the connection. By default,
|
||||||
* the mode is {@link SecurityMode#enabled}.
|
* the mode is {@link SecurityMode#enabled}.
|
||||||
|
|
|
@ -216,6 +216,16 @@ public abstract class XMPPConnection {
|
||||||
|
|
||||||
private Roster roster;
|
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.
|
* 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
|
* 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.
|
* 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() {
|
public String getHost() {
|
||||||
return config.getHost();
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the port number of the XMPP server for this connection. The default port
|
* 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() {
|
public int getPort() {
|
||||||
return config.getPort();
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -439,7 +439,8 @@ public class TCPConnection extends XMPPConnection {
|
||||||
}
|
}
|
||||||
if (exception == null) {
|
if (exception == null) {
|
||||||
// We found a host to connect to, break here
|
// We found a host to connect to, break here
|
||||||
config.setUsedHostAddress(hostAddress);
|
host = hostAddress.getFQDN();
|
||||||
|
port = hostAddress.getPort();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
hostAddress.setException(exception);
|
hostAddress.setException(exception);
|
||||||
|
|
Loading…
Reference in a new issue