public ClientSession getSession(JID from) {
        // Return null if the JID is null or belongs to a foreign server. If the server is
        // shutting down then serverName will be null so answer null too in this case.
        if (from == null || serverName == null || !serverName.equals(from.getDomain())) {
            return null;
        }

        // Initially Check preAuthenticated Sessions
        if (from.getResource() != null) {
            ClientSession session = localSessionManager.findPreAuthenticatedSession(from);
            if (session != null) {
                return session;
            }
        }

        if (from.getResource() == null || from.getNode() == null) {
            return null;
        }

        return routingTable.getClientRoute(from);
    }
Returns the session responsible for this JID data. The returned Session may have never sent
an available presence (thus not have a route) or could be a Session that hasn't
authenticated yet (i.e. preAuthenticatedSessions).

@param from the sender of the packet.
@return the <code>Session</code> associated with the JID.
xmppserver/src/main/java/org/jivesoftware/openfire/SessionManager.java