AnsweredAssumed Answered

Pubsub receive custom payload

Question asked by Deepak on Apr 26, 2017
Latest reply on Apr 26, 2017 by wroot

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<TopicExtension> topicPayload=new PayloadItem<TopicExtension>(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:

 

<iq to='pubsub.celusion.com' id='oa1m9-32' type='set'><pubsub xmlns='http://jabber.org/protocol/pubsub'><publish node='first topic1493009083948'><item><topic xmlns='urn:xmpp:topic' topic_name='first topic' topic_id='first topic1493009083948' topic_message='sample message ' sender_name='Sender name' time_stamp='Now'/></item></publish></pubsub></iq>

 

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

<message to='demo@celusion.com/551e1ae1c3efe924' from='pubsub.celusion.com' type='headline'><event xmlns='http://jabber.org/protocol/pubsub#event'><items node='first topic1493009083948'><item id='5D534FDF4D77D'><topic xmlns='urn:xmpp:topic' topic_name='first topic' topic_id='first topic1493009083948' topic_message='sample message ' sender_name='Sender name' time_stamp='Now'/></item></items></event></message>

 

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

Outcomes