AeroGear Netty SockJS Codec 0.11.0

org.jboss.aerogear.io.netty.handler.codec.sockjs.transport
Class Transports

java.lang.Object
  extended by org.jboss.aerogear.io.netty.handler.codec.sockjs.transport.Transports

public final class Transports
extends Object

Transports contains constants, enums, and utility methods that are common across transport implementations.


Nested Class Summary
static class Transports.Type
           
 
Field Summary
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
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE_PLAIN

public static final String CONTENT_TYPE_PLAIN
See Also:
Constant Field Values

CONTENT_TYPE_JAVASCRIPT

public static final String CONTENT_TYPE_JAVASCRIPT
See Also:
Constant Field Values

CONTENT_TYPE_FORM

public static final String CONTENT_TYPE_FORM
See Also:
Constant Field Values

CONTENT_TYPE_HTML

public static final String CONTENT_TYPE_HTML
See Also:
Constant Field Values

DEFAULT_COOKIE

public static final String DEFAULT_COOKIE
See Also:
Constant Field Values

JSESSIONID

public static final String JSESSIONID
See Also:
Constant Field Values
Method Detail

encodeSessionIdCookie

public static String encodeSessionIdCookie(io.netty.handler.codec.http.HttpRequest request)
Encodes the passes in requests JSESSIONID, if one exists, setting it to path of '/'.

Parameters:
request - the HttpRequest to parse for a JSESSIONID cookie.
Returns:
String the encoded cookie or if no JSESSIONID cookie exits.

writeContent

public 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.

Parameters:
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.

setDefaultHeaders

public 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)

Parameters:
response - the Http Response.
config - the SockJS configuration.

setDefaultHeaders

public 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. - CACHE_CONTROL to setNoCacheHeaders(HttpResponse) - CORS Headers to setCORSHeaders(HttpResponse)

Parameters:
response - the Http Response.
config - the SockJS configuration.

setSessionIdCookie

public 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.

Parameters:
response - the Http Response.
config - the SockJS configuration.
request - the Http request which will be inspected for the existence of a JSESSIONID cookie.

setNoCacheHeaders

public static void setNoCacheHeaders(io.netty.handler.codec.http.HttpResponse response)
Sets the Http response header CACHE_CONTROL to NO_CACHE_HEADER.

Parameters:
response - the Http response for which the CACHE_CONTROL header will be set.

setCORSHeaders

public 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".

Parameters:
response - the Http response for which the CORS headers will be set.

wrapWithLN

public static io.netty.buffer.ByteBuf wrapWithLN(io.netty.buffer.ByteBuf buf)
Will add an new line character to the passed in ByteBuf.

Parameters:
buf - the ByteBuf for which an '\n', new line, will be added.
Returns:
ByteBuf a copied byte buffer with a '\n' appended.

escapeCharacters

public static String escapeCharacters(char[] value)
Escapes unicode characters in the passed in char array to a Java string with Java style escaped charaters.

Parameters:
value - the char[] for which unicode characters should be escaped
Returns:
String Java style escaped unicode characters.

escapeJson

public 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.

Parameters:
input - the bytes of characters to process.
buffer - the ByteBuf into which the result of processing will be added.
Returns:
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.

methodNotAllowedResponse

public static io.netty.handler.codec.http.FullHttpResponse methodNotAllowedResponse(io.netty.handler.codec.http.HttpVersion version)
Creates a FullHttpResponse with the METHOD_NOT_ALLOWED status.

Parameters:
version - the HttpVersion to be used.
Returns:
FullHttpResponse with the HttpResponseStatus.METHOD_NOT_ALLOWED.

badRequestResponse

public 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.

Parameters:
version - the HttpVersion to be used.
content - the content that will become the response body.
Returns:
FullHttpResponse with the HttpResponseStatus.BAD_REQUEST.

internalServerErrorResponse

public 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.

Parameters:
version - the HttpVersion to be used.
content - the content that will become the response body.
Returns:
FullHttpResponse with the HttpResponseStatus.INTERNAL_SERVER_ERROR.

respond

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)
Sends a HttpResponse using the ChannelHandlerContext passed in.

Parameters:
ctx - the ChannelHandlerContext to use.
version - the HttpVersion that the response should have.
status - the status of the HTTP response
contentType - the value for the 'Content-Type' HTTP response header.
content - the content that will become the body of the HTTP response.
promise - the ChannelPromise

respond

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)
Sends a HttpResponse using the ChannelHandlerContext passed in.

Parameters:
ctx - the ChannelHandlerContext to use.
version - the HttpVersion that the response should have.
status - the status of the HTTP response
contentType - the value for the 'Content-Type' HTTP response header.
content - the content that will become the body of the HTTP response.

responseWithoutContent

public 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.

Parameters:
version - the HttpVersion that the response should have.
status - the status of the HTTP response

responseWithContent

public 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.

Parameters:
version - the HttpVersion that the response should have.
status - the status of the HTTP response
contentType - the value for the 'Content-Type' HTTP response header.
content - the content that will become the body of the HTTP response.

writeResponse

public 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.

Parameters:
ctx - the ChannelHandlerContext to write the response to.
response - the HttpResponseStatus to be written.

writeResponse

public 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.

Parameters:
ctx - the ChannelHandlerContext to write the response to.
promise - the ChannelPromise
response - the HttpResponseStatus to be written.

AeroGear Netty SockJS Codec 0.11.0

Copyright © 2014 JBoss by Red Hat. All Rights Reserved.