Java 类org.jivesoftware.smack.ConnectionConfiguration.SecurityMode 实例源码

项目:java-for-playwrights    文件:XMPPWithIQProtocol.java   
public XMPPWithIQProtocol(String ipAddress, int port, String user,
        String password) throws XMPPException {

    // Connect:
    config = new ConnectionConfiguration(ipAddress, port);
    config.setSASLAuthenticationEnabled(false);
       config.setSecurityMode(SecurityMode.disabled);

       connection = new XMPPConnection(config);
       connection.connect();

       // Login:
       connection.login(user, password, "root");

       // Add IQ provider:
       ProviderManager.getInstance().addIQProvider("query", "iq:myOwn", new MyIQProvider());
}
项目:myrobotlab    文件:Xmpp.java   
public void connect(String hostname, int port, String username, String password) throws Exception {

    purgeTask("reconnect");

    this.hostname = hostname;
    this.serviceName = hostname;
    this.port = port;
    this.username = username;
    this.password = password;

    Builder builder = XMPPTCPConnectionConfiguration.builder();
    builder.setUsernameAndPassword(username, password);
    builder.setServiceName(serviceName);
    builder.setServiceName(hostname);
    builder.setPort(port);
    builder.setSecurityMode(SecurityMode.disabled);
    builder.setDebuggerEnabled(true);

    XMPPTCPConnectionConfiguration config = builder.build();

    connection = new XMPPTCPConnection(config);
    connection.connect().login();

    roster = Roster.getInstanceFor(connection);
    chatManager = ChatManager.getInstanceFor(connection);

    roster.addRosterListener(this);

    isConnected = true;

    // not worth it - always empty right after connect
    // getContactList();

    broadcastState();
  }
项目:Chatting-App-    文件:KontalkConnection.java   
public KontalkConnection(EndpointServer server,
        PrivateKey privateKey, X509Certificate bridgeCert,
        boolean acceptAnyCertificate, KeyStore trustStore) throws XMPPException {

    super(new AndroidConnectionConfiguration
            (server.getHost(),
             server.getPort(),
             server.getNetwork()));

    mServer = server;
    // disable reconnection
    config.setReconnectionAllowed(false);
    // we don't need the roster
    config.setRosterLoadedAtLogin(false);
    // enable compression
    config.setCompressionEnabled(true);
    // enable encryption
    config.setSecurityMode(SecurityMode.enabled);
    // we will send a custom presence
    config.setSendPresence(false);

    setupSSL(privateKey, bridgeCert, acceptAnyCertificate, trustStore);
}
项目:openxface-android    文件:XConnectionManager.java   
/**
 * 通过主机名和端口号去对服务器进行连接和一些初始化
 */
private void initConnect() {
    if (!isConnected()) {
        String connectionHost = mNotificationService.getHost();
        int connectionPort = Integer.parseInt(mNotificationService
                .getPort());
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                connectionHost, connectionPort);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);
        mConnection = new XMPPConnection(connConfig);
        try {
            mConnection.connect();
            ProviderManager.getInstance().addIQProvider(ELEMENT_NAME,
                    NAME_SPACE, new NotificationIQProvider());
        } catch (XMPPException e) {
            startReconnection();
        }
    }
}
项目:androidpn-client    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");
    boolean connected = false;
    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());
            connected = true;

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        if (connected) {
            xmppManager.runTask();
        }

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:Smack    文件:XMPPTCPConnection.java   
@Override
protected void afterFeaturesReceived() throws SecurityRequiredException, NotConnectedException {
    StartTls startTlsFeature = getFeature(StartTls.ELEMENT, StartTls.NAMESPACE);
    if (startTlsFeature != null) {
        if (startTlsFeature.required() && config.getSecurityMode() == SecurityMode.disabled) {
            notifyConnectionError(new SecurityRequiredByServerException());
            return;
        }
        // 发送StartTLS的封包
        // 让我们进入TLS链接
        if (config.getSecurityMode() != ConnectionConfiguration.SecurityMode.disabled) {
            send(new StartTls());
        }
    }
    // If TLS is required but the server doesn't offer it, disconnect
    // from the server and throw an error. First check if we've already negotiated TLS
    // and are secure, however (features get parsed a second time after TLS is established).
    if (!isSecureConnection() && startTlsFeature == null
                    && getConfiguration().getSecurityMode() == SecurityMode.required) {
        throw new SecurityRequiredByClientException();
    }

    if (getSASLAuthentication().authenticationSuccessful()) {
        // If we have received features after the SASL has been successfully completed, then we
        // have also *maybe* received, as it is an optional feature, the compression feature
        // from the server.
        maybeCompressFeaturesReceived.reportSuccess();
    }
}
项目:MessagePushClient    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:androidpn_enhanced_client    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());
            xmppManager.runTask();
        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
            xmppManager.dropTask(2);
            xmppManager.startReconnectionThread();
            xmppManager.runTask();
        }
    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:ShoppingMall    文件:XmppManager.java   
