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
FieldsFields inherited from class org.apache.flink.runtime.rest.handler.LeaderRetrievalHandler
leaderRetriever, logger, responseHeaders, timeout -
Constructor Summary
ConstructorsConstructorDescriptionStaticFileServerHandler(GatewayRetriever<? extends T> retriever, Duration timeout, File rootPath) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckFileValidity(File file, File rootPath, org.slf4j.Logger logger) Checks various conditions for file access.voidexceptionCaught(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx, Throwable cause) protected voidrespondAsLeader(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext channelHandlerContext, RoutedRequest routedRequest, T gateway) static voidsendNotModified(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx) Send the "304 Not Modified" response.static voidsetContentTypeHeader(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response, File file) Sets the content type header for the HTTP Response.static voidsetDateAndCacheHeaders(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 voidsetDateHeader(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, getTimeoutMethods inherited from class org.apache.flink.shaded.netty4.io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelReadMethods inherited from class org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredMethods inherited from class org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
HTTP_DATE_FORMAT
Date format for HTTP.- See Also:
-
-
Constructor Details
-
StaticFileServerHandler
public StaticFileServerHandler(GatewayRetriever<? extends T> retriever, Duration timeout, File rootPath) throws IOException - Throws:
IOException
-
-
Method Details
-
respondAsLeader
protected void respondAsLeader(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext channelHandlerContext, RoutedRequest routedRequest, T gateway) throws Exception - Specified by:
respondAsLeaderin classLeaderRetrievalHandler<T extends RestfulGateway>- Throws:
Exception
-
exceptionCaught
public void exceptionCaught(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx, Throwable cause) - Specified by:
exceptionCaughtin interfaceorg.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceorg.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin 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:
IOExceptionRestHandlerException
-