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.ChannelInboundHandlerAdapterHandles 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 StringANY_PATHstatic ObjectCONTENT_FINISHED_EVENTstatic io.netty.util.AttributeKey<RouteContext>CTX_CONTEXTstatic 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 voidchannelActive(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, 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:
channelActivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelActivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelRead
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception- 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
public static MediaType getContentType(io.netty.handler.codec.http.HttpRequest req)
- Returns:
- The Content-Type header if present or else defaults to JSON.
-
-