public class RPCServletUtils extends Object
Modifier and Type | Field and Description |
---|---|
static Charset |
CHARSET_UTF8
The UTF-8 Charset.
|
static String |
CHARSET_UTF8_NAME |
Modifier and Type | Method and Description |
---|---|
static boolean |
acceptsGzipEncoding(javax.servlet.http.HttpServletRequest request)
Returns
true if the HttpServletRequest accepts Gzip
encoding. |
static boolean |
exceedsUncompressedContentLengthLimit(String content)
Returns
true if the response content's estimated UTF-8 byte
length exceeds 256 bytes. |
static Charset |
getCharset(String encoding)
Get the Charset for a named character set.
|
static boolean |
isExpectedException(Method serviceIntfMethod,
Throwable cause)
Returns true if the
Method definition on
the service is specified to throw the exception contained in the
InvocationTargetException or false otherwise. |
static String |
readContent(javax.servlet.http.HttpServletRequest request,
String expectedContentType,
String expectedCharSet)
Returns the content of an
HttpServletRequest by decoding it using
expectedCharSet , or UTF-8 if
expectedCharSet is null. |
static String |
readContentAsGwtRpc(javax.servlet.http.HttpServletRequest request)
Returns the content of an
HttpServletRequest , after verifying a
gwt/x-gwt-rpc; charset=utf-8 content type. |
static String |
readContentAsUtf8(javax.servlet.http.HttpServletRequest request)
Deprecated.
|
static String |
readContentAsUtf8(javax.servlet.http.HttpServletRequest request,
boolean checkHeaders)
Deprecated.
|
static void |
setGzipEncodingHeader(javax.servlet.http.HttpServletResponse response)
Sets the correct header to indicate that a response is gzipped.
|
static boolean |
shouldGzipResponseContent(javax.servlet.http.HttpServletRequest request,
String responseContent)
Returns
true if the request accepts gzip encoding and the
response content's estimated UTF-8 byte length exceeds 256 bytes. |
static void |
writeResponse(javax.servlet.ServletContext servletContext,
javax.servlet.http.HttpServletResponse response,
String responseContent,
boolean gzipResponse)
Write the response content into the
HttpServletResponse . |
static void |
writeResponseForUnexpectedFailure(javax.servlet.ServletContext servletContext,
javax.servlet.http.HttpServletResponse response,
Throwable failure)
Called when the servlet itself has a problem, rather than the invoked
third-party method.
|
public static final String CHARSET_UTF8_NAME
public static final Charset CHARSET_UTF8
public static boolean acceptsGzipEncoding(javax.servlet.http.HttpServletRequest request)
true
if the HttpServletRequest
accepts Gzip
encoding. This is done by checking that the accept-encoding header
specifies gzip as a supported encoding.request
- the request instance to test for gzip encoding acceptancetrue
if the HttpServletRequest
accepts Gzip
encodingpublic static boolean exceedsUncompressedContentLengthLimit(String content)
true
if the response content's estimated UTF-8 byte
length exceeds 256 bytes.content
- the contents of the responsetrue
if the response content's estimated UTF-8 byte
length exceeds 256 bytespublic static Charset getCharset(String encoding)
encoding
- the name of the Charset to get. If this is null
the default UTF-8 character set will be returned.Charset#forName(String)}
public static boolean isExpectedException(Method serviceIntfMethod, Throwable cause)
Method
definition on
the service is specified to throw the exception contained in the
InvocationTargetException or false otherwise. NOTE we do not check that the
type is serializable here. We assume that it must be otherwise the
application would never have been allowed to run.serviceIntfMethod
- the method from the RPC requestcause
- the exception that the method threwpublic static String readContent(javax.servlet.http.HttpServletRequest request, String expectedContentType, String expectedCharSet) throws IOException, javax.servlet.ServletException
HttpServletRequest
by decoding it using
expectedCharSet
, or UTF-8
if
expectedCharSet
is null.
request
- the servlet request whose content we want to readexpectedContentType
- the expected content (i.e. 'type/subtype' only)
in the Content-Type request header, or null
if no
validation is to be performed, and you are willing to allow for
some types of cross type security attacksexpectedCharSet
- the expected request charset, or null
if no charset validation is to be performed and UTF-8
should be assumedHttpServletRequest
by decoding it using
expectedCharSet
, or UTF-8
if
expectedCharSet
is null
IOException
- if the request's input stream cannot be accessed, read
from or closedjavax.servlet.ServletException
- if the request's content type does not
equal the supplied expectedContentType
or
expectedCharSet
public static String readContentAsGwtRpc(javax.servlet.http.HttpServletRequest request) throws IOException, javax.servlet.ServletException
HttpServletRequest
, after verifying a
gwt/x-gwt-rpc; charset=utf-8
content type.request
- the servlet request whose content we want to readHttpServletRequest
by decoding it using
UTF-8
IOException
- if the request's input stream cannot be accessed, read
from or closedjavax.servlet.ServletException
- if the request's content type is not
gwt/x-gwt-rpc; charset=utf-8
, ignoring case@Deprecated public static String readContentAsUtf8(javax.servlet.http.HttpServletRequest request) throws IOException, javax.servlet.ServletException
readContent(javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String)
instead.HttpServletRequest
by decoding it using
the UTF-8 charset.request
- the servlet request whose content we want to readHttpServletRequest
by decoding it using
the UTF-8 charsetIOException
- if the requests input stream cannot be accessed, read
from or closedjavax.servlet.ServletException
- if the content length of the request is not
specified of if the request's content type is not
'text/x-gwt-rpc' and 'charset=utf-8'@Deprecated public static String readContentAsUtf8(javax.servlet.http.HttpServletRequest request, boolean checkHeaders) throws IOException, javax.servlet.ServletException
readContent(javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String)
instead.HttpServletRequest
by decoding it using
the UTF-8 charset.request
- the servlet request whose content we want to readcheckHeaders
- Specify 'true' to check the Content-Type header to see
that it matches the expected value 'text/x-gwt-rpc' and the
content encoding is UTF-8. Disabling this check may allow some
types of cross type security attacks.HttpServletRequest
by decoding it using
the UTF-8 charsetIOException
- if the requests input stream cannot be accessed, read
from or closedjavax.servlet.ServletException
- if the content length of the request is not
specified of if the request's content type is not
'text/x-gwt-rpc' and 'charset=utf-8'public static void setGzipEncodingHeader(javax.servlet.http.HttpServletResponse response)
public static boolean shouldGzipResponseContent(javax.servlet.http.HttpServletRequest request, String responseContent)
true
if the request accepts gzip encoding and the
response content's estimated UTF-8 byte length exceeds 256 bytes.request
- the request associated with the response contentresponseContent
- a string that will betrue
if the request accepts gzip encoding and the
response content's estimated UTF-8 byte length exceeds 256 bytespublic static void writeResponse(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletResponse response, String responseContent, boolean gzipResponse) throws IOException
HttpServletResponse
. If
gzipResponse
is true
, the response content will
be gzipped prior to being written into the response.servletContext
- servlet context for this responseresponse
- response instanceresponseContent
- a string containing the response contentgzipResponse
- if true
the response content will be gzip
encoded before being written into the responseIOException
- if reading, writing, or closing the response's output
stream failspublic static void writeResponseForUnexpectedFailure(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletResponse response, Throwable failure)
servletContext
- response
- failure
- Copyright © 2018. All rights reserved.