private boolean routeToLocalDomain(JID jid, Packet packet)
    {
        boolean routed = false;
        // The receiving server and SHOULD remove the <private/> element before delivering to the recipient.
        final Element packetEl = packet.getElement();
        packetEl.elements(QName.get("private", Received.NAMESPACE)).forEach(packetEl::remove);

        if (jid.getResource() == null) {
            // RFC 6121: 8.5.2. localpart@domainpart (Packet sent to a bare JID of a user)
            if (packet instanceof Message) {
                // Find best route of local user
                routed = routeToBareJID(jid, (Message) packet);
            }
            else {
                throw new PacketException("Cannot route packet of type IQ or Presence to bare JID: " + packet.toXML());
            }
        }
        else {
            // RFC 6121 section 8.5.3. localpart@domainpart/resourcepart (Packet sent to a full JID of a user)
            ClientRoute clientRoute = getClientRouteForLocalUser(jid);
            if (clientRoute != null) {
                // RFC-6121 section 8.5.3.1. Resource Matches
                if (localClientRoutingTable.isLocalRoute(jid)) {
                    if (packet instanceof Message) {
                        ccMessage(jid, (Message) packet);
                    }

                    // This is a route to a local user hosted in this node
                    try {
                        localClientRoutingTable.getRoute(jid).process(packet);
                        routed = true;
                    } catch (Throwable e) {
                        Log.error("Unable to route packet {}", packet.toXML(), e);
                    }
                }
                else {
                    // This is a route to a local user hosted in other node
                    if (remotePacketRouter != null) {
                        routed = remotePacketRouter
                                .routePacket(clientRoute.getNodeID().toByteArray(), jid, packet);
                        if (!routed) {
                            Log.warn("Dropping invalid client route for {}", jid);
                            removeClientRoute(jid);
                        }
                    }
                }
            }
        }
        return routed;
    }
Routes packets that are sent to the XMPP domain itself (excluding subdomains).

@param jid
           the recipient of the packet to route.
@param packet
           the packet to route.
@throws PacketException
            thrown if the packet is malformed (results in the sender's
            session being shutdown).
@return {@code true} if the packet was routed successfully,
        {@code false} otherwise.
xmppserver/src/main/java/org/jivesoftware/openfire/spi/RoutingTableImpl.java