Search in sources :

Example 1 with SSLSocketChannelResponder

use of org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder in project nifi by apache.

the class SSLSocketChannelHandler method processBuffer.

/**
 * Process the contents of the buffer. Give sub-classes a chance to override this behavior.
 *
 * @param sslSocketChannel the channel the data was read from
 * @param socketChannel the socket channel being wrapped by sslSocketChannel
 * @param bytesRead the number of bytes read
 * @param buffer the buffer to process
 * @throws InterruptedException thrown if interrupted while queuing events
 */
protected void processBuffer(final SSLSocketChannel sslSocketChannel, final SocketChannel socketChannel, final int bytesRead, final byte[] buffer) throws InterruptedException, IOException {
    final InetAddress sender = socketChannel.socket().getInetAddress();
    // go through the buffer looking for the end of each message
    for (int i = 0; i < bytesRead; i++) {
        final byte currByte = buffer[i];
        // check if at end of a message
        if (currByte == getDelimiter()) {
            if (currBytes.size() > 0) {
                final SSLSocketChannelResponder response = new SSLSocketChannelResponder(socketChannel, sslSocketChannel);
                final Map<String, String> metadata = EventFactoryUtil.createMapWithSender(sender.toString());
                final E event = eventFactory.create(currBytes.toByteArray(), metadata, response);
                events.offer(event);
                currBytes.reset();
            }
        } else {
            currBytes.write(currByte);
        }
    }
}
Also used : SSLSocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder) InetAddress(java.net.InetAddress)

Example 2 with SSLSocketChannelResponder

use of org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder in project nifi by apache.

the class LumberjackSSLSocketChannelHandler method processBuffer.

@Override
protected void processBuffer(final SSLSocketChannel sslSocketChannel, final SocketChannel socketChannel, final int bytesRead, final byte[] buffer) throws InterruptedException, IOException {
    final InetAddress sender = socketChannel.socket().getInetAddress();
    try {
        // go through the buffer parsing the Lumberjack command
        for (int i = 0; i < bytesRead; i++) {
            byte currByte = buffer[i];
            // if we found the end of a frame, handle the frame and mark the buffer
            if (decoder.process(currByte)) {
                final List<LumberjackFrame> frames = decoder.getFrames();
                // A list of events has been generated
                for (LumberjackFrame frame : frames) {
                    logger.debug("Received Lumberjack frame with transaction {} and command {}", new Object[] { frame.getSeqNumber(), frame.getSeqNumber() });
                    // Ignore the WINDOWS type frames as they contain no payload.
                    if (frame.getFrameType() != 0x57) {
                        final SSLSocketChannelResponder responder = new SSLSocketChannelResponder(socketChannel, sslSocketChannel);
                        frameHandler.handle(frame, responder, sender.toString());
                    }
                }
            }
        }
        logger.debug("Done processing buffer");
    } catch (final LumberjackFrameException rfe) {
        logger.error("Error reading Lumberjack frames due to {}", new Object[] { rfe.getMessage() }, rfe);
        // if an invalid frame or bad data was sent then the decoder will be left in a
        // corrupted state, so lets close the connection and cause the client to re-establish
        dispatcher.completeConnection(key);
    }
}
Also used : LumberjackFrame(org.apache.nifi.processors.lumberjack.frame.LumberjackFrame) LumberjackFrameException(org.apache.nifi.processors.lumberjack.frame.LumberjackFrameException) SSLSocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder) InetAddress(java.net.InetAddress)

Example 3 with SSLSocketChannelResponder

use of org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder in project nifi by apache.

the class RELPSSLSocketChannelHandler method processBuffer.

@Override
protected void processBuffer(final SSLSocketChannel sslSocketChannel, final SocketChannel socketChannel, final int bytesRead, final byte[] buffer) throws InterruptedException, IOException {
    final InetAddress sender = socketChannel.socket().getInetAddress();
    try {
        // go through the buffer parsing the RELP command
        for (int i = 0; i < bytesRead; i++) {
            byte currByte = buffer[i];
            // if we found the end of a frame, handle the frame and mark the buffer
            if (decoder.process(currByte)) {
                final RELPFrame frame = decoder.getFrame();
                logger.debug("Received RELP frame with transaction {} and command {}", new Object[] { frame.getTxnr(), frame.getCommand() });
                final SSLSocketChannelResponder responder = new SSLSocketChannelResponder(socketChannel, sslSocketChannel);
                frameHandler.handle(frame, responder, sender.toString());
            }
        }
        logger.debug("Done processing buffer");
    } catch (final RELPFrameException rfe) {
        logger.error("Error reading RELP frames due to {}", new Object[] { rfe.getMessage() }, rfe);
        // if an invalid frame or bad data was sent then the decoder will be left in a
        // corrupted state, so lets close the connection and cause the client to re-establish
        dispatcher.completeConnection(key);
    }
}
Also used : RELPFrameException(org.apache.nifi.processors.standard.relp.frame.RELPFrameException) SSLSocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder) InetAddress(java.net.InetAddress) RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame)

Example 4 with SSLSocketChannelResponder

use of org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder in project nifi by apache.

the class BeatsSSLSocketChannelHandler method processBuffer.

@Override
protected void processBuffer(final SSLSocketChannel sslSocketChannel, final SocketChannel socketChannel, final int bytesRead, final byte[] buffer) throws InterruptedException, IOException {
    final InetAddress sender = socketChannel.socket().getInetAddress();
    try {
        // go through the buffer parsing the packet command
        for (int i = 0; i < bytesRead; i++) {
            byte currByte = buffer[i];
            // if we found the end of a frame, handle the frame and mark the buffer
            if (decoder.process(currByte)) {
                final List<BeatsFrame> frames = decoder.getFrames();
                // A list of events has been generated
                for (BeatsFrame frame : frames) {
                    logger.debug("Received Beats frame with transaction {} and command {}", new Object[] { frame.getSeqNumber(), frame.getSeqNumber() });
                    // Ignore the WINDOWS type frames as they contain no payload.
                    if (frame.getFrameType() != 0x57) {
                        final SSLSocketChannelResponder responder = new SSLSocketChannelResponder(socketChannel, sslSocketChannel);
                        frameHandler.handle(frame, responder, sender.toString());
                    }
                }
            }
        }
        logger.debug("Done processing buffer");
    } catch (final BeatsFrameException rfe) {
        logger.error("Error reading Beats frames due to {}", new Object[] { rfe.getMessage() }, rfe);
        // if an invalid frame or bad data was sent then the decoder will be left in a
        // corrupted state, so lets close the connection and cause the client to re-establish
        dispatcher.completeConnection(key);
    }
}
Also used : BeatsFrame(org.apache.nifi.processors.beats.frame.BeatsFrame) BeatsFrameException(org.apache.nifi.processors.beats.frame.BeatsFrameException) SSLSocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder) InetAddress(java.net.InetAddress)

Aggregations

InetAddress (java.net.InetAddress)4 SSLSocketChannelResponder (org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder)4 BeatsFrame (org.apache.nifi.processors.beats.frame.BeatsFrame)1 BeatsFrameException (org.apache.nifi.processors.beats.frame.BeatsFrameException)1 LumberjackFrame (org.apache.nifi.processors.lumberjack.frame.LumberjackFrame)1 LumberjackFrameException (org.apache.nifi.processors.lumberjack.frame.LumberjackFrameException)1 RELPFrame (org.apache.nifi.processors.standard.relp.frame.RELPFrame)1 RELPFrameException (org.apache.nifi.processors.standard.relp.frame.RELPFrameException)1