Class NonChunkedHttpMessageHandler

java.lang.Object
com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerAdapter
com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter
com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler
com.couchbase.client.core.io.netty.NonChunkedHttpMessageHandler
All Implemented Interfaces:
com.couchbase.client.core.deps.io.netty.channel.ChannelHandler, com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandler, com.couchbase.client.core.deps.io.netty.channel.ChannelOutboundHandler
Direct Known Subclasses:
NonChunkedEventingMessageHandler

@Sharable
public abstract class NonChunkedHttpMessageHandler
extends com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler
This message handler can be considered the opposite of the ChunkedMessageHandler.

This generic implementation makes sure that when it lives in the pipeline it also pulls in the http aggregator and sends full http requests / receives full http responses.

You usually want to add this handler for non-perf critical messages like creating indexes and similar, so their encoder and decoder implementations are considerably simpler than having to deal with chunking and a streaming parser.

Since:
2.0.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.couchbase.client.core.deps.io.netty.channel.ChannelHandler

    com.couchbase.client.core.deps.io.netty.channel.ChannelHandler.Sharable
  • Field Summary

    Fields
    Modifier and Type Field Description
    static String IDENTIFIER  
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected NonChunkedHttpMessageHandler​(BaseEndpoint endpoint, ServiceType serviceType)  
  • Method Summary

    Modifier and Type Method Description
    void channelActive​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)
    When this channel is marked active it also needs to propagate that to the aggregator.
    void channelInactive​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)  
    void channelRead​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, Object msg)
    Parses the full http response and sends it to decode into the request.
    protected abstract Exception failRequestWith​(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponseStatus status, String content, NonChunkedHttpRequest<Response> request)
    To be implemented by children, should return the proper service exception type for each.
    void handlerAdded​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)
    When the non-chunked handler is added, it also needs to add the http aggregator.
    void handlerRemoved​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)
    When the non-chunked handler is removed, it also needs to remove its http aggregator.
    void write​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, Object msg, com.couchbase.client.core.deps.io.netty.channel.ChannelPromise promise)
    Writes a given request and encodes it.

    Methods inherited from class com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler

    bind, close, connect, deregister, disconnect, flush, read

    Methods inherited from class com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter

    channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered

    Methods inherited from class com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • IDENTIFIER

      public static final String IDENTIFIER
  • Constructor Details

    • NonChunkedHttpMessageHandler

      protected NonChunkedHttpMessageHandler​(BaseEndpoint endpoint, ServiceType serviceType)
  • Method Details

    • failRequestWith

      protected abstract Exception failRequestWith​(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponseStatus status, String content, NonChunkedHttpRequest<Response> request)
      To be implemented by children, should return the proper service exception type for each.
      Parameters:
      content - the raw full content body of the response if not successful.
      Returns:
      the exception with which the request will be failed.
    • write

      public void write​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, Object msg, com.couchbase.client.core.deps.io.netty.channel.ChannelPromise promise)
      Writes a given request and encodes it.
      Specified by:
      write in interface com.couchbase.client.core.deps.io.netty.channel.ChannelOutboundHandler
      Overrides:
      write in class com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler
      Parameters:
      ctx - the channel handler context.
      msg - the msg to write.
      promise - the promise that will be passed along.
    • channelActive

      public void channelActive​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx) throws Exception
      When this channel is marked active it also needs to propagate that to the aggregator.
      Specified by:
      channelActive in interface com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter
      Parameters:
      ctx - the channel handler context.
      Throws:
      Exception
    • channelRead

      public void channelRead​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, Object msg)
      Parses the full http response and sends it to decode into the request.
      Specified by:
      channelRead in interface com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter
      Parameters:
      ctx - the channel handler context.
      msg - the FullHttpResponse from the server.
    • handlerAdded

      public void handlerAdded​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)
      When the non-chunked handler is added, it also needs to add the http aggregator.
      Specified by:
      handlerAdded in interface com.couchbase.client.core.deps.io.netty.channel.ChannelHandler
      Overrides:
      handlerAdded in class com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerAdapter
      Parameters:
      ctx - the channel handler context.
    • channelInactive

      public void channelInactive​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)
      Specified by:
      channelInactive in interface com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter
    • handlerRemoved

      public void handlerRemoved​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)
      When the non-chunked handler is removed, it also needs to remove its http aggregator.
      Specified by:
      handlerRemoved in interface com.couchbase.client.core.deps.io.netty.channel.ChannelHandler
      Overrides:
      handlerRemoved in class com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerAdapter
      Parameters:
      ctx - the channel handler context.