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