public void run() {

            if (!xmppManager.isConnected()) {
                // Create the configuration for this new connection
                ConnectionConfiguration connConfig = new ConnectionConfiguration(xmppHost, xmppPort);
                // connConfig.setSecurityMode(SecurityMode.disabled);
                // connConfig.setSecurityMode(SecurityMode.required);
                connConfig.setSASLAuthenticationEnabled(false);
                connConfig.setCompressionEnabled(false);
                connConfig.setSecurityMode(SecurityMode.disabled);

                XMPPConnection connection = new XMPPConnection(connConfig);
                xmppManager.setConnection(connection);

                try {
                    // Connect to the server
                    connection.connect();

                    // packet provider
                    ProviderManager.getInstance().addIQProvider("notification", "androidpn:iq:notification", new NotificationIQProvider());
                    reconnection.waiting = 0;
                    reconnection.needWork.set(false);
                } catch (XMPPException e) {
                    e.printStackTrace();
                }

                xmppManager.runTask();

            } else {
                xmppManager.runTask();
            }
        }
项目:FastOmiai    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:androidclient    文件:XMPPTCPConnection.java   
@Override
protected void afterFeaturesReceived() throws NotConnectedException, InterruptedException {
    StartTls startTlsFeature = getFeature(StartTls.ELEMENT, StartTls.NAMESPACE);
    if (startTlsFeature != null) {
        if (startTlsFeature.required() && config.getSecurityMode() == SecurityMode.disabled) {
            SmackException smackException = new SecurityRequiredByServerException();
            tlsHandled.reportFailure(smackException);
            notifyConnectionError(smackException);
            return;
        }

        if (config.getSecurityMode() != ConnectionConfiguration.SecurityMode.disabled) {
            sendNonza(new StartTls());
        } else {
            tlsHandled.reportSuccess();
        }
    } else {
        tlsHandled.reportSuccess();
    }

    if (getSASLAuthentication().authenticationSuccessful()) {
        // If we have received features after the SASL has been successfully completed, then we
        // have also *maybe* received, as it is an optional feature, the compression feature
        // from the server.
        maybeCompressFeaturesReceived.reportSuccess();
    }
}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!XmppManager.isConnected(xmppManager)) {

        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        XmppManager.setXMPPConnection(xmppManager, connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        XmppManager.runTask(xmppManager);

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        XmppManager.runTask(xmppManager);
    }

}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!XmppManager.isConnected(xmppManager)) {

        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        XmppManager.setXMPPConnection(xmppManager, connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        XmppManager.runTask(xmppManager);

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        XmppManager.runTask(xmppManager);
    }

}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!XmppManager.isConnected(xmppManager)) {

        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        XmppManager.setXMPPConnection(xmppManager, connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        XmppManager.runTask(xmppManager);

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        XmppManager.runTask(xmppManager);
    }

}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!XmppManager.isConnected(xmppManager)) {

        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        XmppManager.setXMPPConnection(xmppManager, connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        XmppManager.runTask(xmppManager);

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        XmppManager.runTask(xmppManager);
    }

}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!XmppManager.isConnected(xmppManager)) {

        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        XmppManager.setXMPPConnection(xmppManager, connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        XmppManager.runTask(xmppManager);

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        XmppManager.runTask(xmppManager);
    }

}
项目:Androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:myAndroidpnClient    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
项目:Smack    文件:AbstractXMPPConnection.java   
protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException,
                IOException, SmackException {
    streamFeatures.clear();
    final int initialDepth = parser.getDepth();
    while (true) {
        int eventType = parser.next();

        if (eventType == XmlPullParser.START_TAG && parser.getDepth() == initialDepth + 1) {
            ExtensionElement streamFeature = null;
            String name = parser.getName();
            String namespace = parser.getNamespace();
            switch (name) {
            case StartTls.ELEMENT:
                streamFeature = PacketParserUtils.parseStartTlsFeature(parser);
                break;
            case Mechanisms.ELEMENT:
                streamFeature = new Mechanisms(PacketParserUtils.parseMechanisms(parser));
                break;
            case Bind.ELEMENT:
                streamFeature = Bind.Feature.INSTANCE;
                break;
            case Session.ELEMENT:
                streamFeature = PacketParserUtils.parseSessionFeature(parser);
                break;
            case Compress.Feature.ELEMENT:
                streamFeature = PacketParserUtils.parseCompressionFeature(parser);
                break;
            default:
                ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getStreamFeatureProvider(name, namespace);
                if (provider != null) {
                    streamFeature = provider.parse(parser);
                }
                break;
            }
            if (streamFeature != null) {
                // 将特性放入列表中
                addStreamFeature(streamFeature);
            }
        }
        else if (eventType == XmlPullParser.END_TAG && parser.getDepth() == initialDepth) {
            break;
        }
    }

    if (hasFeature(Mechanisms.ELEMENT, Mechanisms.NAMESPACE)) {
        // Only proceed with SASL auth if TLS is disabled or if the server doesn't announce it
        if (!hasFeature(StartTls.ELEMENT, StartTls.NAMESPACE)
                        || config.getSecurityMode() == SecurityMode.disabled) {
            // connecting算事完成了
            saslFeatureReceived.reportSuccess();
        }
    }

    // If the server reported the bind feature then we are that that we did SASL and maybe
    // STARTTLS. We can then report that the last 'stream:features' have been parsed
    if (hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
        if (!hasFeature(Compress.Feature.ELEMENT, Compress.NAMESPACE)
                        || !config.isCompressionEnabled()) {
            // This was was last features from the server is either it did not contain
            // compression or if we disabled it
            lastFeaturesReceived.reportSuccess();
        }
    }
    afterFeaturesReceived();
}
项目:openhab-hdl    文件:XMPPConnect.java   
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    if (config == null) {
        return;
    }
    XMPPConnect.servername = (String) config.get("servername");
    XMPPConnect.proxy = (String) config.get("proxy");
    String portString = (String) config.get("port");
    if (portString != null) {
        XMPPConnect.port = Integer.valueOf(portString);
    }
    XMPPConnect.username = (String) config.get("username");
    XMPPConnect.password = (String) config.get("password");
    XMPPConnect.chatroom = (String) config.get("chatroom");
    XMPPConnect.chatnickname = (String) config.get("chatnickname");
    XMPPConnect.chatpassword = (String) config.get("chatpassword");

    String securityModeString = (String) config.get("securitymode");
    if (securityModeString != null) {
        securityMode = SecurityMode.valueOf(securityModeString);
    }
    XMPPConnect.tlsPin = (String) config.get("tlspin");

    String users = (String) config.get("consoleusers");

    if (!StringUtils.isEmpty(users)) {
        XMPPConnect.consoleUsers = users.split(",");
    } else {
        XMPPConnect.consoleUsers = new String[0];
    }

    // check mandatory settings
    if (StringUtils.isEmpty(servername)) return;
    if (StringUtils.isEmpty(username)) return;
    if (StringUtils.isEmpty(password)) return;

    // set defaults for optional settings
    if (port == null) {
        port = 5222;
    }
    if (StringUtils.isEmpty(chatnickname)) {
        chatnickname = "openhab-bot";
    }

    establishConnection();
}
项目:androidPN-client.    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        // �˴���Ҫ�޸�һ��bug�����connection.connect();���ɹ��������û��������
        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

            xmppManager.runTask();// ֪ͨ��һ������ȥִ�У��ɹ�ʱִ�У�

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
            // ʧ��ʱ
            xmppManager.dropTask(2);// ��������������
            xmppManager.runTask();// ֪ͨ��һ������ȥִ�У����벻���٣�
            xmppManager.startReconnectionThread();// ֪ͨ����
        }
        // �޸�Դ�룬�ı�ִ��λ��
        // xmppManager.runTask();//֪ͨ��һ������ȥִ��

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();// ֪ͨ��һ������ȥִ��
    }
}
项目:androidclient    文件:KontalkConnection.java   
private static XMPPTCPConnectionConfiguration buildConfiguration(String resource,
    EndpointServer server, boolean secure, PrivateKey privateKey, X509Certificate bridgeCert,
    boolean acceptAnyCertificate, KeyStore trustStore, String legacyAuthToken) throws XmppStringprepException {
    XMPPTCPConnectionConfiguration.Builder builder =
        XMPPTCPConnectionConfiguration.builder();

    String host = server.getHost();
    InetAddress inetAddress = null;
    if (host != null) {
        try {
            inetAddress = InetAddress.getByName(host);
        }
        catch (UnknownHostException e) {
            Log.w(TAG, "unable to resolve host " + host + ", will try again during connect", e);
        }
    }

    builder
        // connection parameters
        .setHostAddress(inetAddress)
        // try a last time through Smack
        .setHost(inetAddress != null ? null : host)
        .setPort(secure ? server.getSecurePort() : server.getPort())
        .setXmppDomain(server.getNetwork())
        .setResource(resource)
        // the dummy value is not actually used
        .setUsernameAndPassword(null, legacyAuthToken != null ? legacyAuthToken : "dummy")
        // for EXTERNAL
        .allowEmptyOrNullUsernames()
        // enable compression
        .setCompressionEnabled(true)
        // enable encryption
        .setSecurityMode(secure ? SecurityMode.disabled : SecurityMode.required)
        // we will send a custom presence
        .setSendPresence(false)
        // disable session initiation
        .setLegacySessionDisabled(true)
        // enable debugging
        .setDebuggerEnabled(Log.isDebug());

    // setup SSL
    setupSSL(builder, secure, privateKey, bridgeCert, acceptAnyCertificate, trustStore);

    return builder.build();
}
项目:dohko    文件:XMPPConnectionConfigurationBuilder.java   
public XMPPConnectionConfigurationBuilder securityMode(SecurityMode mode)
{
    this.securityMode_ = mode;
    return this;
}
项目:msf-spaces-sdk-android    文件:ConnectionHandler.java   
/**
 * Instantiates a connection handler with the given connection configuration and user credentials.
 * @param user XMPP username of the user to log in when connecting to the server.
 * @param password Password of the user to log in.
 * @param connectionConfiguration Connection configuration.
 */
