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.
-
-
Field Summary
Fields Modifier and Type Field Description static String
HTTP_DATE_FORMAT
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
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.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
-
-
-
-
Field Detail
-
HTTP_DATE_FORMAT
public static final String HTTP_DATE_FORMAT
Date format for HTTP.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
StaticFileServerHandler
public StaticFileServerHandler(GatewayRetriever<? extends T> retriever, Duration timeout, File rootPath) throws IOException
- Throws:
IOException
-
-
Method Detail
-
respondAsLeader
protected void respondAsLeader(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext channelHandlerContext, RoutedRequest routedRequest, T gateway) throws Exception
- Specified by:
respondAsLeader
in classLeaderRetrievalHandler<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 interfaceorg.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler
- Specified by:
exceptionCaught
in interfaceorg.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler
- Overrides:
exceptionCaught
in classorg.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 responsefile
- 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 aRestHandlerException
, and further processing of the request must be limited to sending an error response.- Throws:
IOException
RestHandlerException
-
-