@NutDaoService public class RequestDispatcherNutDao extends AbstractNutDao implements ServletContextHandler
This NutDao
relies on ServletContext.getResourceAsStream(String)
and ServletContext.getRequestDispatcher(String)
to create nuts
.
The former is used by default and this class fallback to the later only if the path matches the regex corresponding
to the ApplicationConfig.USE_INCLUDE_FOR_PATH_PATTERN
setting. Default behavior should be fine for most of
the case except when the resource behind the path is generated dynamically with for instance a Servlet
or a
JSP
. In that case, use the ApplicationConfig.USE_INCLUDE_FOR_PATH_PATTERN
setting to specify which
resources are dynamic in your application to retrieve their content correctly.
RequestDispatcher.include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
usage:
If you decide to enable RequestDispatcher
in order to process some dynamic resource, read carefully this
paragraph. User should be aware that servlet specifications only require to use a request dispatcher with a real
HttpServletRequest
. This real request is only available when an instance is created when a client requires
its creation (e.g a workflow result is not in the cache). When WUIC is configured to use a RequestDispatcherNutDao
when the server starts (warm up) or when a polling operation is going to be performed (polling interval activated), a
mocked request is created. It is not mandatory for a servlet container work with a mocked request, so using the
RequestDispatcherNutDao may fail in that case. Moreover, the servlet container can also fail if the real request is a
bound to an already closed response, which is the case when running in best effort. Be careful before activating the
RequestDispatcher
and make sure it works correctly in the servlet container(s) that will deploy your application.
AbstractNutDao.VersionNumberStrategy, AbstractNutDao.WithRootPathNutDao
PollingScheduler.Polling
NutDao.PathFormat
Constructor and Description |
---|
RequestDispatcherNutDao(String base,
Boolean basePathAsSysProp,
String[] proxies,
int pollingSeconds,
Boolean computeVersionAsynchronously,
String fixedVersionNumber,
String pathPattern)
Builds a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected Nut |
accessFor(String realPath,
NutType type,
ProcessContext processContext)
Creates an access for the given parameters through a
Nut implementation. |
Boolean |
exists(String path,
ProcessContext processContext)
Indicates if the given path exists or not.
|
protected Long |
getLastUpdateTimestampFor(String path)
Retrieves a timestamp that indicates the last time this nut has changed.
|
protected List<String> |
listNutsPaths(String pattern)
Lists all the nuts path matching the given pattern.
|
InputStream |
newInputStream(String path,
ProcessContext processContext)
Opens the stream for the given path.
|
void |
setServletContext(ServletContext sc)
Sets the servlet context.
|
absolutePathOf, computeRealPaths, create, create, getBasePath, getProxyUris, getVersionNumber, getVersionNumberStrategy, proxyUriFor, run, save, saveSupported, shutdown, toString, withRootPath
getNutObservers, getPollingInterval, observe, setPollingInterval
@ConfigConstructor public RequestDispatcherNutDao(@StringConfigParam(defaultValue="/",propertyKey="c.g.wuic.dao.basePath") String base, @BooleanConfigParam(defaultValue=false,propertyKey="c.g.wuic.dao.basePathAsSystemProperty") Boolean basePathAsSysProp, @ObjectConfigParam(defaultValue="",propertyKey="c.g.wuic.dao.proxyUris",setter=ProxyUrisPropertySetter.class) String[] proxies, @IntegerConfigParam(defaultValue=-1,propertyKey="c.g.wuic.dao.pollingInterval") int pollingSeconds, @BooleanConfigParam(defaultValue=true,propertyKey="c.g.wuic.computeVersionAsynchronously") Boolean computeVersionAsynchronously, @StringConfigParam(defaultValue="",propertyKey="c.g.wuic.fixedVersionNumber") String fixedVersionNumber, @StringConfigParam(defaultValue="",propertyKey="c.g.wuic.dao.useIncludeForPathPattern") String pathPattern)
Builds a new instance.
base
- the directory where we have to look upbasePathAsSysProp
- true
if the base path is a system propertypollingSeconds
- the interval for polling operations in seconds (-1 to deactivate)proxies
- the proxies URIs in front of the nutcomputeVersionAsynchronously
- (@code true} if version number can be computed asynchronously, false
otherwisefixedVersionNumber
- fixed version number, null
if version number is computed from content or is last modification datepathPattern
- use include
in RequestDispatcher
when creating a Nut
with any path matching this patternpublic void setServletContext(ServletContext sc)
Sets the servlet context.
setServletContext
in interface ServletContextHandler
sc
- the contextprotected Long getLastUpdateTimestampFor(String path) throws IOException
Retrieves a timestamp that indicates the last time this nut has changed.
getLastUpdateTimestampFor
in class PollingScheduler<NutDaoListener>
path
- the real path of the nutIOException
- if any I/O error occursprotected List<String> listNutsPaths(String pattern) throws IOException
Lists all the nuts path matching the given pattern.
listNutsPaths
in class AbstractNutDao
pattern
- the patternIOException
- if any I/O error occurs while reading nutsprotected Nut accessFor(String realPath, NutType type, ProcessContext processContext) throws IOException
Creates an access for the given parameters through a Nut
implementation.
accessFor
in class AbstractNutDao
realPath
- the real path to use to access the nuttype
- the path's typeprocessContext
- the process contextNut
IOException
- if an I/O error occurs while creating accesspublic InputStream newInputStream(String path, ProcessContext processContext) throws IOException
Opens the stream for the given path.
newInputStream
in interface NutDao
path
- the path to accessprocessContext
- the process context calling this methodIOException
- if stream could not be openedpublic Boolean exists(String path, ProcessContext processContext) throws IOException
Indicates if the given path exists or not.
exists
in interface NutDao
path
- the path the DAO should be able to resolveprocessContext
- the process context calling this methodtrue
if path is resolved, false
otherwiseIOException
- if any I/O error occursCopyright © 2012-2015. All Rights Reserved.