public class RestletFrameworkServlet
extends org.springframework.web.servlet.FrameworkServlet
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
.
Constructor and Description |
---|
RestletFrameworkServlet() |
Modifier and Type | Method and Description |
---|---|
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(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected ServletAdapter |
getAdapter()
Provides access to the
ServletAdapter 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.
|
applyInitializers, buildLocaleContext, buildRequestAttributes, configureAndRefreshWebApplicationContext, createWebApplicationContext, createWebApplicationContext, destroy, doDelete, doGet, doOptions, doPost, doPut, doTrace, findWebApplicationContext, getContextAttribute, getContextClass, getContextConfigLocation, getContextId, getNamespace, getServletContextAttributeName, getUsernameForRequest, getWebApplicationContext, initServletBean, initWebApplicationContext, onApplicationEvent, onRefresh, postProcessWebApplicationContext, processRequest, refresh, service, setContextAttribute, setContextClass, setContextConfigLocation, setContextId, setContextInitializerClasses, setContextInitializers, setDispatchOptionsRequest, setDispatchTraceRequest, setNamespace, setPublishContext, setPublishEvents, setThreadContextInheritable
addRequiredProperty, createEnvironment, getEnvironment, getServletContext, getServletName, init, initBeanWrapper, setEnvironment
protected Context createContext()
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.
Context
protected void doService(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
doService
in class org.springframework.web.servlet.FrameworkServlet
javax.servlet.ServletException
java.io.IOException
protected ServletAdapter getAdapter()
ServletAdapter
used to handle requests.
Exposed so that subclasses may do additional configuration, if necessary,
by overriding initFrameworkServlet()
.protected Restlet getTargetRestlet()
public java.lang.String getTargetRestletBeanName()
protected void initFrameworkServlet() throws javax.servlet.ServletException, org.springframework.beans.BeansException
initFrameworkServlet
in class org.springframework.web.servlet.FrameworkServlet
javax.servlet.ServletException
org.springframework.beans.BeansException
public void setTargetRestletBeanName(java.lang.String targetRestletBeanName)
targetRestletBeanName
- The bean name.Copyright © 2005-2020 Restlet.