Package org.restlet.ext.spring
Class RestletFrameworkServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.springframework.web.servlet.HttpServletBean
-
- org.springframework.web.servlet.FrameworkServlet
-
- org.restlet.ext.spring.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 existingWebApplicationContext
. The usage is similar to Spring'sDispatcherServlet
. 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 ofApplication
.- Author:
- Rhett Sutphin
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RestletFrameworkServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.restlet.Context
createContext()
Creates the RestletContext
to use if the target application does not already have a context associated, or if the target restlet is not anApplication
at all.protected void
doService(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected ServletAdapter
getAdapter()
Provides access to theServletAdapter
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
-
-
-
-
Method Detail
-
createContext
protected org.restlet.Context createContext()
Creates the RestletContext
to use if the target application does not already have a context associated, or if the target restlet is not anApplication
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 classorg.springframework.web.servlet.FrameworkServlet
- Throws:
javax.servlet.ServletException
java.io.IOException
-
getAdapter
protected ServletAdapter getAdapter()
Provides access to theServletAdapter
used to handle requests. Exposed so that subclasses may do additional configuration, if necessary, by overridinginitFrameworkServlet()
.- 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 classorg.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.
-
-