public class

RemoteServiceServlet

extends AbstractRemoteServiceServlet
implements SerializationPolicyProvider
java.lang.Object
   ↳ javax.servlet.GenericServlet
     ↳ javax.servlet.http.HttpServlet
       ↳ com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet
         ↳ com.google.gwt.user.server.rpc.RemoteServiceServlet
Known Direct Subclasses

Class Overview

The servlet base class for your RPC service implementations that automatically deserializes incoming requests from the client and serializes outgoing responses for client/server RPCs.

Summary

[Expand]
Inherited Fields
From class com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet
Public Constructors
RemoteServiceServlet()
The default constructor used by service implementations that extend this class.
RemoteServiceServlet(Object delegate)
The wrapping constructor used by service implementations that are separate from this class.
Public Methods
final SerializationPolicy getSerializationPolicy(String moduleBaseURL, String strongName)
Returns a SerializationPolicy for a given module base URL and serialization policy strong name.
String processCall(String payload)
Process a call originating from the given request.
final void processPost(HttpServletRequest request, HttpServletResponse response)
Standard HttpServlet method: handle the POST.
Protected Methods
void checkPermutationStrongName()
This method is called by processCall(String) and will throw a SecurityException if getPermutationStrongName() returns null.
SerializationPolicy doGetSerializationPolicy(HttpServletRequest request, String moduleBaseURL, String strongName)
Gets the SerializationPolicy for given module base URL and strong name if there is one.
void onAfterResponseSerialized(String serializedResponse)
Override this method to examine the serialized response that will be returned to the client.
void onBeforeRequestDeserialized(String serializedRequest)
Override this method to examine the serialized version of the request payload before it is deserialized into objects.
boolean shouldCompressResponse(HttpServletRequest request, HttpServletResponse response, String responsePayload)
Determines whether the response to a given servlet request should or should not be GZIP compressed.
[Expand]
Inherited Methods
From class com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet
From class javax.servlet.http.HttpServlet
From class javax.servlet.GenericServlet
From class java.lang.Object
From interface com.google.gwt.user.server.rpc.SerializationPolicyProvider
From interface javax.servlet.Servlet
From interface javax.servlet.ServletConfig

Public Constructors

public RemoteServiceServlet ()

The default constructor used by service implementations that extend this class. The servlet will delegate AJAX requests to the appropriate method in the subclass.

public RemoteServiceServlet (Object delegate)

The wrapping constructor used by service implementations that are separate from this class. The servlet will delegate AJAX requests to the appropriate method in the given object.

Public Methods

public final SerializationPolicy getSerializationPolicy (String moduleBaseURL, String strongName)

Returns a SerializationPolicy for a given module base URL and serialization policy strong name.

Parameters
moduleBaseURL the URL for the module
strongName strong name of the serialization policy for the specified module URL
Returns

public String processCall (String payload)

Process a call originating from the given request. Uses the invokeAndEncodeResponse(Object, java.lang.reflect.Method, Object[]) method to do the actual work.

Subclasses may optionally override this method to handle the payload in any way they desire (by routing the request to a framework component, for instance). The HttpServletRequest and HttpServletResponse can be accessed via the getThreadLocalRequest() and getThreadLocalResponse() methods.

This is public so that it can be unit tested easily without HTTP.

Parameters
payload the UTF-8 request payload
Returns
Throws
SerializationException if we cannot serialize the response
UnexpectedException if the invocation throws a checked exception that is not declared in the service method's signature
RuntimeException if the service method throws an unchecked exception (the exception will be the one thrown by the service)

public final void processPost (HttpServletRequest request, HttpServletResponse response)

Standard HttpServlet method: handle the POST. This doPost method swallows ALL exceptions, logs them in the ServletContext, and returns a GENERIC_FAILURE_MSG response with status code 500.

Throws
ServletException
SerializationException
IOException
ServletException

Protected Methods

protected void checkPermutationStrongName ()

This method is called by processCall(String) and will throw a SecurityException if getPermutationStrongName() returns null. This method can be overridden to be a no-op if there are clients that are not expected to provide the {@value com.google.gwt.user.client.rpc.RpcRequestBuilder#STRONG_NAME_HEADER} header.

protected SerializationPolicy doGetSerializationPolicy (HttpServletRequest request, String moduleBaseURL, String strongName)

Gets the SerializationPolicy for given module base URL and strong name if there is one. Override this method to provide a SerializationPolicy using an alternative approach.

Parameters
request the HTTP request being serviced
moduleBaseURL as specified in the incoming payload
strongName a strong name that uniquely identifies a serialization policy file
Returns

protected void onAfterResponseSerialized (String serializedResponse)

Override this method to examine the serialized response that will be returned to the client. The default implementation does nothing and need not be called by subclasses.

protected void onBeforeRequestDeserialized (String serializedRequest)

Override this method to examine the serialized version of the request payload before it is deserialized into objects. The default implementation does nothing and need not be called by subclasses.

protected boolean shouldCompressResponse (HttpServletRequest request, HttpServletResponse response, String responsePayload)

Determines whether the response to a given servlet request should or should not be GZIP compressed. This method is only called in cases where the requester accepts GZIP encoding.

This implementation currently returns true if the response string's estimated byte length is longer than 256 bytes. Subclasses can override this logic.

Parameters
request the request being served
response the response that will be written into
responsePayload the payload that is about to be sent to the client
Returns
  • true if responsePayload should be GZIP compressed, otherwise false.