public final class NettyUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
addFormData(io.netty.handler.codec.http.multipart.InterfaceHttpData data,
ai.djl.modality.Input input)
Parses form data and added to the
Input object. |
static void |
closeOnFlush(io.netty.channel.Channel ch)
Closes the specified channel after all queued write requests are flushed.
|
static byte[] |
getBytes(io.netty.buffer.ByteBuf buf)
Returns the bytes for the specified
ByteBuf. |
static int |
getIntParameter(io.netty.handler.codec.http.QueryStringDecoder decoder,
java.lang.String key,
int def)
Read the parameter's integer value for the key from the uri.
|
static java.lang.String |
getParameter(io.netty.handler.codec.http.QueryStringDecoder decoder,
java.lang.String key,
java.lang.String def)
Reads the parameter's value for the key from the uri.
|
static java.lang.String |
getRequestId(io.netty.channel.Channel channel)
Returns the request ID for the specified channel.
|
static void |
requestReceived(io.netty.channel.Channel channel,
io.netty.handler.codec.http.HttpRequest request)
Updates session when a HTTP request is received.
|
static void |
sendError(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpResponseStatus status,
java.lang.Throwable t)
Sends error to client with HTTP status and exception.
|
static void |
sendError(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Throwable t)
Sends error to client with exception.
|
static void |
sendHttpResponse(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.FullHttpResponse resp,
boolean keepAlive)
Send HTTP response to client.
|
static void |
sendJsonResponse(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Object obj)
Sends the json object to client.
|
static void |
sendJsonResponse(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Object obj,
io.netty.handler.codec.http.HttpResponseStatus status)
Sends the json string to client with specified status.
|
static void |
sendJsonResponse(io.netty.channel.ChannelHandlerContext ctx,
java.lang.String json)
Sends the json string to client.
|
static void |
sendJsonResponse(io.netty.channel.ChannelHandlerContext ctx,
java.lang.String json,
io.netty.handler.codec.http.HttpResponseStatus status)
Sends the json object to client with specified status.
|
public static void requestReceived(io.netty.channel.Channel channel,
io.netty.handler.codec.http.HttpRequest request)
channel - the connection channelrequest - the HTTP requestpublic static java.lang.String getRequestId(io.netty.channel.Channel channel)
channel - the connection channelpublic static void sendJsonResponse(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Object obj)
ctx - the connection contextobj - the object to be sentpublic static void sendJsonResponse(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Object obj,
io.netty.handler.codec.http.HttpResponseStatus status)
ctx - the connection contextobj - the object to be sentstatus - the HTTP statuspublic static void sendJsonResponse(io.netty.channel.ChannelHandlerContext ctx,
java.lang.String json)
ctx - the connection contextjson - the json stringpublic static void sendJsonResponse(io.netty.channel.ChannelHandlerContext ctx,
java.lang.String json,
io.netty.handler.codec.http.HttpResponseStatus status)
ctx - the connection contextjson - the json objectstatus - the HTTP statuspublic static void sendError(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Throwable t)
ctx - the connection contextt - the exception to be sendpublic static void sendError(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpResponseStatus status,
java.lang.Throwable t)
ctx - the connection contextstatus - the HTTP statust - the exception to be sendpublic static void sendHttpResponse(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.FullHttpResponse resp,
boolean keepAlive)
ctx - ChannelHandlerContextresp - HttpResponse to sendkeepAlive - if keep the connectionpublic static void closeOnFlush(io.netty.channel.Channel ch)
ch - the channel to be closedpublic static byte[] getBytes(io.netty.buffer.ByteBuf buf)
ByteBuf.buf - the ByteBuf to readByteBufpublic static java.lang.String getParameter(io.netty.handler.codec.http.QueryStringDecoder decoder,
java.lang.String key,
java.lang.String def)
decoder - the QueryStringDecoder parsed from urikey - the parameter keydef - the default valuepublic static int getIntParameter(io.netty.handler.codec.http.QueryStringDecoder decoder,
java.lang.String key,
int def)
decoder - the QueryStringDecoder parsed from urikey - the parameter keydef - the default valuejava.lang.NumberFormatException - exception is thrown when the parameter-value is not numeric.public static void addFormData(io.netty.handler.codec.http.multipart.InterfaceHttpData data,
ai.djl.modality.Input input)
Input object.data - the form datainput - the Input object to be added to