Skip navigation
17735 Views 32 Replies Latest reply: Feb 7, 2012 6:14 AM by rcollier RSS
rcollier KeyContributor 600 posts since
Mar 4, 2009
Currently Being Moderated

Aug 7, 2009 8:28 AM

Pubsub Extensions for Smack

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.

Attachments:
  • squaremo Bronze 3 posts since
    Jun 14, 2009
    Currently Being Moderated
    Jun 14, 2009 7:26 PM (in response to rcollier)
    Re: Pubsub Extensions for Smack

    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

  • williamyeh Bronze 4 posts since
    Jul 20, 2009
    Currently Being Moderated
    Aug 9, 2009 8:09 PM (in response to rcollier)
    Re: Pubsub Extensions for Smack

    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?

      • Dele Olajide KeyContributor 708 posts since
        Apr 10, 2006
        Currently Being Moderated
        Aug 21, 2009 2:01 PM (in response to rcollier)
        Re: Pubsub Extensions for Smack

        Hi Rob,

         

        Excellent work on the pubsub extensions for Smack. Very well written code. Your 15years of experience shows for itself

          • talsam Bronze 10 posts since
            Sep 10, 2009
            Currently Being Moderated
            Sep 18, 2009 6:12 AM (in response to rcollier)
            Re: Pubsub Extensions for Smack

            HI
            I'd like to know how to add this code in Openfire?

            and create a node pubsub?

            thanks

              • talsam Bronze 10 posts since
                Sep 10, 2009
                Currently Being Moderated
                Sep 10, 2009 8:23 AM (in response to rcollier)
                Re: Pubsub Extensions for Smack
                thank you
                is that your code allows me or help me create a node in Openfire?
                • loic Bronze 3 posts since
                  Sep 11, 2009
                  Currently Being Moderated
                  Sep 11, 2009 1:52 AM (in response to talsam)
                  Re: Pubsub Extensions for Smack

                  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

                  Attachments:
                  • squaremo Bronze 3 posts since
                    Jun 14, 2009
                    Currently Being Moderated
                    Sep 11, 2009 3:21 AM (in response to loic)
                    Re: Pubsub Extensions for Smack

                    @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.

                    • loic Bronze 3 posts since
                      Sep 11, 2009
                      Currently Being Moderated
                      Sep 11, 2009 3:41 AM (in response to squaremo)
                      Re: Pubsub Extensions for Smack

                      Hi

                      I had just to run the jar file smackx-pubsub.0.6.jar?????????
                        • loic Bronze 3 posts since
                          Sep 11, 2009
                          Currently Being Moderated
                          Sep 11, 2009 6:31 AM (in response to rcollier)
                          Re: Pubsub Extensions for Smack

                          thank you for your patience robin

                           

                          can tell you how you made a node in your  server Openfire

                          • talsam Bronze 10 posts since
                            Sep 10, 2009
                            Currently Being Moderated
                            Sep 18, 2009 7:15 AM (in response to loic)
                            Re: Pubsub Extensions for Smack
                            we use the library of rcollier I added this connection and I installed Openfire on my machine but there is always a connection problem, where is the problem?
                            can you help me!!

                             

                             

                            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());

                             

                             

                             


                                }
                            }

                              • talsam Bronze 10 posts since
                                Sep 10, 2009
                                Currently Being Moderated
                                Sep 17, 2009 5:05 AM (in response to rcollier)
                                Re: Pubsub Extensions for Smack

                                can you see where is the probleme in theses files

                                 

                                cheers

                              • talsam Bronze 10 posts since
                                Sep 10, 2009
                                Currently Being Moderated
                                Sep 18, 2009 3:30 AM (in response to rcollier)
                                Re: Pubsub Extensions for Smack
                                I took the code hellow word and I add the connection

                                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 ??

                                Attachments:
                                • cometta Bronze 16 posts since
                                  Oct 11, 2009
                                  Currently Being Moderated
                                  Oct 11, 2009 5:21 AM (in response to talsam)
                                  Re: Pubsub Extensions for Smack

                                  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?

                                  • cometta Bronze 16 posts since
                                    Oct 11, 2009
                                    Currently Being Moderated
                                    Oct 16, 2009 5:57 AM (in response to cometta)
                                    Re: Pubsub Extensions for Smack

                                    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 ?

  • MauiMauer Bronze 1 posts since
    Jan 4, 2010
    Currently Being Moderated
    Jan 4, 2010 1:18 PM (in response to rcollier)
    Re: Pubsub Extensions for Smack

    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

    • treffer Bronze 20 posts since
      Dec 10, 2009
      Currently Being Moderated
      Jan 13, 2010 2:42 AM (in response to MauiMauer)
      Re: Pubsub Extensions for Smack

      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.

  • calzon Bronze 1 posts since
    Feb 7, 2012
    Currently Being Moderated
    Feb 7, 2012 1:00 AM (in response to rcollier)
    Pubsub Extensions for Smack

    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).

    calzoncillos

    *A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes.*

More Like This

  • Retrieving data ...

Bookmarked By (0)