Class PlainTextOrHttpFrameDecoder

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

    public final class PlainTextOrHttpFrameDecoder
    extends io.netty.handler.codec.ByteToMessageDecoder
    This class handles 2 different protocols on a single port. Supported protocols include HTTP and a plain text protocol. It dynamically adds the appropriate encoder/decoder based on the detected protocol. This class was largely adapted from the example provided with netty v4.0
    Author:
    Mike McLaughlin ([email protected])
    See Also:
    Netty Port Unification Example
    • Nested Class Summary

      • Nested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder

        io.netty.handler.codec.ByteToMessageDecoder.Cumulator
      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

        io.netty.channel.ChannelHandler.Sharable
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static Logger logger  
      • Fields inherited from class io.netty.handler.codec.ByteToMessageDecoder

        COMPOSITE_CUMULATOR, MERGE_CUMULATOR
    • Constructor Summary

      Constructors 
      Constructor Description
      PlainTextOrHttpFrameDecoder​(io.netty.channel.ChannelHandler handler, io.netty.handler.codec.http.cors.CorsConfig corsConfig, int maxLengthPlaintext, int maxLengthHttp)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void decode​(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf buffer, List<Object> out)
      Dynamically adds the appropriate encoder/decoder(s) to the pipeline based on the detected protocol.
      • Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder

        actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggered
      • Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

        channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
      • Methods inherited from class io.netty.channel.ChannelHandlerAdapter

        ensureNotSharable, handlerAdded, isSharable
      • Methods inherited from interface io.netty.channel.ChannelHandler

        handlerAdded
    • Field Detail

      • logger

        protected static final Logger logger
    • Constructor Detail

      • PlainTextOrHttpFrameDecoder

        public PlainTextOrHttpFrameDecoder​(io.netty.channel.ChannelHandler handler,
                                           @Nullable
                                           io.netty.handler.codec.http.cors.CorsConfig corsConfig,
                                           int maxLengthPlaintext,
                                           int maxLengthHttp)
        Parameters:
        handler - the object responsible for handling the incoming messages on either protocol.
        corsConfig - enables CORS when CorsConfig is specified
        maxLengthPlaintext - max allowed line length for line-delimiter protocol
        maxLengthHttp - max allowed size for incoming HTTP requests
    • Method Detail

      • decode

        protected void decode​(io.netty.channel.ChannelHandlerContext ctx,
                              io.netty.buffer.ByteBuf buffer,
                              List<Object> out)
        Dynamically adds the appropriate encoder/decoder(s) to the pipeline based on the detected protocol.
        Specified by:
        decode in class io.netty.handler.codec.ByteToMessageDecoder