尝试使用 Smackx pubsub 获取节点时出现 item-not-found(404)

发布于 2024-08-31 16:43:00 字数 1696 浏览 10 评论 0原文

我正在尝试使用最新的 Smackx 主干来获取并订阅 pubsub 节点。然而,openfire 只是给我发回一个错误:未找到项目(404)。

我正在实例化 ColdFusion 中的 java 对象,因此我的代码片段可能看起来很有趣,但也许有人能够告诉我我忘记了什么。

这是我创建节点的方式:

    ftype = createObject("java", "org.jivesoftware.smackx.pubsub.FormType");
    cform = createObject("java", "org.jivesoftware.smackx.pubsub.ConfigureForm").init(ftype.submit);
    cform.setPersistentItems(true);
    cform.setDeliverPayloads(true);
    caccess = createObject("java", "org.jivesoftware.smackx.pubsub.AccessModel");
    cform.setAccessModel(caccess.open);
    cpublish = createObject("java", "org.jivesoftware.smackx.pubsub.PublishModel");
    cform.setPublishModel(cpublish.open);
    cform.setMaxItems(99);

    manager = createObject("java", "org.jivesoftware.smackx.pubsub.PubSubManager").init(XMPPConnection);

    myNode = manager.createNode("subber", cform);

这是我尝试访问它的方式(在代码的不同部分):

    manager = createObject("java", "org.jivesoftware.smackx.pubsub.PubSubManager").init(XMPPConnection);
    myNode = manager.getNode("subber");

创建节点后,我似乎能够像这样发布到它:

    payload = createObject("java", "org.jivesoftware.smackx.pubsub.SimplePayload").init("book","pubsub:test:book","<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>");
    item = createObject("java", "org.jivesoftware.smackx.pubsub.Item").init(payload);
    myNode.publish(item);

但是,正是 getNode() 调用导致我的代码出错。

我已经通过检查 openfire 服务器使用的数据库来验证节点是否正在创建。我可以在那里看到它们,正确地归因于叶节点等。

有什么建议吗? 还有其他人在使用 XMPP 和 ColdFusion 做任何事情吗? 我在使用 CF 和 Smack 发送和接收消息方面取得了巨大成功,只是 pubsub 还没有工作:)

谢谢!

I'm trying to use the latest Smackx trunk to get and then subscribe to a pubsub node. However, openfire just sends me a back an error: item not found (404).

I am instantiating the java objects from ColdFusion, so my code snippets might look funny but maybe someone will be able to tell me what I've forgotten.

Here's how I create the node:

    ftype = createObject("java", "org.jivesoftware.smackx.pubsub.FormType");
    cform = createObject("java", "org.jivesoftware.smackx.pubsub.ConfigureForm").init(ftype.submit);
    cform.setPersistentItems(true);
    cform.setDeliverPayloads(true);
    caccess = createObject("java", "org.jivesoftware.smackx.pubsub.AccessModel");
    cform.setAccessModel(caccess.open);
    cpublish = createObject("java", "org.jivesoftware.smackx.pubsub.PublishModel");
    cform.setPublishModel(cpublish.open);
    cform.setMaxItems(99);

    manager = createObject("java", "org.jivesoftware.smackx.pubsub.PubSubManager").init(XMPPConnection);

    myNode = manager.createNode("subber", cform);

And here's how I am trying to get to it (in a different section of code):

    manager = createObject("java", "org.jivesoftware.smackx.pubsub.PubSubManager").init(XMPPConnection);
    myNode = manager.getNode("subber");

Immediately upon creating the node I seem to be able to publish to it like so:

    payload = createObject("java", "org.jivesoftware.smackx.pubsub.SimplePayload").init("book","pubsub:test:book","<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>");
    item = createObject("java", "org.jivesoftware.smackx.pubsub.Item").init(payload);
    myNode.publish(item);

However, it is the getNode() call that is causing my code to error.

I have verified that the nodes are being created by checking the DB used by my openfire server. I can see them in there, properly attributed as leaf nodes, etc.

Any advice?
Anyone else out there doing anything with XMPP and ColdFusion?
I have had great success sending and receiving messages with CF and Smack just haven't had the pubsub working yet :)

Thanks!

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

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

发布评论

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

