use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.
the class IoTDiscoveryManager method unregister.
public void unregister(Jid registry, NodeInfo nodeInfo) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
interactWithRegistry(registry);
IoTUnregister iotUnregister = new IoTUnregister(nodeInfo);
iotUnregister.setTo(registry);
connection().createStanzaCollectorAndSend(iotUnregister).nextResultOrThrow();
ThingState state = getStateFor(nodeInfo);
state.setUnregistered();
final XMPPConnection connection = connection();
IoTDataManager.getInstanceFor(connection).uninstallThing(nodeInfo);
IoTControlManager.getInstanceFor(connection).uninstallThing(nodeInfo);
}
use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.
the class JingleManager method setJingleServiceEnabled.
/**
* Setup the jingle system to let the remote clients know we support Jingle.
* (This used to be a static part of construction. The problem is a remote client might
* attempt a Jingle connection to us after we've created an XMPPConnection, but before we've
* setup an instance of a JingleManager. We will appear to not support Jingle. With the new
* method you just call it once and all new connections will report Jingle support.)
*/
public static void setJingleServiceEnabled() {
ProviderManager.addIQProvider("jingle", "urn:xmpp:tmp:jingle", new JingleProvider());
// Enable the Jingle support on every established connection
// The ServiceDiscoveryManager class should have been already
// initialized
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) {
JingleManager.setServiceEnabled(connection, true);
}
});
}
use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.
the class CloseListenerTest method shouldReplyErrorIfSessionIsUnknown.
/**
* If a close request to an unknown session is received it should be replied
* with an <item-not-found/> error.
*
* @throws Exception should not happen
*/
@Test
public void shouldReplyErrorIfSessionIsUnknown() throws Exception {
// mock connection
XMPPConnection connection = mock(XMPPConnection.class);
// initialize InBandBytestreamManager to get the CloseListener
InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
// get the CloseListener from InBandByteStreamManager
CloseListener closeListener = Whitebox.getInternalState(byteStreamManager, CloseListener.class);
Close close = new Close("unknownSessionId");
close.setFrom(initiatorJID);
close.setTo(targetJID);
closeListener.handleIQRequest(close);
// wait because packet is processed in an extra thread
Thread.sleep(200);
// capture reply to the In-Band Bytestream close request
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct error packet
assertEquals(initiatorJID, argument.getValue().getTo());
assertEquals(IQ.Type.error, argument.getValue().getType());
assertEquals(XMPPError.Condition.item_not_found, argument.getValue().getError().getCondition());
}
use of org.jivesoftware.smack.XMPPConnection in project xabber-android by redsolution.
the class ConnectionItem method getRealJid.
/**
* Returns real full jid, that was assigned while login.
*
* @return <code>null</code> if connection is not established.
*/
public String getRealJid() {
ConnectionThread connectionThread = getConnectionThread();
if (connectionThread == null) {
return null;
}
XMPPConnection xmppConnection = connectionThread.getXMPPConnection();
if (xmppConnection == null) {
return null;
}
String user = xmppConnection.getUser();
if (user == null) {
return null;
}
return user;
}
use of org.jivesoftware.smack.XMPPConnection in project xabber-android by redsolution.
the class ConnectionManager method sendStanza.
/**
* Send stanza to authenticated connection.
*
* @param account
* @param stanza
*/
public void sendStanza(String account, Stanza stanza) throws NetworkException {
ConnectionThread connectionThread = null;
for (ConnectionThread check : managedConnections) {
if (check.getConnectionItem() instanceof AccountItem && ((AccountItem) check.getConnectionItem()).getAccount().equals(account)) {
connectionThread = check;
break;
}
}
if (connectionThread == null || !connectionThread.getConnectionItem().getState().isConnected()) {
throw new NetworkException(R.string.NOT_CONNECTED);
}
XMPPConnection xmppConnection = connectionThread.getXMPPConnection();
try {
xmppConnection.sendStanza(stanza);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
throw new NetworkException(R.string.XMPP_EXCEPTION);
}
}
Aggregations