powered by Jive Software

Cannot parse 4.2.3 messages with 4.3 Smack

Hello, we are attempting an upgrade from Smack 4.2.3 to 4.3.

One of the issues we are working through involves parsing messages that are saved in a local database. With 4.2.3 the messages are saved to a database as an XML string, and they are parsed out of the database upon next app restart.

However with 4.3, the messages are not being parsed as they were in 4.2.3. The parser is complaining about Namespace. Should I be parsing some other way now? Or is there some type of fixup required for messages that were saved prior to 4.3?

09-27 00:50:36.337 5467-5467/com.atakmap.app W/XmppChatDatabase: cursorToChatMessage: <message to='byoung@sample.net/ANDROID-355301074232615' from='test@conference.sample.net/Test User' id='purple52c3c317' type='groupchat'><body>in</body></message>
     java.lang.IllegalArgumentException: Namespace must not be null or empty
         at org.jivesoftware.smack.util.StringUtils.requireNotNullOrEmpty(StringUtils.java:449)
         at org.jivesoftware.smack.packet.StandardExtensionElement.<init>(StandardExtensionElement.java:70)
         at org.jivesoftware.smack.packet.StandardExtensionElement.<init>(StandardExtensionElement.java:44)
         at org.jivesoftware.smack.packet.StandardExtensionElement$Builder.build(StandardExtensionElement.java:215)
         at org.jivesoftware.smack.parsing.StandardExtensionElementProvider.parse(StandardExtensionElementProvider.java:97)
         at org.jivesoftware.smack.parsing.StandardExtensionElementProvider.parse(StandardExtensionElementProvider.java:38)
         at org.jivesoftware.smack.provider.Provider.parse(Provider.java:43)
         at org.jivesoftware.smack.util.PacketParserUtils.parseExtensionElement(PacketParserUtils.java:922)
         at org.jivesoftware.smack.util.PacketParserUtils.addExtensionElement(PacketParserUtils.java:989)
         at org.jivesoftware.smack.util.PacketParserUtils.parseMessage(PacketParserUtils.java:264)
         at org.jivesoftware.smack.util.PacketParserUtils.parseStanza(PacketParserUtils.java:155)
         at org.jivesoftware.smack.util.PacketParserUtils.parseStanza(PacketParserUtils.java:138)
         at com.sample.ChatDatabase.cursorToChatMessage(ChatDatabase.java:1143)
         at com.sample.ChatDatabase.getMessages(ChatDatabase.java:788)
         at com.sample.ChatDatabase.getMessages(ChatDatabase.java:721)
         at com.sample.ChatView.refresh(ChatView.java:722)
         at com.sample.ChatView.getChatView(ChatView.java:187)
         at com.sample.ChatDropDown.onReceive(ChatDropDown.java:250)
         at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
         at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
         at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116)
         at android.os.Handler.dispatchMessage(Handler.java:102)
         at android.os.Looper.loop(Looper.java:158)
         at android.app.ActivityThread.main(ActivityThread.java:7224)
         at java.lang.reflect.Method.invoke(Native Method)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

For comparison, here is how the 4.3 messages appear in the local DB, it includes the xmlns

<message xmlns='jabber:client' to='test@conference.sample.net' from='byoung@sample.net/ANDROID-355301074232615' id='qvw9c-148' type='groupchat'><body>I see</body><tak xmlns='urn:xmpp:tak'><uid>ANDROID-355301074232615</uid></tak></message>

Please let me know if any suggestions, or what specifically changed regarding parsing stanza

The message stanza has no XML namespae declaration. Smack 4.3 requires one. Either add it manually by manipulating the string, or wrap the stanza into a dummy element, possibly even stream which declares the XML namespace.