powered by Jive Software

[asmack] get node subscriptions?

Hi, I know this forum is not about asmack but it seems there is not actual support for it (only thing I know is “rtreffer” compiled asmack-jse-buddycloud-2010.12.11.jar which I am currently using). Hopefully someone here can help me.

I am owner and need to retrieve all the node subscriptions in order to remove all the subscriptions of a specific user.

The problem is that if I use leafnode.getSubscriptions() I just get an empty list.

<iq id="bU563-16" to="pubsub.pongells.local" type="get">
      <pubsub xmlns="http://jabber.org/protocol/pubsub">
            <subscriptions node='test/6Y528AHAb3'/>
<iq type="result" id="bU563-16" from="pubsub.pongells.local" to="test@pongells.local/losha">
      <pubsub xmlns="http://jabber.org/protocol/pubsub">
            <subscriptions node="test/6Y528AHAb3"/>

While if I use leafnode.getAllSubscriptions() I get the subscriptions:

<iq id="bU563-18" to="pubsub.pongells.local" type="get">
      <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
            <subscriptions node='test/6Y528AHAb3'/>
<iq type="result" id="bU563-18" from="pubsub.pongells.local" to="test@pongells.local/losha">
      <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
            <subscriptions node="test/6Y528AHAb3">
                  <subscription jid="ste@pongells.local" subscription="subscribed" subid="F5M2zilXWAIuQRf21cQM7s5FDJYXS41RCzfprwmY"/>
                  <subscription jid="ste@pongells.local" subscription="subscribed" subid="tXcgEA2ss6JTm3F42052XheiVG4K5hrsIt78ey6r"/>

But I also get a NullPointerException:

java.lang.NullPointerException at org.jivesoftware.smackx.pubsub.Node.getAllSubscriptions(Node.java:146)

Is there somebody with a more recent build of asmack? Or does somebody know how to fix this?

(e.g. I don’t even know where to find an up-to-date source code with Node.java)



Woah, found it. Got to go a bit deeper into the Smack code before finding out what was wrong.

It seems the problem was (I was the problem) in SubscriptionProvider… it didn’t parse the Subscription object the right way and since it does an implicit cast (List content, where content is List<? extends PacketExtension> content)… well… long story short I added the wrong ExtensionProvider to the manager…

pm.addExtensionProvider("subscription", PubSubNamespace.BASIC.getXmlns(), new SubscriptionProvider());

is for the normal Subscription (duh, I don’t even get those)… while to make it work with the getAllSubscriptions() method (which adds the #owner to the namespace request) the provider should be added this way:

pm.addExtensionProvider("subscription", PubSubNamespace.OWNER.getXmlns(), new SubscriptionProvider());

It took me 1 afternoon, lol.

Actually, getAllSubscriptions() is still broken.

Since I don’t have the source, I suppose the method is as found here:

http://code.google.com/p/asmack/source/browse/patch/buddycloud/99-PubSubNode-get AllSubscriptions.patch?r=ab16c7aaefd4eab1e5c06933dc4baea86bfcb188

well, it is wrong. line 32 should read:

SubscriptionsExtension subElem = (SubscriptionsExtension)reply.getExtension(PubSubElementType.SUBSCRIPTIONS);

To sum it up what I am using is:

ProviderManager pm = ProviderManager.getInstance();
pm.addExtensionProvider("subscription", PubSubNamespace.OWNER.getXmlns(), new SubscriptionProvider());
pm.addExtensionProvider("subscriptions", "http://jabber.org/protocol/pubsub#owner", new SubscriptionsProvider());

then, extrapolating from the method, to get all the subscriptions you do:

PubSub request = new PubSub();
request.addExtension(new NodeExtension(PubSubElementType.SUBSCRIPTIONS_OWNER, node.getId()));
PubSub reply = (PubSub) SyncPacketSend.getReply(conn, request); SubscriptionsExtension subElem = (SubscriptionsExtension)reply.getExtension(PubSubElementType.SUBSCRIPTIONS); List<Subscription> list = subElem.getSubscriptions(); for (Subscription sub : list) {

Hope it helps.

1 Like

Thx for the solution! help very much.:smiley: