Search in sources :

Example 31 with PubSub

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

the class PubSubProviderTest method subscriptionsOwnerResultTest.

@Test
public void subscriptionsOwnerResultTest() throws Exception {
    // @formatter:off
    final String resultStanza = "<iq from='pubsub.example.org' to='julia@example.org/Smack' id='HaT4m-13' type='result'>" + "<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>" + "<subscriptions node='test'>" + "<subscription jid='foo@example.org/Smack' subscription='subscribed' subid='58C1A6F99F2A7'/>" + "<subscription jid='julia@example.org/Smack' subscription='subscribed' subid='58C18F8917321'/>" + "</subscriptions>" + "</pubsub>" + "</iq>";
    // @formatter:on
    XmlPullParser parser = TestUtils.getIQParser(resultStanza);
    PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser);
    SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS_OWNER);
    List<Subscription> subscriptions = subElem.getSubscriptions();
    assertEquals(2, subscriptions.size());
    Subscription sub1 = subscriptions.get(0);
    assertThat("foo@example.org/Smack", equalsCharSequence(sub1.getJid()));
    assertEquals(Subscription.State.subscribed, sub1.getState());
    assertEquals("58C1A6F99F2A7", sub1.getId());
    Subscription sub2 = subscriptions.get(1);
    assertThat("julia@example.org/Smack", equalsCharSequence(sub2.getJid()));
    assertEquals(Subscription.State.subscribed, sub2.getState());
    assertEquals("58C18F8917321", sub2.getId());
}
Also used : SubscriptionsExtension(org.jivesoftware.smackx.pubsub.SubscriptionsExtension) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Subscription(org.jivesoftware.smackx.pubsub.Subscription) Test(org.junit.jupiter.api.Test)

Example 32 with PubSub

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

the class XmppBinding method extractHeadersFromXmpp.

public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange) {
    Map<String, Object> answer = new HashMap<String, Object>();
    PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
    if (jpe != null && jpe instanceof JivePropertiesExtension) {
        extractHeadersFrom((JivePropertiesExtension) jpe, exchange, answer);
    }
    if (jpe != null && jpe instanceof DefaultPacketExtension) {
        extractHeadersFrom((DefaultPacketExtension) jpe, exchange, answer);
    }
    if (xmppPacket instanceof Message) {
        Message xmppMessage = (Message) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, xmppMessage.getType());
        answer.put(XmppConstants.SUBJECT, xmppMessage.getSubject());
        answer.put(XmppConstants.THREAD_ID, xmppMessage.getThread());
    } else if (xmppPacket instanceof PubSub) {
        PubSub pubsubPacket = (PubSub) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, pubsubPacket.getType());
    }
    answer.put(XmppConstants.FROM, xmppPacket.getFrom());
    answer.put(XmppConstants.PACKET_ID, xmppPacket.getPacketID());
    answer.put(XmppConstants.TO, xmppPacket.getTo());
    return answer;
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) Message(org.jivesoftware.smack.packet.Message) HashMap(java.util.HashMap) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 33 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 34 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 35 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)

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