powered by Jive Software

Pubsub receive custom payload

I am using smack 4.1.0.

I want to send custom payload while publishing to a pubsub node, which I am doing like following:

public void addItem(String topicId, TopicExtension topicExtension) {

try {

PubSubManager topicManager = new PubSubManager(connection);
LeafNode leafNode = topicManager.getNode(topicId);
PayloadItem topicPayload=new PayloadItem(topicExtension);
leafNode.send(topicPayload);
} catch (SmackException.NoResponseException e) {

e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {

e.printStackTrace();
} catch (SmackException.NotConnectedException e) {

e.printStackTrace();
}

}

and the resultant XML stanza which is being published is following:

At receiving end, I am receiving the message like this:

To handle published items I am handling like this:

PubSubManager topicManager = new PubSubManager(connection);
LeafNode eventNode = topicManager.getNode(“first topic1493009083948”); // harcoded node id for testing
eventNode.addItemEventListener(new ItemEventListener() {

@Override
public void handlePublishedItems(ItemPublishEvent items) {

Log.v(“Received published item”, items.toString());
}

});

But now, how do I convert the published items payload into an actual object? I have my TopicExtension class which implements ExtensionElement.

Please help, as I spent a whole day getting payload data but to vain. My last resort will be using custom XML parser but i am sure there is a better way.Smack Support @Flow @rcollier @CSH @wroot

Hey, stop doing this thing adding other people to the message so everyone will get a notification. Don’t demand attention like that. It’s rude.

1 Like