Search in sources :

Example 56 with PubSub

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

the class Node method getAffiliations.

private List<Affiliation> getAffiliations(AffiliationNamespace affiliationsNamespace, List<XmlElement> additionalExtensions, Collection<XmlElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSubElementType pubSubElementType = affiliationsNamespace.type;
    PubSub pubSub = createPubsubPacket(IQ.Type.get, new NodeExtension(pubSubElementType, getId()));
    if (additionalExtensions != null) {
        for (XmlElement pe : additionalExtensions) {
            pubSub.addExtension(pe);
        }
    }
    PubSub reply = sendPubsubPacket(pubSub);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(reply.getExtensions());
    }
    AffiliationsExtension affilElem = reply.getExtension(pubSubElementType);
    return affilElem.getAffiliations();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) XmlElement(org.jivesoftware.smack.packet.XmlElement)

Example 57 with PubSub

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

the class Node method subscribe.

/**
 * The user subscribes to the node using the supplied jid.  The
 * bare jid portion of this one must match the jid for the connection.
 *
 * Please note that the {@link Subscription.State} should be checked
 * on return since more actions may be required by the caller.
 * {@link Subscription.State#pending} - The owner must approve the subscription
 * request before messages will be received.
 * {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true,
 * the caller must configure the subscription before messages will be received.  If it is false
 * the caller can configure it but is not required to do so.
 * @param jid The jid to subscribe as.
 * @return The subscription
 * @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 Subscription subscribe(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub pubSub = createPubsubPacket(IQ.Type.set, new SubscribeExtension(jid, getId()));
    PubSub reply = sendPubsubPacket(pubSub);
    return reply.getExtension(PubSubElementType.SUBSCRIPTION);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

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