Export to GitHub

asmack - issue #9

problem with subscriber


Posted on Apr 19, 2010 by Happy Bear

Hi, I'm getting in trouble with the Subscribe function. I created a new method to connect the ItemEventListener to the sever node. I'd like to print the node content by means of the handlePublishedItems but it seems ItemEventListener is not working. Please find enclosed both the code and the log cat session:

Node eventNode; public void subscribe() { manager = new PubSubManager(connection, "pubsub.acer-sele");
eventNode = null; try { eventNode = manager.getNode(PUBLISHER_NODE); Log.i("Subscribe",PUBLISHER_NODE);

} catch (XMPPException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }

// you will need this first time only if(x==0){ try { eventNode.subscribe("user1@acer-sele");

} catch (XMPPException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }

eventNode.addItemEventListener(new ItemEventListener() { public void handlePublishedItems(ItemPublishEvent items) {

Toast.makeText(androidPublishSubscribe.this, items.getItems().toString(), Toast.LENGTH_SHORT).show();

}

});}

}

Thanks in advance for your help Selene

Attachments

Comment #1

Posted on Apr 19, 2010 by Grumpy Rhino

The log actually looks good! The only thing that comes to my mind is a forgotten registration for or item(s), which would (of course) block the parsing. Could you verify (with a pkg listener) that the parsing chain is in deed working?

Comment #2

Posted on Apr 21, 2010 by Happy Bear

Dear René,

First of all, I would like explain better the log that I sent you. In fact, I forgot to mention that the log is produced by an Android application which either acts as publisher and subscriber. Thus, the log contains also the subscriber XML communication.

I have tryed to understand the XML communication too, and I have noticed the following xml stanza the lord of the rings

Considering that I'm not an expert of the XMPP protocol, I thought it was an error sent from by Openfire (XMPP Server) to the ASmack publisher, am I right? If that is the case the problem seems to be related not to the subscriber but to the publishing phase which seems to fail.

Thanks you in advance for your help and time, Selene

Comment #3

Posted on Apr 21, 2010 by Grumpy Rhino

Yes, this is an error message. Which is different from "Listener not working" (I've investigated just that).

Posting rights depend on your "affiliation" with a pubsub node, see http://xmpp.org/extensions/xep-0060.html#affiliations

Please check that your client has sufficient rights to post. XEP-0060 is quite long, but you should have a basic understanding of affiliations, subsciptions, nodes and items.

You should look into PSI (a good-for-debugging xmpp client, just enable the "xml console"). Then try to send (modified version of) the stanzas described in http://xmpp.org/extensions/xep-0060.html#entity-affiliations

Do you have other clients succeeding at posting?

Regards, René

Comment #4

Posted on Apr 21, 2010 by Swift Hippo

Dear René,

I have helped Selene in performing further testing and we figure out that the problem is a bit different. In fact, from your last message you confirm that the problem was not the callback of the listener but the publishing that was failing. Thus, we performed other tests to understand better the problem. Following the test that we performed.

A - Preliminary Test: Two Java plain application (both using Smack from SVN), namely Publisher and Subscriber. The Publisher was generating events every 5s, while the Subscriber subscribe to event and show them on the STDOUT. The test worked perfectly, thus from now on, we can rely on the goodness of both Publisher and Subscriber for testing ASmack.

B - Testing ASmack PubSub status: B.1 - ASmack used as Publisher We started the Java Subscriber application, and later we started the Android application which publishes events. The result was that the Subscriber never received the event notification B.2 - ASmack used as Susbcriber We started the Java Publisher application, and later we started the Android application which subscribe for events. The result was that the SMACK library on Android received XML Stanza as event notification but the ItemEventListener registered never got the notification.

Regarding your questions "Do you have other clients succeeding at posting?", in out latest test we used Smack for sending events and during that test the problem was exactly the one that you guessed in your #1 comment. Regarding that we will try to repeat the Test B.2 with an org.jivesoftware.smack.PacketListener registered (as you suggested).

As additional point, when ASmack was used as subscriber, even if the library was getting the notification (but the ItemEventListener was not invoked), ASmack disconnection from the XMPP Server after a certain amount of time.

Best regards, Stefano "Kismet" Lenzi

P.S.: You can find attach the log of either Smack and ASmack for all the tests.

Attachments

Comment #5

Posted on Apr 21, 2010 by Swift Hippo

Hi René,

We have just tested the subscriber part with the most generic packet filter: connection.addPacketListener(listener,new PacketTypeFilter(Message.class)); and we actually received the notification, which means that we may have missed the registration of some ExtensionProvider or IQProvider. Do you have any tips for figuring out which registration we missed?

Of course, the publishing problem is still open but we will look at it after fixing this one -_^

Best Regards, Stefano "Kismet" Lenzi

P.S.: I haven't attached the log this time but I can do that if you want to

Comment #6

Posted on Apr 21, 2010 by Grumpy Rhino

I'm doing heavy pubsubing @buddycloud, so just scan through http://code.google.com/p/buddycloud/source/browse/trunk/client/android/main/src/com/buddycloud/jbuddycloud/BuddycloudClient.java#45 - look for "pubsub", "event", "item"

It's an in-code translation of https://svn.igniterealtime.org/svn/repos/smack/trunk/build/resources/META-INF/smack.providers

Comment #7

Posted on Apr 21, 2010 by Grumpy Rhino

Could you verify that your Smack app can publish as user1? I'm seeing just a publish as selene....

Comment #8

Posted on Apr 21, 2010 by Swift Hippo

Hi again,

I hope that we are not spamming you too much -_^, in fact we are going deeper and deeper, and I believe that we are near to seize the problem :) In fact, we checked if we missed the registration of any PacketExtension, and it doesn't seem the case :S In the following, our consideration: let's start from the message that does not trigger the event notification: http://jabber.org/protocol/pubsub#event'> nullnullIt's time to work 21-apr-2010 18.25.02nullnull mpjTff3gc3Wec57vLt6V2VEgPYv5CUabG3L6h4Ka As far as I understood for parsing the above message I have to register an ExtensionProvider only for the XML element: event, items and item, am I right?

