com.google.gwt.user.server.rpc
Class OpenRemoteServiceServlet

java.lang.Object
  extended by HttpServlet
      extended by com.google.gwt.user.server.rpc.OpenRemoteServiceServlet
Direct Known Subclasses:
AsyncRemoteServiceServlet

public class OpenRemoteServiceServlet
extends HttpServlet

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. This version is a modified version of RemoteServiceServlet. The only changes have been to remove some final declarations and to convert some private methods to protected to allow extension of this class.


Constructor Summary
OpenRemoteServiceServlet()
          The default constructor.
 
Method Summary
 void doPost(HttpServletRequest request, HttpServletResponse response)
          This is called internally.
protected  HttpServletRequest getThreadLocalRequest()
          Gets the HttpServletRequest object for the current call.
protected  HttpServletResponse getThreadLocalResponse()
          Gets the HttpServletResponse object for the current call.
protected  void handleException(String responsePayload, Throwable caught)
           
protected  void onAfterResponseSerialized(String serializedResponse)
          Override this method to examine the serialized response that will be returned to the client.
protected  void onBeforeRequestDeserialized(String serializedRequest)
          Override this method to examine the serialized version of the request payload before it is deserialized into objects.
 String processCall(String payload)
          This is public so that it can be unit tested easily without HTTP.
protected  String readPayloadAsUtf8(HttpServletRequest request)
           
protected  void respondWithFailure(HttpServletResponse response, Throwable caught)
          Called when the machinery of this class itself has a problem, rather than the invoked third-party method.
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.
protected  void writeResponse(HttpServletRequest request, HttpServletResponse response, String responsePayload)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OpenRemoteServiceServlet

public OpenRemoteServiceServlet()
The default constructor.

Method Detail

doPost

public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
This is called internally.


processCall

public String processCall(String payload)
                   throws SerializationException
This is public so that it can be unit tested easily without HTTP.

Throws:
SerializationException

handleException

protected void handleException(String responsePayload,
                               Throwable caught)

getThreadLocalRequest

protected final HttpServletRequest getThreadLocalRequest()
Gets the HttpServletRequest object for the current call. It is stored thread-locally so that simultaneous invocations can have different request objects.


getThreadLocalResponse

protected final HttpServletResponse getThreadLocalResponse()
Gets the HttpServletResponse object for the current call. It is stored thread-locally so that simultaneous invocations can have different response objects.


onAfterResponseSerialized

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.


onBeforeRequestDeserialized

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.


shouldCompressResponse

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

readPayloadAsUtf8

protected String readPayloadAsUtf8(HttpServletRequest request)
                            throws IOException,
                                   ServletException
Throws:
IOException
ServletException

respondWithFailure

protected void respondWithFailure(HttpServletResponse response,
                                  Throwable caught)
Called when the machinery of this class itself has a problem, rather than the invoked third-party method. It writes a simple 500 message back to the client.


writeResponse

protected void writeResponse(HttpServletRequest request,
                             HttpServletResponse response,
                             String responsePayload)
                      throws IOException
Throws:
IOException


Copyright © 2007 Mort Bay Consulting. All Rights Reserved.