Smack 4.4.2 - Exception occurs while parsing the incoming messages from iOS client application

We were using a Java XMPP client with smack version 3.3.1 to communicate with an iOS client built with Robbiehanson XMPP Framework. The XMPP server used for this communication is Openfire-4.0.4.
When we tried to upgrade the Java client with the latest smack libraries**(Smack-4.4.2)** we were stuck with an Unparsable Exception (Note: There is no change in the iOS client).
We are able to login in XMPP with the Java client and send XMPP messages to the iOS client. The iOS client also receives the message successfully.
While trying to send an XMPP message(in XML format) from iOS client to Java client, that message stanza is received in Openfire server. But it is throwing an Unparsable exception in Java client. Because of this we could not receive the message in the Java client.

The input xml message given in iOS client:
<Sample>Test</Sample>

Received message in Openfire server:
<message type="chat" to="user1@192.168.1.14/Smack"><body><Sample>Test</Sample></body></message>

Exception in Java client:

[xmppengine.connection.XmppConn$1] [50]: Unparsable Exception :   
org.jivesoftware.smack.xml.XmlPullParserException: Non-empty element tag not followed by text, while Mixed Content (XML 3.2.2) is disallowed
	at org.jivesoftware.smack.util.PacketParserUtils.parseElementText(PacketParserUtils.java:236)
	at org.jivesoftware.smack.provider.BodyElementProvider.parse(BodyElementProvider.java:34)
	at org.jivesoftware.smack.provider.BodyElementProvider.parse(BodyElementProvider.java:29)
	at org.jivesoftware.smack.provider.Provider.parse(Provider.java:53)
	at org.jivesoftware.smack.util.PacketParserUtils.parseExtensionElement(PacketParserUtils.java:834)
	at org.jivesoftware.smack.util.PacketParserUtils.parseMessage(PacketParserUtils.java:186)
	at org.jivesoftware.smack.util.PacketParserUtils.parseStanza(PacketParserUtils.java:111)
	at org.jivesoftware.smack.AbstractXMPPConnection.parseAndProcessStanza(AbstractXMPPConnection.java:1448)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1000(XMPPTCPConnection.java:130)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:969)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$700(XMPPTCPConnection.java:913)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:936)
	at java.base/java.lang.Thread.run(Thread.java:834)

Used the Smack’s UnparseableStanza.getContent() method to get received content in Java client:
<Sample xmlns='jabber:client'>Test</Sample></body></message>

Seems like the message from the iOS client reaches openfire server and the Java client could not be able to parse it.
Help us resolve this issue. Thanks in advance.

A body element containing further XML elements in not standards compliant and hence rejected by Smack. So you want to fix the messages your clients send. They should be standards compliant.

1 Like
[quote="e2_kavinkumar, post:1, topic:90302"]
<message type="chat" to="user1@192.168.1.14/Smack"><body><Sample>Test</Sample></body></message>
[/quote]

We are receiving the above xml message in Openfire server. Can you give some suggestions about fixing the message to achieve the standards?

A body element can only contain XML character data, not further XML child elements. If you really want to shove XML elements into the message body, then you have to escape it.

1 Like

Thanks for your help. It works for us.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.