sr6582924 / asmack

Automatically exported from code.google.com/p/asmack
Other
0 stars 0 forks source link

problem with subscriber #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

Original issue reported on code.google.com by el3t...@gmail.com on 19 Apr 2010 at 3:00

Attachments:

GoogleCodeExporter commented 9 years ago
The log actually looks good! The only thing that comes to my mind is a forgotten
registration for <event xmlns="http://jabber.org/protocol/pubsub#event"> 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?

Original comment by rtreffer@gmail.com on 19 Apr 2010 at 10:09

GoogleCodeExporter commented 9 years ago
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
<iq type="error" id="M0ynN-6" from="pubsub.acer-sele" to="user1@acer-
sele/Smack"><pubsub xmlns="http://jabber.org/protocol/pubsub"><publish 
node="SeleneNode"><item id="titolo1"><book xmlns="pubsub:test:book"><title>the 
lord 
of the rings</title></book></item></publish></pubsub><error code="403" 
type="auth"><forbidden 
xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

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

Original comment by el3t...@gmail.com on 21 Apr 2010 at 2:32

GoogleCodeExporter commented 9 years ago
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é

Original comment by rtreffer@gmail.com on 21 Apr 2010 at 3:22

GoogleCodeExporter commented 9 years ago
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.

Original comment by kismet...@gmail.com on 21 Apr 2010 at 4:07

Attachments:

GoogleCodeExporter commented 9 years ago
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

Original comment by kismet...@gmail.com on 21 Apr 2010 at 4:30

GoogleCodeExporter commented 9 years ago
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/sm
ack.providers

Original comment by rtreffer@gmail.com on 21 Apr 2010 at 4:44

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

Original comment by rtreffer@gmail.com on 21 Apr 2010 at 4:45

GoogleCodeExporter commented 9 years ago
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:
<message 
 id="SeleneNode__user1@acer-sele__FfqUl" 
 to="user1@acer-sele" 
 from="pubsub.acer-sele">
  <event xmlns='http://jabber.org/protocol/pubsub#event'>
   <items node='SeleneNode'>
    <item id='qCROUWBL09x1JP6'>
     nullnullIt's time to work 21-apr-2010 18.25.02nullnull
    </item>
   </items>
  </event>
  <headers xmlns="http://jabber.org/protocol/shim">
   <header>mpjTff3gc3Wec57vLt6V2VEgPYv5CUabG3L6h4Ka</header>
  </headers>
</message>
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

Original comment by kismet...@gmail.com on 21 Apr 2010 at 4:57

GoogleCodeExporter commented 9 years ago
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/sm
ack.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

Original comment by kismet...@gmail.com on 21 Apr 2010 at 5:10

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

Stefano "Kismet" Lenzi

Original comment by kismet...@gmail.com on 21 Apr 2010 at 5:12

GoogleCodeExporter commented 9 years ago
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)

Original comment by rtreffer@gmail.com on 21 Apr 2010 at 5:34

GoogleCodeExporter commented 9 years ago
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

Original comment by el3t...@gmail.com on 21 Apr 2010 at 5:46

GoogleCodeExporter commented 9 years ago
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

Original comment by rtreffer@gmail.com on 21 Apr 2010 at 8:00

GoogleCodeExporter commented 9 years ago
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?

Original comment by kismet...@gmail.com on 22 Apr 2010 at 1:31

Attachments:

GoogleCodeExporter commented 9 years ago
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 

Original comment by ntim...@gmail.com on 16 Dec 2012 at 6:47

GoogleCodeExporter commented 9 years ago
#15 You find a solution?
i can subscribe ,publish ,but i can't get the pubsub message event!

Original comment by lengxueb...@gmail.com on 15 Nov 2013 at 6:40

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

Original comment by ntim...@gmail.com on 17 Nov 2013 at 10:52

GoogleCodeExporter commented 9 years ago
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?

Original comment by fschm...@gmail.com on 18 Nov 2013 at 12:48