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;
}
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());
}
};
}
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());
}
};
}
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());
}
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());
}
Aggregations