I am adding some custom XML to the message packet using a custom extension. I am seeing something strange when I receive the groupchat message. Here is the debug output of the sent packet:
03-05 12:48:28.211: I/System.out(26882): 12:48:28 PM SENT (1097037712):
<message id="ww6KD-13" to="xxxx@conference.talk.---.---.com" type="groupchat"><body>Location Changed: New Location</body><location xmlns="jabber:client">5</location></message>
Here is what is received by the listener:
03-05 12:48:28.291: I/System.out(26882): 12:48:28 PM RCV (1097037712):
<message id="ww6KD-13" to="407ffe65384993980ffce9eb8f764753@talk.---.----.com/---" type="groupchat" from="xxxx@conference.talk.---.---.com/407ffe65384993980ffce9eb8f764753"><body>Location Changed: New Location</body><location>5</location></message>
Notice that the xmlns is lost, now at this point something breaks in smack and it will not fire any messagelisteners until the app is restarted. What is odd is that when openfire sends me message history when I login again it will have the namespace and it will work until I send a message again that has a custom packet.
I have the packets registered using
pm.addExtensionProvider("urgent", "jabber:client",
new UrgentMessageProvider());
pm.addExtensionProvider("media", "jabber:client",
new MediaMessageProvider());
pm.addExtensionProvider("location", "jabber:client",
new LocationMessageProvider());
pm.addExtensionProvider("arrived", "jabber:client",
new ArrivedMessageProvider());
Am I missing somthing in the registeration that is causing smack to remove the namespace?
Here is the code for the LocationPacket
public class LocationPacket implements PacketExtension {
private String ElementName = "location";
private String Namespace = "jabber:client";
private String value = null; public void setValue(String xmlValue) {
this.value = xmlValue;
} public String getValue() {
return this.value;
} @Override
public String getElementName() {
// TODO Auto-generated method stub
return ElementName;
} @Override
public String getNamespace() {
// TODO Auto-generated method stub
return Namespace;
} @Override
public String toXML() {
// TODO Auto-generated method stub
if (Namespace == null) {
return String.format("<%s>%s</%s>", this.ElementName, this.value,
this.ElementName);
} else {
return String.format("<%s xmlns=\"%s\">%s</%s>", this.ElementName,
this.Namespace, this.value, this.ElementName);
} } }
And the Provider
public class LocationMessageProvider implements PacketExtensionProvider { public LocationMessageProvider() { } @Override
public PacketExtension parseExtension(XmlPullParser parser) { LocationPacket packet = new LocationPacket();
try { boolean done = false;
while (!done) {
int eventType = parser.getEventType(); if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals(packet.getElementName())) {
// advance to text
parser.next();
packet.setValue(parser.getText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(packet.getElementName())) {
done = true;
}
} parser.next();
}
} catch (Exception e) {
e.printStackTrace();
} return packet;
}