net.sf.gwtspringrpc.servlet
Class AbstractRemoteServiceServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.google.gwt.user.server.rpc.RemoteServiceServlet
              extended by net.sf.gwtspringrpc.servlet.AbstractRemoteServiceServlet
All Implemented Interfaces:
SerializationPolicyProvider, Serializable, Servlet, ServletConfig
Direct Known Subclasses:
DelegatingRemoteServiceServlet

public abstract class AbstractRemoteServiceServlet
extends RemoteServiceServlet

This abstract class extends the RemoteServiceServlet class to provide access to a Spring web application context. The application context instance is retrieved using a WebApplicationContextRetriever instance.

This class is extended by the DelegatingRemoteServiceServlet class which delegates remote procedure calls to a bean managed by the Spring application context. This class can also be extended by application code to write remote service servlets with access to the Spring application context.

Since:
1.0
Author:
Mike Clemens
See Also:
Serialized Form

Field Summary
private  Log log
           
private  WebApplicationContextRetriever webApplicationContextRetriever
          The object used to retrieve the WebApplicationContext instance
 
Constructor Summary
AbstractRemoteServiceServlet()
           
 
Method Summary
 Object getBean(String name)
          Retrieves a bean from the web application context.
 Object getBean(String name, Class requiredType)
          Retrieves a bean from the web application context and validates that it is of the required type.
 WebApplicationContext getWebApplicationContext()
          Retrieves the WebApplicationContext.
 void init()
          Initializes the servlet.
protected  Object instantiate(String classname, Class targetClass)
          Instantiates the specified class and validates that the resulting class is an instance of the target class.
 String processCall(String payload)
          Assigns HTTP objects to the HTTPObjectHolder class before processing the remote procedure call.
 
Methods inherited from class com.google.gwt.user.server.rpc.RemoteServiceServlet
doGetSerializationPolicy, doPost, doUnexpectedFailure, getSerializationPolicy, getThreadLocalRequest, getThreadLocalResponse, onAfterResponseSerialized, onBeforeRequestDeserialized, shouldCompressResponse
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private final Log log

webApplicationContextRetriever

private WebApplicationContextRetriever webApplicationContextRetriever
The object used to retrieve the WebApplicationContext instance

Constructor Detail

AbstractRemoteServiceServlet

public AbstractRemoteServiceServlet()
Method Detail

processCall

public String processCall(String payload)
                   throws SerializationException
Assigns HTTP objects to the HTTPObjectHolder class before processing the remote procedure call.

Overrides:
processCall in class RemoteServiceServlet
Parameters:
payload - The UTF-8 request payload
Returns:
The encoded method response
Throws:
SerializationException - If the response cannot be serialized

getWebApplicationContext

public WebApplicationContext getWebApplicationContext()
Retrieves the WebApplicationContext.

Returns:
The WebApplicationContext

getBean

public Object getBean(String name)
Retrieves a bean from the web application context.

Parameters:
name - The bean name
Returns:
The bean
Throws:
NoSuchBeanDefinitionException - If no bean matches the specified name
BeansException - If the bean could not be created

getBean

public Object getBean(String name,
                      Class requiredType)
Retrieves a bean from the web application context and validates that it is of the required type.

Parameters:
name - The bean name
requiredType - The type the bean must match
Returns:
The bean
Throws:
NoSuchBeanDefinitionException - If no bean matches the specified name
BeanNotOfRequiredTypeException - If the bean is not of the required type
BeansException - If the bean could not be created

init

public void init()
          throws ServletException
Initializes the servlet. This method will check for an overridden WebApplicationContextRetriever instance, first in the servlet configuration and then in the GWTSpringRPC configuration properties file.

Overrides:
init in class GenericServlet
Throws:
ServletException - If an exception occurs initializing the servlet

instantiate

protected Object instantiate(String classname,
                             Class targetClass)
                      throws ServletException
Instantiates the specified class and validates that the resulting class is an instance of the target class. This method handles all reflection and instantiation exceptions and wraps them in a servlet exception.

Parameters:
classname - The class to instantiate
targetClass - The class the resulting instance must be an instance of
Returns:
The resulting instance
Throws:
ServletException - If an exception occurs creating the instance