Search in sources :

Example 1 with UnknownStanzaException

use of org.jivesoftware.openfire.multiplex.UnknownStanzaException in project Openfire by igniterealtime.

the class XmppWebSocket method processStanza.

// helper/utility methods
/*
	 * Process stream headers/footers and authentication stanzas locally;
	 * otherwise delegate stanza handling to the session packet router.
	 */
private void processStanza(Element stanza) {
    try {
        String tag = stanza.getName();
        if (STREAM_FOOTER.equals(tag)) {
            closeStream(null);
        } else if ("auth".equals(tag)) {
            // User is trying to authenticate using SASL
            startedSASL = true;
            // Process authentication stanza
            xmppSession.incrementClientPacketCount();
            saslStatus = SASLAuthentication.handle(xmppSession, stanza);
        } else if (startedSASL && "response".equals(tag) || "abort".equals(tag)) {
            // User is responding to SASL challenge. Process response
            xmppSession.incrementClientPacketCount();
            saslStatus = SASLAuthentication.handle(xmppSession, stanza);
        } else if (STREAM_HEADER.equals(tag)) {
            // restart the stream
            openStream(stanza.attributeValue(QName.get("lang", XMLConstants.XML_NS_URI), "en"), stanza.attributeValue("from"));
            configureStream();
        } else if (Status.authenticated.equals(saslStatus)) {
            if (router == null) {
                if (isStreamManagementAvailable()) {
                    router = new StreamManagementPacketRouter(xmppSession);
                } else {
                    // fall back for older Openfire installations
                    router = new SessionPacketRouter(xmppSession);
                }
            }
            router.route(stanza);
        } else {
            // require authentication
            Log.warn("Not authorized: " + stanza.asXML());
            sendPacketError(stanza, PacketError.Condition.not_authorized);
        }
    } catch (UnknownStanzaException use) {
        Log.warn("Received invalid stanza: " + stanza.asXML());
        sendPacketError(stanza, PacketError.Condition.bad_request);
    } catch (Exception ex) {
        Log.error("Failed to process incoming stanza: " + stanza.asXML(), ex);
        closeStream(new StreamError(StreamError.Condition.internal_server_error));
    }
}
Also used : StreamError(org.xmpp.packet.StreamError) SessionPacketRouter(org.jivesoftware.openfire.SessionPacketRouter) IOException(java.io.IOException) UnknownStanzaException(org.jivesoftware.openfire.multiplex.UnknownStanzaException) UnknownStanzaException(org.jivesoftware.openfire.multiplex.UnknownStanzaException)

Aggregations

IOException (java.io.IOException)1 SessionPacketRouter (org.jivesoftware.openfire.SessionPacketRouter)1 UnknownStanzaException (org.jivesoftware.openfire.multiplex.UnknownStanzaException)1 StreamError (org.xmpp.packet.StreamError)1