Class HttpRequestHandler

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

    public class HttpRequestHandler
    extends io.netty.channel.ChannelInboundHandlerAdapter
    Handles handshakes and messages. A new instance of this handler is created for every request. We have following different request types
    • static requests - sent to the fileRequestHandler - do no go higher in the netty pipeline
    • websocket requests - the pipeline is modified to add the websocket handshaker.
    • load data requests - the pipeline is modified by the respective route handler
    • standard API calls (the vast majority) - the HttpObjectAgreggator is added upstream to collect (and limit) all data from the http request in one object.
    Because we support multiple http requests on one connection (keep-alive), we have to clean the pipeline when the request type changes
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void channelActive​(io.netty.channel.ChannelHandlerContext ctx)  
      void channelRead​(io.netty.channel.ChannelHandlerContext ctx, Object msg)  
      void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)  
      static MediaType getContentType​(io.netty.handler.codec.http.HttpRequest req)  
      static <T extends com.google.protobuf.Message>
      io.netty.channel.ChannelFuture
      sendMessageResponse​(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponseStatus status, T responseMsg)  
      static io.netty.channel.ChannelFuture sendPlainTextError​(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponseStatus status)  
      static io.netty.channel.ChannelFuture sendPlainTextError​(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponseStatus status, String msg)  
      static io.netty.channel.ChannelFuture sendResponse​(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponse response)  
      • Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

        channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
      • Methods inherited from class io.netty.channel.ChannelHandlerAdapter

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

        handlerAdded, handlerRemoved
    • Field Detail

      • CTX_HTTP_REQUEST

        public static final io.netty.util.AttributeKey<io.netty.handler.codec.http.HttpRequest> CTX_HTTP_REQUEST
      • CTX_CONTEXT

        public static final io.netty.util.AttributeKey<RouteContext> CTX_CONTEXT
      • CONTENT_FINISHED_EVENT

        public static final Object CONTENT_FINISHED_EVENT
    • Constructor Detail

      • HttpRequestHandler

        public HttpRequestHandler​(HttpServer httpServer)
    • Method Detail

      • channelActive

        public void channelActive​(io.netty.channel.ChannelHandlerContext ctx)
                           throws Exception
        Specified by:
        channelActive in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • channelRead

        public void channelRead​(io.netty.channel.ChannelHandlerContext ctx,
                                Object msg)
                         throws Exception
        Specified by:
        channelRead in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • exceptionCaught

        public void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx,
                                    Throwable cause)
                             throws Exception
        Specified by:
        exceptionCaught in interface io.netty.channel.ChannelHandler
        Specified by:
        exceptionCaught in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • sendMessageResponse

        public static <T extends com.google.protobuf.Message> io.netty.channel.ChannelFuture sendMessageResponse​(io.netty.channel.ChannelHandlerContext ctx,
                                                                                                                 io.netty.handler.codec.http.HttpRequest req,
                                                                                                                 io.netty.handler.codec.http.HttpResponseStatus status,
                                                                                                                 T responseMsg)
      • sendPlainTextError

        public static io.netty.channel.ChannelFuture sendPlainTextError​(io.netty.channel.ChannelHandlerContext ctx,
                                                                        io.netty.handler.codec.http.HttpRequest req,
                                                                        io.netty.handler.codec.http.HttpResponseStatus status)
      • sendPlainTextError

        public static io.netty.channel.ChannelFuture sendPlainTextError​(io.netty.channel.ChannelHandlerContext ctx,
                                                                        io.netty.handler.codec.http.HttpRequest req,
                                                                        io.netty.handler.codec.http.HttpResponseStatus status,
                                                                        String msg)
      • sendResponse

        public static io.netty.channel.ChannelFuture sendResponse​(io.netty.channel.ChannelHandlerContext ctx,
                                                                  io.netty.handler.codec.http.HttpRequest req,
                                                                  io.netty.handler.codec.http.HttpResponse response)
      • getContentType

        public static MediaType getContentType​(io.netty.handler.codec.http.HttpRequest req)
        Returns:
        The Content-Type header if present or else defaults to JSON.