public ConnectionHandler(String user, String password, de.imc.mirror.sdk.ConnectionConfiguration connectionConfiguration){
    this.connectionConfiguration = connectionConfiguration;
    this.password = password;
    listeners = new ArrayList<ConnectionStatusListener>();
    setConnectionStatus(ConnectionStatus.OFFLINE);
    ProviderInitializer.initializeProviderManager();
    org.jivesoftware.smack.ConnectionConfiguration config = 
            new org.jivesoftware.smack.ConnectionConfiguration(connectionConfiguration.getHost(),
                    connectionConfiguration.getPort());
    SecurityMode mode;
    if (connectionConfiguration.isSecureConnection()){
        mode = SecurityMode.required;
    } else {
        mode = SecurityMode.disabled;
    }
    userInfo = new de.imc.mirror.sdk.android.UserInfo(user, 
                                connectionConfiguration.getDomain(), 
                                connectionConfiguration.getApplicationID());
    config.setSecurityMode(mode);
    config.setSelfSignedCertificateEnabled(connectionConfiguration.isSelfSignedCertificateEnabled());
    config.setReconnectionAllowed(true);
    connection = new XMPPConnection(config);

    networkInformation = null;
    pendingIQRequests = new HashMap<String, RequestFuture<Element>>();
    iqPacketListener = new PacketListener() {
        @Override
        public void processPacket(Packet packet) {
            if (pendingIQRequests.containsKey(packet.getPacketID())){
                RequestFuture<Element> iqFuture = pendingIQRequests.get(packet.getPacketID());
                pendingIQRequests.remove(packet.getPacketID());
                SAXBuilder reader = new SAXBuilder();
                Document document = null;
                try {
                    document = reader.build(new StringReader(packet.toXML()));
                } catch (Exception e) {
                    logger.log(Level.WARNING, "Failed to parse incoming IQ packet.", e);
                }
                Element childElement = document.getRootElement();
                if (childElement != null) {
                    iqFuture.setResponse(childElement);
                }
            }
        }
    };
    connection.addPacketListener(iqPacketListener, new PacketTypeFilter(IQ.class));
}
项目:Androidpn    文件:XmppManager.java   
public void run() {

            Log.i(LOGTAG, "ConnectTask.run()...");

            if (!XmppManager.isConnected(xmppManager)) {

                // Create the configuration for this new connection
                ConnectionConfiguration connConfig = new ConnectionConfiguration(
                        xmppHost, xmppPort);
                connConfig.setSecurityMode(SecurityMode.disabled);
                connConfig.setSASLAuthenticationEnabled(false);
                connConfig.setCompressionEnabled(false);

                XMPPConnection connection = new XMPPConnection(connConfig);
                XmppManager.setXMPPConnection(xmppManager, connection);

                try {
                    // Connect to the server
                    connection.connect();
                    Log.i(LOGTAG, "XMPP connected successfully");

                    // packet provider
                    ProviderManager.getInstance().addIQProvider("registration",
                            "androidpn:iq:registration",
                            new RegistrationProvider());
                    ProviderManager.getInstance().addIQProvider("notification",
                            "androidpn:iq:notification",
                            new NotificationProvider());

                } catch (XMPPException e) {
                    Log.e(LOGTAG, "XMPP connection failed", e);
                }

                XmppManager.runTask(xmppManager);

            } else {
                Log.i(LOGTAG, "XMPP connected already");
                XmppManager.runTask(xmppManager);
            }

        }
