我安卓端 使用 smack4.1.4 对message 扩展一个节点 <ext>

发布于 2021-12-02 06:00:18 字数 4316 浏览 867 评论 1

public class Ext implements ExtensionElement {
private String orderID;
public String getOrderID() {
return orderID;
}
public void setOrderID(String orderID) {
this.orderID = orderID;
}
@Override
public String getElementName() {
// TODO Auto-generated method stub
return "ext";
}
@Override
public String getNamespace() {
return "ihelper:chat:text";
}
@Override
public String toXML() {
StringBuilder sb = new StringBuilder();
sb.append("<ext");
sb.append("   xmlns=");
sb.append("'ihelper:chat:text'");
sb.append(">");
sb.append("<orderID>");
sb.append(orderID);
sb.append("</orderID>");
sb.append("</ext>");
return sb.toString();
}

}



下面的时候对 扩展节点的解析

public class ExtProvider extends DataPacketProvider.PacketExtensionProvider {
private String orderID;
private String url;
private String type;


public ExtensionElement parseExtension(XmlPullParser parser)
throws Exception {
Ext ext = new Ext();
StringBuffer buffer = new StringBuffer();
boolean done = false;
while (!done) {
int eventType = parser.getEventType();
switch (eventType) {
case XmlPullParser.START_TAG:
String startTag = parser.getName();
switch (startTag) {
case "orderID":
orderID = parser.nextText();
break;
}
   break;
case XmlPullParser.END_TAG:
String endTag = parser.getName();
switch (endTag) {
case "ext":
done = true;
break;
}
break;
}
}
ext.setOrderID(orderID);
return ext;
}
}


当对方给我发来消息的时候 报

12-21 21:59:50.822: W/AbstractXMPPConnection(5312):     java.lang.NumberFormatException: Invalid long: "null"
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at java.lang.Long.invalidLong(Long.java:125)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at java.lang.Long.parseLong(Long.java:342)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at java.lang.Long.parseLong(Long.java:319)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider$PacketExtensionProvider.parse(DataPacketProvider.java:56)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider$PacketExtensionProvider.parse(DataPacketProvider.java:49)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.provider.Provider.parse(Provider.java:35)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.util.PacketParserUtils.parseExtensionElement(PacketParserUtils.java:929)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.util.PacketParserUtils.addExtensionElement(PacketParserUtils.java:1060)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.util.PacketParserUtils.parseMessage(PacketParserUtils.java:287)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.util.PacketParserUtils.parseStanza(PacketParserUtils.java:151)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.AbstractXMPPConnection.parseAndProcessStanza(AbstractXMPPConnection.java:956)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$500(XMPPTCPConnection.java:140)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:989)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:944)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:959)
12-21 21:59:50.822: W/AbstractXMPPConnection(5312): at java.lang.Thread.run(Thread.java:841)

请问 是不是 我写的扩展节点以及解析不对 

是不是应该继承DataPacketExtension来写扩展节点呢  有使用过smack4.1.4 对message进行扩展的前辈吗 求指教。谢谢



如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本王不退位尔等都是臣 2021-12-02 09:45:20

异常信息很明显啊,传递了null

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文