@ChannelHandler.Sharable public class StaticFileServerHandler<T extends RestfulGateway> extends LeaderRetrievalHandler<T>
This code is based on the "HttpStaticFileServerHandler" from the Netty project's HTTP server example.
| Modifier and Type | Field and Description |
|---|---|
static String |
HTTP_DATE_FORMAT
Date format for HTTP.
|
leaderRetriever, logger, responseHeaders, timeout| Constructor and Description |
|---|
StaticFileServerHandler(GatewayRetriever<? extends T> retriever,
org.apache.flink.api.common.time.Time timeout,
File rootPath) |
| Modifier and Type | Method and Description |
|---|---|
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.
|
channelRead0acceptInboundMessage, channelReadchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredensureNotSharable, handlerAdded, handlerRemoved, isSharablepublic static final String HTTP_DATE_FORMAT
public StaticFileServerHandler(GatewayRetriever<? extends T> retriever, org.apache.flink.api.common.time.Time timeout, File rootPath) throws IOException
IOExceptionprotected void respondAsLeader(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext channelHandlerContext,
RoutedRequest routedRequest,
T gateway)
throws Exception
respondAsLeader in class LeaderRetrievalHandler<T extends RestfulGateway>Exceptionpublic void exceptionCaught(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx,
Throwable cause)
exceptionCaught in interface org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerexceptionCaught in interface org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandlerexceptionCaught in class org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandlerAdapterpublic static void sendNotModified(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx)
ctx - The channel context to write the response to.public static void setDateHeader(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse response)
response - HTTP responsepublic static void setDateAndCacheHeaders(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response,
File fileToCache)
response - The HTTP response object.fileToCache - File to extract the modification timestamp from.public static void setContentTypeHeader(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response,
File file)
response - HTTP responsefile - file to extract content typeCopyright © 2014–2020 The Apache Software Foundation. All rights reserved.