Search in sources :

Example 26 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class LeafNode method getItems.

@SuppressWarnings("unchecked")
private <T extends Item> List<T> getItems(PubSub request, List<XmlElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub result = pubSubManager.getConnection().sendIqRequestAndWaitForResponse(request);
    ItemsExtension itemsElem = result.getExtension(PubSubElementType.ITEMS);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(result.getExtensions());
    }
    return (List<T>) itemsElem.getItems();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) List(java.util.List) ArrayList(java.util.ArrayList)

Example 27 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class LeafNode method deleteItem.

/**
 * Delete the items with the specified id's from the node.
 *
 * @param itemIds The list of id's of items to delete
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void deleteItem(Collection<String> itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    List<Item> items = new ArrayList<>(itemIds.size());
    for (String id : itemIds) {
        items.add(new Item(id));
    }
    PubSub request = createPubsubPacket(IQ.Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items));
    pubSubManager.getConnection().sendIqRequestAndWaitForResponse(request);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) ArrayList(java.util.ArrayList)

Example 28 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class LeafNode method publish.

/**
 * Publishes an event to the node.  This is an empty event
 * with no item.
 *
 * This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false
 * and {@link ConfigureForm#isDeliverPayloads()}=false.
 *
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void publish() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub packet = createPubsubPacket(IQ.Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId()));
    pubSubManager.getConnection().sendIqRequestAndWaitForResponse(packet);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 29 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class ConfigureFormTest method getConfigFormWithInsufficientPrivileges.

@Test
public void getConfigFormWithInsufficientPrivileges() throws XMPPException, SmackException, IOException, InterruptedException {
    ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
    PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
    DiscoverInfoBuilder info = DiscoverInfo.builder("disco-result").ofType(IQ.Type.result).from(PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
    Identity ident = new Identity("pubsub", null, "leaf");
    info.addIdentity(ident);
    DiscoverInfo discoverInfo = info.build();
    con.addIQReply(discoverInfo);
    Node node = mgr.getNode("princely_musings");
    PubSub errorIq = new PubSub();
    errorIq.setType(IQ.Type.error);
    errorIq.setFrom(PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
    StanzaError error = StanzaError.getBuilder(Condition.forbidden).build();
    errorIq.setError(error);
    con.addIQReply(errorIq);
    try {
        node.getNodeConfiguration();
        fail();
    } catch (XMPPErrorException e) {
        assertEquals(StanzaError.Type.AUTH, e.getStanzaError().getType());
    }
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) DiscoverInfoBuilder(org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity) StanzaError(org.jivesoftware.smack.packet.StanzaError) Test(org.junit.jupiter.api.Test)

Example 30 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class PubSubManagerTest method deleteNodeTest.

@Test
public void deleteNodeTest() throws InterruptedException, SmackException, IOException, XMPPException {
    ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
    PubSubManager mgr = new PubSubManager(con, DUMMY_PUBSUB_SERVICE);
    mgr.deleteNode("foo@bar.org");
    PubSub pubSubDeleteRequest = con.getSentPacket();
    assertEquals("http://jabber.org/protocol/pubsub#owner", pubSubDeleteRequest.getChildElementNamespace());
    assertEquals("pubsub", pubSubDeleteRequest.getChildElementName());
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) Test(org.junit.jupiter.api.Test)

Aggregations

PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)57 ArrayList (java.util.ArrayList)10 List (java.util.List)7 Test (org.junit.jupiter.api.Test)5 ThreadedDummyConnection (org.jivesoftware.smack.ThreadedDummyConnection)4 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)2 PacketExtension (org.jivesoftware.smack.packet.PacketExtension)2 XmlElement (org.jivesoftware.smack.packet.XmlElement)2 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)2 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)2 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)2 PubSubNamespace (org.jivesoftware.smackx.pubsub.packet.PubSubNamespace)2 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)2 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 RuntimeExchangeException (org.apache.camel.RuntimeExchangeException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 DefaultPacketExtension (org.jivesoftware.smack.packet.DefaultPacketExtension)1