Search in sources :

Example 1 with RELPFrameException

use of org.apache.nifi.processors.standard.relp.frame.RELPFrameException 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 2 with RELPFrameException

use of org.apache.nifi.processors.standard.relp.frame.RELPFrameException in project nifi by apache.

the class RELPSocketChannelHandler method processBuffer.

@Override
protected void processBuffer(final SocketChannel socketChannel, final ByteBuffer socketBuffer) throws InterruptedException, IOException {
    // get total bytes in buffer
    final int total = socketBuffer.remaining();
    final InetAddress sender = socketChannel.socket().getInetAddress();
    try {
        // go through the buffer parsing the RELP command
        for (int i = 0; i < total; i++) {
            byte currByte = socketBuffer.get();
            // 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 SocketChannelResponder responder = new SocketChannelResponder(socketChannel);
                frameHandler.handle(frame, responder, sender.toString());
                socketBuffer.mark();
            }
        }
        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 : SocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder) RELPFrameException(org.apache.nifi.processors.standard.relp.frame.RELPFrameException) InetAddress(java.net.InetAddress) RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame)

Aggregations

InetAddress (java.net.InetAddress)2 RELPFrame (org.apache.nifi.processors.standard.relp.frame.RELPFrame)2 RELPFrameException (org.apache.nifi.processors.standard.relp.frame.RELPFrameException)2 SSLSocketChannelResponder (org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder)1 SocketChannelResponder (org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder)1