use of org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration in project spring-integration by spring-projects.
the class XmppConnectionFactoryBean method createInstance.
@Override
protected XMPPConnection createInstance() throws Exception {
XMPPTCPConnectionConfiguration connectionConfiguration = this.connectionConfiguration;
if (this.connectionConfiguration == null) {
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder().setHost(this.host).setPort(this.port);
if (StringUtils.hasText(this.resource)) {
builder.setResource(this.resource);
}
if (StringUtils.hasText(this.serviceName)) {
builder.setUsernameAndPassword(this.user, this.password).setXmppDomain(this.serviceName);
} else {
builder.setUsernameAndPassword(XmppStringUtils.parseLocalpart(this.user), this.password).setXmppDomain(this.user);
}
connectionConfiguration = builder.build();
}
return new XMPPTCPConnection(connectionConfiguration);
}
use of org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration in project Smack by igniterealtime.
the class IoT method iotScenario.
public static void iotScenario(String dataThingJidString, String dataThingPassword, String readingThingJidString, String readingThingPassword, IotScenario scenario) throws Exception {
final EntityBareJid dataThingJid = JidCreate.entityBareFrom(dataThingJidString);
final EntityBareJid readingThingJid = JidCreate.entityBareFrom(readingThingJidString);
final XMPPTCPConnectionConfiguration dataThingConnectionConfiguration = XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword(dataThingJid.getLocalpart(), dataThingPassword).setXmppDomain(dataThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled).enableDefaultDebugger().build();
final XMPPTCPConnectionConfiguration readingThingConnectionConfiguration = XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword(readingThingJid.getLocalpart(), readingThingPassword).setXmppDomain(readingThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled).enableDefaultDebugger().build();
final XMPPTCPConnection dataThingConnection = new XMPPTCPConnection(dataThingConnectionConfiguration);
final XMPPTCPConnection readingThingConnection = new XMPPTCPConnection(readingThingConnectionConfiguration);
dataThingConnection.setReplyTimeout(TIMEOUT);
readingThingConnection.setReplyTimeout(TIMEOUT);
dataThingConnection.setUseStreamManagement(false);
readingThingConnection.setUseStreamManagement(false);
try {
dataThingConnection.connect().login();
readingThingConnection.connect().login();
scenario.iotScenario(dataThingConnection, readingThingConnection);
} finally {
dataThingConnection.disconnect();
readingThingConnection.disconnect();
}
}
use of org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration in project Smack by igniterealtime.
the class DoX method runDoxResolver.
public static XMPPTCPConnection runDoxResolver(String jid, String password) throws XMPPException, SmackException, IOException, InterruptedException {
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder().setXmppAddressAndPassword(jid, password).setResource("dns").setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE).build();
XMPPTCPConnection connection = new XMPPTCPConnection(config);
connection.connect().login();
DnsOverXmppManager dox = DnsOverXmppManager.getInstanceFor(connection);
dox.setDnsOverXmppResolver(DnsOverXmppMiniDnsResolver.INSTANCE);
dox.enable();
return connection;
}
use of org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration in project Spark by igniterealtime.
the class AccountCreationWizard method getConnection.
/**
* Creates an XMPPConnection based on the users settings.
*
* @return the XMPPConnection created.
*/
private XMPPConnection getConnection() throws SmackException, IOException, XMPPException {
final LocalPreferences localPreferences = SettingsManager.getLocalPreferences();
int port = localPreferences.getXmppPort();
String serverName = getServer();
int checkForPort = serverName.indexOf(":");
if (checkForPort != -1) {
String portString = serverName.substring(checkForPort + 1);
if (ModelUtil.hasLength(portString)) {
// Set new port.
port = Integer.valueOf(portString);
}
}
ConnectionConfiguration.SecurityMode securityMode = localPreferences.getSecurityMode();
boolean useOldSSL = localPreferences.isSSL();
boolean hostPortConfigured = localPreferences.isHostAndPortConfigured();
final XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword("username", "password").setServiceName(serverName).setPort(port).setCompressionEnabled(localPreferences.isCompressionEnabled()).setSecurityMode(securityMode);
if (hostPortConfigured) {
builder.setHost(localPreferences.getXmppHost());
}
if (securityMode != ConnectionConfiguration.SecurityMode.disabled && !useOldSSL) {
// plain connections which is 5222.
try {
SSLContext context = SparkSSLContext.setUpContext(SparkSSLContext.Options.ONLY_SERVER_SIDE);
builder.setCustomSSLContext(context);
builder.setSecurityMode(securityMode);
} catch (NoSuchAlgorithmException | KeyManagementException | UnrecoverableKeyException | KeyStoreException | NoSuchProviderException e) {
Log.warning("Couldnt establish secured connection", e);
}
}
if (securityMode != ConnectionConfiguration.SecurityMode.disabled && useOldSSL) {
if (!hostPortConfigured) {
// SMACK 4.1.9 does not support XEP-0368, and does not apply a port change, if the host is not changed too.
// Here, we force the host to be set (by doing a DNS lookup), and force the port to 5223 (which is the
// default 'old-style' SSL port).
builder.setHost(DNSUtil.resolveXMPPDomain(serverName, null).get(0).getFQDN());
builder.setPort(5223);
}
builder.setSocketFactory(new SparkSSLSocketFactory(SparkSSLContext.Options.ONLY_SERVER_SIDE));
// SMACK 4.1.9 does not recognize an 'old-style' SSL socket as being secure, which will cause a failure when
// the 'required' Security Mode is defined. Here, we work around this by replacing that security mode with an
// 'if-possible' setting.
builder.setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible);
}
final XMPPTCPConnectionConfiguration configuration = builder.build();
final AbstractXMPPConnection connection = new XMPPTCPConnection(configuration);
connection.setParsingExceptionCallback(new ExceptionLoggingCallback());
connection.connect();
return connection;
}
use of org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration in project structr by structr.
the class XMPPContext method connect.
public static void connect(final XMPPInfo callback) throws FrameworkException {
new Java7SmackInitializer().initialize();
final XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword(callback.getUsername(), callback.getPassword()).setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible).setServiceName(callback.getService()).setHost(callback.getHostName()).setPort(callback.getPort()).build();
try {
final AbstractXMPPConnection connection = new XMPPTCPConnection(config);
connections.put(callback.getUuid(), new StructrXMPPConnection(callback, connection));
connection.connect();
} catch (IOException | SmackException | XMPPException ex) {
logger.warn("", ex);
}
}
Aggregations