protected Boolean doInBackground(String... jid) { // Get the XMMPConnection from the manager AbstractXMPPConnection conn = XMPPConnectionManager.getConnection(); // Obtain the PingManager associated with my XMPP connection this.pingManager = PingManager.getInstanceFor(conn); // I do not want background pings but a single foreground ping pingManager.setPingInterval( -1 ); // Do the ping try { return pingManager.ping( jid[0] ); } catch (Exception ex) { Log.w(LOGTAG, "XMPP error " + ex); this.errorMessage = "XMPP error:" + ex ; return false ; } }
protected EntityViewActivity doInBackground(EntityViewActivity... activity) { // Get the XMMPConnection from the manager AbstractXMPPConnection conn = XMPPConnectionManager.getConnection(); // Obtain the ServiceDiscoveryManager associated with my XMPP connection this.discoManager = ServiceDiscoveryManager.getInstanceFor(conn); Entity entity = activity[0].myEntity; try { if ( entity.getNode() != null && entity.getNode() != "" ) { activity[0].myLeafInfo = discoManager.discoverInfo( entity.getJid() , entity.getNode() ); } else { activity[0].myLeafInfo = discoManager.discoverInfo( entity.getJid() ); } Log.d(LOGTAG, "Got Info!"); } catch (Exception ex) { Log.w(LOGTAG, "XMPP Disco error " + ex); errorMessage = ex.toString() ; } return activity[0]; }
@Override public void connect(XmppURI uri, String password) throws IOException, XMPPException, SmackException { this.disconnect(); XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder() .setUsernameAndPassword(uri.getNode(), password) .setServiceName(uri.getDomain()) .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled) .setDebuggerEnabled(true) .build(); AbstractXMPPConnection connection = new XMPPTCPConnection(configuration); connection.connect(); connection.login(); // keep connection alive // when connection is idle it will run into timeout PingManager pingManager = PingManager.getInstanceFor(connection); pingManager.setPingInterval(60); pingManager.pingMyServer(); this.connection = connection; }
@Override public AbstractXMPPConnection getConnection() throws SmackException.NotConnectedException { if (null == this.connection) { logger.warn("Could not get Xmpp Connection, connection was null."); throw new SmackException.NotConnectedException(); } else if (!this.connection.isConnected()) { try { // reconnect if ran into timeout this.connection.connect(); } catch (Exception e) { this.connection = null; logger.error("Could not get Xmpp Connection, failed to reconnect."); throw new SmackException.NotConnectedException(); } } return this.connection; }
@Override public ResourceDocument sendRestDocument(XmppURI uri, ResourceDocument document) throws XMPPException, IOException, SmackException { AbstractXMPPConnection connection = this.connectionManager.getConnection(); // create an set IQ stanza to uri RestIQ setIQ = new RestIQ(uri, document); // send stanza connection.sendStanza(setIQ); // wait for response StanzaFilter filter = new AndFilter(new IQReplyFilter(setIQ, connection)); PacketCollector collector = connection.createPacketCollector(filter); IQ resultIQ = collector.nextResultOrThrow(); if(resultIQ instanceof RestIQ) { // create rest doc return ((RestIQ) resultIQ).getResourceDocument(); } else { throw new SmackException("Wrong RestIQ has been passed"); } }
@Override public ResourceTypeDocument getXwadlDocument(XmppURI uri) throws XMPPException, IOException, SmackException { AbstractXMPPConnection connection = this.connectionManager.getConnection(); // create an get IQ stanza to uri IQ getIQ = new GetXwadlIQ(uri); // send stanza connection.sendStanza(getIQ); // wait for response StanzaFilter filter = new AndFilter(new IQReplyFilter(getIQ, connection)); PacketCollector collector = connection.createPacketCollector(filter); IQ resultIQ = collector.nextResultOrThrow(); if (resultIQ instanceof XwadlIQ) { // create xwadl return ((XwadlIQ) resultIQ).getXwadl(); } else { throw new SmackException("Wrong IQ has been passed"); } }
@Override public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { if (!sampler.getXMPPConnection().isConnected()) { return res; } AbstractXMPPConnection conn = (AbstractXMPPConnection)sampler.getXMPPConnection(); conn.disconnect(); if (sampler.getXMPPConnectionConfig() != null) sampler.getXMPPConnectionConfig().resetConnection(); return res; }
@Override public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { AbstractXMPPConnection conn = (AbstractXMPPConnection)sampler.getXMPPConnection(); conn.connect(); res.setResponseData(sampler.getXMPPConnection().getConnectionID().getBytes()); return res; }
@Override public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { XMPPConnection conn = sampler.getXMPPConnection(); String loginStr = sampler.getPropertyAsString(LOGIN); String pwdStr = sampler.getPropertyAsString(PASSWORD); String resStr = sampler.getPropertyAsString(RESOURCE); res.setSamplerData("Username: " + loginStr + "\nPassword: " + pwdStr + "\nResource: " + resStr); AbstractXMPPConnection absConn = (AbstractXMPPConnection) conn; if (loginStr.isEmpty()) { absConn.loginAnonymously(); } else { absConn.login(loginStr, pwdStr, resStr); } return res; }
@Override protected Boolean doInBackground(ArrayList<Entity>... entityList) { Entity entity = null ; Iterator entityIterator = entityList[0].iterator(); // Get the XMMPConnection from the manager AbstractXMPPConnection conn = XMPPConnectionManager.getConnection(); // Obtain the ServiceDiscoveryManager associated with my XMPP connection this.discoManager = ServiceDiscoveryManager.getInstanceFor(conn); while ( entityIterator.hasNext() ) { if (this.isCancelled()) { Log.d(LOGTAG , "Cancelling" ); return null; } Log.d(LOGTAG , "Loading info for icons" ); entity = (Entity) entityIterator.next(); try { if ( entity.getNode() != null && entity.getNode() != "" ) { entityInfo = discoManager.discoverInfo( entity.getJid() , entity.getNode() ); } else { entityInfo = discoManager.discoverInfo( entity.getJid() ); } } catch (Exception ex) { Log.w(LOGTAG, "XMPP Disco error " + ex); errorMessage = ex.toString() ; this.publishProgress( false ); continue; } entity.setIdentities( entityInfo.getIdentities() ); this.publishProgress( true ); } return null ; }
public static AbstractXMPPConnection getConnection() { if ( XMPPConnectionManager.isConfigured == false ) { Log.w(LOGTAG, "Instating unconfigured connection" ); return null; } if ( XMPPConnectionManager.isConnected == false ) { // Send the configuration // TODO: Yes I know, this is restrictive, DNS must be working XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder(); configBuilder.setUsernameAndPassword( XMPPConnectionManager.xmppUserName, XMPPConnectionManager.xmppPassword); configBuilder.setServiceName( XMPPConnectionManager.xmppUserDomain ); configBuilder.setResource( "FlowsManager" ); XMPPConnectionManager.connection = new XMPPTCPConnection(configBuilder.build()); try { // Create a connection to the XMPP server. XMPPConnectionManager.connection.connect(); // Log into the server XMPPConnectionManager.connection.login(); } catch (Exception ex) { Log.w(LOGTAG, "XMPP Connection error " + ex); return null ; } XMPPConnectionManager.isConnected = true ; } return XMPPConnectionManager.connection ; }
protected CollectionViewActivity doInBackground(CollectionViewActivity... activity) { // Get the XMMPConnection from the manager AbstractXMPPConnection conn = XMPPConnectionManager.getConnection(); // Obtain the ServiceDiscoveryManager associated with my XMPP connection this.discoManager = ServiceDiscoveryManager.getInstanceFor(conn); DiscoverItems discoItems; // This example gets the items associated with online catalog service try { discoItems = this.discoManager.discoverItems( activity[0].currentEntity.getJid() , activity[0].currentEntity.getNode() ); } catch (Exception ex) { Log.w(LOGTAG, "XMPP Disco error " + ex); errorMessage = ex.getMessage() ; return activity[0]; } // Get the discovered items of the queried XMPP entity Iterator it = discoItems.getItems().iterator(); Log.i(LOGTAG, "Got items:" + it.toString()); this.entityList = new ArrayList<>(); this.entityList.clear(); // Display the items of the remote XMPP entity int id = 0; while (it.hasNext()) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); Entity entity = new Entity(item.getEntityID(), item.getNode() , item.getName() ); Log.i(LOGTAG, "Got item:" + item.getName() + " : " + item.getEntityID()); entity.setId(id); entity.setName(item.getName()); this.entityList.add(entity); id++; } Collections.sort(this.entityList); return activity[0]; }
public TestClient(AbstractXMPPConnection connection) throws XMPPErrorException, URISyntaxException, SmackException, XmlException { this.connection = connection; discover(); }
public AbstractXMPPConnection getConnection() { return mConn; }
public void registerAccount(View view) { final EntityBareJid jid = mSettings.getJid(); final String password = mSettings.getPassword(); if (jid == null) { Toast.makeText(this, "Please enter a valid bare JID", Toast.LENGTH_SHORT).show(); return; } if (password.isEmpty()) { Toast.makeText(this, "Please enter a password", Toast.LENGTH_SHORT).show(); return; } (new Thread() { @Override public void run() { if (!ConnectivityManagerUtil.hasDataConnection(InfoAndSettings.this)) { showToast("Data connection not available", Toast.LENGTH_SHORT); return; } try { final Localpart username = jid.getLocalpart(); final AbstractXMPPConnection connection = new XMPPTCPConnection( mSettings.getConnectionConfiguration(InfoAndSettings.this)); showToast("Connecting to server", Toast.LENGTH_SHORT); connection.connect(); AccountManager accountManager = AccountManager.getInstance(connection); showToast("Connected, trying to create account", Toast.LENGTH_SHORT); accountManager.createAccount(username, password); connection.disconnect(); } catch (Exception e) { LOG.i("registerAccount", e); showToast("Error creating account: " + e, Toast.LENGTH_LONG); return; } showToast("Account created", Toast.LENGTH_SHORT); } private final void showToast(final String text, final int duration) { InfoAndSettings.this.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(InfoAndSettings.this, text, duration).show(); } }); } }).start(); }
AbstractXMPPConnection getConnection() throws SmackException.NotConnectedException;