AnsweredAssumed Answered

EmbeddedExtensionProvider: How to parse custom stanza

Question asked by Amitoj on Aug 21, 2016
Latest reply on May 6, 2019 by Nischal Manandhar

A part of a new proposed extension, I receive a custom stanza from Ejabberd.

 

<message to='9739937980@gappi.in/Smack' from='191a4c4ae410f104679b8f53db51315eda3@conference.gappi.in'>
    <thread>704af2be-1637-4c23-a292-55617bbfce9e</thread>
    <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='urn:xmpp:mucsub:nodes:messages'>
            <item id='15596740304331624371'>
                <message xmlns='jabber:client' from='191a4c4ae410f104679b8f53db51315eda3@conference.gappi.in/tempnickpubsub' to='9739937980@gappi.in/Smack' type='groupchat' lang='en'>
                    <body xmlns='jabber:client'>{&quot;body&quot;: &quot;Your speech was successfully submitted. You have earned 100 Gappi Points1471755183&quot;, &quot;sender&quot;: &quot;pubsub@gappi.in/sleekxmpp&quot;, &quot;messageCount&quot;: 0, &quot;isMine&quot;: false, &quot;sentSuccess&quot;: 1, &quot;msgid&quot;: 0, &quot;senderid&quot;: &quot;pubsub@gappi.in/sleekxmpp&quot;, &quot;stanzaId&quot;: &quot;pubsubmessage-0f113ee289c241e2996fe0aab78f1485-2016-08-21 04:53&quot;, &quot;receiver&quot;: &quot;191a4c4ae410f104679b8f53db51315eda3@conference.gappi.in&quot;, &quot;date&quot;: &quot;2016-08-21 04:53&quot;, &quot;type&quot;: 1}</body>
                </message>
            </item>
        </items>
    </event>
    <delay xmlns='urn:xmpp:delay' stamp='2016-08-21T04:53:03.597+00:00' from='gappi.in'>Offline Storage</delay>
</message>

 

I'm mainly interested in getting the 'inner' message element, that is child of "item" element. This stanza is very similar to one mentioned in the EmbeddedExtensionProvider documentation EmbeddedExtensionProvider (Smack 4.1.8 API) . But I'm not very clear on the exact steps to follow to retrieve the inner message.

 

I've tried something like this until now.

 

private class MMessageListener implements ChatMessageListener {

        public MMessageListener(Context context) {

        }

 

        @Override

        public void processMessage(final org.jivesoftware.smack.chat.Chat chat,

                                   final Message message) {

            Log.i(TAG, "Xmpp message received:"+ message);

            //Possibly a pubsub offline message

            EventElement eventElement = message.getExtension("event","http://jabber.org/protocol/pubsub#event");

            if(eventElement != null) {

                Log.i(TAG, "EventElement:" + eventElement.getEvent());

                List<ExtensionElement> itemExtensions = eventElement.getExtensions();

                for(int i = 0;i < itemExtensions.size(); i++) {

                    ItemsExtension itemsExtension = (ItemsExtension) itemExtensions.get(i);

                    Log.i(TAG, "ItemExtension:" + itemExtensions.getClass());

                    List<Item> items = (List<Item>)itemsExtension.getItems();

                    for(int j=0; j<items.size(); j++){

                        PayloadItem it = (PayloadItem)items.get(j);

                        SimplePayload payloadElement = (SimplePayload) it.getPayload();

                    }

                }

            }

        }

}

 

How do I convert this "SimplePayload" element to a proper "Message" object.

Outcomes