让 Smackx PubSub 正常工作

发布于 2024-10-27 16:06:48 字数 1210 浏览 1 评论 0原文

我有以下代码:

        PubSubManager manager = new PubSubManager(connection, "pubsub.openfire.local");
        LeafNode myNode = (LeafNode) manager.createNode("NewNode", form);

        SimplePayload payload = new SimplePayload("session", "pubsub:NewNode:session", "<sessionId>1234</sessionId>");


        // putting null for id means you let server generate id
        PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null, payload);

        // you could use publish() for asynchronous call
        myNode.send(item);

并且在尝试发送节点值时不断收到以下错误:

冲突(409) 在>org.jivesoftware.smackx.pubsub.packet.SyncPacketSend.getReply(SyncPacketSend.java:53) 在>org.jivesoftware.smackx.pubsub.packet.SyncPacketSend.getReply(SyncPacketSend.java:61) 在> org.jivesoftware.smackx.pubsub.PubSubManager.sendPubsubPacket(PubSubManager.java:324) >org.jivesoftware.smackx.pubsub.PubSubManager.sendPubsubPacket(PubSubManager.java:318) 在 org.jivesoftware.smackx.pubsub.PubSubManager.createNode(PubSubManager.java:134) 在 PubSubPublisher.main(PubSubPublisher.java:33)

希望有任何关于如何调试或继续推进的想法。谢谢。

I've got the following code:

        PubSubManager manager = new PubSubManager(connection, "pubsub.openfire.local");
        LeafNode myNode = (LeafNode) manager.createNode("NewNode", form);

        SimplePayload payload = new SimplePayload("session", "pubsub:NewNode:session", "<sessionId>1234</sessionId>");


        // putting null for id means you let server generate id
        PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null, payload);

        // you could use publish() for asynchronous call
        myNode.send(item);

and I continuously get the following error on trying to send the node value:

conflict(409)
at >org.jivesoftware.smackx.pubsub.packet.SyncPacketSend.getReply(SyncPacketSend.java:53)
at >org.jivesoftware.smackx.pubsub.packet.SyncPacketSend.getReply(SyncPacketSend.java:61)
at >org.jivesoftware.smackx.pubsub.PubSubManager.sendPubsubPacket(PubSubManager.java:324)
at >org.jivesoftware.smackx.pubsub.PubSubManager.sendPubsubPacket(PubSubManager.java:318)
at org.jivesoftware.smackx.pubsub.PubSubManager.createNode(PubSubManager.java:134)
at PubSubPublisher.main(PubSubPublisher.java:33)

Would love any ideas about how to debug, or move forward with this. Thanks.

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

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

发布评论

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

评论(1

缱绻入梦 2024-11-03 16:06:48

您尝试创建的节点已存在。调用 getNode 和/或 先删除Node,然后createNode。将代码包装在 try/catch 块中以处理可能引发的 XMPPException

LeafNode myNode = null;
try{
  try{
    LeafNode existingNode = manager.getNode("NewNode");  
    //exists, so delete
    manager.deleteNode("NewNode");
  }catch(XMPPException e){
    //'getNode' threw an exception.
    //so we know that the node did not exist
  }
  myNode = (LeafNode) manager.createNode("NewNode", form);
}catch(XMPPException e){
  System.err.println(e);
}

The node you are trying to create already exists. Call getNode and/or deleteNode first and then createNode. Wrap your code in a try/catch block to handle the XMPPException that may be thrown.

LeafNode myNode = null;
try{
  try{
    LeafNode existingNode = manager.getNode("NewNode");  
    //exists, so delete
    manager.deleteNode("NewNode");
  }catch(XMPPException e){
    //'getNode' threw an exception.
    //so we know that the node did not exist
  }
  myNode = (LeafNode) manager.createNode("NewNode", form);
}catch(XMPPException e){
  System.err.println(e);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文