public final class Transports extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Transports.Type |
| Modifier and Type | Field and Description |
|---|---|
static String |
CONTENT_TYPE_FORM |
static String |
CONTENT_TYPE_HTML |
static String |
CONTENT_TYPE_JAVASCRIPT |
static String |
CONTENT_TYPE_PLAIN |
static String |
DEFAULT_COOKIE |
static String |
JSESSIONID |
| Modifier and Type | Method and Description |
|---|---|
static io.netty.handler.codec.http.FullHttpResponse |
badRequestResponse(io.netty.handler.codec.http.HttpVersion version,
String content)
Creates a
FullHttpResponse with the BAD_REQUEST status and a body. |
static String |
encodeSessionIdCookie(io.netty.handler.codec.http.HttpRequest request)
Encodes the passes in requests JSESSIONID, if one exists, setting it to path of '/'.
|
static String |
escapeCharacters(char[] value)
Escapes unicode characters in the passed in char array to a Java string with
Java style escaped charaters.
|
static io.netty.buffer.ByteBuf |
escapeJson(io.netty.buffer.ByteBuf input,
io.netty.buffer.ByteBuf buffer)
Processes the input ByteBuf and escapes the any control characters, quotes, slashes,
and unicode characters.
|
static io.netty.handler.codec.http.FullHttpResponse |
internalServerErrorResponse(io.netty.handler.codec.http.HttpVersion version,
String content)
Creates a
FullHttpResponse with the INTERNAL_SERVER_ERROR status and a body. |
static io.netty.handler.codec.http.FullHttpResponse |
methodNotAllowedResponse(io.netty.handler.codec.http.HttpVersion version)
Creates a
FullHttpResponse with the METHOD_NOT_ALLOWED status. |
static void |
respond(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpVersion version,
io.netty.handler.codec.http.HttpResponseStatus status,
String contentType,
String content)
Sends a HttpResponse using the ChannelHandlerContext passed in.
|
static void |
respond(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpVersion version,
io.netty.handler.codec.http.HttpResponseStatus status,
String contentType,
String content,
io.netty.channel.ChannelPromise promise)
Sends a HttpResponse using the ChannelHandlerContext passed in.
|
static io.netty.handler.codec.http.FullHttpResponse |
responseWithContent(io.netty.handler.codec.http.HttpVersion version,
io.netty.handler.codec.http.HttpResponseStatus status,
String contentType,
String content)
Creates FullHttpResponse with a response body.
|
static io.netty.handler.codec.http.FullHttpResponse |
responseWithoutContent(io.netty.handler.codec.http.HttpVersion version,
io.netty.handler.codec.http.HttpResponseStatus status)
Creates FullHttpResponse without a response body.
|
static void |
setCORSHeaders(io.netty.handler.codec.http.HttpResponse response)
Sets the CORS Http response headers ACCESS_CONTROLL_ALLOW_ORIGIN to '*', and ACCESS_CONTROL_ALLOW_CREDENTIALS to
'true".
|
static void |
setDefaultHeaders(io.netty.handler.codec.http.FullHttpResponse response,
SockJsConfig config,
io.netty.handler.codec.http.HttpRequest request)
Sets the following Http response headers
- SET_COOKIE if
SockJsConfig.areCookiesNeeded() is true, and uses the requests cookie |
static void |
setDefaultHeaders(io.netty.handler.codec.http.HttpResponse response,
SockJsConfig config)
Sets the following Http response headers
- SET_COOKIE if
SockJsConfig.areCookiesNeeded() is true
- CACHE_CONTROL to setNoCacheHeaders(HttpResponse)
- CORS Headers to setCORSHeaders(HttpResponse) |
static void |
setNoCacheHeaders(io.netty.handler.codec.http.HttpResponse response)
Sets the Http response header CACHE_CONTROL to
NO_CACHE_HEADER. |
static void |
setSessionIdCookie(io.netty.handler.codec.http.FullHttpResponse response,
SockJsConfig config,
io.netty.handler.codec.http.HttpRequest request)
Sets the Http response header SET_COOKIE if
SockJsConfig.areCookiesNeeded() is true. |
static io.netty.buffer.ByteBuf |
wrapWithLN(io.netty.buffer.ByteBuf buf)
Will add an new line character to the passed in ByteBuf.
|
static void |
writeContent(io.netty.handler.codec.http.FullHttpResponse response,
String content,
String contentType)
Writes the passed in String content to the response and also sets te content-type and content-lenght headaers.
|
static void |
writeResponse(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise,
io.netty.handler.codec.http.HttpResponse response)
Writes the passed in respone to the
ChannelHandlerContext if it is active. |
static void |
writeResponse(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpResponse response)
Writes the passed in respone to the
ChannelHandlerContext if it is active. |
public static final String CONTENT_TYPE_PLAIN
public static final String CONTENT_TYPE_JAVASCRIPT
public static final String CONTENT_TYPE_FORM
public static final String CONTENT_TYPE_HTML
public static final String DEFAULT_COOKIE
public static final String JSESSIONID
public static String encodeSessionIdCookie(io.netty.handler.codec.http.HttpRequest request)
request - the HttpRequest to parse for a JSESSIONID cookie.String the encoded cookie or if no JSESSIONID cookie exits.public static void writeContent(io.netty.handler.codec.http.FullHttpResponse response,
String content,
String contentType)
response - the FullHttpResponse to write the content to.content - the content to be written.contentType - the content-type that will be set as the Content-Type Http response header.public static void setDefaultHeaders(io.netty.handler.codec.http.HttpResponse response,
SockJsConfig config)
SockJsConfig.areCookiesNeeded() is true
- CACHE_CONTROL to setNoCacheHeaders(HttpResponse)
- CORS Headers to setCORSHeaders(HttpResponse)response - the Http Response.config - the SockJS configuration.public static void setDefaultHeaders(io.netty.handler.codec.http.FullHttpResponse response,
SockJsConfig config,
io.netty.handler.codec.http.HttpRequest request)
SockJsConfig.areCookiesNeeded() is true, and uses the requests cookie.
- CACHE_CONTROL to setNoCacheHeaders(HttpResponse)
- CORS Headers to setCORSHeaders(HttpResponse)response - the Http Response.config - the SockJS configuration.public static void setSessionIdCookie(io.netty.handler.codec.http.FullHttpResponse response,
SockJsConfig config,
io.netty.handler.codec.http.HttpRequest request)
SockJsConfig.areCookiesNeeded() is true.response - the Http Response.config - the SockJS configuration.request - the Http request which will be inspected for the existence of a JSESSIONID cookie.public static void setNoCacheHeaders(io.netty.handler.codec.http.HttpResponse response)
NO_CACHE_HEADER.response - the Http response for which the CACHE_CONTROL header will be set.public static void setCORSHeaders(io.netty.handler.codec.http.HttpResponse response)
response - the Http response for which the CORS headers will be set.public static io.netty.buffer.ByteBuf wrapWithLN(io.netty.buffer.ByteBuf buf)
buf - the ByteBuf for which an '\n', new line, will be added.ByteBuf a copied byte buffer with a '\n' appended.public static String escapeCharacters(char[] value)
value - the char[] for which unicode characters should be escapedString Java style escaped unicode characters.public static io.netty.buffer.ByteBuf escapeJson(io.netty.buffer.ByteBuf input,
io.netty.buffer.ByteBuf buffer)
input - the bytes of characters to process.buffer - the ByteBuf into which the result of processing will be added.ByteBuf which is the same ByteBuf as passed in as the buffer param. This is done to
simplify method invocation where possible which might require a return value.public static io.netty.handler.codec.http.FullHttpResponse methodNotAllowedResponse(io.netty.handler.codec.http.HttpVersion version)
FullHttpResponse with the METHOD_NOT_ALLOWED status.version - the HttpVersion to be used.FullHttpResponse with the HttpResponseStatus.METHOD_NOT_ALLOWED.public static io.netty.handler.codec.http.FullHttpResponse badRequestResponse(io.netty.handler.codec.http.HttpVersion version,
String content)
FullHttpResponse with the BAD_REQUEST status and a body.version - the HttpVersion to be used.content - the content that will become the response body.FullHttpResponse with the HttpResponseStatus.BAD_REQUEST.public static io.netty.handler.codec.http.FullHttpResponse internalServerErrorResponse(io.netty.handler.codec.http.HttpVersion version,
String content)
FullHttpResponse with the INTERNAL_SERVER_ERROR status and a body.version - the HttpVersion to be used.content - the content that will become the response body.FullHttpResponse with the HttpResponseStatus.INTERNAL_SERVER_ERROR.public static void respond(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpVersion version,
io.netty.handler.codec.http.HttpResponseStatus status,
String contentType,
String content,
io.netty.channel.ChannelPromise promise)
ctx - the ChannelHandlerContext to use.version - the HttpVersion that the response should have.status - the status of the HTTP responsecontentType - the value for the 'Content-Type' HTTP response header.content - the content that will become the body of the HTTP response.promise - the ChannelPromisepublic static void respond(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpVersion version,
io.netty.handler.codec.http.HttpResponseStatus status,
String contentType,
String content)
ctx - the ChannelHandlerContext to use.version - the HttpVersion that the response should have.status - the status of the HTTP responsecontentType - the value for the 'Content-Type' HTTP response header.content - the content that will become the body of the HTTP response.public static io.netty.handler.codec.http.FullHttpResponse responseWithoutContent(io.netty.handler.codec.http.HttpVersion version,
io.netty.handler.codec.http.HttpResponseStatus status)
version - the HttpVersion that the response should have.status - the status of the HTTP responsepublic static io.netty.handler.codec.http.FullHttpResponse responseWithContent(io.netty.handler.codec.http.HttpVersion version,
io.netty.handler.codec.http.HttpResponseStatus status,
String contentType,
String content)
version - the HttpVersion that the response should have.status - the status of the HTTP responsecontentType - the value for the 'Content-Type' HTTP response header.content - the content that will become the body of the HTTP response.public static void writeResponse(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpResponse response)
ChannelHandlerContext if it is active.ctx - the ChannelHandlerContext to write the response to.response - the HttpResponseStatus to be written.public static void writeResponse(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise,
io.netty.handler.codec.http.HttpResponse response)
ChannelHandlerContext if it is active.ctx - the ChannelHandlerContext to write the response to.promise - the ChannelPromiseresponse - the HttpResponseStatus to be written.Copyright © 2014 JBoss by Red Hat. All Rights Reserved.