I’'m trying to write a Java application that can process incoming and send outgoing
XMPP messages with custom extensions. The extensions look something like this:
Value
Value2>/SubTag1>
…
I assumed that PacketExtension was the correct way of dealing with this, so I wrote
a class that looks something like this:
import org.jivesoftware.smack.packet.*;
import java.util.*;
public class CustomExtension implements PacketExtension
{
private String val;
public CustomExtension()
{
}
public void SetVal(String newVal)
{
val=newVal;
}
public String getNamespace()
{
return “TEST”;
}
public String getElementName()
{
return “CustomExtension”;
}
public String toXML()
{
String tmpXML;
tmpXML="<“getElementName()” xlns="“getNamespace()”>";
tmpXML*=""*val+"";
return tmpXML;
}
}
Now to send it I use the following code:
XMPPConnection connection = new XMPPConnection(“my.own.server”);
connection.login(“test”, “1234”);
Chat c=connection.createChat(“me@my.own.server”);
Message testPack=new Message();
CustomExtension q=new CustomExtension();
q.SetVal(“TESTING”);
testPack.addExtension(q);
testPack.setBody("");
testPack.setType(Message.Type.CHAT);
c.sendMessage(testPack);
This works, which I can verify with a normal Jabber that allows viewing/editing of XML
messages (like PSI for example).
Now I want to be able to receive these messages in my application aswell.
That is, I want my application to get the message, and be able to somehow parse the
custom XML code to get my values.
As far as I understand it, I should be using a PacketExtensionProvider and
ProviderManager somehow, but I’'m not quite getting how.
Any example code/tutorial would be helpful.