@Override public void run() { Log.i(LOGTAG, "ConnectTask.run()..."); XmppManager xmppManager = getXmppManager(); if (!xmppManager.isConnected()) { ConnectionConfiguration connCfg = new ConnectionConfiguration(xmppManager.getXmppHost(), xmppManager.getXmppPort()); connCfg.setSecurityMode(SecurityMode.required); connCfg.setSASLAuthenticationEnabled(false); connCfg.setCompressionEnabled(false); XMPPConnection connection = new XMPPConnection(connCfg); xmppManager.setConnection(connection); try { connection.connect(); ProviderManager.getInstance() .addIQProvider( "notification", Constants.NOTIFICATION_NAMESPACE, new NotificationIQProvider()); Log.i(LOGTAG, "XMPP connected successfully"); xmppManager.getContext().sendBroadcast(new Intent(Constants.ACTION_CONNECT_SUCCESS)); } catch (XMPPException e) { Log.e(LOGTAG, "XMPP connection failed", e); xmppManager.getContext().sendBroadcast(new Intent(Constants.ACTION_CONNECT_FAIL)); } xmppManager.runTask(); } else { Log.i(LOGTAG, "XMPP connected already"); xmppManager.runTask(); } }
public void prepareSession(String domain) { System.out.printf("Initializing connection to server %1$s:%2$d\n", domain, port); SmackConfiguration.setPacketReplyTimeout(PACKET_REPLY_TIMEOUT); config = new ConnectionConfiguration(domain, port); config.setSASLAuthenticationEnabled(true); config.setSecurityMode(SecurityMode.disabled); }
@Override public synchronized void connect(String username, String password) throws RemoteException { if (isConnected()) { notifyLogin(1, "already connected"); return; } ConnectionConfiguration config = new ConnectionConfiguration(serveraddress, serverPort); config.setCompressionEnabled(true); config.setSASLAuthenticationEnabled(true); try { connection = new XMPPConnection(config); connection.connect(); connection.login(username, password, "smack"); assert connection.isSecureConnection(); notifyLogin(0, "login succeeded"); } catch (XMPPException e) { notifyLogin(-1, "login failed, reason : " + e.getMessage()); } }
@Override public void run() { if (!xmppManager.isConnected() && !xmppManager.isRunning()) { try { xmppManager.setRunning(true); // Create the configuration for this new connection ConnectionConfiguration connConfig = new ConnectionConfiguration(xmppManager.getXmppHost(), xmppManager.getXmppPort()); connConfig.setSecurityMode(SecurityMode.disabled); // connConfig.setSecurityMode(SecurityMode.required); connConfig.setSASLAuthenticationEnabled(false); connConfig.setCompressionEnabled(false); XMPPConnection connection = new XMPPConnection(connConfig); xmppManager.setConnection(connection); // Connect to the server connection.connect(); // packet provider connection.addConnectionListener(xmppManager.getConnectionListener()); ProviderManager.getInstance() .addIQProvider( "notification", "androidpn:iq:notification", xmppManager.getNotificationIQProvider()); Log.i(LOG_TAG, "XMPP connected successfully"); callback.onSuccess(); } catch (Exception e) { Log.e(LOG_TAG, "XMPP connection failed", e); callback.onFailed("XMPP connection failed"); } finally { xmppManager.setRunning(false); } } else { Log.w(LOG_TAG, "XMPP is connected or is running"); callback.onFailed("XMPP is connected or is running"); } }
public String getJid() { try { System.out.println("getJid method executed"); ConnectionConfiguration config = new ConnectionConfiguration(DOMAIN, PORT); config.setSASLAuthenticationEnabled(true); XMPPConnection con = new XMPPConnection(config); con.connect(); System.out.println("Connection ok"); con.login("searchuser", "search"); System.out.println("Logged in"); UserSearchManager search = new UserSearchManager(con); System.out.println("User Search created"); Collection services = search.getSearchServices(); System.out.println("Search Services found:"); Iterator it = services.iterator(); while (it.hasNext()) { System.out.println(it.next()); } Form searchForm = search.getSearchForm("search." + "cuopencomm"); System.out.println("Available search fields:"); Iterator<FormField> fields = searchForm.getFields(); while (fields.hasNext()) { FormField field = fields.next(); System.out.println(field.getVariable() + " : " + field.getType()); } Form answerForm = searchForm.createAnswerForm(); answerForm.setAnswer("search", email); answerForm.setAnswer("Email", true); ReportedData data = search.getSearchResults(answerForm, "search." + "cuopencomm"); System.out.println("\nColumns that are included as part of the search results:"); Iterator<Column> columns = data.getColumns(); while (columns.hasNext()) { System.out.println(columns.next().getVariable()); } System.out.println("\nThe jids and emails from our each of our hits:"); Iterator<Row> rows = data.getRows(); while (rows.hasNext()) { Row row = rows.next(); Iterator<String> jids = row.getValues("jid"); Iterator<String> emails = row.getValues("email"); String jidFound = null; String emailFound = null; while (emails.hasNext() && jids.hasNext()) { jidFound = jids.next(); emailFound = emails.next(); System.out.println(jidFound); System.out.println(emailFound); if (emailFound.equalsIgnoreCase(email)) { jid = jidFound; String[] jidCleaned = jid.split("@"); jid = jidCleaned[0]; System.out.println(jid); } } } con.disconnect(); return jid; } catch (Exception ex) { System.out.println("Caught Exception :" + ex.getMessage()); return jid; } }
/** Constructor for XMPPNotificationManager. */ protected XMPPNotificationManager() { Map<String, String> mdc = Logging.getCopyOfContextMap(); try { mdc.put(Logging.PREFIX_KEY, LOG4J_CATEGORY); // Load up some properties File config = null; try { config = ConfigFileConstants.getFile(ConfigFileConstants.XMPP_CONFIG_FILE_NAME); } catch (IOException e) { LOG.warn("{} not readable", ConfigFileConstants.XMPP_CONFIG_FILE_NAME, e); } if (Boolean.getBoolean("useSystemXMPPConfig") || !config.canRead()) { this.props.putAll(System.getProperties()); } else { FileInputStream fis = null; try { fis = new FileInputStream(config); this.props.load(fis); } catch (FileNotFoundException e) { LOG.warn("unable to load {}", config, e); } catch (IOException e) { LOG.warn("unable to load {}", config, e); } finally { IOUtils.closeQuietly(fis); } } xmppServer = this.props.getProperty("xmpp.server"); String xmppServiceName = this.props.getProperty("xmpp.servicename", xmppServer); xmppUser = this.props.getProperty("xmpp.user"); xmppPassword = this.props.getProperty("xmpp.pass"); xmppPort = Integer.valueOf(this.props.getProperty("xmpp.port", XMPP_PORT)); ConnectionConfiguration xmppConfig = new ConnectionConfiguration(xmppServer, xmppPort, xmppServiceName); boolean debuggerEnabled = Boolean.parseBoolean(props.getProperty("xmpp.debuggerEnabled")); xmppConfig.setDebuggerEnabled(debuggerEnabled); xmppConfig.setSASLAuthenticationEnabled( Boolean.parseBoolean(props.getProperty("xmpp.SASLEnabled", "true"))); xmppConfig.setSelfSignedCertificateEnabled( Boolean.parseBoolean(props.getProperty("xmpp.selfSignedCertificateEnabled"))); if (Boolean.parseBoolean(props.getProperty("xmpp.TLSEnabled"))) { xmppConfig.setSecurityMode(SecurityMode.enabled); } else { xmppConfig.setSecurityMode(SecurityMode.disabled); } if (this.props.containsKey("xmpp.truststorePassword")) { xmppConfig.setTruststorePassword(this.props.getProperty("xmpp.truststorePassword")); } else { xmppConfig.setTruststorePassword(TRUST_STORE_PASSWORD); } LOG.debug("XMPP Manager connection config: {}", xmppConfig.toString()); xmpp = new XMPPConnection(xmppConfig); // Connect to xmpp server connectToServer(); } finally { Logging.setContextMap(mdc); } }
/** Constructor for XMPPNotificationManager. */ protected XMPPNotificationManager() { // get the category logger String oldPrefix = ThreadCategory.getPrefix(); ThreadCategory.setPrefix(LOG4J_CATEGORY); try { // Load up some properties File config = null; try { config = ConfigFileConstants.getFile(ConfigFileConstants.XMPP_CONFIG_FILE_NAME); } catch (IOException e) { log().warn(ConfigFileConstants.XMPP_CONFIG_FILE_NAME + " not readable", e); } if (Boolean.getBoolean("useSystemXMPPConfig") || !config.canRead()) { this.props.putAll(System.getProperties()); } else { FileInputStream fis = null; try { fis = new FileInputStream(config); this.props.load(fis); } catch (FileNotFoundException e) { log().warn("unable to load " + config, e); } catch (IOException e) { log().warn("unable to load " + config, e); } finally { IOUtils.closeQuietly(fis); } } xmppServer = this.props.getProperty("xmpp.server"); xmppServiceName = this.props.getProperty("xmpp.servicename", xmppServer); xmppUser = this.props.getProperty("xmpp.user"); xmppPassword = this.props.getProperty("xmpp.pass"); xmppPort = Integer.valueOf(this.props.getProperty("xmpp.port", XMPP_PORT)); xmppConfig = new ConnectionConfiguration(xmppServer, xmppPort, xmppServiceName); boolean debuggerEnabled = Boolean.parseBoolean(props.getProperty("xmpp.debuggerEnabled")); xmppConfig.setDebuggerEnabled(debuggerEnabled); if (debuggerEnabled) { log().setLevel(ThreadCategory.Level.DEBUG); } xmppConfig.setSASLAuthenticationEnabled( Boolean.parseBoolean(props.getProperty("xmpp.SASLEnabled", "true"))); xmppConfig.setSelfSignedCertificateEnabled( Boolean.parseBoolean(props.getProperty("xmpp.selfSignedCertificateEnabled"))); if (Boolean.parseBoolean(props.getProperty("xmpp.TLSEnabled"))) { xmppConfig.setSecurityMode(SecurityMode.enabled); } else { xmppConfig.setSecurityMode(SecurityMode.disabled); } if (this.props.containsKey("xmpp.truststorePassword")) { xmppConfig.setTruststorePassword(this.props.getProperty("xmpp.truststorePassword")); } else { xmppConfig.setTruststorePassword(TRUST_STORE_PASSWORD); } if (log().isDebugEnabled()) { log().debug("XMPP Manager connection config: " + xmppConfig.toString()); } xmpp = new XMPPConnection(xmppConfig); // Connect to xmpp server connectToServer(); } finally { ThreadCategory.setPrefix(oldPrefix); } }