Search in sources :

Example 26 with XMPPConnection

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);
}
Also used : XMPPConnection(org.jivesoftware.smack.XMPPConnection) IoTUnregister(org.jivesoftware.smackx.iot.discovery.element.IoTUnregister)

Example 27 with XMPPConnection

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);
        }
    });
}
Also used : ConnectionCreationListener(org.jivesoftware.smack.ConnectionCreationListener) XMPPConnection(org.jivesoftware.smack.XMPPConnection) JingleProvider(org.jivesoftware.smackx.jingleold.provider.JingleProvider)

Example 28 with XMPPConnection

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());
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) Close(org.jivesoftware.smackx.bytestreams.ibb.packet.Close) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Test(org.junit.Test)

Example 29 with XMPPConnection

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;
}
Also used : AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 30 with XMPPConnection

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);
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) SmackException(org.jivesoftware.smack.SmackException) XMPPConnection(org.jivesoftware.smack.XMPPConnection) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

XMPPConnection (org.jivesoftware.smack.XMPPConnection)64 XMPPException (org.jivesoftware.smack.XMPPException)14 Message (org.jivesoftware.smack.packet.Message)9 SmackException (org.jivesoftware.smack.SmackException)7 IQ (org.jivesoftware.smack.packet.IQ)7 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 ArrayList (java.util.ArrayList)6 SynchronousQueue (java.util.concurrent.SynchronousQueue)6 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)6 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)6 TimeoutException (java.util.concurrent.TimeoutException)5 StanzaCollector (org.jivesoftware.smack.StanzaCollector)5 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)5 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)5 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)4 ConnectionConfiguration (org.jivesoftware.smack.ConnectionConfiguration)4 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)4 Packet (org.jivesoftware.smack.packet.Packet)4 Jid (org.jxmpp.jid.Jid)4