Package com.google.gwt.user.server.rpc
Class RPCServletUtils
- java.lang.Object
-
- com.google.gwt.user.server.rpc.RPCServletUtils
-
public class RPCServletUtils extends java.lang.ObjectUtility class containing helper methods used by servlets that integrate with the RPC system.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intBUFFER_SIZEPackage protected for use in tests.static java.nio.charset.CharsetCHARSET_UTF8The UTF-8 Charset.static java.lang.StringCHARSET_UTF8_NAME
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleanacceptsGzipEncoding(javax.servlet.http.HttpServletRequest request)Returnstrueif theHttpServletRequestaccepts Gzip encoding.static booleanexceedsUncompressedContentLengthLimit(java.lang.String content)Returnstrueif the response content's estimated UTF-8 byte length exceeds 256 bytes.static java.nio.charset.CharsetgetCharset(java.lang.String encoding)Get the Charset for a named character set.static booleanisExpectedException(java.lang.reflect.Method serviceIntfMethod, java.lang.Throwable cause)Returns true if theMethoddefinition on the service is specified to throw the exception contained in the InvocationTargetException or false otherwise.static java.lang.StringreadContent(javax.servlet.http.HttpServletRequest request, java.lang.String expectedContentType, java.lang.String expectedCharSet)Returns the content of anHttpServletRequestby decoding it usingexpectedCharSet, orUTF-8ifexpectedCharSetisnull.static java.lang.StringreadContentAsGwtRpc(javax.servlet.http.HttpServletRequest request)Returns the content of anHttpServletRequest, after verifying agwt/x-gwt-rpc; charset=utf-8content type.static java.lang.StringreadContentAsUtf8(javax.servlet.http.HttpServletRequest request)Deprecated.static java.lang.StringreadContentAsUtf8(javax.servlet.http.HttpServletRequest request, boolean checkHeaders)Deprecated.static voidsetGzipEncodingHeader(javax.servlet.http.HttpServletResponse response)Sets the correct header to indicate that a response is gzipped.static booleanshouldGzipResponseContent(javax.servlet.http.HttpServletRequest request, java.lang.String responseContent)Returnstrueif the request accepts gzip encoding and the response content's estimated UTF-8 byte length exceeds 256 bytes.static voidwriteResponse(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletResponse response, java.lang.String responseContent, boolean gzipResponse)Write the response content into theHttpServletResponse.static voidwriteResponseForUnexpectedFailure(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletResponse response, java.lang.Throwable failure)Called when the servlet itself has a problem, rather than the invoked third-party method.
-
-
-
Field Detail
-
CHARSET_UTF8_NAME
public static final java.lang.String CHARSET_UTF8_NAME
- See Also:
- Constant Field Values
-
CHARSET_UTF8
public static final java.nio.charset.Charset CHARSET_UTF8
The UTF-8 Charset. Use this to avoid concurrency bottlenecks when converting between byte arrays and Strings. See http://code.google.com/p/google-web-toolkit/issues/detail?id=6398
-
BUFFER_SIZE
static final int BUFFER_SIZE
Package protected for use in tests.- See Also:
- Constant Field Values
-
-
Method Detail
-
acceptsGzipEncoding
public static boolean acceptsGzipEncoding(javax.servlet.http.HttpServletRequest request)
Returnstrueif theHttpServletRequestaccepts Gzip encoding. This is done by checking that the accept-encoding header specifies gzip as a supported encoding.- Parameters:
request- the request instance to test for gzip encoding acceptance- Returns:
trueif theHttpServletRequestaccepts Gzip encoding
-
exceedsUncompressedContentLengthLimit
public static boolean exceedsUncompressedContentLengthLimit(java.lang.String content)
Returnstrueif the response content's estimated UTF-8 byte length exceeds 256 bytes.- Parameters:
content- the contents of the response- Returns:
trueif the response content's estimated UTF-8 byte length exceeds 256 bytes
-
getCharset
public static java.nio.charset.Charset getCharset(java.lang.String encoding)
Get the Charset for a named character set. Caches Charsets to work around a concurrency bottleneck in FastCharsetProvider. See http://code.google.com/p/google-web-toolkit/issues/detail?id=6398- Parameters:
encoding- the name of the Charset to get. If this is null the default UTF-8 character set will be returned.- Returns:
- the named Charset.
-
isExpectedException
public static boolean isExpectedException(java.lang.reflect.Method serviceIntfMethod, java.lang.Throwable cause)Returns true if theMethoddefinition 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.- Parameters:
serviceIntfMethod- the method from the RPC requestcause- the exception that the method threw- Returns:
- true if the exception's type is in the method's signature
-
readContent
public static java.lang.String readContent(javax.servlet.http.HttpServletRequest request, java.lang.String expectedContentType, java.lang.String expectedCharSet) throws java.io.IOException, javax.servlet.ServletExceptionReturns the content of anHttpServletRequestby decoding it usingexpectedCharSet, orUTF-8ifexpectedCharSetisnull.- Parameters:
request- the servlet request whose content we want to readexpectedContentType- the expected content (i.e. 'type/subtype' only) in the Content-Type request header, ornullif no validation is to be performed, and you are willing to allow for some types of cross type security attacksexpectedCharSet- the expected request charset, ornullif no charset validation is to be performed andUTF-8should be assumed- Returns:
- the content of an
HttpServletRequestby decoding it usingexpectedCharSet, orUTF-8ifexpectedCharSetisnull - Throws:
java.io.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 suppliedexpectedContentTypeorexpectedCharSet
-
readContentAsGwtRpc
public static java.lang.String readContentAsGwtRpc(javax.servlet.http.HttpServletRequest request) throws java.io.IOException, javax.servlet.ServletExceptionReturns the content of anHttpServletRequest, after verifying agwt/x-gwt-rpc; charset=utf-8content type.- Parameters:
request- the servlet request whose content we want to read- Returns:
- the content of an
HttpServletRequestby decoding it usingUTF-8 - Throws:
java.io.IOException- if the request's input stream cannot be accessed, read from or closedjavax.servlet.ServletException- if the request's content type is notgwt/x-gwt-rpc; charset=utf-8, ignoring case
-
readContentAsUtf8
@Deprecated public static java.lang.String readContentAsUtf8(javax.servlet.http.HttpServletRequest request) throws java.io.IOException, javax.servlet.ServletExceptionDeprecated.Returns the content of anHttpServletRequestby decoding it using the UTF-8 charset.- Parameters:
request- the servlet request whose content we want to read- Returns:
- the content of an
HttpServletRequestby decoding it using the UTF-8 charset - Throws:
java.io.IOException- 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'
-
readContentAsUtf8
@Deprecated public static java.lang.String readContentAsUtf8(javax.servlet.http.HttpServletRequest request, boolean checkHeaders) throws java.io.IOException, javax.servlet.ServletExceptionDeprecated.Returns the content of anHttpServletRequestby decoding it using the UTF-8 charset.- Parameters:
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.- Returns:
- the content of an
HttpServletRequestby decoding it using the UTF-8 charset - Throws:
java.io.IOException- 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'
-
setGzipEncodingHeader
public static void setGzipEncodingHeader(javax.servlet.http.HttpServletResponse response)
Sets the correct header to indicate that a response is gzipped.
-
shouldGzipResponseContent
public static boolean shouldGzipResponseContent(javax.servlet.http.HttpServletRequest request, java.lang.String responseContent)Returnstrueif the request accepts gzip encoding and the response content's estimated UTF-8 byte length exceeds 256 bytes.- Parameters:
request- the request associated with the response contentresponseContent- a string that will be- Returns:
trueif the request accepts gzip encoding and the response content's estimated UTF-8 byte length exceeds 256 bytes
-
writeResponse
public static void writeResponse(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletResponse response, java.lang.String responseContent, boolean gzipResponse) throws java.io.IOExceptionWrite the response content into theHttpServletResponse. IfgzipResponseistrue, the response content will be gzipped prior to being written into the response.- Parameters:
servletContext- servlet context for this responseresponse- response instanceresponseContent- a string containing the response contentgzipResponse- iftruethe response content will be gzip encoded before being written into the response- Throws:
java.io.IOException- if reading, writing, or closing the response's output stream fails
-
writeResponseForUnexpectedFailure
public static void writeResponseForUnexpectedFailure(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletResponse response, java.lang.Throwable failure)Called when the servlet itself has a problem, rather than the invoked third-party method. It writes a simple 500 message back to the client.- Parameters:
servletContext-response-failure-
-
-