I have looked again to the list of the ExtensionProvider that our Android application register and we found out (among other) the following: pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub#event", new org.jivesoftware.smackx.pubsub.provider.ItemsProvider());

     pm.addExtensionProvider("item",
            "http://jabber.org/protocol/pubsub#event",
            new org.jivesoftware.smackx.pubsub.provider.ItemProvider());
     pm.addExtensionProvider("event",
            "http://jabber.org/protocol/pubsub#event",
            new org.jivesoftware.smackx.pubsub.provider.EventProvider());

So it looks like that the parsing of the packet should complete without any error, am I right? Is it possible, that, by chance, we should register parser also for the headers and header XML elements?

I'm looking forward for your comments -_^

Best regards, Stefano "Kismet" Lenzi

Comment #9

Posted on Apr 21, 2010 by Swift Hippo

I think I found the problem and we may be stuck. In fact, I found out (by comparing the buddycloud extension registration with smack sources on the link that you posted in the comment #6) that Smack registers the PacketExtension for headers and header element of the "http://jabber.org/protocol/shim" namespace (look at line 482 of https://svn.igniterealtime.org/svn/repos/smack/trunk/build/resources/META-INF/smack.providers), but current version of ASmack does not contain the PacketExtension implementing the parsing for such elements. How can we proceed?

Should I steal the code from Smack original library and try to adapt them to android if they are using reflection (aka Java Bean) design ? Or are you going to update ASmack to fulfill the gap?

Waiting on you...

Stefano "Kismet" Lenzi

Comment #10

Posted on Apr 21, 2010 by Swift Hippo

I have just read the comment #7 , but I have not understood it what are you suggested me to do....

Stefano "Kismet" Lenzi

Comment #11

Posted on Apr 21, 2010 by Grumpy Rhino

Comment #7 is very simple, I see different users / resources for the smack and asmack test cases, and I'd like to eliminate this as a possible source.

I'll also try to push out a new release, look like I've missed some recent trunk action. But please don't wait for that.

Missing header support sounds bad. Smack hat a horrible parser for messages iirc. Might kill the whole message parsing (and, as a result, kill the connection)

Comment #12

Posted on Apr 21, 2010 by Happy Bear

Let me say only..... IT WORKS :)

We added the missing PacketExtension for element header and headers which we found out are available in the current version of ASmack

Thank you for the help!

We will post the final "initialization code" that may result useful to other people tomorrow!

Thank you again!

Best regards, Selene Stefano "Kismet" Lenzi

Comment #13

Posted on Apr 21, 2010 by Grumpy Rhino

Ok, so I'll regard the key problems as solved. Please open a new issue if you I can help e.g. by syncing with trunk or alike! Oh, and feel free to add arty@jabber.ccc.de

Regards. Rene

Comment #14

Posted on Apr 22, 2010 by Swift Hippo

Dear Renè,

The solution as I told you was only related to the initialization of ASmack. In particular, we missed the registration of PacketExtension for the elements headers and header which are contained by the XML stanza representing the event.

Moreover, we found out that ASmack contains the PacketExtension for the elements headers and header ( I was wrong in comment #9 when I said that "ASmack does not contain the PacketExtension implementing the parsing for such elements")

You can find attched the code that we used and that is working for receiving event on Android with ASmack ( I don't know yet if it is enough for publishing event too because the publishing is not working yet )

I think that the code attached could result really useful to other people, and it would be nice if you can create a wiki page where we can start to document "How to use ASmack" or "FAQ for beginner"

Best regards, Stefano "Kismet" Lenzi

P.S.: Is arty@jabber.ccc.de your jabber account?

Attachments

Comment #15

Posted on Dec 16, 2012 by Helpful Bear

Is there any one here who has solved the issue of getting published item , as i am using following code and i am not be able to receiver the notification of published item for subscribers

   PubSubManager mgr = new PubSubManager(cxmpp,"pubsub.example.com");

        Node node = null;
                try {

           //get the node

                          node = mgr.getNode("mynode/loc");

           // register listner

                          node.addItemEventListener(new ItemEventCoordinator());

          //subscribe
                          node.subscribe("james@example.com");

                } catch (XMPPException e) {


                          e.printStackTrace();
                }

and the event listener for incoming published items

       class ItemEventCoordinator  implements ItemEventListener
 {
     @Override
     public void handlePublishedItems(ItemPublishEvent items)
     {
         System.out.println("Item count: " + items.getItems().size());
         System.out.println(items);
                }
      }

even i have tried to listen incoming packets , but i am not getting anything not even in debug window

    PacketTypeFilter filter = new PacketTypeFilter(org.jivesoftware.smack.packet.Message.class);

can anyone help me over this

Comment #16

Posted on Nov 15, 2013 by Happy Rhino

15 You find a solution?

i can subscribe ,publish ,but i can't get the pubsub message event!

Comment #17

Posted on Nov 17, 2013 by Helpful Bear

you got to modify the asmack code as the current jar that you having doesnt send notification of published item for subscribers

Comment #18

Posted on Nov 18, 2013 by Swift Rabbit

Please report any problems with the current version of (a)Smack's pubsub code to the igniterealtime community forums. Extra kudos if it contains the fix as a patch. :)

Are you using the latest aSmack version?

Status: Done

Labels:
Type-Defect Priority-Medium