com.noelios.restlet.ext.spring
Class RestletFrameworkServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.springframework.web.servlet.HttpServletBean
              extended by org.springframework.web.servlet.FrameworkServlet
                  extended by com.noelios.restlet.ext.spring.RestletFrameworkServlet
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, Servlet, ServletConfig, ApplicationListener

public class RestletFrameworkServlet
extends FrameworkServlet

A Servlet which provides an automatic Restlet integration with an existing WebApplicationContext. The usage is similar to Spring's DispatcherServlet . In the web.xml file, declare the Servlet and map its root URL like this:

 <servlet>
    <servlet-name>api</servlet-name>
    <servlet-class>com.noelios.restlet.ext.spring.RestletFrameworkServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
 </servlet>
 
 <servlet-mapping>
    <servlet-name>api</servlet-name>
    <url-pattern>/api/v1/*</url-pattern>
 </servlet-mapping>
 

Then, create a beans XML file called /WEB-INF/[servlet-name]-servlet.xml — in this case, /WEB-INF/api-servlet.xml — and define your restlets and resources in it.

All requests to this servlet will be delegated to a single top-level restlet loaded from the Spring application context. By default, this servlet looks for a bean named "root". You can override that by passing in the targetRestletBeanName parameter. For example:

 <servlet>
    <servlet-name>api</servlet-name>
    <servlet-class>com.noelios.restlet.ext.spring.RestletFrameworkServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
       <param-name>targetRestletBeanName</param-name>
       <param-value>guard</param-value>
    </init-param>
 </servlet>
 

If the target restlet is an Application, it will be used directly. Otherwise, it will be wrapped in an instance of Application.

Author:
Rhett Sutphin
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.springframework.web.servlet.FrameworkServlet
DEFAULT_CONTEXT_CLASS, DEFAULT_NAMESPACE_SUFFIX, SERVLET_CONTEXT_PREFIX
 
Fields inherited from class org.springframework.web.servlet.HttpServletBean
logger
 
Constructor Summary
RestletFrameworkServlet()
           
 
Method Summary
protected  Context createContext()
          Creates the Restlet Context to use if the target application does not already have a context associated, or if the target restlet is not an Application at all.
protected  void doService(HttpServletRequest request, HttpServletResponse response)
           
protected  ServletConverter getConverter()
          Provides access to the ServletConverter used to handle requests.
protected  Restlet getTargetRestlet()
          Returns the target Restlet from Spring's Web application context.
 java.lang.String getTargetRestletBeanName()
          Returns the bean name of the target Restlet.
protected  void initFrameworkServlet()
           
 void setTargetRestletBeanName(java.lang.String targetRestletBeanName)
          Sets the bean name of the target Restlet.
 
Methods inherited from class org.springframework.web.servlet.FrameworkServlet
createWebApplicationContext, destroy, doDelete, doGet, doOptions, doPost, doPut, doTrace, findWebApplicationContext, getContextAttribute, getContextClass, getContextConfigLocation, getNamespace, getServletContextAttributeName, getUsernameForRequest, getWebApplicationContext, initServletBean, initWebApplicationContext, onApplicationEvent, onRefresh, postProcessWebApplicationContext, processRequest, refresh, setContextAttribute, setContextClass, setContextConfigLocation, setDispatchOptionsRequest, setDispatchTraceRequest, setNamespace, setPublishContext, setPublishEvents
 
Methods inherited from class org.springframework.web.servlet.HttpServletBean
addRequiredProperty, getServletContext, getServletName, init, initBeanWrapper
 
Methods inherited from class javax.servlet.http.HttpServlet
doHead, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletInfo, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RestletFrameworkServlet

public RestletFrameworkServlet()
Method Detail

doService

protected void doService(HttpServletRequest request,
                         HttpServletResponse response)
                  throws ServletException,
                         java.io.IOException
Specified by:
doService in class FrameworkServlet
Throws:
ServletException
java.io.IOException

getTargetRestlet

protected Restlet getTargetRestlet()
Returns the target Restlet from Spring's Web application context.

Returns:
The target Restlet.

getTargetRestletBeanName

public java.lang.String getTargetRestletBeanName()
Returns the bean name of the target Restlet. Returns "root" by default.

Returns:
The bean name.

getConverter

protected ServletConverter getConverter()
Provides access to the ServletConverter used to handle requests. Exposed so that subclasses may do additional configuration, if necessary, by overriding initFrameworkServlet().

Returns:
The converter of Servlet calls into Restlet equivalents.

initFrameworkServlet

protected void initFrameworkServlet()
                             throws ServletException,
                                    BeansException
Overrides:
initFrameworkServlet in class FrameworkServlet
Throws:
ServletException
BeansException

createContext

protected Context createContext()
Creates the Restlet Context to use if the target application does not already have a context associated, or if the target restlet is not an Application at all.

Uses a simple Context by default.

Returns:
A new instance of Context

setTargetRestletBeanName

public void setTargetRestletBeanName(java.lang.String targetRestletBeanName)
Sets the bean name of the target Restlet.

Parameters:
targetRestletBeanName - The bean name.


Copyright © 2005-2008 Noelios Technologies.