Java Code Examples for org.jivesoftware.openfire.session.Session#STATUS_CLOSED

The following examples show how to use org.jivesoftware.openfire.session.Session#STATUS_CLOSED . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Openfire   File: S2STestService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Logs the status of the session.
 */
private void logSessionStatus() {
    final DomainPair pair = new DomainPair(XMPPServer.getInstance().getServerInfo().getXMPPDomain(), domain);
    OutgoingServerSession session = XMPPServer.getInstance().getSessionManager().getOutgoingServerSession(pair);
    if (session != null) {
        int connectionStatus = session.getStatus();
        switch(connectionStatus) {
        case Session.STATUS_CONNECTED:
            Log.info("Session is connected.");
            break;
        case Session.STATUS_CLOSED:
            Log.info("Session is closed.");
            break;
        case Session.STATUS_AUTHENTICATED:
            Log.info("Session is authenticated.");
            break;
        }
    } else {
        Log.info("Failed to establish server to server session.");
    }
}
 
Example 2
Source Project: Openfire   File: AuditorImpl.java    License: Apache License 2.0 5 votes vote down vote up
public AuditPacket(Packet packet, Session session) {
    element = docFactory.createElement("packet", "http://www.jivesoftware.org");
    creationDate = new Date();
    if (session != null && session.getStreamID() != null) {
        element.addAttribute("streamID", session.getStreamID().toString());
    }
    switch (session == null ? 0 : session.getStatus()) {
        case Session.STATUS_AUTHENTICATED:
            element.addAttribute("status", "auth");
            break;
        case Session.STATUS_CLOSED:
            element.addAttribute("status", "closed");
            break;
        case Session.STATUS_CONNECTED:
            element.addAttribute("status", "connected");
            // This is a workaround. Since we don't want to have an incorrect FROM attribute
            // value we need to clean up the FROM attribute. The FROM attribute will contain
            // an incorrect value since we are setting a fake JID until the user actually
            // authenticates with the server.
            packet.setFrom((String) null);
            break;
        default:
            element.addAttribute("status", "unknown");
            break;
    }
    element.addAttribute("timestamp", auditFormat.format(creationDate));
    element.add(packet.getElement());
}
 
Example 3
Source Project: Openfire   File: PresenceUpdateHandler.java    License: Apache License 2.0 4 votes vote down vote up
private void process(Presence presence, ClientSession session) throws UnauthorizedException, PacketException {
    try {
        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;
            }

            if (session != null) {
                session.setPresence(presence);
            }

            broadcastUpdate(presence.createCopy());

            if (session != null && !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) {
            if (session != null) {
                session.setPresence(presence);
            }
            broadcastUpdate(presence.createCopy());
            broadcastUnavailableForDirectedPresences(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, true));
                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: " + presence, e);
    }
}