Class RestletFrameworkServlet

  • All Implemented Interfaces:
    java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.EnvironmentAware, org.springframework.core.env.EnvironmentCapable

    public class RestletFrameworkServlet
    extends org.springframework.web.servlet.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>org.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>org.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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.restlet.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​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected ServletAdapter getAdapter()
      Provides access to the ServletAdapter used to handle requests.
      protected org.restlet.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

        applyInitializers, buildLocaleContext, buildRequestAttributes, configureAndRefreshWebApplicationContext, createWebApplicationContext, createWebApplicationContext, destroy, doDelete, doGet, doOptions, doPost, doPut, doTrace, findWebApplicationContext, getContextAttribute, getContextClass, getContextConfigLocation, getContextId, getNamespace, getServletContextAttributeName, getUsernameForRequest, getWebApplicationContext, initServletBean, initWebApplicationContext, isEnableLoggingRequestDetails, onApplicationEvent, onRefresh, postProcessWebApplicationContext, processRequest, refresh, service, setApplicationContext, setContextAttribute, setContextClass, setContextConfigLocation, setContextId, setContextInitializerClasses, setContextInitializers, setDispatchOptionsRequest, setDispatchTraceRequest, setEnableLoggingRequestDetails, setNamespace, setPublishContext, setPublishEvents, setThreadContextInheritable
      • Methods inherited from class org.springframework.web.servlet.HttpServletBean

        addRequiredProperty, createEnvironment, getEnvironment, getServletName, init, initBeanWrapper, setEnvironment
      • Methods inherited from class javax.servlet.http.HttpServlet

        doHead, getLastModified, service
      • Methods inherited from class javax.servlet.GenericServlet

        getInitParameter, getInitParameterNames, getServletConfig, getServletContext, 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

      • createContext

        protected org.restlet.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
      • doService

        protected void doService​(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response)
                          throws javax.servlet.ServletException,
                                 java.io.IOException
        Specified by:
        doService in class org.springframework.web.servlet.FrameworkServlet
        Throws:
        javax.servlet.ServletException
        java.io.IOException
      • getAdapter

        protected ServletAdapter getAdapter()
        Provides access to the ServletAdapter used to handle requests. Exposed so that subclasses may do additional configuration, if necessary, by overriding initFrameworkServlet().
        Returns:
        The adapter of Servlet calls into Restlet equivalents.
      • getTargetRestlet

        protected org.restlet.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.
      • initFrameworkServlet

        protected void initFrameworkServlet()
                                     throws javax.servlet.ServletException,
                                            org.springframework.beans.BeansException
        Overrides:
        initFrameworkServlet in class org.springframework.web.servlet.FrameworkServlet
        Throws:
        javax.servlet.ServletException
        org.springframework.beans.BeansException
      • setTargetRestletBeanName

        public void setTargetRestletBeanName​(java.lang.String targetRestletBeanName)
        Sets the bean name of the target Restlet.
        Parameters:
        targetRestletBeanName - The bean name.