Answer the question
In order to leave comments, you need to log in
Java: smack xmpp custom extensions (Extension)?
And again for all of the day, very recently I created the question that smack works crookedly.
There I wrote: “Once again I remind you that the first problem exists independently from the second, they are somehow connected.”
Let me remind you once again the rephrased problem (under the cut):
There are self-written custom ( extensions ), I register it for the connection, add a listener, process, again, everything would be fine - but it works every other time.
As I understand it, this is my mistake, incorrect in the use of parsing, as a result of which the overall parsing of packets falls. But why this happens, I still do not understand.
Creating, registering, listening to an extension looks like this:
Initializing and throwing a listener:
ProviderManager pm = ProviderManager.getInstance();
pm.addExtensionProvider(TestEvent.elementname, TestEvent.namespace, new TestEvent.Provider());
...
OnlineListener onlineListener = new OnlineListener();
PacketExtensionFilter onlineFilter = new PacketExtensionFilter(TestEvent.namespace);
connection.addPacketListener(onlineListener, onlineFilter);
public static class OnlineListener implements PacketListener
{
@Override
public void processPacket(Packet packet)
{
TestEvent e = (TestEvent) packet.getExtension(TestEvent.namespace);
Message message = new Message();
message.setTo(e.getUser().aid + "@" + SERVER);
OnlineEvent response = new OnlineEvent();
message.addExtension(response);
connection.sendPacket(message);
}
public class TestEvent implements PacketExtension {
private UserRepresentation user;
public static String namespace = "sometext:event:testevent";
public static String elementname = "event";
public ProfileviewEvent()
{
}
public void setUser(UserRepresentation value) {
user = value;
}
public UserRepresentation getUser() {
return user;
}
public String getElementName() {
return ProfileviewEvent.elementname;
}
public String getNamespace() {
return ProfileviewEvent.namespace;
}
public String toXML() {
StringBuffer buf = new StringBuffer();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\">");
if(user != null) buf.append(user.toXML());
buf.append("</").append(getElementName()).append(">");
return buf.toString();
}
public static class Provider implements PacketExtensionProvider
{
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
TestEvent extension = new TestEvent();
boolean done = false;
while(!done) {
int eventType = parser.next();
breakpoint(parser.getName()); // ###
if(eventType == XmlPullParser.START_TAG) {
if(parser.getName().equals("User"))
{
UserRepresentation user = new UserRepresentation();
...
extension.setUser(user);
done = true;
}
}
}
return extension;
}
}
}
pm.addExtensionProvider(TestEvent.elementname, TestEvent.namespace, new TestEvent.Provider());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question