Class BinaryMessageFramer

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.codec.ByteToMessageDecoder
org.mockserver.netty.proxy.BinaryMessageFramer
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler
Direct Known Subclasses:
LengthPrefixMessageFramer, MysqlMessageFramer, PostgresqlMessageFramer, RedisMessageFramer

public abstract class BinaryMessageFramer extends io.netty.handler.codec.ByteToMessageDecoder
Cuts a binary connection into the messages of a protocol, as a client sends them, so that each is matched, forwarded and logged as one message however it was read. One per connection, in front of BinaryRequestProxyingHandler, in place of BinaryMessageGatherer.

At most maxMessageBytes are held: a connection that declares a longer message, or sends bytes the protocol does not allow, is closed and the rest of what it sends is dropped. The part of a message held when the connection closes is released with the cumulation.

  • 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 final long
    What messageBytes(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf) answers while the bytes held cannot yet say how long the message is.

    Fields inherited from class io.netty.handler.codec.ByteToMessageDecoder

    COMPOSITE_CUMULATOR, MERGE_CUMULATOR
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BinaryMessageFramer(int maxMessageBytes, org.mockserver.logging.MockServerLogger mockServerLogger, String framing)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    True when no part of a message is held: what is read next starts a message.
    int
    bytesBeforeTlsMayStart(io.netty.buffer.ByteBuf in, int available)
    How many of the available bytes from in's reader index, read in the clear, end a message after which a client may start a TLS handshake without waiting for a reply, when more bytes follow; otherwise 0.
    protected final void
    decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out)
     
    forConfiguration(org.mockserver.configuration.Configuration configuration, org.mockserver.logging.MockServerLogger mockServerLogger)
    The framer binaryMessageFraming names, or null for RAW.
    protected int
     
    protected abstract long
    messageBytes(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in)
    How many bytes the message that starts at the reader index has, NOT_YET_KNOWN while the bytes held cannot say, or anything after refuse(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.lang.String).
    protected void
    messageTaken(io.netty.buffer.ByteBuf message)
    Called with each whole message before it is passed on.
    protected boolean
     
    protected final void
    refuse(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, String declared)
     
    boolean
    Whether a TLS handshake may begin with the next byte read: only at a message boundary, and only where the protocol lets one begin.

    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 class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded
  • Field Details

  • Constructor Details

    • BinaryMessageFramer

      protected BinaryMessageFramer(int maxMessageBytes, org.mockserver.logging.MockServerLogger mockServerLogger, String framing)
  • Method Details

    • forConfiguration

      public static BinaryMessageFramer forConfiguration(org.mockserver.configuration.Configuration configuration, org.mockserver.logging.MockServerLogger mockServerLogger)
      The framer binaryMessageFraming names, or null for RAW.
    • maxMessageBytes

      protected int maxMessageBytes()
    • atMessageBoundary

      public boolean atMessageBoundary()
      True when no part of a message is held: what is read next starts a message. Anything else is the middle of one, whatever its bytes look like.
    • tlsMayStartHere

      public boolean tlsMayStartHere()
      Whether a TLS handshake may begin with the next byte read: only at a message boundary, and only where the protocol lets one begin.
    • protocolAllowsTlsHere

      protected boolean protocolAllowsTlsHere()
    • bytesBeforeTlsMayStart

      public int bytesBeforeTlsMayStart(io.netty.buffer.ByteBuf in, int available)
      How many of the available bytes from in's reader index, read in the clear, end a message after which a client may start a TLS handshake without waiting for a reply, when more bytes follow; otherwise 0.
    • messageBytes

      protected abstract long messageBytes(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in)
      How many bytes the message that starts at the reader index has, NOT_YET_KNOWN while the bytes held cannot say, or anything after refuse(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.lang.String). Must not move the reader index.
    • messageTaken

      protected void messageTaken(io.netty.buffer.ByteBuf message)
      Called with each whole message before it is passed on.
    • decode

      protected final void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out)
      Specified by:
      decode in class io.netty.handler.codec.ByteToMessageDecoder
    • refuse

      protected final void refuse(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, String declared)