powered by Jive Software

Retrieving full JID (including ressource)

Jingle needs to use the full JID (user@server/ressource).

When looping through the collection of RosterEntries in my roster, I do have access to all the RosterEntry BUT this object’'s getUser() method only returns the formatted string “user@server”. Therefore, the ressource is missing and I cannot use the Jingle library without this information…

What am i missing ???

Here is the portion of code that authentificate a users, searches for a matching “skaber” user in the roster and tries to open a jingle session using the ICETransportManager. Shouldn’'t entry.getUser() return the full JID as written in the source comments instead of the “user@server” format ?

public void actionPerformed(ActionEvent e)

{

if (“btnLoginClick” == e.getActionCommand()) {

if (comm == null && !comm.isConnected()) {

comm = new XMPPConnection(“gmail.com”);

try {

comm.connect();

comm.login(txtUser.getText(), String.valueOf(txtPass.getPassword()));

} catch (Exception exp) {

System.out.println(exp.getMessage());

}
}

if (comm.isConnected()) {

Roster roster = comm.getRoster();

Collection entries = roster.getEntries();

Iterator i = entries.iterator();

while (i.hasNext()) {

RosterEntry entry = (RosterEntry)i.next();

System.out.println(entry.getUser());

if (entry.getUser().contains(“skaber”)) {

Message msg = new Message(entry.getUser(), Message.Type.chat);

msg.setBody(“You will receive a call…”);

comm.sendPacket(msg);

ICETransportManager icetm0 = new ICETransportManager(comm, “jivesoftware.com”, 3478);

JingleManager jm = new JingleManager(comm, icetm0, new JmfMediaManager());

try {

OutgoingJingleSession session = jm.createOutgoingJingleSession(entry.getUser());

session.start();

} catch (Exception exp) {

System.out.println(exp.getMessage());

}

}

}

}

}

}

Hello,

You are actually confusing a roster entry with a particular user session. You add entries to the roster in the form of user@domain and the documentation says that the getUser() method returns the JID, not the full JID. Using just the basic JID in the roster allows you to get information about all the user’‘s sessions. Once you have a user entry in your roster, you can then monitor their presence. Since a user can login multiple times, each login is associated with a named resource to distinguish the different sessions, which is the last part of the full JID (user@domain/resource). Therefore, in order to get a full JID you need to look at the user’'s most active/current presence packet, which would include that information.

Look at the documentation for the following methods in the Roster class: getPresence(), getPresenceResource(), getPresences() to get the presence information you need. Then, once you have a presence object, use the getFrom() method to get the full JID.

Chris

1 Like