Class StaticFileServerHandler<T extends RestfulGateway>

java.lang.Object
org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerAdapter
org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandlerAdapter
org.apache.flink.shaded.netty4.io.netty.channel.SimpleChannelInboundHandler<RoutedRequest>
org.apache.flink.runtime.rest.handler.LeaderRetrievalHandler<T>
org.apache.flink.runtime.rest.handler.legacy.files.StaticFileServerHandler<T>
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
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Date format for HTTP.

    Fields inherited from class org.apache.flink.runtime.rest.handler.LeaderRetrievalHandler

    leaderRetriever, logger, responseHeaders, timeout
  • Constructor Summary

    Constructors
    Constructor
    Description
    StaticFileServerHandler(GatewayRetriever<? extends T> retriever, Duration timeout, File rootPath)
     
  • Method Summary

    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.runtime.rest.handler.LeaderRetrievalHandler

    channelRead0, getTimeout

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

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

    Methods inherited from interface org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Field Details

  • Constructor Details

  • Method Details

    • respondAsLeader

      protected void respondAsLeader(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext channelHandlerContext, RoutedRequest routedRequest, T gateway) throws Exception
      Specified by:
      respondAsLeader in class LeaderRetrievalHandler<T extends RestfulGateway>
      Throws:
      Exception
    • 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