评论(3

明明#如月 2024-09-07 16:43:00

这个问题已经得到解答:

PubSubManager 类上有第二种方法,它接受两个参数:一个连接和一个 to 参数。显然 Openfire 需要这个 to 参数,经过一些实验我发现它可以使用 pubsub.your.xmpp.address

manager = createObject("java", "org.jivesoftware.smackx.pubsub.PubSubManager").init(XMPPConnection,"pubsub.127.0.0.1");

This has been answered:

There is a second method on the PubSubManager class that accepts two arguments, a connection and a to parameter. Apparently Openfire requires this to parameter and after some experimenting i discovered that it works using pubsub.your.xmpp.address

manager = createObject("java", "org.jivesoftware.smackx.pubsub.PubSubManager").init(XMPPConnection,"pubsub.127.0.0.1");
猥琐帝 2024-09-07 16:43:00

也许这个例子可以给你一个参考:

 public void login(String Ip,String username,String passwaord)
     {
         try 
         {
            connConfig = new AndroidConnectionConfiguration(Ip, 5222);
            connection = new XMPPConnection(connConfig);
            connection.connect();  
            connection.login(username, passwaord);
            pubSubAddress = "pubsub."+ connection.getServiceName();
            manager = new PubSubManager(connection,pubSubAddress);
            Log.i("MyError","connection success");  
         }
         catch (XMPPException e) 
         {
             Log.i("MyError","connection failed");      
             e.printStackTrace();
         }

     }

Maybe this example can be used as a reference for you:

 public void login(String Ip,String username,String passwaord)
     {
         try 
         {
            connConfig = new AndroidConnectionConfiguration(Ip, 5222);
            connection = new XMPPConnection(connConfig);
            connection.connect();  
            connection.login(username, passwaord);
            pubSubAddress = "pubsub."+ connection.getServiceName();
            manager = new PubSubManager(connection,pubSubAddress);
            Log.i("MyError","connection success");  
         }
         catch (XMPPException e) 
         {
             Log.i("MyError","connection failed");      
             e.printStackTrace();
         }

     }
独行侠 2024-09-07 16:43:00

规范化示例如下:

发布节点:

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.SimplePayload;

public class XmppPubsub_Publisher {
    private static XMPPConnection connection = new XMPPConnection("think");
    private static String USRE_NAME = "test1";
    private static String PASSWORD = "1";
    static{
        try {
            connection.connect();
            connection.login(USRE_NAME,PASSWORD);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args)throws Exception{
        try{
            PubSubManager manager = new PubSubManager(connection);
            String nodeId = "test2";
            LeafNode myNode = null;
            try {
                myNode = manager.getNode(nodeId);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if(myNode == null){
                myNode = manager.createNode(nodeId);
            }
            String msg = "fsadfasdfsadfasdfd---";
            SimplePayload payload = new SimplePayload("message","pubsub:test:message", "<message xmlns='pubsub:test:message'><body>"+msg+"</body></message>");
            PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>("5", payload);
            myNode.publish(item);
            System.out.println("-----publish-----------");
        }
        catch(Exception E)
        {E.printStackTrace();}
    }
}

检索节点:

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.pubsub.ItemPublishEvent;
import org.jivesoftware.smackx.pubsub.Node;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.listener.ItemEventListener;

public class XmppPubsub_Reciever {
    private static XMPPConnection connection = new XMPPConnection("think");
    private static String USRE_NAME = "test1";
    private static String PASSWORD = "1";
    static {
        try {
            connection.connect();
            connection.login(USRE_NAME, PASSWORD);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws Exception {
        String nodeId = "test2";
        PubSubManager manager = new PubSubManager(connection);
        Node eventNode = manager.getNode(nodeId);
        eventNode.addItemEventListener(new ItemEventListener<PayloadItem>() {
            public void handlePublishedItems(ItemPublishEvent evt) {
                for (Object obj : evt.getItems()) {
                    PayloadItem item = (PayloadItem) obj;
                    System.out.println("--:Payload=" + item.getPayload().toString());
                }
            }
        });
        eventNode.subscribe(connection.getUser());
        while(true);
    }
}

A normalized example are showed as following:

Publish node:

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.SimplePayload;

public class XmppPubsub_Publisher {
    private static XMPPConnection connection = new XMPPConnection("think");
    private static String USRE_NAME = "test1";
    private static String PASSWORD = "1";
    static{
        try {
            connection.connect();
            connection.login(USRE_NAME,PASSWORD);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args)throws Exception{
        try{
            PubSubManager manager = new PubSubManager(connection);
            String nodeId = "test2";
            LeafNode myNode = null;
            try {
                myNode = manager.getNode(nodeId);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if(myNode == null){
                myNode = manager.createNode(nodeId);
            }
            String msg = "fsadfasdfsadfasdfd---";
            SimplePayload payload = new SimplePayload("message","pubsub:test:message", "<message xmlns='pubsub:test:message'><body>"+msg+"</body></message>");
            PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>("5", payload);
            myNode.publish(item);
            System.out.println("-----publish-----------");
        }
        catch(Exception E)
        {E.printStackTrace();}
    }
}

Retrieve node:

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.pubsub.ItemPublishEvent;
import org.jivesoftware.smackx.pubsub.Node;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.listener.ItemEventListener;

public class XmppPubsub_Reciever {
    private static XMPPConnection connection = new XMPPConnection("think");
    private static String USRE_NAME = "test1";
    private static String PASSWORD = "1";
    static {
        try {
            connection.connect();
            connection.login(USRE_NAME, PASSWORD);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws Exception {
        String nodeId = "test2";
        PubSubManager manager = new PubSubManager(connection);
        Node eventNode = manager.getNode(nodeId);
        eventNode.addItemEventListener(new ItemEventListener<PayloadItem>() {
            public void handlePublishedItems(ItemPublishEvent evt) {
                for (Object obj : evt.getItems()) {
                    PayloadItem item = (PayloadItem) obj;
                    System.out.println("--:Payload=" + item.getPayload().toString());
                }
            }
        });
        eventNode.subscribe(connection.getUser());
        while(true);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文