Search in sources :

Example 6 with Open

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Open in project Smack by igniterealtime.

the class InBandBytestreamManager method establishSession.

/**
     * Establishes an In-Band Bytestream with the given user using the given session ID and returns
     * the session to send/receive data to/from the user.
     * 
     * @param targetJID the JID of the user an In-Band Bytestream should be established
     * @param sessionID the session ID for the In-Band Bytestream request
     * @return the session to send/receive data to/from the user
     * @throws XMPPErrorException if the user doesn't support or accept in-band bytestreams, or if the
     *         user prefers smaller block sizes
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
@Override
public InBandBytestreamSession establishSession(Jid targetJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Open byteStreamRequest = new Open(sessionID, this.defaultBlockSize, this.stanza);
    byteStreamRequest.setTo(targetJID);
    // sending packet will throw exception on timeout or error reply
    connection.createStanzaCollectorAndSend(byteStreamRequest).nextResultOrThrow();
    InBandBytestreamSession inBandBytestreamSession = new InBandBytestreamSession(this.connection, byteStreamRequest, targetJID);
    this.sessions.put(sessionID, inBandBytestreamSession);
    return inBandBytestreamSession;
}
Also used : Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open)

Example 7 with Open

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Open in project Smack by igniterealtime.

the class InBandBytestreamSessionMessageTest method setup.

/**
     * Initialize fields used in the tests.
     * @throws XMPPException 
     * @throws SmackException 
     * @throws InterruptedException 
     */
@Before
public void setup() throws XMPPException, SmackException, InterruptedException {
    // build protocol verifier
    protocol = new Protocol();
    // create mocked XMPP connection
    connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID, xmppServer);
    // initialize InBandBytestreamManager to get the InitiationListener
    byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
    // create a In-Band Bytestream open packet with message stanza
    initBytestream = new Open(sessionID, blockSize, StanzaType.MESSAGE);
    initBytestream.setFrom(initiatorJID);
    initBytestream.setTo(targetJID);
    incrementingSequence = new Verification<Message, IQ>() {

        long lastSeq = 0;

        @Override
        public void verify(Message request, IQ response) {
            DataPacketExtension dpe = (DataPacketExtension) request.getExtension(DataPacketExtension.ELEMENT, DataPacketExtension.NAMESPACE);
            assertEquals(lastSeq++, dpe.getSeq());
        }
    };
}
Also used : DataPacketExtension(org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension) Message(org.jivesoftware.smack.packet.Message) IQ(org.jivesoftware.smack.packet.IQ) Protocol(org.jivesoftware.util.Protocol) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open) Before(org.junit.Before)

Example 8 with Open

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Open in project Smack by igniterealtime.

the class InBandBytestreamSessionTest method setup.

/**
     * Initialize fields used in the tests.
     * @throws XMPPException 
     * @throws SmackException 
     * @throws InterruptedException 
     */
@Before
public void setup() throws XMPPException, SmackException, InterruptedException {
    // build protocol verifier
    protocol = new Protocol();
    // create mocked XMPP connection
    connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID, xmppServer);
    // initialize InBandBytestreamManager to get the InitiationListener
    byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
    // create a In-Band Bytestream open packet
    initBytestream = new Open(sessionID, blockSize);
    initBytestream.setFrom(initiatorJID);
    initBytestream.setTo(targetJID);
    incrementingSequence = new Verification<Data, IQ>() {

        long lastSeq = 0;

        @Override
        public void verify(Data request, IQ response) {
            assertEquals(lastSeq++, request.getDataPacketExtension().getSeq());
        }
    };
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) Data(org.jivesoftware.smackx.bytestreams.ibb.packet.Data) Protocol(org.jivesoftware.util.Protocol) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open) Before(org.junit.Before)

Example 9 with Open

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Open in project Smack by igniterealtime.

the class OpenIQProviderTest method shouldCorrectlyParseMessageStanzaAttribute.

@Test
public void shouldCorrectlyParseMessageStanzaAttribute() throws Exception {
    String control = XMLBuilder.create("open").a("xmlns", "http://jabber.org/protocol/ibb").a("block-size", "4096").a("sid", "i781hf64").a("stanza", "message").asString(outputProperties);
    OpenIQProvider oip = new OpenIQProvider();
    Open open = oip.parse(getParser(control));
    assertEquals(StanzaType.MESSAGE, open.getStanza());
}
Also used : Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open) Test(org.junit.Test)

Example 10 with Open

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Open in project Smack by igniterealtime.

the class OpenIQProviderTest method shouldCorrectlyParseIQStanzaAttribute.

@Test
public void shouldCorrectlyParseIQStanzaAttribute() throws Exception {
    String control = XMLBuilder.create("open").a("xmlns", "http://jabber.org/protocol/ibb").a("block-size", "4096").a("sid", "i781hf64").a("stanza", "iq").asString(outputProperties);
    OpenIQProvider oip = new OpenIQProvider();
    Open open = oip.parse(getParser(control));
    assertEquals(StanzaType.IQ, open.getStanza());
}
Also used : Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open) Test(org.junit.Test)

Aggregations

Open (org.jivesoftware.smackx.bytestreams.ibb.packet.Open)10 Before (org.junit.Before)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 IQ (org.jivesoftware.smack.packet.IQ)2 Protocol (org.jivesoftware.util.Protocol)2 Test (org.junit.Test)2 StanzaCollector (org.jivesoftware.smack.StanzaCollector)1 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)1 Message (org.jivesoftware.smack.packet.Message)1 Packet (org.jivesoftware.smack.packet.Packet)1 BytestreamListener (org.jivesoftware.smackx.bytestreams.BytestreamListener)1 StanzaType (org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType)1 Data (org.jivesoftware.smackx.bytestreams.ibb.packet.Data)1 DataPacketExtension (org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension)1