Search in sources :

Example 6 with XMPPTCPConnectionConfiguration

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);
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration)

Example 7 with XMPPTCPConnectionConfiguration

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();
    }
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 8 with XMPPTCPConnectionConfiguration

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;
}
Also used : DnsOverXmppManager(org.jivesoftware.smackx.dox.DnsOverXmppManager) XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration)

Example 9 with XMPPTCPConnectionConfiguration

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;
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) SparkSSLSocketFactory(org.jivesoftware.sparkimpl.certificates.SparkSSLSocketFactory) SSLContext(javax.net.ssl.SSLContext) SparkSSLContext(org.jivesoftware.sparkimpl.certificates.SparkSSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) UnrecoverableKeyException(java.security.UnrecoverableKeyException) ExceptionLoggingCallback(org.jivesoftware.smack.parsing.ExceptionLoggingCallback) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) NoSuchProviderException(java.security.NoSuchProviderException)

Example 10 with XMPPTCPConnectionConfiguration

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);
    }
}
Also used : Java7SmackInitializer(org.jivesoftware.smack.java7.Java7SmackInitializer) XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) SmackException(org.jivesoftware.smack.SmackException) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) IOException(java.io.IOException) XMPPException(org.jivesoftware.smack.XMPPException) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Aggregations

XMPPTCPConnectionConfiguration (org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration)12 XMPPTCPConnection (org.jivesoftware.smack.tcp.XMPPTCPConnection)11 SmackException (org.jivesoftware.smack.SmackException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 IOException (java.io.IOException)3 XMPPException (org.jivesoftware.smack.XMPPException)3 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 SSLContext (javax.net.ssl.SSLContext)2 SparkSSLContext (org.jivesoftware.sparkimpl.certificates.SparkSSLContext)2 SparkSSLSocketFactory (org.jivesoftware.sparkimpl.certificates.SparkSSLSocketFactory)2 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)2 Config (com.sun.enterprise.config.serverbeans.Config)1 MessageAcknowledgementEvent (com.yellowmessenger.sdk.events.MessageAcknowledgementEvent)1 XMPPUser (com.yellowmessenger.sdk.models.XMPPUser)1 ChatMessage (com.yellowmessenger.sdk.models.db.ChatMessage)1 CustomSCRAMSHA1Mechanism (com.yellowmessenger.sdk.xmpp.CustomSCRAMSHA1Mechanism)1 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)1