powered by Jive Software

XEP-0060 (PubSub) New Node Creation -- Ownership

Hi,

When I create a PubSub node (leaf or collection) the owner (serviceID field in the pubsubNode table) always seems to be of the user which created the node. From what I understand – according to the XEP – a user can send a create request with the “to” field set to a server name (e.g. to=“a.xmpp.host”) and another user can subscribe to the node by sending a subscribe request to the same “to” address. However – every time I try and subscribe to a newly created node, I get an error saying item-not-found.

Upon further investigation I’ve found that if I set the “to” field (from the subscriber) to be the of the user which create the node, subscription succeeds and I can be notified of all new events published to this node.

Shouldn’t the subscription be tied to the server as opposed to the user which created the node? E.g. shouldn’t any user be able to send a subscription request to a server for a given node (to=“a.xmpp.host”) and be subscribed to this node without knowing the original creator/JID of the node?

Thanks,

-Michoel

I believe I found the root cause here. It seems that when I address my create and subscribe requests to “pubsub.a.xmpp.host” (as opposed to just “a.xmpp.host”) all the create/subscribe requests work as expected. If I just address my create request to “a.xmpp.host” then in order to subscribe to the node I need to address the request to “OriginalCreatorOfNode@a.xmpp.host”.

Sample Client/Server conversations and their results:

Example 1:

User1@a.xmpp.host/Resource --> a.xmpp.host --> Create Node1

a.xmpp.host --> User1@a.xmpp.host/Resource --> Success

User2@a.xmpp.host/Resource --> a.xmpp.host --> Subscribe Node1

a.xmpp.host --> User2@a.xmpp.host/Resource --> 404 – item-not-found

User2@a.xmpp.host/Resource --> User1@a.xmpp.host/Resource --> Subscribe Node1

User1@a.xmpp.host/Resource --> User2@a.xmpp.host/Resource --> Success

Example 2:

User1@a.xmpp.host/Resource --> pubsub.a.xmpp.host --> Create Node2

pubsub.a.xmpp.host --> User1@a.xmpp.host/Resource --> Success

User2@a.xmpp.host/Resource --> pubsub.a.xmpp.host --> Subscribe Node2

pubsub.a.xmpp.host --> User2@a.xmpp.host/Resource --> Success

-Michoel

Item not found error occurs while subscribing (getNode() ) in the subscribing program

Now i have posted both programs

Node creation and publishing code:

import java.util.List;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.pubsub.AccessModel;
import org.jivesoftware.smackx.pubsub.ConfigureForm;
import org.jivesoftware.smackx.pubsub.FormType;
import org.jivesoftware.smackx.pubsub.Item;
import org.jivesoftware.smackx.pubsub.ItemPublishEvent;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.SimplePayload;
import org.jivesoftware.smackx.pubsub.Subscription;
import org.jivesoftware.smackx.pubsub.listener.ItemEventListener;

public class Se
{

public static void main(String[] args) throws XMPPException {

String itemId=“TestNode071”;
XMPPConnection connection = new XMPPConnection(“localhost”);
connection.connect();
connection.login(“knandha”, “knandha”);
System.out.println(“Connected”);
ConfigureForm form = new ConfigureForm(FormType.submit);
form.setPersistentItems(false);
form.setDeliverPayloads(true);
form.setAccessModel(AccessModel.open);
PubSubManager manager = new PubSubManager(connection);
LeafNode myNode = (LeafNode) manager.createNode(itemId, form);
System.out.println(“Node Created”);

SimplePayload payload = new SimplePayload(“book”,“pubsub:test:book”, “Lord of the Rings”);
PayloadItem item = new PayloadItem(itemId, payload);
ItemEventListener myListener = new ItemEventListener() {
public void handlePublishedItems(ItemPublishEvent items) {
System.out.println(“result=”+items.getItems().toString());
}
};
myNode.addItemEventListener(myListener);
myNode.publish(item);
System.out.println(“Node Published”);
}
}

output:

Connected
Node Created
Node Published
result=[org.jivesoftware.smackx.pubsub.PayloadItem | Content [Lord of the Rings]]

Subscribing Program:

package org.jivesoftware.smackx;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.pubsub.AccessModel;
import org.jivesoftware.smackx.pubsub.ConfigureForm;
import org.jivesoftware.smackx.pubsub.FormType;
import org.jivesoftware.smackx.pubsub.Item;
import org.jivesoftware.smackx.pubsub.ItemPublishEvent;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.SimplePayload;
import org.jivesoftware.smackx.pubsub.listener.ItemEventListener;

public class TestSubscriber {

public static void main(String[] args) throws XMPPException{
XMPPConnection.DEBUG_ENABLED = false;
String itemId=“TestNode071”;
ConnectionConfiguration config = new ConnectionConfiguration(“localhost”, 5222);
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login(“knandha”, “knandha”);
System.out.println(“Connected”);
PubSubManager manager = new PubSubManager(connection);
LeafNode myNode = (LeafNode) manager.getNode(itemId); //Error occured in this line(TestSubscriber.java:32))
System.out.println(“Node Received”);
ItemEventListener myListener = new ItemEventListener() {
public void handlePublishedItems(ItemPublishEvent items) {
System.out.println(“result=”+items.getItems().toString());
} };
myNode.addItemEventListener(myListener);
myNode.subscribe(“knandha@srinicomputer”);
System.out.println(“Node Subscriped”);

} }

Output:

Connected
Exception in thread “main” item-not-found(404)
at org.jivesoftware.smackx.packet.SyncPacketSend.getReply(SyncPacketSend.java:53)
at org.jivesoftware.smackx.packet.SyncPacketSend.getReply(SyncPacketSend.java:61)
at org.jivesoftware.smackx.pubsub.PubSubManager.getNode(PubSubManager.java:161)
at org.jivesoftware.smackx.TestSubscriber.main(TestSubscriber.java:32)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

How to resolve this problem? Solution Please!..

When creating a PubSubManager use:

**new PubSubManager(connection, “pubsub.localhost”); // For server on localhost which is your case
**

You have to set up the pubsub manager to address the pubsub service. This is typically called pubsub, so the address to use is pubsub plus the xmpp server domain that you used to create the connection.

Thanks for reply

I follow your step in Pubsubmanager

new PubSubManager(connection, “pubsub.localhost”);

It displays following exception,

Connected
Exception in thread “main” remote-server-not-found(404)
at org.jivesoftware.smackx.packet.SyncPacketSend.getReply(SyncPacketSend.java:53)
at org.jivesoftware.smackx.packet.SyncPacketSend.getReply(SyncPacketSend.java:61)
at org.jivesoftware.smackx.pubsub.PubSubManager.getNode(PubSubManager.java:161)
at Os.main(Os.java:26)

Replace localhost with your xmpp.domain srinicomputer