我做了一些研究,并在网上尝试了几个建议,以便从我的openfire服务器获得MAM响应。 这是我发送给服务器的IQ数据包
<iq id="v7sWB-10" type="set">
<query xmlns="urn:xmpp:mam:0" queryid="e8f7a935-4c49-4955-b7ee-57a832be7da9">
<x xmlns="jabber:x:data" type="submit">
<field var="FORM_TYPE" type="hidden">
<value>urn:xmpp:mam:0</value>
</field>
<field var="with">
<value>xxxxx@xxxxxyy.com</value>
</field>
</x>
</query>
</iq>
以下是我从服务器获取的响应日志:
<iq type="result" id="v7sWB-10" to="xxxxx@xxxx.com/smack-0.03822310071941204"/>
<message to="xxxx@txxxxxx.com/smack-0.03822310071941204">
<result xmlns="urn:xmpp:mam:0" id="1" queryid="e8f7a935-4c49-4955-b7ee-57a832be7da9">
<forwarded xmlns="urn:xmpp:forward:0"><delay xmlns="urn:xmpp:delay" stamp="2016-05-31T08:42:38.837Z"/>
<message xmlns="" from="xxxx@xxxx.com/converse.js-30995" to="xxxx@xxxx.com" type="chat" id="6bdf41ad-f37d-431b-acdc-4475af480db3">
<body>test1111</body>
<active xmlns="http://jabber.org/protocol/chatstates">
</active>
</message>
</forwarded>
</result>
</message>
以下是我的过滤器的代码:
PacketListener packetListener = new PacketListener() {
@Override
public void processPacket(Stanza packet) throws SmackException.NotConnectedException {
Log.e("message ",packet.toXML().toString());
if (packet instanceof Message) {
Message message = (Message) packet;
String chatMessage = message.getBody();
}
}
};
private void regiSterPackateListner() {
PacketExtensionFilter filter = new PacketExtensionFilter(MamElements.MamResultExtension.ELEMENT,MamElements.NAMESPACE);
try {
if (packetListener != null) {
//Avoid adding multiple packetlistner
connection.removePacketListener(packetListener);
}
connection.addPacketListener(packetListener, filter);
} catch (Exception e) {
e.printStackTrace();
}
}
但是我从服务器获得的结果是缺少转发和延迟标记:
<message to='xxxx@xxxx.com/smack-0.03822310071941204'>
<result xmlns='urn:xmpp:mam:0'>
</result>
</message>
我做错了什么?以及如何创建一个过滤器来解析这样的数据包?