Project

General

Profile

not able to receive subscription request

sujan m
Added about 1 month ago

i was able to send a subscription request from one user to other but not able to receive that request. If anyone provide that handler code that will be very helpful. thank you


Replies (8)

(1)

Added by Wojciech Kapcia about 1 month ago

You need to define a handler responsible for handling received subscription request, for example:

        Jaxmpp.getEventBus().addHandler(PresenceModule.SubscribeRequestHandler.SubscribeRequestEvent.class, new PresenceModule.SubscribeRequestHandler() {
            @Override
            public void onSubscribeRequest(SessionObject sessionObject, Presence stanza, BareJID jid) {

            }
        });

Added by sujan m about 1 month ago

I did the same thing but was not able to get it work. please help me with this

this is my code:

final Jaxmpp user1 = new Jaxmpp();
final Jaxmpp user2=new Jaxmpp();
user1.login();
tigase.jaxmpp.j2se.Presence.initialize(user1);
tigase.jaxmpp.j2se.Presence.initialize(user2);
user1.getModulesManager().register(new PresenceModule());
user2.getModulesManager().register(new PresenceModule());
Presence p = Presence.create();
p.setType(StanzaType.subscribe);
p.setTo(JID.jidInstance(""));
user1.send(p);
user2.login();
user2.getEventBus().addHandler(PresenceModule.SubscribeRequestHandler.SubscribeRequestEvent.class, new PresenceModule.SubscribeRequestHandler() {
@Override
public void onSubscribeRequest(SessionObject sessionObject, Presence stanza, BareJID jid) {
// TODO Auto-generated method stub
System.out.println(jid.toString());
try {
System.out.println(stanza.getAsString());
} catch (XMLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});

Added by Andrzej Wójcik about 1 month ago

There are a few issues with the code which you presented:
  • addHandler() on user2 should be called before calling login()
  • call to tigase.jaxmpp.j2se.Presence.initialize() should be done before login() method of Jaxmpp instance is called
  • if you use tigase.jaxmpp.j2se.Presence.initialize() then there is no point to call getModulesManager().register()
Except from that I assume that:
  • you are aware that Jaxmpp login() method is asynchronous, so you need to wait for connection establishment before you will receive SubscribeRequestEvent
  • you have configure user/account credentials properly for user1 and user2 instances of Jaxmpp

Added by sujan m about 1 month ago

I have incorporated all the changes you pointed out. The user credentials is also correct. Even though I am not able to get it work.

this is my code:

            final Jaxmpp user1 = new Jaxmpp();
            final Jaxmpp user2=new Jaxmpp();

        tigase.jaxmpp.j2se.Presence.initialize(user1);
            tigase.jaxmpp.j2se.Presence.initialize(user2);

            user1.login();

        Presence p = Presence.create();
          p.setType(StanzaType.subscribe);
          p.setTo(JID.jidInstance("mangala@idc.oracle.com"));
          user1.send(p);

         user2.getEventBus().addHandler(PresenceModule.SubscribeRequestHandler.SubscribeRequestEvent.class, new PresenceModule.SubscribeRequestHandler() {

            @Override
            public void onSubscribeRequest(SessionObject sessionObject, Presence stanza, BareJID jid) {
                // TODO Auto-generated method stub
                System.out.println(jid.toString());
                try {
                    System.out.println(stanza.getAsString());
                } catch (XMLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

          });
          user2.login();

Added by sujan m about 1 month ago

Is there anything I should do with the dispatch method. If yes can anyone provide that code. Thank you.

Added by Wojciech Kapcia about 1 month ago

sujan m wrote:

Is there anything I should do with the dispatch method. If yes can anyone provide that code. Thank you.

You could use simpler form:

Jaxmpp.getModule(PresenceModule.class).subscribe(userJID);

At any rate:
  • please check that the presence is actually send and delivered - you can enabled/adjust logging with:
    Logger log = Logger.getLogger( "tigase.jaxmpp" );
    log.setLevel( Level.ALL );
    

Added by sujan m about 1 month ago

Yes, I made sure that the presence packet is received but was not able to get it in the client i wrote(The handler is not getting invoked)

Added by Wojciech Kapcia 28 days ago

sujan m wrote:

Yes, I made sure that the presence packet is received but was not able to get it in the client i wrote(The handler is not getting invoked)

How did you verified that the packet is received? Have you seen the packet in the logs but only the handler wasn't invoked? Could you share the complete logs?

    (1-8/8)