项目:NewCommunication-Android    文件:XmppManager.java   
public void run() {
            Log.i(LOGTAG, "ConnectTask.run()...");

            if (!xmppManager.isConnected()) {
                // Create the configuration for this new connection
                ConnectionConfiguration connConfig = new ConnectionConfiguration(
                        "10.58.108.201", 5222);

                // connConfig.setSecurityMode(SecurityMode.disabled);
                connConfig.setSecurityMode(SecurityMode.required);
                connConfig.setSASLAuthenticationEnabled(false);
                connConfig.setCompressionEnabled(false);
                connConfig.setDebuggerEnabled(true);
                connConfig.setReconnectionAllowed(true);
                connConfig.setSendPresence(true);

                XMPPConnection connection = new XMPPConnection(connConfig);
                xmppManager.setConnection(connection);

                try {
                    // Connect to the server
                    connection.connect();
                    Log.i(LOGTAG, "XMPP connected successfully");

//                    // packet provider
                    ProviderManager.getInstance().addIQProvider("notification",
                            "androidpn:iq:notification",
                            new NotificationIQProvider());

                    if(mConnectListener != null){
                        mConnectListener.connectSuccess();
                    }

                } catch (XMPPException e) {
                    Log.e(LOGTAG, "XMPP connection failed", e);

                    if(mConnectListener != null){
                        mConnectListener.connectFail();
                    }
                }

                xmppManager.runTask();

            } else {
                Log.i(LOGTAG, "XMPP connected already");
                xmppManager.runTask();
            }
        }
