Search in sources :

Example 21 with PubSub

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

the class LeafNode method getItems.

/**
     * Get items persisted on the node.
     * <p>
     * {@code additionalExtensions} can be used e.g. to add a "Result Set Management" extension.
     * {@code returnedExtensions} will be filled with the stanza(/packet) extensions found in the answer.
     * </p>
     * 
     * @param additionalExtensions additional {@code PacketExtensions} to be added to the request.
     *        This is an optional argument, if provided as null no extensions will be added.
     * @param returnedExtensions a collection that will be filled with the returned packet
     *        extensions. This is an optional argument, if provided as null it won't be populated.
     * @return List of {@link Item}
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException 
     */
public <T extends Item> List<T> getItems(List<ExtensionElement> additionalExtensions, List<ExtensionElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId()));
    request.addExtensions(additionalExtensions);
    return getItems(request, returnedExtensions);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 22 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<ExtensionElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub result = pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
    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 23 with PubSub

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

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 XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     * 
     */
public void send() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId()));
    pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 24 with PubSub

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

the class PubSubProvider method parse.

@Override
public PubSub parse(XmlPullParser parser, int initialDepth) throws Exception {
    String namespace = parser.getNamespace();
    PubSubNamespace pubSubNamespace = PubSubNamespace.valueOfFromXmlns(namespace);
    PubSub pubsub = new PubSub(pubSubNamespace);
    outerloop: while (true) {
        int eventType = parser.next();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                PacketParserUtils.addExtensionElement(pubsub, parser);
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return pubsub;
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) PubSubNamespace(org.jivesoftware.smackx.pubsub.packet.PubSubNamespace)

Example 25 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)

Aggregations

PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)25 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ThreadedDummyConnection (org.jivesoftware.smack.ThreadedDummyConnection)2 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)2 HashMap (java.util.HashMap)1 List (java.util.List)1 RuntimeExchangeException (org.apache.camel.RuntimeExchangeException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 DefaultPacketExtension (org.jivesoftware.smack.packet.DefaultPacketExtension)1 Message (org.jivesoftware.smack.packet.Message)1 PacketExtension (org.jivesoftware.smack.packet.PacketExtension)1 Stanza (org.jivesoftware.smack.packet.Stanza)1 XMPPError (org.jivesoftware.smack.packet.XMPPError)1 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)1 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)1 JivePropertiesExtension (org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)1 Subscription (org.jivesoftware.smackx.pubsub.Subscription)1 SubscriptionsExtension (org.jivesoftware.smackx.pubsub.SubscriptionsExtension)1