Search in sources :

Example 6 with XMPPPacketReader

use of org.dom4j.io.XMPPPacketReader in project Openfire by igniterealtime.

the class ConnectionHandler method messageReceived.

@Override
public void messageReceived(IoSession session, Object message) throws Exception {
    // Get the stanza handler for this session
    StanzaHandler handler = (StanzaHandler) session.getAttribute(HANDLER);
    // Get the parser to use to process stanza. For optimization there is going
    // to be a parser for each running thread. Each Filter will be executed
    // by the Executor placed as the first Filter. So we can have a parser associated
    // to each Thread
    final XMPPPacketReader parser = PARSER_CACHE.get();
    // Update counter of read btyes
    updateReadBytesCounter(session);
    // Let the stanza handler process the received stanza
    try {
        handler.process((String) message, parser);
    } catch (Exception e) {
        Log.error("Closing connection due to error while processing message: " + message, e);
        final Connection connection = (Connection) session.getAttribute(CONNECTION);
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : XMPPPacketReader(org.dom4j.io.XMPPPacketReader) StanzaHandler(org.jivesoftware.openfire.net.StanzaHandler) Connection(org.jivesoftware.openfire.Connection) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 7 with XMPPPacketReader

use of org.dom4j.io.XMPPPacketReader in project Openfire by igniterealtime.

the class ServerDialback method verifyKey.

/**
     * Verifies the key with the Authoritative Server.
     */
private VerifyResult verifyKey(String key, StreamID streamID, String recipient, String remoteDomain, Socket socket, boolean skipTLS) throws IOException, XmlPullParserException, RemoteConnectionFailedException {
    final Logger log = LoggerFactory.getLogger(Log.getName() + "[Acting as Receiving Server: Verify key with AS: " + remoteDomain + " for OS: " + recipient + " (id " + streamID + ")]");
    log.debug("Verifying key ...");
    XMPPPacketReader reader;
    Writer writer = null;
    // Set a read timeout
    socket.setSoTimeout(RemoteServerManager.getSocketTimeout());
    VerifyResult result = VerifyResult.error;
    try {
        reader = new XMPPPacketReader();
        reader.setXPPFactory(FACTORY);
        reader.getXPPParser().setInput(new InputStreamReader(socket.getInputStream(), CHARSET));
        // Get a writer for sending the open stream tag
        writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), CHARSET));
        result = sendVerifyKey(key, streamID, recipient, remoteDomain, writer, reader, socket, skipTLS);
    } finally {
        try {
            // Close the stream
            StringBuilder sb = new StringBuilder();
            sb.append("</stream:stream>");
            writer.write(sb.toString());
            writer.flush();
            // Close the TCP connection
            socket.close();
        } catch (IOException ioe) {
        // Do nothing
        }
    }
    switch(result) {
        case valid:
            log.debug("Successfully verified key!");
            break;
        case invalid:
            log.debug("Unable to verify key: AS reports that the key is invalid.");
            break;
        default:
        case decline:
        case error:
            log.debug("Unable to verify key: An error occurred.");
            break;
    }
    return result;
}
Also used : XMPPPacketReader(org.dom4j.io.XMPPPacketReader) InputStreamReader(java.io.InputStreamReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Logger(org.slf4j.Logger) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Aggregations

XMPPPacketReader (org.dom4j.io.XMPPPacketReader)7 IOException (java.io.IOException)4 InputStreamReader (java.io.InputStreamReader)3 Logger (org.slf4j.Logger)3 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)3 Socket (java.net.Socket)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 DocumentException (org.dom4j.DocumentException)2 XmlPullParser (org.xmlpull.v1.XmlPullParser)2 JID (org.xmpp.packet.JID)2 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 Document (org.dom4j.Document)1 Element (org.dom4j.Element)1 OnWebSocketMessage (org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)1 Connection (org.jivesoftware.openfire.Connection)1 StreamID (org.jivesoftware.openfire.StreamID)1 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)1