powered by Jive Software

PubSub how to get payload? aSmack 4.0

Hey there,

I am trying to get PubSub to work. I am publishing an item to the node with payload like this:

SimplePayload payload = new SimplePayload("book","pubsub:location",     "<test xmlns='pubsub:test'><time>" + System.currentTimeMillis() + "</time></test>"); PayloadItem payload = new PayloadItem("test" + System.currentTimeMillis(), payload);
node.send(payload);

This works fine. I can also see the payload in the mySQL database.

However I am not able to receive the payload. I am trying to receive the payload like this:

class ItemEventCoordinator  implements ItemEventListener<PayloadItem>
{
    public static final String TAG = "ItemEvent";     @Override
    public void handlePublishedItems(ItemPublishEvent items)
    {
          Log.v(TAG,"Got something from " + items.getNodeId());
          Log.v(TAG,"Item count: " + items.getItems().size());           Object itm = items.getItems().get(0);
          PayloadItem<Item> item = (PayloadItem<Item>) itm;
    }
}

I always get this exception after the logs:

Exception in packet listener
java.lang.ClassCastException: org.jivesoftware.smackx.pubsub.Item cannot be cast to org.jivesoftware.smackx.pubsub.PayloadItem

What is the right way to get the payload from a PubSub node?

I got the info from here https://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions /pubsub.html and I set deliverPayload to true.

Thank you in advance

Unfortunately, since I’m no expert with the PubSub API, all I can say is that the code looks correct (or at least I can’t spot any obvious errors).

I suggest attaching an debugger and tracing the way of the stanza to down to jandlePublishedItems(). From the Exception it appears that it’s not parsed as PayloadItem for whatever reason.

When I log the following

Log.v(TAG,"Item : " + items.getItems().get(0).toString());

I get this result:

org.jivesoftware.smackx.pubsub.Item | Content []

is the payload not sent or why is the content just the item ID?