use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.
the class XMPPConnection method connectUsingConfiguration.
private void connectUsingConfiguration(ConnectionConfiguration config) throws XMPPException {
XMPPException exception = null;
Iterator<HostAddress> it = config.getHostAddresses().iterator();
List<HostAddress> failedAddresses = new LinkedList<HostAddress>();
boolean xmppIOError = false;
while (it.hasNext()) {
exception = null;
HostAddress hostAddress = it.next();
String host = hostAddress.getFQDN();
int port = hostAddress.getPort();
try {
if (config.getSocketFactory() == null) {
this.socket = new Socket(host, port);
} else {
this.socket = config.getSocketFactory().createSocket(host, port);
}
} catch (UnknownHostException uhe) {
String errorMessage = "Could not connect to " + host + ":" + port + ".";
exception = new XMPPException(errorMessage, new XMPPError(XMPPError.Condition.remote_server_timeout, errorMessage), uhe);
} catch (IOException ioe) {
String errorMessage = "XMPPError connecting to " + host + ":" + port + ".";
exception = new XMPPException(errorMessage, new XMPPError(XMPPError.Condition.remote_server_error, errorMessage), ioe);
xmppIOError = true;
}
if (exception == null) {
// We found a host to connect to, break here
config.setUsedHostAddress(hostAddress);
break;
}
hostAddress.setException(exception);
failedAddresses.add(hostAddress);
if (!it.hasNext()) {
// There are no more host addresses to try
// throw an exception and report all tried
// HostAddresses in the exception
StringBuilder sb = new StringBuilder();
for (HostAddress fha : failedAddresses) {
sb.append(fha.getErrorMessage());
sb.append("; ");
}
XMPPError xmppError;
if (xmppIOError) {
xmppError = new XMPPError(XMPPError.Condition.remote_server_error);
} else {
xmppError = new XMPPError(XMPPError.Condition.remote_server_timeout);
}
throw new XMPPException(sb.toString(), xmppError);
}
}
socketClosed = false;
initConnection();
}
Aggregations