Search in sources :

Example 56 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class InBandBytestreamRequest method accept.

/**
     * Accepts the In-Band Bytestream open request and returns the session to
     * send/receive data.
     * 
     * @return the session to send/receive data
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
@Override
public InBandBytestreamSession accept() throws NotConnectedException, InterruptedException {
    XMPPConnection connection = this.manager.getConnection();
    // create In-Band Bytestream session and store it
    InBandBytestreamSession ibbSession = new InBandBytestreamSession(connection, this.byteStreamRequest, this.byteStreamRequest.getFrom());
    this.manager.getSessions().put(this.byteStreamRequest.getSessionID(), ibbSession);
    // acknowledge request
    IQ resultIQ = IQ.createResultIQ(this.byteStreamRequest);
    connection.sendStanza(resultIQ);
    return ibbSession;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 57 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class Socks5ByteStreamManagerTest method shouldHaveOneManagerForEveryConnection.

/**
     * Test that {@link Socks5BytestreamManager#getBytestreamManager(XMPPConnection)} returns one
     * bytestream manager for every connection.
     */
@Test
public void shouldHaveOneManagerForEveryConnection() {
    // mock two connections
    XMPPConnection connection1 = mock(XMPPConnection.class);
    XMPPConnection connection2 = mock(XMPPConnection.class);
    /*
         * create service discovery managers for the connections because the
         * ConnectionCreationListener is not called when creating mocked connections
         */
    ServiceDiscoveryManager.getInstanceFor(connection1);
    ServiceDiscoveryManager.getInstanceFor(connection2);
    // get bytestream manager for the first connection twice
    Socks5BytestreamManager conn1ByteStreamManager1 = Socks5BytestreamManager.getBytestreamManager(connection1);
    Socks5BytestreamManager conn1ByteStreamManager2 = Socks5BytestreamManager.getBytestreamManager(connection1);
    // get bytestream manager for second connection
    Socks5BytestreamManager conn2ByteStreamManager1 = Socks5BytestreamManager.getBytestreamManager(connection2);
    // assertions
    assertEquals(conn1ByteStreamManager1, conn1ByteStreamManager2);
    assertNotSame(conn1ByteStreamManager1, conn2ByteStreamManager1);
}
Also used : XMPPConnection(org.jivesoftware.smack.XMPPConnection) Test(org.junit.Test)

Example 58 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class InBandBytestreamManagerTest method shouldHaveOneManagerForEveryConnection.

/**
     * Test that
     * {@link InBandBytestreamManager#getByteStreamManager(XMPPConnection)} returns
     * one bytestream manager for every connection.
     */
@Test
public void shouldHaveOneManagerForEveryConnection() {
    // mock two connections
    XMPPConnection connection1 = mock(XMPPConnection.class);
    XMPPConnection connection2 = mock(XMPPConnection.class);
    // get bytestream manager for the first connection twice
    InBandBytestreamManager conn1ByteStreamManager1 = InBandBytestreamManager.getByteStreamManager(connection1);
    InBandBytestreamManager conn1ByteStreamManager2 = InBandBytestreamManager.getByteStreamManager(connection1);
    // get bytestream manager for second connection
    InBandBytestreamManager conn2ByteStreamManager1 = InBandBytestreamManager.getByteStreamManager(connection2);
    // assertions
    assertEquals(conn1ByteStreamManager1, conn1ByteStreamManager2);
    assertNotSame(conn1ByteStreamManager1, conn2ByteStreamManager1);
}
Also used : XMPPConnection(org.jivesoftware.smack.XMPPConnection) Test(org.junit.Test)

Example 59 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class DataListenerTest method shouldReplyErrorIfSessionIsUnknown.

/**
     * If a data stanza(/packet) of 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 DataListener
    InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
    // get the DataListener from InBandByteStreamManager
    DataListener dataListener = Whitebox.getInternalState(byteStreamManager, DataListener.class);
    DataPacketExtension dpe = new DataPacketExtension("unknownSessionID", 0, "Data");
    Data data = new Data(dpe);
    data.setFrom(initiatorJID);
    data.setTo(targetJID);
    dataListener.handleIQRequest(data);
    // 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 : DataPacketExtension(org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension) IQ(org.jivesoftware.smack.packet.IQ) Data(org.jivesoftware.smackx.bytestreams.ibb.packet.Data) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Test(org.junit.Test)

Example 60 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project xabber-android by redsolution.

the class ConnectionItem method onDisconnect.

/**
     * Called when disconnect should occur.
     *
     * @param connectionThread
     * @return <code>true</code> if connection thread was managed.
     */
private boolean onDisconnect(ConnectionThread connectionThread) {
    XMPPConnection xmppConnection = connectionThread.getXMPPConnection();
    boolean acceptable = isManaged(connectionThread);
    if (xmppConnection == null) {
        LogManager.i(this, "onClose " + acceptable);
    } else {
        LogManager.i(this, "onClose " + xmppConnection.hashCode() + " - " + xmppConnection.getConnectionCounter() + ", " + acceptable);
    }
    ConnectionManager.getInstance().onDisconnect(connectionThread);
    if (acceptable) {
        connectionThread.shutdown();
    }
    return acceptable;
}
Also used : AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

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