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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final Object
static final io.netty.util.AttributeKey<RouteContext>
static final io.netty.util.AttributeKey<String>
static final io.netty.util.AttributeKey<io.netty.handler.codec.http.HttpRequest>
static final io.netty.util.AttributeKey<String>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
ANY_PATH
- See Also:
-
CTX_CONTEXT_PATH
-
CTX_HTTP_REQUEST
public static final io.netty.util.AttributeKey<io.netty.handler.codec.http.HttpRequest> CTX_HTTP_REQUEST -
CTX_USERNAME
-
CTX_CONTEXT
-
CONTENT_FINISHED_EVENT
-
-
Constructor Details
-
HttpRequestHandler
-
-
Method Details
-
channelActive
- Specified by:
channelActive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelActive
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
Exception
-
channelRead
- 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
- Returns:
- The Content-Type header if present or else defaults to JSON.
-