}
// Implementation methods
// -------------------------------------------------------------------------
protected XMPPConnection createConnection() throws XMPPException {
XMPPConnection connection;
if (port > 0) {
if (getServiceName() == null) {
connection = new XMPPConnection(new ConnectionConfiguration(host, port));
} else {
connection = new XMPPConnection(new ConnectionConfiguration(host, port, getServiceName()));
}
} else {
connection = new XMPPConnection(host);
}
connection.connect();
if (login && !connection.isAuthenticated()) {
if (user != null) {
LOG.info("Logging in to XMPP as user: " + user + " on connection: " + connection);
if (password == null) {
LOG.warn("No password configured for user: " + user);
}
if (createAccount) {
AccountManager accountManager = new AccountManager(connection);
accountManager.createAccount(user, password);
}
if (resource != null) {
connection.login(user, password, resource);
} else {
connection.login(user, password);
}
} else {
LOG.info("Logging in anonymously to XMPP on connection: " + connection);
connection.loginAnonymously();
}
// presence is not needed to be sent after login
}
return connection;