Search in sources :

Example 41 with PubSub

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

the class ConfigureFormTest method getConfigFormWithInsufficientPriviliges.

@Test
public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException, InterruptedException {
    ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
    PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
    DiscoverInfo info = new DiscoverInfo();
    Identity ident = new Identity("pubsub", null, "leaf");
    info.addIdentity(ident);
    con.addIQReply(info);
    Node node = mgr.getNode("princely_musings");
    PubSub errorIq = new PubSub();
    XMPPError.Builder error = XMPPError.getBuilder(Condition.forbidden);
    errorIq.setError(error);
    con.addIQReply(errorIq);
    try {
        node.getNodeConfiguration();
    } catch (XMPPErrorException e) {
        Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().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) XMPPError(org.jivesoftware.smack.packet.XMPPError) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity) Test(org.junit.Test)

Example 42 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project ecf by eclipse.

the class LeafNode method send.

/**
 * Publishes multiple events to the node.  Same rules apply as in {@link #send(Item)}.
 *
 * In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input
 * list will get stored on the node, assuming it stores the last sent item.
 *
 * This is a synchronous call which will throw an exception
 * on failure.
 *
 * For asynchronous calls, use {@link #publish(Collection) publish(Collection))}.
 *
 * @param items - The collection of {@link Item} objects being sent
 *
 * @throws XMPPException
 */
public <T extends Item> void send(Collection<T> items) throws XMPPException {
    PubSub packet = createPubsubPacket(Type.SET, new PublishItem<T>(getId(), items));
    SyncPacketSend.getReply(con, packet);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 43 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project ecf by eclipse.

the class LeafNode method getItems.

/**
 * Get items persisted on the node, limited to the specified number
 * based on the subscription associated with the provided subscriptionId.
 *
 * @param maxItems Maximum number of items to return
 * @param subscriptionId The subscription which the retrieval is based
 * on.
 *
 * @return List of {@link Item}
 *
 * @throws XMPPException
 */
public <T extends Item> List<T> getItems(int maxItems, String subscriptionId) throws XMPPException {
    PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId(), subscriptionId, maxItems));
    PubSub result = (PubSub) SyncPacketSend.getReply(con, request);
    ItemsExtension itemsElem = (ItemsExtension) result.getExtension(PubSubElementType.ITEMS);
    return (List<T>) itemsElem.getItems();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) List(java.util.List) ArrayList(java.util.ArrayList)

Example 44 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project ecf by eclipse.

the class LeafNode method send.

/**
 * 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.
 *
 * This is a synchronous call which will throw an exception
 * on failure.
 *
 * For asynchronous calls, use {@link #publish() publish()}.
 *
 * @throws XMPPException
 */
public void send() throws XMPPException {
    PubSub packet = createPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.PUBLISH, getId()));
    SyncPacketSend.getReply(con, packet);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 45 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project ecf by eclipse.

the class LeafNode method getItems.

/**
 * Get the items specified from the node.  This would typically be
 * used when the server does not return the payload due to size
 * constraints.  The user would be required to retrieve the payload
 * after the items have been retrieved via {@link #getItems()} or an
 * event, that did not include the payload.
 *
 * @param ids Item ids of the items to retrieve
 *
 * @return The list of {@link Item} with payload
 *
 * @throws XMPPException
 */
public <T extends Item> List<T> getItems(Collection<String> ids) throws XMPPException {
    List<Item> itemList = new ArrayList<Item>(ids.size());
    for (String id : ids) {
        itemList.add(new Item(id));
    }
    PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList));
    PubSub result = (PubSub) SyncPacketSend.getReply(con, request);
    ItemsExtension itemsElem = (ItemsExtension) result.getExtension(PubSubElementType.ITEMS);
    return (List<T>) itemsElem.getItems();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

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