This class offers the following functionality:
WebApplicationContext instance per servlet. The servlet's configuration is determined
by beans in the servlet's namespace.
Subclasses must implement doService to handle requests. Because this extends
HttpServletBean rather than HttpServlet directly, bean properties are
automatically mapped onto it. Subclasses can override initFrameworkServlet()
for custom initialization.
Detects a "contextClass" parameter at the servlet init-param level,
falling back to the default context class,
XmlWebApplicationContext, if not found. Note that, with the default
FrameworkServlet, a custom context class needs to implement the
ConfigurableWebApplicationContext SPI.
Accepts an optional "contextInitializerClasses" servlet init-param that
specifies one or more ApplicationContextInitializer classes. The managed web application context will be
delegated to these initializers, allowing for additional programmatic configuration,
e.g. adding property sources or activating profiles against the context's
environment. See also org. which
supports a "contextInitializerClasses" context-param with identical semantics for
the "root" web application context.
Passes a "contextConfigLocation" servlet init-param to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, like "test-servlet.xml, myServlet.xml". If not explicitly specified, the context implementation is supposed to build a default location from the namespace of the servlet.
Note
In case of multiple config locations, later bean definitions will override ones defined in earlier loaded files, at least when using Spring's default ApplicationContext implementation. This can be leveraged to deliberately override certain bean definitions via an extra XML file.
The default namespace is "'servlet-name'-servlet", e.g. "test-servlet" for a servlet-name "test" (leading to a "/WEB-INF/test-servlet.xml" default location with XmlWebApplicationContext). The namespace can also be set explicitly via the "namespace" servlet init-param.
FrameworkServlet may be injected with a web application context,
rather than creating its own internally. This is useful in Servlet 3.0+
environments, which support programmatic registration of servlet instances. See
FrameworkServlet(WebApplicationContext) Javadoc for details.
doService, setContextClass, setContextConfigLocation, setContextInitializerClasses, setNamespace
| Modifier and Type | Class and Description |
|---|---|
| private class | FrameworkServlet.
ApplicationListener endpoint that receives events from this servlet's WebApplicationContext
only, delegating to |
| private class | FrameworkServlet.
CallableProcessingInterceptor implementation that initializes and resets FrameworkServlet's context holders, i.e. LocaleContextHolder and RequestContextHolder. |
| Modifier and Type | Field and Description |
|---|---|
| private String | contextAttribute
ServletContext attribute to find the WebApplicationContext in. |
| private Class | contextClass
WebApplicationContext implementation class to create. |
| private String | contextConfigLocation
Explicit context config location. |
| private String | contextId
WebApplicationContext id to assign. |
| private String | contextInitializerClasses
Comma-delimited ApplicationContextInitializer class names set through init param. |
| private final List | contextInitializers
Actual ApplicationContextInitializer instances to apply to the context. |
| public static final Class | DEFAULT_CONTEXT_CLASS
Default context class for FrameworkServlet. |
| public static final String | DEFAULT_NAMESPACE_SUFFIX
Suffix for WebApplicationContext namespaces. |
| private boolean | dispatchOptionsRequest
Should we dispatch an HTTP OPTIONS request to |
| private boolean | dispatchTraceRequest
Should we dispatch an HTTP TRACE request to |
| private boolean | enableLoggingRequestDetails
Whether to log potentially sensitive info (request params at DEBUG + headers at TRACE). |
| private static final Set | HTTP_SERVLET_METHODS
HTTP methods supported by |
| private static final String | INIT_PARAM_DELIMITERS
Any number of these characters are considered delimiters between multiple values in a single init-param String value. |
| private String | namespace
Namespace for this servlet. |
| private final Object | onRefreshMonitor
Monitor for synchronized onRefresh execution. |
| private boolean | publishContext
Should we publish the context as a ServletContext attribute?. |
| private boolean | publishEvents
Should we publish a ServletRequestHandledEvent at the end of each request?. |
| private volatile boolean | refreshEventReceived
Flag used to detect whether onRefresh has already been called. |
| public static final String | SERVLET_CONTEXT_PREFIX
Prefix for the ServletContext attribute for the WebApplicationContext. |
| private boolean | threadContextInheritable
Expose LocaleContext and RequestAttributes as inheritable for child threads?. |
| private WebApplicationContext | webApplicationContext
WebApplicationContext for this servlet. |
| private boolean | webApplicationContextInjected
If the WebApplicationContext was injected via |
| Access | Constructor and Description |
|---|---|
| public | FrameworkServlet()
Create a new |
| public | FrameworkServlet(WebApplicationContext
the context to use webApplicationContext)Create a new |
| Modifier and Type | Method and Description |
|---|---|
| protected void | applyInitializers(ConfigurableApplicationContext
the configured WebApplicationContext (not refreshed yet) wac)Delegate the WebApplicationContext before it is refreshed to any
|
| protected LocaleContext | Returns: the corresponding LocaleContext, ornull if none to bindcurrent HTTP request request)Build a LocaleContext for the given request, exposing the request's primary locale as current locale. |
| protected ServletRequestAttributes | Returns: the ServletRequestAttributes to bind, ornull to preserve
the previously bound instance (or not binding any, if none bound before)current HTTP request request, HttpServletResponse current HTTP response response, RequestAttributes pre-bound RequestAttributes instance, if any previousAttributes)Build ServletRequestAttributes for the given request (potentially also holding a reference to the response), taking pre-bound attributes (and their type) into consideration. |
| protected void | |
| protected WebApplicationContext | Returns: the WebApplicationContext for this servletthe parent ApplicationContext to use, or parent)null if noneInstantiate the WebApplicationContext for this servlet, either a default
|
| protected WebApplicationContext | Returns: the WebApplicationContext for this servletthe parent WebApplicationContext to use, or parent)null if noneInstantiate the WebApplicationContext for this servlet, either a default
|
| public void | destroy()
Overrides jakarta. Implements jakarta. Close the WebApplicationContext of this servlet. |
| protected final void | doDelete(HttpServletRequest
the request, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe response)HttpServletResponse object that contains the response the servlet returns to the clientOverrides jakarta. Delegate DELETE requests to |
| protected final void | doGet(HttpServletRequest
an request, HttpServletResponse HttpServletRequest object that contains the request the client has made of the servletan response)HttpServletResponse object that contains the response the servlet sends to the clientOverrides jakarta. Delegate GET requests to processRequest/doService. |
| protected void | doOptions(HttpServletRequest
the request, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe response)HttpServletResponse object that contains the response the servlet returns to the clientOverrides jakarta. Delegate OPTIONS requests to |
| protected final void | doPost(HttpServletRequest
an request, HttpServletResponse HttpServletRequest object that contains the request the client has made of the servletan response)HttpServletResponse object that contains the response the servlet sends to the clientOverrides jakarta. Delegate POST requests to |
| protected final void | doPut(HttpServletRequest
the request, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe response)HttpServletResponse object that contains the response the servlet returns to the clientOverrides jakarta. Delegate PUT requests to |
| protected abstract void | doService(HttpServletRequest
current HTTP request request, HttpServletResponse current HTTP response response)Subclasses must implement this method to do the work of request handling, receiving a centralized callback for GET, POST, PUT and DELETE. |
| protected void | doTrace(HttpServletRequest
the request, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe response)HttpServletResponse object that contains the response the servlet returns to the clientOverrides jakarta. Delegate TRACE requests to |
| protected WebApplicationContext | Returns: the WebApplicationContext for this servlet, ornull if not foundRetrieve a |
| public String | getContextAttribute()
Return the name of the ServletContext attribute which should be used to retrieve the
|
| public Class | |
| public String | |
| public String | |
| public String | getNamespace()
Return the namespace for this servlet, falling back to default scheme if no custom namespace was set: e.g. "test-servlet" for a servlet named "test". |
| public String | getServletContextAttributeName()
Return the ServletContext attribute name for this servlet's WebApplicationContext. |
| protected String | Returns: the username, ornull if none foundcurrent HTTP request request)Determine the username for the given request. |
| public final WebApplicationContext | |
| private void | initContextHolders(HttpServletRequest request, LocaleContext localeContext, RequestAttributes requestAttributes)
|
| protected void | initFrameworkServlet()
This method will be invoked after any bean properties have been set and the WebApplicationContext has been loaded. |
| protected final void | initServletBean()
Overrides org. Overridden method of |
| protected WebApplicationContext | Returns: the WebApplicationContext instanceInitialize and publish the WebApplicationContext for this servlet. |
| public boolean | isEnableLoggingRequestDetails()
Whether logging of potentially sensitive, request details at DEBUG and TRACE level is allowed. |
| private ApplicationContextInitializer | |
| private void | logResult(HttpServletRequest request, HttpServletResponse response, Throwable failureCause, WebAsyncManager asyncManager)
|
| public void | onApplicationEvent(ContextRefreshedEvent
the incoming ApplicationContext event event)Callback that receives refresh events from this servlet's WebApplicationContext. |
| protected void | onRefresh(ApplicationContext
the current WebApplicationContext context)Template method which can be overridden to add servlet-specific refresh work. |
| protected void | postProcessWebApplicationContext(ConfigurableWebApplicationContext
the configured WebApplicationContext (not refreshed yet) wac)Post-process the given WebApplicationContext before it is refreshed and activated as context for this servlet. |
| protected final void | processRequest(HttpServletRequest request, HttpServletResponse response)
Process this request, publishing an event regardless of the outcome. |
| private void | publishRequestHandledEvent(HttpServletRequest request, HttpServletResponse response, long startTime, Throwable failureCause)
|
| public void | |
| private void | resetContextHolders(HttpServletRequest request, LocaleContext prevLocaleContext, RequestAttributes previousAttributes)
|
| protected void | service(HttpServletRequest
the request, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe response)HttpServletResponse object that contains the response the servlet returns to the clientOverrides jakarta. Override the parent class implementation in order to intercept requests using PATCH or non-standard HTTP methods (WebDAV). |
| public void | setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object applicationContext)Implements org. Called by Spring via |
| public void | setContextAttribute(String contextAttribute)
Set the name of the ServletContext attribute which should be used to retrieve the
|
| public void | |
| public void | setContextConfigLocation(String contextConfigLocation)
Set the context config location explicitly, instead of relying on the default location built from the namespace. |
| public void | setContextId(String contextId)
Specify a custom WebApplicationContext id, to be used as serialization id for the underlying BeanFactory. |
| public void | setContextInitializerClasses(String contextInitializerClasses)
Specify the set of fully-qualified |
| public void | setContextInitializers(ApplicationContextInitializer<?>... initializers)
Specify which |
| public void | setDispatchOptionsRequest(boolean dispatchOptionsRequest)
Set whether this servlet should dispatch an HTTP OPTIONS request to
the |
| public void | setDispatchTraceRequest(boolean dispatchTraceRequest)
Set whether this servlet should dispatch an HTTP TRACE request to
the |
| public void | setEnableLoggingRequestDetails(boolean
whether to enable or not enable)Whether to log request params at DEBUG level, and headers at TRACE level. |
| public void | setNamespace(String namespace)
Set a custom namespace for this servlet, to be used for building a default context config location. |
| public void | setPublishContext(boolean publishContext)
Set whether to publish this servlet's context as a ServletContext attribute, available to all objects in the web container. |
| public void | setPublishEvents(boolean publishEvents)
Set whether this servlet should publish a ServletRequestHandledEvent at the end of each request. |
| public void | setThreadContextInheritable(boolean threadContextInheritable)
Set whether to expose the LocaleContext and RequestAttributes as inheritable
for child threads (using an |