项目:android-demo-xmpp-androidpn    文件:XmppManager.java   
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {       //未连接到XMPP服务器
        // Create the configuration for this new connection
        /**
         * 设置连接的一些参数
         */
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            /** 
             * 这个就是对于通信的xml文本进行解析的解析器,再把信息转换成IQ,这个相当于QQ的聊天信息 
             * 如果要用这个协议,其IQ的子类(NotificationIQ)
             * 和IQProvider的子类(NotificationIQProvider)要进行重写 
             */
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
            running = false;
        }
        //执行任务
        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        //执行任务
        xmppManager.runTask();
    }
}
项目:openhab1-addons    文件:XMPPConnect.java   
@Override
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    if (config == null) {
        return;
    }
    XMPPConnect.servername = (String) config.get("servername");
    XMPPConnect.proxy = (String) config.get("proxy");
    String portString = (String) config.get("port");
    if (portString != null) {
        XMPPConnect.port = Integer.valueOf(portString);
    }
    XMPPConnect.username = (String) config.get("username");
    XMPPConnect.password = (String) config.get("password");
    XMPPConnect.chatroom = (String) config.get("chatroom");
    XMPPConnect.chatnickname = (String) config.get("chatnickname");
    XMPPConnect.chatpassword = (String) config.get("chatpassword");

    String securityModeString = (String) config.get("securitymode");
    if (securityModeString != null) {
        securityMode = SecurityMode.valueOf(securityModeString);
    }
    XMPPConnect.tlsPin = (String) config.get("tlspin");

    String users = (String) config.get("consoleusers");

    if (!StringUtils.isEmpty(users)) {
        XMPPConnect.consoleUsers = users.split(",");
    } else {
        XMPPConnect.consoleUsers = new String[0];
    }

    // check mandatory settings
    if (StringUtils.isEmpty(servername)) {
        return;
    }
    if (StringUtils.isEmpty(username)) {
        return;
    }
    if (StringUtils.isEmpty(password)) {
        return;
    }

    // set defaults for optional settings
    if (port == null) {
        port = 5222;
    }
    if (StringUtils.isEmpty(chatnickname)) {
        chatnickname = "openhab-bot";
    }

    establishConnection();
}
项目:Android_Resource_Controller    文件:XMPPCommunicator.java   
/**
* XMPPClass Constructor
* @param username : XMPP server username
* @param password : XMPP server password
* @param topicName : XMPP main topic name (RC topic name)
* @param Server : XMPP Server name
* @param appContext : The application context
*/
public XMPPCommunicator(String username, String password, String topicName, String Server, Context appContext){

    NodeListeners = new HashMap<String, ItemEventCoordinator>();
    Nodes = new HashMap<String, Node>();

    Username = username;
    Password = password;
    Topic = topicName;
    ctx = appContext;
    flag = true;

    serverName = Server;

    msgPub = new MessagePublisher("XMPP");

    //Init aSmack
    SmackAndroid.init(ctx);

    //Set the reply timeout of asmack in ms to avoid server not responding fast enough if busy
    //SmackConfiguration.setPacketReplyTimeout(10000);

    // XMPP CONNECTION      
    connConfig = new ConnectionConfiguration(serverName,PORT);

    //connConfig.setSASLAuthenticationEnabled(true);
    connConfig.setCompressionEnabled(true);
    connConfig.setSecurityMode(SecurityMode.disabled);
    /*
    //Connection configuration - generates a warning on startup because the truststore path is set to null
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        connConfig.setKeystoreType("AndroidCAStore");
        //connConfig.setKeystorePassword(null);
        connConfig.setKeystorePath(null);
        //connConfig.set
    } else {
        connConfig.setKeystoreType("BKS");
        String path = System.getProperty("javax.net.ssl.trustStore");
        if (path == null)
            path = System.getProperty("java.home") + File.separatorChar + "etc"
                + File.separatorChar + "security" + File.separatorChar
                + "cacerts.bks";
        connConfig.setKeystorePath(path);
    }
    */
    xmpp = new XMPPTCPConnection(connConfig);

}