public void route(Presence packet) {
        if (packet == null) {
            throw new NullPointerException();
        }
        ClientSession session = sessionManager.getSession(packet.getFrom());
        try {
            // Invoke the interceptors before we process the read packet
            InterceptorManager.getInstance().invokeInterceptors(packet, session, true, false);
            if (session == null || session.getStatus() != Session.Status.CONNECTED) {
                handle(packet);
            }
            else if (SessionPacketRouter.isInvalidStanzaSentPriorToResourceBinding(packet, session)) {
                Log.debug("Closing session that attempts to send stanza to an entity other than the server itself or the client's account, before completing resource binding. Session closed: {}", session);
                session.deliverRawText(new StreamError(StreamError.Condition.not_authorized).toXML());
                return;
            }
            else {
                packet.setTo(session.getAddress());
                packet.setFrom((JID)null);
                packet.setError(PacketError.Condition.not_authorized);
                session.process(packet);
            }
            // Invoke the interceptors after we have processed the read packet
            InterceptorManager.getInstance().invokeInterceptors(packet, session, true, true);
        }
        catch (PacketRejectedException e) {
            if (session != null) {
                // An interceptor rejected this packet so answer with an error.
                Presence reply = new Presence();
                reply.setID(packet.getID());
                reply.setTo(session.getAddress());
                reply.setFrom(packet.getTo());

                if (e.getRejectionError() != null) {
                    reply.setError(e.getRejectionError());
                } else {
                    reply.setError(PacketError.Condition.not_allowed);
                }
                session.process(reply);

                // Check if a message notifying the rejection should be sent
                if (e.getRejectionMessage() != null && !e.getRejectionMessage().trim().isEmpty()) {
                    // A message for the rejection will be sent to the sender of the rejected packet
                    Message notification = new Message();
                    notification.setTo(session.getAddress());
                    notification.setFrom(packet.getTo());
                    notification.setBody(e.getRejectionMessage());
                    session.process(notification);
                }
            }
        }
    }
Routes presence packets.

@param packet the packet to route.
@throws NullPointerException if the packet is null.
xmppserver/src/main/java/org/jivesoftware/openfire/PresenceRouter.java