Package org.yamcs.http
Class HttpRequestHandler
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- org.yamcs.http.HttpRequestHandler
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
public class HttpRequestHandler extends io.netty.channel.ChannelInboundHandlerAdapter
Handles handshakes and messages. A new instance of this handler is created for every request. We have following different request types- static requests - sent to the fileRequestHandler - do no go higher in the netty pipeline
- websocket requests - the pipeline is modified to add the websocket handshaker.
- load data requests - the pipeline is modified by the respective route handler
- standard API calls (the vast majority) - the HttpObjectAgreggator is added upstream to collect (and limit) all data from the http request in one object.
-
-
Field Summary
Fields Modifier and Type Field Description static String
ANY_PATH
static Object
CONTENT_FINISHED_EVENT
static io.netty.util.AttributeKey<RouteContext>
CTX_CONTEXT
static io.netty.util.AttributeKey<io.netty.handler.codec.http.HttpRequest>
CTX_HTTP_REQUEST
-
Constructor Summary
Constructors Constructor Description HttpRequestHandler(HttpServer httpServer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
channelActive(io.netty.channel.ChannelHandlerContext ctx)
void
channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
void
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
static MediaType
getContentType(io.netty.handler.codec.http.HttpRequest req)
static <T extends com.google.protobuf.Message>
io.netty.channel.ChannelFuturesendMessageResponse(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponseStatus status, T responseMsg)
static io.netty.channel.ChannelFuture
sendPlainTextError(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponseStatus status)
static io.netty.channel.ChannelFuture
sendPlainTextError(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponseStatus status, String msg)
static io.netty.channel.ChannelFuture
sendResponse(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponse response)
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
-
-
-
Field Detail
-
ANY_PATH
public static final String ANY_PATH
- See Also:
- Constant Field Values
-
CTX_HTTP_REQUEST
public static final io.netty.util.AttributeKey<io.netty.handler.codec.http.HttpRequest> CTX_HTTP_REQUEST
-
CTX_CONTEXT
public static final io.netty.util.AttributeKey<RouteContext> CTX_CONTEXT
-
CONTENT_FINISHED_EVENT
public static final Object CONTENT_FINISHED_EVENT
-
-
Constructor Detail
-
HttpRequestHandler
public HttpRequestHandler(HttpServer httpServer)
-
-
Method Detail
-
channelActive
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
- Specified by:
channelActive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelActive
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
Exception
-
channelRead
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
- Specified by:
channelRead
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelRead
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
Exception
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelHandler
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
exceptionCaught
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
Exception
-
sendMessageResponse
public static <T extends com.google.protobuf.Message> io.netty.channel.ChannelFuture sendMessageResponse(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponseStatus status, T responseMsg)
-
sendPlainTextError
public static io.netty.channel.ChannelFuture sendPlainTextError(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponseStatus status)
-
sendPlainTextError
public static io.netty.channel.ChannelFuture sendPlainTextError(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponseStatus status, String msg)
-
sendResponse
public static io.netty.channel.ChannelFuture sendResponse(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponse response)
-
getContentType
public static MediaType getContentType(io.netty.handler.codec.http.HttpRequest req)
- Returns:
- The Content-Type header if present or else defaults to JSON.
-
-