powered by Jive Software

Create Entry and subscription issue. Pls help!

Hi there,

I have been trying to crack this problem for some time now. I am trying to add a roster entry to a user. Here is a sample test code for me to achieve this mean. I used SUBSCRIPTION_ACCEPT_ALL

  • // My own XMPP connection factory+
  • roster = connectionFactory.getConnection().getRoster("user1@localhost.com");+ + Roster.setDefaultSubscriptionMode(Roster.SUBSCRIPTION_ACCEPT_ALL);+ + roster.setSubscriptionMode(Roster.SUBSCRIPTION_ACCEPT_ALL)-+ + roster.createEntry("user2@localhost.com", “myNick”, null);*

I notice that user1 can only see user2 but user2 cannot see user1. In my packetlistener (I know its supposed to be automatic, but one of my futile attemps!):

           if(packet instanceof Presence)
                {
                    Presence presence = (Presence) packet;                                                                    logger.info("Packet instanceof Presence received! Type - " + presence.getType().toString());
                    logger.info(presence.toXML());                         if (presence.getType() == Presence.Type.SUBSCRIBE)
                    {
                            Presence response = new Presence(Presence.Type.SUBSCRIBED);
                            response.setTo(presence.getFrom());
                            connectionFactory.getConnection().sendPacket(response);
                            logger.info("Packet response sent! -> " + response.toXML());
                      }
                    if (presence.getType() == Presence.Type.UNSUBSCRIBE)
                    {                                 Presence response = new Presence(Presence.Type.UNSUBSCRIBED);
                            response.setTo(presence.getFrom());
                            connectionFactory.getConnection().sendPacket(response);
                            logger.info("Packet response sent! -> " + response.toXML());
                      }                                            }

In the jiveroster table

I see that user1 has a ‘sub’ value of 1 while user2 has a ‘sub’ value of 2. Can anybody please point me to the right direction. I am still struggling to find out what the problem is. I have read all the archived messages and tried every suggestion but in vain (or maybe I still dun understand what it means). I am currently using OpenFire 3.3.2 and Smack 2.2.1

Another question: What will happen if user1 try to add user2 while user2 is still offline? Will the user2 receive the Presence packet once he is online? I did not get that behaviour if its so.

I have finally solved (hopefully!) it by adding anothe packet response

if (presence.getType() == Presence.Type.SUBSCRIBE)

{

Presence response = new Presence(Presence.Type.SUBSCRIBED);

response.setTo(presence.getFrom());

connectionFactory.getConnection().sendPacket(response);

{color:#ff0000} Presence response2 = new Presence(Presence.Type.SUBSCRIBE);

response2.setTo(presence.getFrom());

connectionFactory.getConnection().sendPacket(response2);

logger.info("Packet response sent! -> " + response.toXML());

}

if (presence.getType() == Presence.Type.UNSUBSCRIBE)

{

Presence response = new Presence(Presence.Type.UNSUBSCRIBED);

response.setTo(presence.getFrom());

connectionFactory.getConnection().sendPacket(response);

logger.info("Packet response sent! -> " + response.toXML());

}

I have to send a ‘subscribe’ AND ‘subscribed’ request. I tried this after looking at how webjabber works. But i still do not get it. I have set the subscription to AUTO, why do I still need to do this?

Thanks!

Bump…

anybody can explain to me these following doubts? I need to find out whether I am doing this correctly or I am making a mess here.

  1. How does the subscription works if the user1 send a subscribe request to user2 who is still offline? Will user2 get the presence packet once he goes online. I am quite worried here as I do not get any such packets after being online

  2. from the codes above, I set my listener to grab presence packets to make it work. Funnily, I already set subscription mode to ACCEPT_ALL but to no effects. I find no difference even if I set it to MANUAL.

Thanks