Search in sources :

Example 1 with RemotePacketRouter

use of org.jivesoftware.openfire.RemotePacketRouter in project Openfire by igniterealtime.

the class BaseTransport method processPacket.

/**
     * Handles all incoming XMPP stanzas, passing them to individual
     * packet type handlers.
     *
     * @param packet The packet to be processed.
     */
public void processPacket(Packet packet) {
    JID from = packet.getFrom();
    JID to = packet.getTo();
    if (to == null) {
        // Well clearly it's for us or it wouldn't have gotten here...
        packet.setTo(getJID());
        to = getJID();
    }
    if (from != null && to != null) {
        Lock l = CacheFactory.getLock(from.toBareJID() + "@" + transportType.toString() + "pp", sessionRouter.sessionLocations);
        try {
            l.lock();
            byte[] targetNodeID = sessionRouter.getSession(transportType.toString(), from.toBareJID());
            if (targetNodeID != null && !Arrays.equals(targetNodeID, XMPPServer.getInstance().getNodeID().toByteArray())) {
                RemotePacketRouter router = XMPPServer.getInstance().getRoutingTable().getRemotePacketRouter();
                if (router != null) {
                    // Not for our node, send it elsewhere.
                    router.routePacket(targetNodeID, to, packet);
                    return;
                }
            }
        } finally {
            l.unlock();
        }
    }
    try {
        List<Packet> reply = new ArrayList<Packet>();
        if (packet instanceof IQ) {
            reply.addAll(processPacket((IQ) packet));
        } else if (packet instanceof Presence) {
            reply.addAll(processPacket((Presence) packet));
        } else if (packet instanceof Message) {
            reply.addAll(processPacket((Message) packet));
        } else {
            Log.debug("Received an unhandled packet: " + packet.toString());
        }
        if (reply.size() > 0) {
            for (Packet p : reply) {
                this.sendPacket(p);
            }
        }
    } catch (Exception e) {
        Log.warn("Error occured while processing packet:", e);
    }
}
Also used : RemotePacketRouter(org.jivesoftware.openfire.RemotePacketRouter) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) NotFoundException(org.jivesoftware.util.NotFoundException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Lock(java.util.concurrent.locks.Lock)

Aggregations

NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Lock (java.util.concurrent.locks.Lock)1 RemotePacketRouter (org.jivesoftware.openfire.RemotePacketRouter)1 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)1 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 NotFoundException (org.jivesoftware.util.NotFoundException)1