我让Smack在OpenFire上运行。邮件传输工作正常,但自定义扩展程序永远不会完全到达。
这是发送的内容(由一个非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();
注册,但我不能说为什么它的代码永远不会被调用。
答案 0 :(得分:2)
我认为您还可以使用PacketExtension扩展自定义消息数据包。
Message message = new Message();
DefaultPacketExtension yourExt = new DefaultPacketExtension("your_ext", "com:your:ext:namespace");
yourExt.setValue("<XML element name>", <XML element value>);
messgae.addExtension(yourExt);
答案 1 :(得分:1)
简而言之,它是String中的大写小写错字,Robin通过在评论中询问详细信息帮助我找到它,并且上面的代码可行。谢谢罗宾!