Aug 7, 2009 8:28 AM
Pubsub Extensions for Smack
-
Like (0)
I have included the work I have done for adding pubsub support to Smack. The three jars contain the binaries, source and javadoc. I will try to create some user documentation as soon as I get the chance. It was suggested to upload it as an eclipse patch, but this is entirely new code with no alterations to the existing Smack library, so I just uploaded the source code as is.
This code has been tested against a customized version of OpenFire in which I fixed a couple of existing bugs, I will be uploading those as real patches as soon as possible. It was designed around version 1.12 of the spec, and the current OpenFire implementation supports 1.8 (I believe). Some of the basic functionality should still work with that spec, I will try to document the issues when I get the chance.
For anyone that wants to give it a try, start at the PubSubManager class, it should be pretty simple from there (famous last words).
I have created a new thread instead of posting to the existing one (http://www.igniterealtime.org/community/message/191247#191247) since I wasn't sure if the patch tag would get picked up by the powers that be.
Updated to version 0.6
- Fixed some bugs
- Node from previous version is now LeafNode. Node is a base class for LeafNode and CollectionNode. Please note though, CollectionNode exists as a placeholder for future usage, it has not been tested! That being said, some of the basic functionality from the base class (Node) should still work since it is not specific to either node type.
- There is now an Item and PayloadItem vs. the Item<PacketExtension> type that previously existed.
- Source code jar has been removed and will now only reside in the <a href="http://www.igniterealtime.org/issues/browse/
SMACK-272" target="_blank">JIRA task</a>.
Javadoc still needs to be updated to reflect these changes.
Awesome.
rcollier, I hope you don't mind, I've mavenised this and started making the tests work with ejabberd too. It's up at github: http://github.com/squaremo/smackx-pubsub/tree/master
At the minute I am pointing to your profile here as the original author. Let me know if I can do better.
cheers
mikeb
That's great. I don't have the time and resources right now to test against other implementations, so any help in that domain is definitely appreciated.
Changing the node naming convention should work in OpenFire as well (although I haven't tried it), as I didn't see any restrictions when perusing that code.
Also, I have a newer version that fixes a bug I found. Just one file to update so I will see if I can manage that in github (haven't used it before).
OK, I probably don't have permissions for updating the source, so I will include the file here.
I replaces the existing one in org.jivesoftware.smackx.pubsub
If you follow smackx-pubsub on github, I will spot you and add you as a developer (let me know your username there if it's not rcollier); or, if you prefer, you can fork it and pull across changesets.
In the meantime I'll apply your patch -- thanks!
mikeb.
I have created an account there under rcollier as well.
The new LeafNode/CollectionNode and Item/PayloadItem organization is much better than 0.4. Thanks for your job!
BTW, the PubSubManager.getNodes() was missing in 0.6. Is there any alternative?
Thanks for the feedback and I am glad you like the changes.
I removed it since it didn't actually do as was advertised (get all nodes). It was only returning all nodes under root, the same as discoverNodes(), and then creating ready to use Node objects. Since the node creation could also be an issue fi there were a significant number of nodes, I removed it. You can use discoverNodes() to get the same list of node id's and then call getNode(id) to retrieve the actual Node object, so no actual functionality is missing.
I am hoping to get a chance to work on the CollectionNode in the near future so that will have the ability to get the child nodes and drill down a hierarchy.
Hi Rob,
Excellent work on the pubsub extensions for Smack. Very well written code. Your 15years of experience shows for itself ![]()
Thank you, I am not sure how I am going to get my head through the door now ![]()
HI
I'd like to know how to add this code in Openfire?
and create a node pubsub?
thanks
Not sure what you mean. This is a client library, so it is inherently meant for developers to use to access the pubsub features of an XMPP server, such as OpenFire. If you want some kind of admin console or UI for creating nodes, to my knowledge neither one exists for OpenFire specifically, but you may be able to find one that supports that functionality from a third party. Personally, I don't know of one, but I haven't looked either.
There is a Jira task for Openfire already to create a pubsub admin console, but it is not done yet.
I'm in the same situation as you I d'ont know how to integrate this code, although in Openfire is a link to download the plugin and I can not download the plugin rcollier
thank you for help
@loic: this library isn't a server plugin -- OpenFire already supports XEP-0060 (pubsub). It's a client library, which you can use to drive pubsub operations in OpenFire and with some luck, ejabberd and others.
@talsam You can indeed use it to create a node and publish to it. The unit tests have examples of doing that.
Hi
No. It is a library, not an application. That means it is used by developers to write applications for using pubsub features.
An application which allows the user to administer (create/edit) nodes would be an example of such usage that someone could use this library for.
thank you for your patience robin
public class Test
{
public static void main(String[] args) {
//PubSubManager test = new PubSubManager(connection, "");
XMPPConnection connection = new XMPPConnection("127.0.0");
PubSubManager test = new PubSubManager("127.0.0");
test.connection("127.0.0");
test.createNode("firstnode");
//System.out.println(test.createNode);
System.out.println(test.getNodes());
}
}
You still need smack.jar and smackx.jar on your classpath (before smacx-pubsub.jar). You have classpath issues, plus the output is not even from the Test class specified, but from another one called Toto?!? There is also no connection method on PubSubManager. Please look at the Hello World example as that is working code. The only thing missing is the connect and login to your server. Look at the last posting which explains how to setup the PubSubManager.
can you see where is the probleme in theses files
cheers
public class Toto1
{
public static void main(String[] args) {
XMPPConnection connection = new XMPPConnection("127.0.0.1", 5222);
//XMPPConnection connection = new XMPPConnection("localhost",5222);
//connection.login("admin", "admin");
ConfigureForm form = new ConfigureForm(FormType.submit);
form.setPersistentItems(false);
form.setDeliverPayloads(true);
form.setAccessModel(AccessModel.open);
PubSubManager manager = new PubSubManager(connection);
myNode = manager.createNode("TestNode", form);
//public SimplePayload(String elementName, String namespace, String xmlPayload)
SimplePayload payload = new SimplePayload("book","pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>");
Item<SimplePayload> item = new Item<SimplePayload>(itemId, payload);
// Required to recieve the events being published
myNode.addItemEventListener(myEventHandler);
// Publish item
myNode.publish(item);
eventNode = manager.getNode("TestNode");
eventNode.addItemEventListener(myEventHandler);
eventNode.subscribe("myJID");
connection.close();
}
}
in fiel "PubSubManager"
final public class PubSubManager
{
/** Server name */
public static final String SERVER_NAME = "localhost";
/** Server port */
public static final int SERVER_PORT = 5222;
/** user - for login */
private final String user;
/** Client password - for login*/
private final String password;
private XMPPConnection con;
private String to;
private ConcurrentHashMap<String, Node> nodeMap = new ConcurrentHashMap<String, Node>();
// Create a connection to the igniterealtime.org XMPP server.
XMPPConnection connection = new XMPPConnection("localhost",5222);
// Connect to the server
connection.connect();
// Most servers require you to login before performing other tasks.
connection.login("user", "password");
/**
* Create a pubsub manager associated to the specified connection.
*
* @param connection The XMPP connection
*/
public PubSubManager(XMPPConnection connection)
{
con = connection;
}
|
|
|
|
|
// Disconnect from the server
connection.disconnect();
}
error ???????????
C:\Documents and Settings\Bureau\noeudspubsub\org\jivesoftware\smackx\pubsub\Toto1.java:10: cannot find symbol
symbol : class XMPPConnection
location: class Toto1
XMPPConnection connection = new XMPPConnection("127.0.0.1", 5222);
^
C:\Documents and Settings\Bureau\noeudspubsub\org\jivesoftware\smackx\pubsub\Toto1.java:10: cannot find symbol
symbol : class XMPPConnection
location: class Toto1
XMPPConnection connection = new XMPPConnection("127.0.0.1", 5222);
^
C:\Documents and Settings\Bureau\noeudspubsub\org\jivesoftware\smackx\pubsub\Toto1.java:16: cannot access ConfigureForm
bad class file: .\ConfigureForm.class
class file contains wrong class: org.jivesoftware.smackx.pubsub.ConfigureForm
Please remove or make sure it appears in the correct subdirectory of the classpath.
ConfigureForm form = new ConfigureForm(FormType.submit);
^
3 errors
Processus terminé avec code quitter 1
where is the probleme ??
1.can someone post workabout example of helloworld with "xmppconnection" ?
2.is there any configuration need to add/edit at openfire server?
3. is openfire port 5222 open by default for the connection?
The subscriber will only receive content from the moment he is subscripting to a node and all old content published by publisher will not be received by subscriber. Is this correct? May i know, what do i need to do in order for subscriber to receive all previous old content ?
Old content can only be retrieved if the node is persistent. If it is configured this way, then calling LeafNode.getItems() will retrieve all persisted items.
The pubsub extensions for Smack have now been committed to the codebase (in trunk) and can be obtained if you retrieve it from svn. From what I can tell, the nightly builds are no longer done or published, which is too bad as this would be a much easier way to obtain and use it.
Hi there,
thanks to your great contribution I was able to integrate XEP-0118 (Tune) into my application. Publishing my current track works as expected and could be confirmed with Psi at the other end. However now I'm quite confused on how to react on PubSub Events on my side. E.g. what do I have to do to process for ex. Tune Events from other users?
Could anybody be so kind and point me into the right direction or even post a small example?
Thanks in Advance,
Maui
You have several options.
No customization:
You can deal with the XML via the SimplePayload class which will already be returned in the PayloadItem. This requires no extra work, but is not overly friendly to deal with. In all likelihood, you will want to have a custom class to represent a Tune element.
Create custom TunePayload:
The best thing to do is
1) create a TunePayloadProvider that implements PacketExtensionProvider that will parse the Tune element of the item and return a TunePayload which extends PacketExtension
2) register this provider in the smack.providers file by its namespace "http://jabber.org/protocol/tune"
3) Now a call to PayloadItem.getItem() will return a TunePayload.
This also has the added benefit of being able to create TunePayload objects to publish as well.
Sorry but I don't have more time to elaborate with examples, but this is the basics of what you should do.
Good luck.
Robin
Here is our samplecode:
@SuppressWarnings("unchecked")
@Override
public void processPacket(Packet packet) {
try {
if (packet instanceof Message) {
Message message = (Message) packet;
for (PacketExtension packetExtension : message.getExtensions()) {
if (!(packetExtension instanceof EventElement)) {
continue;
}
EventElement event = (EventElement) packetExtension;
for (PacketExtension eventExtension : event.getExtensions()) {
if (!(eventExtension instanceof ItemsExtension)) {
continue;
}
ItemsExtension items = (ItemsExtension) eventExtension;
String node = items.getNode();
for (PacketExtension itemsExtension : items.getExtensions()) {
if (!(itemsExtension instanceof PayloadItem)) {
continue;
}
PayloadItem payload = (PayloadItem) itemsExtension;
if (payload.getPayload() instanceof BCAtom) {
Works so far. Just replace BCAtom with your payload.
If you register a listener for the node, then you don't need any of the code you are using since the method, handlePublishedItems(ItemPublishEvent<T> items) will be called on your listener. The ItemPublishEvent contains the list of items already.
Your code sample shows how to filter incoming packets manually to get the item events, but this is not really necessary.
Thanks a bunch! Will try it out. Wish there was a PEP example like yours ![]()
I have almost completed a pubsub extension to Smack and will be submitting it as a patch in a week or two. It does not actually change the existing smack libraries, so it can be used along with the existing version (3.1) by simply including the additional jar file. It is compliant to pubsub version 1.12 though,so I have had to make a few upgrades and fixes to OpenFire as well for it to work properly (since the current supported version is earlier than that).
*A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes.*
Sounds great, new contributions are welcome.
When you are done, can you attach it as a patch file against the current trunk (we are up to 3.2.2 now)? I will then attach it to
SMACK-364.
Could you please add it as a new discussion item altogether though instead of continuing this rather old one.
Thanks!