use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.
the class PrivacyProviderTest method parsePrivacyList.
@Test
public void parsePrivacyList() throws Exception {
// @formatter:off
final String xmlPrivacyList = "<iq type='result' id='getlist2' to='romeo@example.net/orchard'>" + "<query xmlns='jabber:iq:privacy'>" + "<list name='public'>" + "<item type='jid'" + "value='tybalt@example.com'" + "action='deny'" + "order='1'/>" + "<item action='allow' order='2'/>" + "</list>" + "</query>" + "</iq>";
// @formatter:on
IQ iqPrivacyList = (IQ) PacketParserUtils.parseStanza(xmlPrivacyList);
assertTrue(iqPrivacyList instanceof Privacy);
Privacy privacyList = (Privacy) iqPrivacyList;
List<PrivacyItem> pl = privacyList.getPrivacyList("public");
PrivacyItem first = pl.get(0);
assertEquals(PrivacyItem.Type.jid, first.getType());
assertEquals("tybalt@example.com", first.getValue());
assertEquals(false, first.isAllow());
assertEquals(1, first.getOrder());
PrivacyItem second = pl.get(1);
assertEquals(true, second.isAllow());
assertEquals(2, second.getOrder());
}
use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.
the class RSMSetProviderTest method testRsmSetProvider.
@Test
public void testRsmSetProvider() throws Exception {
// @formatter:off
final String rsmset = "<iq type='get' id='iqget'>" + "<pubsub xmlns='http://jabber.org/protocol/pubsub'>" + "<set xmlns='http://jabber.org/protocol/rsm'>" + "<after>aftervalue</after>" + "<before>beforevalue</before>" + "<count>1</count>" + "<first index='2'>foo@bar.com</first>" + "<index>3</index>" + "<last>lastvalue</last>" + "<max>4</max>" + "</set>" + "</pubsub>" + "</iq>";
// @formatter:on
IQ iqWithRsm = (IQ) PacketParserUtils.parseStanza(rsmset);
RSMSet rsm = (RSMSet) iqWithRsm.getExtension(RSMSet.ELEMENT, RSMSet.NAMESPACE);
assertNotNull(rsm);
assertEquals("aftervalue", rsm.getAfter());
assertEquals("beforevalue", rsm.getBefore());
assertEquals(1, rsm.getCount());
assertEquals(2, rsm.getFirstIndex());
assertEquals("foo@bar.com", rsm.getFirst());
assertEquals(3, rsm.getIndex());
assertEquals("lastvalue", rsm.getLast());
assertEquals(4, rsm.getMax());
}
use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.
the class InBandBytestreamSession method closeByPeer.
/**
* This method is invoked if a request to close the In-Band Bytestream has been received.
*
* @param closeRequest the close request from the remote peer
* @throws NotConnectedException
* @throws InterruptedException
*/
protected void closeByPeer(Close closeRequest) throws NotConnectedException, InterruptedException {
/*
* close streams without flushing them, because stream is already considered closed on the
* remote peers side
*/
this.inputStream.closeInternal();
this.inputStream.cleanup();
this.outputStream.closeInternal(false);
// acknowledge close request
IQ confirmClose = IQ.createResultIQ(closeRequest);
this.connection.sendStanza(confirmClose);
}
use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.
the class Socks5BytestreamManager method replyRejectPacket.
/**
* Responses to the given packet's sender with an XMPP error that a SOCKS5 Bytestream is not
* accepted.
* <p>
* Specified in XEP-65 5.3.1 (Example 13)
* </p>
*
* @param packet Stanza(/Packet) that should be answered with a not-acceptable error
* @throws NotConnectedException
* @throws InterruptedException
*/
protected void replyRejectPacket(IQ packet) throws NotConnectedException, InterruptedException {
XMPPError.Builder xmppError = XMPPError.getBuilder(XMPPError.Condition.not_acceptable);
IQ errorIQ = IQ.createErrorResponse(packet, xmppError);
connection().sendStanza(errorIQ);
}
use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.
the class StreamNegotiator method initiateIncomingStream.
protected final IQ initiateIncomingStream(final XMPPConnection connection, StreamInitiation initiation) throws NoResponseException, XMPPErrorException, NotConnectedException {
final StreamInitiation response = createInitiationAccept(initiation, getNamespaces());
newStreamInitiation(initiation.getFrom(), initiation.getSessionID());
final String eventKey = initiation.getFrom().toString() + '\t' + initiation.getSessionID();
IQ streamMethodInitiation;
try {
streamMethodInitiation = initationSetEvents.performActionAndWaitForEvent(eventKey, connection.getReplyTimeout(), new Callback<NotConnectedException>() {
@Override
public void action() throws NotConnectedException {
try {
connection.sendStanza(response);
} catch (InterruptedException e) {
// Ignore
}
}
});
} catch (InterruptedException e) {
// TODO remove this try/catch once merged into 4.2's master branch
throw new IllegalStateException(e);
}
if (streamMethodInitiation == null) {
throw NoResponseException.newWith(connection, "stream initiation");
}
XMPPErrorException.ifHasErrorThenThrow(streamMethodInitiation);
return streamMethodInitiation;
}
Aggregations