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
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Objectstatic 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelActive(io.netty.channel.ChannelHandlerContext ctx) voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) static MediaTypegetContentType(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.ChannelFuturesendPlainTextError(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest req, io.netty.handler.codec.http.HttpResponseStatus status) static io.netty.channel.ChannelFuturesendPlainTextError(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.ChannelFuturesendResponse(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, userEventTriggeredMethods inherited from class 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 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:
channelActivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelActivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelRead
- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception - Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin 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.
-