Search in sources :

Example 1 with OutgoingServerSession

use of org.jivesoftware.openfire.session.OutgoingServerSession in project Openfire by igniterealtime.

the class S2STestService method logSessionStatus.

/**
 * 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.");
    }
}
Also used : DomainPair(org.jivesoftware.openfire.session.DomainPair) OutgoingServerSession(org.jivesoftware.openfire.session.OutgoingServerSession)

Example 2 with OutgoingServerSession

use of org.jivesoftware.openfire.session.OutgoingServerSession in project Openfire by igniterealtime.

the class S2STestService method run.

/**
 * Run a test against the domain.
 * @return K-V pairs of debug information.
 * @throws Exception On error.
 */
public Map<String, String> run() throws Exception {
    waitUntil = new Semaphore(0);
    Map<String, String> results = new HashMap<>();
    final DomainPair pair = new DomainPair(XMPPServer.getInstance().getServerInfo().getXMPPDomain(), domain);
    // Tear down existing routes.
    final SessionManager sessionManager = SessionManager.getInstance();
    for (final Session incomingServerSession : sessionManager.getIncomingServerSessions(domain)) {
        incomingServerSession.close();
    }
    final Session outgoingServerSession = sessionManager.getOutgoingServerSession(pair);
    if (outgoingServerSession != null) {
        outgoingServerSession.close();
    }
    final IQ pingRequest = new IQ(Type.get);
    pingRequest.setChildElement("ping", IQPingHandler.NAMESPACE);
    pingRequest.setFrom(pair.getLocal());
    pingRequest.setTo(domain);
    // Intercept logging.
    final Writer logs = new StringWriter();
    final String appenderName = addAppender(logs);
    // Intercept packets.
    final PacketInterceptor interceptor = new S2SInterceptor(pingRequest);
    InterceptorManager.getInstance().addInterceptor(interceptor);
    // Send ping.
    try {
        Log.info("Sending server to server ping request to " + domain);
        XMPPServer.getInstance().getIQRouter().route(pingRequest);
        // Wait for success or exceed socket timeout.
        waitUntil.tryAcquire(RemoteServerManager.getSocketTimeout(), TimeUnit.MILLISECONDS);
        // Check on the connection status.
        logSessionStatus();
        // Prepare response.
        results.put("certs", getCertificates());
        results.put("stanzas", interceptor.toString());
        results.put("logs", logs.toString());
        return results;
    } finally {
        // Cleanup
        InterceptorManager.getInstance().removeInterceptor(interceptor);
        removeAppender(appenderName);
    }
}
Also used : StringWriter(java.io.StringWriter) DomainPair(org.jivesoftware.openfire.session.DomainPair) SessionManager(org.jivesoftware.openfire.SessionManager) IQ(org.xmpp.packet.IQ) Semaphore(java.util.concurrent.Semaphore) PacketInterceptor(org.jivesoftware.openfire.interceptor.PacketInterceptor) StringWriter(java.io.StringWriter) Writer(java.io.Writer) OutgoingServerSession(org.jivesoftware.openfire.session.OutgoingServerSession) Session(org.jivesoftware.openfire.session.Session)

Aggregations

DomainPair (org.jivesoftware.openfire.session.DomainPair)2 OutgoingServerSession (org.jivesoftware.openfire.session.OutgoingServerSession)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Semaphore (java.util.concurrent.Semaphore)1 SessionManager (org.jivesoftware.openfire.SessionManager)1 PacketInterceptor (org.jivesoftware.openfire.interceptor.PacketInterceptor)1 Session (org.jivesoftware.openfire.session.Session)1 IQ (org.xmpp.packet.IQ)1