Package org.jivesoftware.smack

Examples of org.jivesoftware.smack.ConnectionConfiguration


    public 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);
        }
View Full Code Here


        }

        if (connection == null) {
            if (port > 0) {
                if (getServiceName() == null) {
                    connection = new XMPPConnection(new ConnectionConfiguration(host, port));
                } else {
                    connection = new XMPPConnection(new ConnectionConfiguration(host, port, serviceName));
                }
            } else {
                connection = new XMPPConnection(host);
            }
        }
View Full Code Here

        pi = ProxyInfo.forNoProxy();
        break;
    }
   
    String serviceName = desc.getServiceName();
    final ConnectionConfiguration cfg;
    if (serviceName == null) {
      cfg = new ConnectionConfiguration(
          this.hostnameOverride, this.port, pi);
    } else if (this.hostnameOverride == null) {
        // uses DNS lookup, to get the actual hostname for this service:
      cfg = new ConnectionConfiguration(serviceName, pi);
    } else {
      cfg = new ConnectionConfiguration(
          this.hostnameOverride, this.port,
          serviceName, pi);
    }
    // Currently, we handle reconnects ourself.
    // Maybe we should change it in the future, but currently I'm
    // not sure what Smack's reconnect feature really does.
    cfg.setReconnectionAllowed(false);
   
    cfg.setDebuggerEnabled(true);

    if (acceptAllCerts) {
      // TODO Smack 4.1 provides TLSUtil.acceptAllCertificates, replace
      // the code here with the code provided by Smack
      SSLContext context = SSLContext.getInstance("TLS");
      // Install an "accept all" trust manager
      X509TrustManager tm = new X509TrustManager() {
        @Override
        public void checkClientTrusted(X509Certificate[] arg0,
            String arg1) throws CertificateException {
          // Nothing to do here
        }
        @Override
        public void checkServerTrusted(X509Certificate[] arg0,
            String arg1) throws CertificateException {
          // Nothing to do here
        }
        @Override
        public X509Certificate[] getAcceptedIssuers() {
          return new X509Certificate[0];
        }
      };
      context.init(null, new TrustManager[] { tm }, new SecureRandom());
      cfg.setCustomSSLContext(context);
      cfg.setHostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(String arg0, SSLSession arg1) {
          return true;
        }
      });
    } else {
      // TODO This hostname verifier is the default in Smack 4.1 when
      // smack-java7 is used, remove the code once Smack 4.1 is used
      cfg.setHostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
          HostnameChecker checker = HostnameChecker
              .getInstance(HostnameChecker.TYPE_TLS);

          boolean validCertificate = false, validPrincipal = false;
          try {
            Certificate[] peerCertificates = session
                .getPeerCertificates();

            if (peerCertificates.length > 0
                && peerCertificates[0] instanceof X509Certificate) {
              X509Certificate peerCertificate = (X509Certificate) peerCertificates[0];

              try {
                checker.match(hostname, peerCertificate);
                // Certificate matches hostname
                validCertificate = true;
              } catch (CertificateException ex) {
                // Certificate does not match hostname
              }
            } else {
              // Peer does not have any certificates or they
              // aren't X.509
            }
          } catch (SSLPeerUnverifiedException ex) {
            // Not using certificates for peers, try verifying the
            // principal
            try {
              Principal peerPrincipal = session
                  .getPeerPrincipal();
              if (peerPrincipal instanceof KerberosPrincipal) {
                validPrincipal = HostnameChecker.match(
                    hostname,
                    (KerberosPrincipal) peerPrincipal);
              } else {
                // Can't verify principal, not Kerberos
              }
            } catch (SSLPeerUnverifiedException ex2) {
              // Can't verify principal, no principal
            }
          }

          return validCertificate || validPrincipal;
        }
      });
    }

        LOGGER.info("Trying to connect to XMPP on "
                + "/" + cfg.getServiceName()
                + (cfg.isCompressionEnabled() ? " using compression" : "")
                + (pi.getProxyType() != ProxyInfo.ProxyType.NONE ? " via proxy " + pi.getProxyType() + " "
                        + pi.getProxyAddress() + ":" + pi.getProxyPort() : "")
                );

        boolean retryWithLegacySSL = false;
View Full Code Here

        if (logger.isDebugEnabled())
        {
            logger.debug("Connecting to " + host + ":" + port);
        }

        ConnectionConfiguration connectionConfig = null;
        if (serviceName != null)
        {
            connectionConfig = new ConnectionConfiguration(host, port, serviceName);
        }
        else
        {
            connectionConfig = new ConnectionConfiguration(host, port);
        }
        // no need to load the roster (this is not an interactive app)
        connectionConfig.setRosterLoadedAtLogin(false);
       
        connection = new XMPPConnection(connectionConfig);
    }
View Full Code Here

        chats = new HashMap<String, Chat>();
    }

    public void connect(CountDownLatch latch) throws Exception
    {
        ConnectionConfiguration connectionConfig = new ConnectionConfiguration(host);
        // no roster required
        connectionConfig.setRosterLoadedAtLogin(false);
       
        connection = new XMPPConnection(connectionConfig);
        connection.connect();
        if (logger.isDebugEnabled())
        {
View Full Code Here

    private class LoginTask extends Task<Void> {
        public Void execute() throws TaskExecutionException {
            try {
                String domain = domainTextInput.getText();

                ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(domain);
                xmppConnection = new XMPPConnection(connectionConfiguration);

                String username = usernameTextInput.getText();
                String password = passwordTextInput.getText();
                xmppConnection.connect();
View Full Code Here

    this.username = username;
    this.resource = resource;
   
    try {
      // configure and connect
      ConnectionConfiguration connConfig =
          new ConnectionConfiguration(host, port, serviceName);
      conn = new XMPPConnection(connConfig);
      conn.connect();

      // login
      if (resource == null) {
View Full Code Here

    for (String s: to.split(";")) {
      if (s != null && !"".equals(s)) {
        this.toUsers.add(s);
      }
    }
        ConnectionConfiguration conf = new ConnectionConfiguration(server, port , service);
        XMPPConnection connection = null;
        try {

           if(server !=null && !server.equals("") && port != 0){
             connection = new XMPPConnection(conf);
View Full Code Here

          //Listen for Message type packets from specified server url
          packetFilter = new FromContainsFilter(serverCredentials.getServerUrl());         
        }
      } 
    }else if(XMPPConstants.XMPP_SERVER_TYPE_GOOGLETALK.equals(serverCredentials.getServerType())){
      ConnectionConfiguration connectionConfiguration =
        new ConnectionConfiguration(XMPPConstants.GOOGLETALK_URL
          ,XMPPConstants.GOOGLETALK_PORT
          ,XMPPConstants.GOOGLETALK_SERVICE_NAME);       
      xmppConnection = new XMPPConnection(connectionConfiguration);
      try {
        xmppConnection.connect();
View Full Code Here

          //    new FromContainsFilter(serverCredentials.getServerUrl()));
          packetFilter = new FromContainsFilter(serverCredentials.getServerUrl());         
        }
      } 
    }else if(XMPPConstants.XMPP_SERVER_TYPE_GOOGLETALK.equals(serverCredentials.getServerType())){
      ConnectionConfiguration connectionConfiguration =
        new ConnectionConfiguration(XMPPConstants.GOOGLETALK_URL
          ,XMPPConstants.GOOGLETALK_PORT
          ,XMPPConstants.GOOGLETALK_SERVICE_NAME);       
      xmppConnection = new XMPPConnection(connectionConfiguration);
      try {
        xmppConnection.connect();
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.ConnectionConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.