@ChannelHandler.Sharable
public class StaticFileServerHandler
extends io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.router.Routed>
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
|
Constructor and Description |
---|
StaticFileServerHandler(JobManagerRetriever retriever,
scala.concurrent.Future<String> localJobManagerAddressPromise,
scala.concurrent.duration.FiniteDuration timeout,
File rootPath,
boolean httpsEnabled) |
StaticFileServerHandler(JobManagerRetriever retriever,
scala.concurrent.Future<String> localJobManagerAddressFuture,
scala.concurrent.duration.FiniteDuration timeout,
File rootPath,
boolean httpsEnabled,
org.slf4j.Logger logger) |
Modifier and Type | Method and Description |
---|---|
void |
channelRead0(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.router.Routed routed) |
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
static void |
sendError(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpResponseStatus status)
Writes a simple error response message.
|
static void |
sendNotModified(io.netty.channel.ChannelHandlerContext ctx)
Send the "304 Not Modified" response.
|
static void |
setContentTypeHeader(io.netty.handler.codec.http.HttpResponse response,
File file)
Sets the content type header for the HTTP Response.
|
static void |
setDateAndCacheHeaders(io.netty.handler.codec.http.HttpResponse response,
File fileToCache)
Sets the "date" and "cache" headers for the HTTP Response.
|
static void |
setDateHeader(io.netty.handler.codec.http.FullHttpResponse response)
Sets the "date" header for the HTTP response.
|
acceptInboundMessage, channelRead
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
handlerAdded, handlerRemoved, isSharable
public static final String HTTP_DATE_FORMAT
public StaticFileServerHandler(JobManagerRetriever retriever, scala.concurrent.Future<String> localJobManagerAddressPromise, scala.concurrent.duration.FiniteDuration timeout, File rootPath, boolean httpsEnabled) throws IOException
IOException
public StaticFileServerHandler(JobManagerRetriever retriever, scala.concurrent.Future<String> localJobManagerAddressFuture, scala.concurrent.duration.FiniteDuration timeout, File rootPath, boolean httpsEnabled, org.slf4j.Logger logger) throws IOException
IOException
public void channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.router.Routed routed) throws Exception
channelRead0
in class io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.router.Routed>
Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
public static void sendError(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpResponseStatus status)
ctx
- The channel context to write the response to.status
- The response status.public static void sendNotModified(io.netty.channel.ChannelHandlerContext ctx)
ctx
- The channel context to write the response to.public static void setDateHeader(io.netty.handler.codec.http.FullHttpResponse response)
response
- HTTP responsepublic static void setDateAndCacheHeaders(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(io.netty.handler.codec.http.HttpResponse response, File file)
response
- HTTP responsefile
- file to extract content typeCopyright © 2014–2018 The Apache Software Foundation. All rights reserved.