public class

RPCServletUtils

extends Object
java.lang.Object
   ↳ com.google.gwt.user.server.rpc.RPCServletUtils

Class Overview

Utility class containing helper methods used by servlets that integrate with the RPC system.

Summary

Public Methods
static boolean acceptsGzipEncoding(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 boolean isExpectedException(Method serviceIntfMethod, Throwable cause)
Returns true if the java.lang.reflect.Method Method definition on the service is specified to throw the exception contained in the InvocationTargetException or false otherwise.
static String readContent(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(HttpServletRequest request)
Returns the content of an HttpServletRequest, after verifying a gwt/x-gwt-rpc; charset=utf-8 content type.
static String readContentAsUtf8(HttpServletRequest request)
This method is deprecated. Use readContent(HttpServletRequest, String, String) instead.
static String readContentAsUtf8(HttpServletRequest request, boolean checkHeaders)
This method is deprecated. Use readContent(HttpServletRequest, String, String) instead.
static void setGzipEncodingHeader(HttpServletResponse response)
Sets the correct header to indicate that a response is gzipped.
static boolean shouldGzipResponseContent(HttpServletRequest request, String responseContent)
Returns true if the request accepts gzip encoding and the the response content's estimated UTF-8 byte length exceeds 256 bytes.
static void writeResponse(ServletContext servletContext, HttpServletResponse response, String responseContent, boolean gzipResponse)
Write the response content into the HttpServletResponse.
static void writeResponseForUnexpectedFailure(ServletContext servletContext, HttpServletResponse response, Throwable failure)
Called when the servlet itself has a problem, rather than the invoked third-party method.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static boolean acceptsGzipEncoding (HttpServletRequest request)

Returns true if the HttpServletRequest accepts 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
  • true if the HttpServletRequest accepts Gzip encoding

public static boolean exceedsUncompressedContentLengthLimit (String content)

Returns true if the response content's estimated UTF-8 byte length exceeds 256 bytes.

Parameters
content the contents of the response
Returns
  • true if the response content's estimated UTF-8 byte length exceeds 256 bytes

public static boolean isExpectedException (Method serviceIntfMethod, Throwable cause)

Returns true if the java.lang.reflect.Method 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.

Parameters
serviceIntfMethod the method from the RPC request
cause the exception that the method threw
Returns
  • true if the exception's type is in the method's signature

public static String readContent (HttpServletRequest request, String expectedContentType, String expectedCharSet)

Returns the content of an HttpServletRequest by decoding it using expectedCharSet, or UTF-8 if expectedCharSet is null.

Parameters
request the servlet request whose content we want to read
expectedContentType 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 attacks
expectedCharSet the expected request charset, or null if no charset validation is to be performed and UTF-8 should be assumed
Returns
  • the content of an HttpServletRequest by decoding it using expectedCharSet, or UTF-8 if expectedCharSet is null
Throws
IOException if the request's input stream cannot be accessed, read from or closed
ServletException if the request's content type does not equal the supplied expectedContentType or expectedCharSet

public static String readContentAsGwtRpc (HttpServletRequest request)

Returns the content of an HttpServletRequest, after verifying a gwt/x-gwt-rpc; charset=utf-8 content type.

Parameters
request the servlet request whose content we want to read
Returns
  • the content of an HttpServletRequest by decoding it using UTF-8
Throws
IOException if the request's input stream cannot be accessed, read from or closed
ServletException if the request's content type is not gwt/x-gwt-rpc; charset=utf-8, ignoring case

public static String readContentAsUtf8 (HttpServletRequest request)

This method is deprecated.
Use readContent(HttpServletRequest, String, String) instead.

Returns the content of an HttpServletRequest by decoding it using the UTF-8 charset.

Parameters
request the servlet request whose content we want to read
Returns
  • the content of an HttpServletRequest by decoding it using the UTF-8 charset
Throws
IOException if the requests input stream cannot be accessed, read from or closed
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 String readContentAsUtf8 (HttpServletRequest request, boolean checkHeaders)

This method is deprecated.
Use readContent(HttpServletRequest, String, String) instead.

Returns the content of an HttpServletRequest by decoding it using the UTF-8 charset.

Parameters
request the servlet request whose content we want to read
checkHeaders 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 HttpServletRequest by decoding it using the UTF-8 charset
Throws
IOException if the requests input stream cannot be accessed, read from or closed
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 (HttpServletResponse response)

Sets the correct header to indicate that a response is gzipped.

public static boolean shouldGzipResponseContent (HttpServletRequest request, String responseContent)

Returns true if the request accepts gzip encoding and the the response content's estimated UTF-8 byte length exceeds 256 bytes.

Parameters
request the request associated with the response content
responseContent a string that will be
Returns
  • true if the request accepts gzip encoding and the the response content's estimated UTF-8 byte length exceeds 256 bytes

public static void writeResponse (ServletContext servletContext, HttpServletResponse response, String responseContent, boolean gzipResponse)

Write the response content into the HttpServletResponse. If gzipResponse is true, the response content will be gzipped prior to being written into the response.

Parameters
servletContext servlet context for this response
response response instance
responseContent a string containing the response content
gzipResponse if true the response content will be gzip encoded before being written into the response
Throws
IOException if reading, writing, or closing the response's output stream fails

public static void writeResponseForUnexpectedFailure (ServletContext servletContext, HttpServletResponse response, 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.