class XmppConnectionFactoryBean implements FactoryBean<XMPPTCPConnection>, InitializingBean, DisposableBean {

	@Override
	public void afterPropertiesSet() throws XMPPException, IOException, SmackException {
		XMPPTCPConnectionConfiguration configuration = createConnectionConfiguration(host, port, serviceName);
		Assert.notNull(configuration, "'configuration' must not be null");
		Assert.hasText(username, "'username' must not be empty");
		Assert.hasText(password, "'password' must not be empty");

		connection = new XMPPTCPConnection(configuration);
		try {
			connection.connect();
			if (StringUtils.hasText(resource)) {
				connection.login(username, password, Resourcepart.from(resource));
			} else {
				connection.login(username, password);
			}
		} catch (InterruptedException e) {
			throw new IOException(e);
		}
	}

}