public void process(Packet xmppPacket) throws UnauthorizedException, PacketException { Presence presence = (Presence)xmppPacket; try { ClientSession session = sessionManager.getSession(presence.getFrom()); Presence.Type type = presence.getType(); // Available if (type == null) { if (session != null && session.getStatus() == Session.STATUS_CLOSED) { Log.warn("Rejected available presence: " + presence + " - " + session); return; } broadcastUpdate(presence.createCopy()); if (session != null) { session.setPresence(presence); if (!session.isInitialized()) { initSession(session); session.setInitialized(true); } } // Notify the presence manager that the user is now available. The manager may // remove the last presence status sent by the user when he went offline. presenceManager.userAvailable(presence); } else if (Presence.Type.unavailable == type) { broadcastUpdate(presence.createCopy()); broadcastUnavailableForDirectedPresences(presence); if (session == null) { // Recovery logic. Check if a session can be found in the routing table. session = (ClientSession) XMPPServer.getInstance().getRoutingTable() .getRoute(presence.getFrom()); } if (session != null) { session.setPresence(presence); } // Notify the presence manager that the user is now unavailable. The manager may // save the last presence status sent by the user and keep track when the user // went offline. presenceManager.userUnavailable(presence); } else { presence = presence.createCopy(); if (session != null) { presence.setFrom(new JID(null, session.getServerName(), null)); presence.setTo(session.getAddress()); } else { JID sender = presence.getFrom(); presence.setFrom(presence.getTo()); presence.setTo(sender); } presence.setError(PacketError.Condition.bad_request); deliverer.deliver(presence); } } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error") + ". Triggered by packet: " + xmppPacket, e); } }