Search in sources :

Example 16 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project camel by apache.

the class XmppPubSubProducer method process.

public void process(Exchange exchange) throws Exception {
    try {
        if (connection == null) {
            connection = endpoint.createConnection();
        }
        // make sure we are connected
        if (!connection.isConnected()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Reconnecting to: " + XmppEndpoint.getConnectionMessage(connection));
            }
            connection.connect();
        }
    } catch (XMPPException e) {
        throw new RuntimeExchangeException("Cannot connect to XMPP Server: " + ((connection != null) ? XmppEndpoint.getConnectionMessage(connection) : endpoint.getHost()), exchange, e);
    }
    try {
        Object body = exchange.getIn().getBody(Object.class);
        if (body instanceof PubSub) {
            PubSub pubsubpacket = (PubSub) body;
            endpoint.getBinding().populateXmppPacket(pubsubpacket, exchange);
            exchange.getIn().setHeader(XmppConstants.DOC_HEADER, pubsubpacket);
            connection.sendPacket(pubsubpacket);
        } else {
            throw new Exception("Message does not contain a pubsub packet");
        }
    } catch (XMPPException xmppe) {
        throw new RuntimeExchangeException("Cannot send XMPP pubsub: from " + endpoint.getUser() + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
    } catch (Exception e) {
        throw new RuntimeExchangeException("Cannot send XMPP pubsub: from " + endpoint.getUser() + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, e);
    }
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) RuntimeExchangeException(org.apache.camel.RuntimeExchangeException) XMPPException(org.jivesoftware.smack.XMPPException) RuntimeExchangeException(org.apache.camel.RuntimeExchangeException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 17 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 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public Subscription subscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub pubSub = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
    PubSub reply = sendPubsubPacket(pubSub);
    return reply.getExtension(PubSubElementType.SUBSCRIPTION);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 18 with PubSub

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

the class Node method sendConfigurationForm.

/**
     * Update the configuration with the contents of the new {@link Form}.
     * 
     * @param submitForm
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public void sendConfigurationForm(Form submitForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub packet = createPubsubPacket(Type.set, new FormNode(FormNodeType.CONFIGURE_OWNER, getId(), submitForm), PubSubNamespace.OWNER);
    pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 19 with PubSub

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

the class PubSubManager method getAffiliations.

/**
     * Gets the affiliations on the root node.
     * 
     * @return List of affiliations
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     * 
     */
public List<Affiliation> getAffiliations() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS), null);
    AffiliationsExtension listElem = reply.getExtension(PubSubElementType.AFFILIATIONS);
    return listElem.getAffiliations();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 20 with PubSub

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

the class PubSubManager method createNode.

/**
     * Creates a node with specified configuration.
     * 
     * Note: This is the only way to create a collection node.
     * 
     * @param nodeId The name of the node, which must be unique within the 
     * pubsub service
     * @param config The configuration for the node
     * @return The node that was created
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public Node createNode(String nodeId, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub request = PubSub.createPubsubPacket(pubSubService, Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId), null);
    boolean isLeafNode = true;
    if (config != null) {
        request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
        FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());
        if (nodeTypeField != null)
            isLeafNode = nodeTypeField.getValues().get(0).equals(NodeType.leaf.toString());
    }
    // Errors will cause exceptions in getReply, so it only returns
    // on success.
    sendPubsubPacket(request);
    Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId);
    nodeMap.put(newNode.getId(), newNode);
    return newNode;
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) FormField(org.jivesoftware.smackx.xdata.FormField)

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