* sender cannot probe the presence of the requested user. Or if the requested user
* does not exist in the local server.
*/
public Presence getPresence(String sender, String jid) throws UserNotFoundException {
if (jid == null) {
throw new UserNotFoundException("Target JID not found in request");
}
JID targetJID = new JID(jid);
// Check that the sender is not requesting information of a remote server entity
if (targetJID.getDomain() == null || XMPPServer.getInstance().isRemote(targetJID)) {
throw new UserNotFoundException("Domain does not matches local server domain");
}
if (!hostname.equals(targetJID.getDomain())) {
// Sender is requesting information about component presence, so we send a
// presence probe to the component.
presenceManager.probePresence(componentJID, targetJID);
// Wait 30 seconds until we get the probe presence result
int count = 0;
Presence presence = probedPresence.get(jid);
while (presence == null) {
if (count > 300) {
// After 30 seconds, timeout
throw new UserNotFoundException(
"Request for component presence has timed-out.");
}
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
// don't care!
}
presence = probedPresence.get(jid);
count++;
}
// Clean-up probe presence result
probedPresence.remove(jid);
// Return component presence
return presence;
}
if (targetJID.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(targetJID.getNode())) {
// Sender is requesting presence information of an anonymous user
throw new UserNotFoundException("Username is null");
}
if (!isPresencePublic()) {
if (sender == null) {
throw new UserNotFoundException("Sender is null");
}
else if (!presenceManager.canProbePresence(new JID(sender), targetJID.getNode())) {
throw new UserNotFoundException("Sender is not allowed to probe this user");
}
}
User user = userManager.getUser(targetJID.getNode());
return presenceManager.getPresence(user);
}