Class StaticFileServerHandler<T extends RestfulGateway>

  • All Implemented Interfaces:
    org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler, org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler

    @Sharable
    public class StaticFileServerHandler<T extends RestfulGateway>
    extends LeaderRetrievalHandler<T>
    Simple file server handler that serves requests to web frontend's static files, such as HTML, CSS, or JS files.

    This code is based on the "HttpStaticFileServerHandler" from the Netty project's HTTP server example.

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler

        org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler.Sharable
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkFileValidity​(File file, File rootPath, org.slf4j.Logger logger)
      Checks various conditions for file access.
      void exceptionCaught​(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx, Throwable cause)  
      protected void respondAsLeader​(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext channelHandlerContext, RoutedRequest routedRequest, T gateway)  
      static void sendNotModified​(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx)
      Send the "304 Not Modified" response.
      static void setContentTypeHeader​(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response, File file)
      Sets the content type header for the HTTP Response.
      static void setDateAndCacheHeaders​(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response, File fileToCache)
      Sets the "date" and "cache" headers for the HTTP Response.
      static void setDateHeader​(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse response)
      Sets the "date" header for the HTTP response.
      • Methods inherited from class org.apache.flink.shaded.netty4.io.netty.channel.SimpleChannelInboundHandler

        acceptInboundMessage, channelRead
      • Methods inherited from class org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandlerAdapter

        channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
      • Methods inherited from class org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerAdapter

        ensureNotSharable, handlerAdded, handlerRemoved, isSharable
      • Methods inherited from interface org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler

        handlerAdded, handlerRemoved
    • Method Detail

      • exceptionCaught

        public void exceptionCaught​(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx,
                                    Throwable cause)
        Specified by:
        exceptionCaught in interface org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler
        Specified by:
        exceptionCaught in interface org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler
        Overrides:
        exceptionCaught in class org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandlerAdapter
      • sendNotModified

        public static void sendNotModified​(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx)
        Send the "304 Not Modified" response. This response can be used when the file timestamp is the same as what the browser is sending up.
        Parameters:
        ctx - The channel context to write the response to.
      • setDateHeader

        public static void setDateHeader​(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse response)
        Sets the "date" header for the HTTP response.
        Parameters:
        response - HTTP response
      • setDateAndCacheHeaders

        public static void setDateAndCacheHeaders​(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response,
                                                  File fileToCache)
        Sets the "date" and "cache" headers for the HTTP Response.
        Parameters:
        response - The HTTP response object.
        fileToCache - File to extract the modification timestamp from.
      • setContentTypeHeader

        public static void setContentTypeHeader​(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response,
                                                File file)
        Sets the content type header for the HTTP Response.
        Parameters:
        response - HTTP response
        file - file to extract content type
      • checkFileValidity

        public static void checkFileValidity​(File file,
                                             File rootPath,
                                             org.slf4j.Logger logger)
                                      throws IOException,
                                             RestHandlerException
        Checks various conditions for file access. If all checks pass this method returns, and processing of the request may continue. If any check fails this method throws a RestHandlerException, and further processing of the request must be limited to sending an error response.
        Throws:
        IOException
        RestHandlerException