我已经让 Smack 与 OpenFire 一起运行。消息传输工作正常,但自定义扩展永远不会完全到达。
这是 get 发送的内容(由非 smack 库发送):
<message type="normal" id="42444f16-761f-471d-a37c-c9204cf14cfc" to="timmy@openfireserver.eu">
<operation xmlns="http://www.openfireserver.eu/ns/xmpp-rest" ack="false">PUT</operation>
<part xmlns="http://www.openfireserver.eu/ns/xmpp-rest" RIDDL-TYPE="simple" content-disposition="riddl-data; name="value"">stopped</part>
<part xmlns="http://www.openfireserver.eu/ns/xmpp-rest" RIDDL-TYPE="simple" content-disposition="riddl-data; name="tims"">world</part>
<part xmlns="http://www.openfireserver.eu/ns/xmpp-rest" RIDDL-TYPE="complex" content-disposition="riddl-data; name="excellent"" content-transfer-encoding="binary" content-type="text/plain">party time</part>
</message>
这是到达的:
<message id="42444f16-761f-471d-a37c-c9204cf14cfc" to="timmy@openfireserver.eu" from="jürgen@openfireserver.eu/f8c64ccb">
<operation xmlns="http://www.openfireserver.eu/ns/xmpp-rest"></operation>
<part xmlns="http://www.openfireserver.eu/ns/xmpp-rest"></part>
<part xmlns="http://www.openfireserver.eu/ns/xmpp-rest"></part>
<part xmlns="http://www.openfireserver.eu/ns/xmpp-rest"></part>
</message>
我尝试创建一个 OperationExtension 并在创建连接之前对其进行设置,如下所示:
OperationProvider o = new OperationProvider();
ProviderManager.getInstance().addExtensionProvider(o.getExtension().getElementName(),o.getExtension().getNamespace(), o);
OperationProvider 看起来像这样用于测试,但我的断点永远不会被击中:-(
public class OperationProvider implements PacketExtensionProvider {
private OperationExtension extension = new OperationExtension();
@Override
public PacketExtension parseExtension(XmlPullParser xmlparser) throws Exception {
OperationExtension o = new OperationExtension();
System.out.println("YAAAA + " + xmlparser.getText());
String text = xmlparser.nextText();
while (text != null)
{
System.out.println("YAAAA + " + text);
text = xmlparser.nextText();
}
return o;
}
public OperationExtension getExtension() {
return extension;
}
public void setExtension(OperationExtension extension) {
this.extension = extension;
}
}
OperationExtension 本身非常基本(在此处设置断点以希望它们有时会被命中,但不起作用):
public class OperationExtension implements PacketExtension {
public static final String NAMESPACE = "http://www.openfireserver.eu/ns/xmpp-rest";
public String getElementName()
{
return "Operation"; // <-- here was my error, it should say (lower-case) "operation"
}
public String getNamespace()
{
return NAMESPACE;
}
@Override
public String toXML() {
return "<Operation>GET</Operation>"; // this is also just mockup with a breakpoint ;-)
}
}
,但 toXml() 方法也不会被调用。正如一些可用的文档所建议的那样,我将一个 smack.properties 文件放在项目的 /src 路径内的 META-INF 文件夹中,我使它看起来像这样:
<?xml version="1.0"?>
<extensionProvider>
<elementName>operation</elementName>
<namespace>http://www.openfireserver.eu/ns/xmpp-rest</namespace>
<className>adventure.messagerouting.XmppExtensions.OperationExtension</className>
</extensionProvider>
<extensionProvider>
<elementName>part</elementName>
<namespace>http://www.openfireserver.eu/ns/xmpp-rest</namespace>
<className>adventure.messagerouting.XmppExtensions.PartExtension</className>
</extensionProvider>
我可以注册我的提供程序,ProviderManager.getInstance().getExtensionProviders();
但我不能说为什么它的代码永远不会被调用。
- 我在这里做错了吗?为什么我的属性和标签内容没有及时到达?
- OpenFire 有可能过滤掉一些东西吗?