|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.dispatcher.DispatcherHelper
Class static helper methods for request dispatching. Contains various generally useful procedural abstractions.
Field Summary | |
static String |
DISPATCHER_PREFIX_ATTR
|
static String |
ERROR_REQUEST_ATTRIBUTE
Attribute name for the URI that caused an error when the servlet container forwards to an error page. |
static String |
INCLUDE_URI
The attribute name for an included resource URI after a servlet include (nesting). |
static String |
JSP_EXCEPTION_ATTRIBUTE
Attribute name for the Throwable object saved when a JSP handles an error with the errorPage directive. |
static String |
ORIGINAL_REQUEST_ATTR
The attribute where we store the original HttpServletRequest object when we need to wrap the servlet request. |
static String |
REDIRECT_SEMAPHORE
The session attribute where we store an identifier for the previous request that made a redirect. |
static String |
REENTRANCE_ATTRIBUTE
Attribute name to indicate that the dispatcher is within a request--that is, request start listeners have run but request end listeners haven't yet. |
static String |
REQUEST_CONTEXT_ATTR
The attribute where we store the current RequestContext object. |
static SimpleDateFormat |
rfc1123_formatter
|
static String |
versionId
|
static String |
WELCOME_FILES
The application attribute (in ServletContext) where we store the list of welcome files from web.xml. |
static String |
WRAPPED_REQUEST_ATTR
The attribute where we store the wrapped servlet request object when we need to restore the original request object for a forward/include. |
Method Summary | |
static void |
abortRequest()
Aborts all processing of the current request and treat it as successfully completed. |
static void |
addParameterProvider(ParameterProvider provider)
Deprecated. use URLRewriter.addParameterProvider |
static void |
cacheDisable(javax.servlet.http.HttpServletResponse response)
Aggressively disable all caching of the response |
static void |
cacheForUser(javax.servlet.http.HttpServletResponse response)
Allow caching of the response for this user only, as identified by the Cookie header. |
static void |
cacheForUser(javax.servlet.http.HttpServletResponse response,
Date expiry)
Allowing caching of the response for this user only. |
static void |
cacheForUser(javax.servlet.http.HttpServletResponse response,
int maxage)
Allow caching of the response for this user only, as identified by the Cookie header. |
static void |
cacheForWorld(javax.servlet.http.HttpServletResponse response)
Allow caching of this response for anyone in the world. |
static void |
cacheForWorld(javax.servlet.http.HttpServletResponse response,
Date expiry)
Allow caching of this response for anyone in the world. |
static void |
cacheForWorld(javax.servlet.http.HttpServletResponse response,
int maxage)
Allow caching of this response for anyone in the world. |
static void |
clearParameterProviders()
Deprecated. use URLRewriter#clearParameterProviders() instead |
static String |
encodeURL(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String url)
Deprecated. use URLRewriter.encodeURL instead |
static void |
forceCacheDisable(javax.servlet.http.HttpServletResponse response)
|
static void |
forwardRequestByName(String name,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Equivalent to forwardRequestByName(name, req, resp,
DispatcherHelper.getRequestContext(req).getServletContext()) . |
static void |
forwardRequestByName(String name,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
javax.servlet.ServletContext sctx)
Forwards the request from this resource to a servlet resource (named in server.xml) at the servlet-container level. |
static void |
forwardRequestByPath(String path,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Equivalent to forwardRequestByPath(path, req, resp,
DispatcherHelper.getRequestContext(req).getServletContext()) . |
static void |
forwardRequestByPath(String path,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
javax.servlet.ServletContext sctx)
Forwards the request from this resource to another resource at the servlet-container level. |
static void |
forwardRequestByPath(String path,
javax.servlet.jsp.PageContext pageContext)
Forwards the request from this resource to another resource at the JSP container level. |
static DispatcherConfig |
getConfig()
This returns a reference to the dispatcher configuration file |
static String |
getCurrentResourcePath(javax.servlet.http.HttpServletRequest req)
Returns the URL path (relative to the webapp root) for the current (calling) resource. |
static int |
getDefaultCacheExpiry()
|
static String |
getDispatcherPrefix(javax.servlet.http.HttpServletRequest req)
|
static Set |
getGlobalModels()
Deprecated. use URLRewriter.getGlobalModels instead |
static Set |
getGlobalParams(javax.servlet.http.HttpServletRequest req)
Deprecated. use URLRewriter.getGlobalParams instead |
static javax.servlet.http.HttpServletRequest |
getRequest()
Gets the current HttpServletRequest for this thread. |
static RequestContext |
getRequestContext()
|
static RequestContext |
getRequestContext(javax.servlet.http.HttpServletRequest req)
Gets the application context from the request attributes. |
static String |
getStaticURL()
Returns a global URL prefix for referencing static assets (images, CSS, etc.) on disk in href attributes. |
static String |
getWebappContext()
Gets the webapp Context using the following procedure: 1. |
static boolean |
isCachingActive()
|
static void |
maybeCacheDisable(javax.servlet.http.HttpServletResponse response)
If no existing cache policy is set, then call cacheDisable to disable all caching of the response. |
static void |
maybeCacheForUser(javax.servlet.http.HttpServletResponse response)
If no existing cache policy is set, then call cacheForUser to enable caching for a user |
static void |
maybeCacheForUser(javax.servlet.http.HttpServletResponse response,
Date expiry)
If no existing cache policy is set, then call cacheForUser to enable caching for a user |
static void |
maybeCacheForUser(javax.servlet.http.HttpServletResponse response,
int maxage)
If no existing cache policy is set, then call cacheForUser to enable caching for a user |
static void |
maybeCacheForWorld(javax.servlet.http.HttpServletResponse response)
If no existing cache policy is set, then call cacheForUser to enable caching for the world. |
static void |
maybeCacheForWorld(javax.servlet.http.HttpServletResponse response,
Date expiry)
If no existing cache policy is set, then call cacheForUser to enable caching for the world |
static void |
maybeCacheForWorld(javax.servlet.http.HttpServletResponse response,
int maxage)
If no existing cache policy is set, then call cacheForUser to enable caching for the world |
static javax.servlet.http.HttpServletRequest |
maybeWrapRequest(javax.servlet.http.HttpServletRequest sreq)
This method will optionally wrap the request if it is a multipart POST, or restore the original wrapper if it was already wrapped |
static String |
prepareURL(String url,
javax.servlet.http.HttpServletRequest req)
Deprecated. This method does not encode the servlet session ID. Use encodeURL(req, res, url) instead. |
static String |
resolveAbstractFile(File abstractFile,
RequestContext actx)
Deprecated. abstract URLs are no longer supported. Use extensions when your file on disk has an extension. |
static javax.servlet.http.HttpServletRequest |
restoreOriginalRequest(javax.servlet.http.HttpServletRequest req)
If the given servlet request is wrapped in one of our own classes, returns the original (unwrapped) request object and stores a reference to the request wrapper in the request attributes of the returned request. |
static javax.servlet.http.HttpServletRequest |
restoreRequestWrapper(javax.servlet.http.HttpServletRequest req)
If we've stored a reference to a request wrapper as a request attribute to the current servlet request, returns the wrapper object. |
static void |
saveOriginalRequest(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletRequest oldReq)
Stores req as request attribute of oldReq. |
static void |
sendExternalRedirect(javax.servlet.http.HttpServletResponse resp,
String url)
Redirects the client to the given URL without rewriting it. |
static void |
sendRedirect(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String url)
Rewrites the given URL and redirects the client to the rewritten URL. |
static void |
sendRedirect(javax.servlet.http.HttpServletResponse resp,
String url)
Deprecated. This method does not rewrite URLs. Use sendRedirect(HttpServletRequest, HttpServletResponse, String) for redirects within this ACS or sendExternalRedirect(HttpServletResponse, String) for redirects to sites outside this ACS. |
static void |
setDispatcherPrefix(javax.servlet.http.HttpServletRequest req,
String val)
|
static void |
setRequest(javax.servlet.http.HttpServletRequest r)
Stores the HttpServletRequest in a ThreadLocal so that it can be accessed globally. |
static void |
setRequestContext(javax.servlet.http.HttpServletRequest req,
RequestContext ac)
Sets the current request context as a request attribute for later retrieval. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final SimpleDateFormat rfc1123_formatter
public static final String versionId
public static final String JSP_EXCEPTION_ATTRIBUTE
public static final String ERROR_REQUEST_ATTRIBUTE
public static final String REENTRANCE_ATTRIBUTE
public static final String INCLUDE_URI
public static final String REQUEST_CONTEXT_ATTR
public static final String ORIGINAL_REQUEST_ATTR
public static final String WRAPPED_REQUEST_ATTR
public static final String REDIRECT_SEMAPHORE
public static final String WELCOME_FILES
public static final String DISPATCHER_PREFIX_ATTR
Method Detail |
public static int getDefaultCacheExpiry()
public static boolean isCachingActive()
public static String getCurrentResourcePath(javax.servlet.http.HttpServletRequest req)
public static RequestContext getRequestContext(javax.servlet.http.HttpServletRequest req)
public static RequestContext getRequestContext()
public static String getDispatcherPrefix(javax.servlet.http.HttpServletRequest req)
public static void setDispatcherPrefix(javax.servlet.http.HttpServletRequest req, String val)
public static void setRequestContext(javax.servlet.http.HttpServletRequest req, RequestContext ac)
req
- the current request objectac
- the current request contextpublic static void forwardRequestByPath(String path, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, javax.servlet.ServletContext sctx) throws IOException, javax.servlet.ServletException
path
- the URL of the resource, relative to the webapp
root. For example, if you request a JSP page with /context/foo/bar,
you would call this method with path == /foo/bar.req
- the current requestresp
- the current responsesctx
- the current servlet context
IOException
- may be propagated from target resource
javax.servlet.ServletException
- may be
propagated from target resourcepublic static void forwardRequestByPath(String path, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws IOException, javax.servlet.ServletException
forwardRequestByPath(path, req, resp,
DispatcherHelper.getRequestContext(req).getServletContext())
.
IOException
javax.servlet.ServletException
public static void forwardRequestByPath(String path, javax.servlet.jsp.PageContext pageContext) throws IOException, javax.servlet.ServletException
PageContext.forward
and PageContext.include
and is intended to transparently switch between "forward" and
"include" depending on whether or not an include has already been
done on the request.
path
- the URL of the resource, relative to the webapp
root. For example, if you request a JSP page with /context/foo/bar,
you would call this method with path == /foo/bar.pageContext
- the JSP page context
IOException
- may be propagated from target resource
javax.servlet.ServletException
- may be
propagated from target resourcepublic static void forwardRequestByName(String name, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, javax.servlet.ServletContext sctx) throws IOException, javax.servlet.ServletException
name
- the named servlet to forward toreq
- the current requestresp
- the current responsesctx
- the current servlet context
IOException
- may be propagated from target resource
javax.servlet.ServletException
- may be
propagated from target resourcepublic static void forwardRequestByName(String name, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws IOException, javax.servlet.ServletException
forwardRequestByName(name, req, resp,
DispatcherHelper.getRequestContext(req).getServletContext())
.
IOException
javax.servlet.ServletException
public static String resolveAbstractFile(File abstractFile, RequestContext actx) throws RedirectException, DirectoryListingException, FileNotFoundException
.jsp
extension first, if available.
Otherwise picks any file
that matches. For directories, it tacks on the "index"
filename plus the extension.
abstractFile
- the extensionless fileactx
- the current application context
RedirectException
- if the
requested file is a directory and the original request URL does
not end with a trailing slash.
FileNotFoundException
- if no matching
file exists.
DirectoryListingException
public static javax.servlet.http.HttpServletRequest restoreOriginalRequest(javax.servlet.http.HttpServletRequest req)
req
- the servlet request
public static javax.servlet.http.HttpServletRequest restoreRequestWrapper(javax.servlet.http.HttpServletRequest req)
req
- the current servlet request
public static javax.servlet.http.HttpServletRequest maybeWrapRequest(javax.servlet.http.HttpServletRequest sreq) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public static void saveOriginalRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletRequest oldReq)
req
- the current servlet request (wrapper)oldReq
- the original servlet requestpublic static void sendRedirect(javax.servlet.http.HttpServletResponse resp, String url) throws IOException
resp
- the current responseurl
- the destination URL for redirect
IOException
public static void sendRedirect(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String url) throws IOException
req
- the current request; used as a source for parameters
for URL rewritingresp
- the current responseurl
- the destination URL for redirect
IOException
public static void sendExternalRedirect(javax.servlet.http.HttpServletResponse resp, String url) throws IOException
resp
- the current responseurl
- the destination URL for redirect
IOException
public static void addParameterProvider(ParameterProvider provider)
ParameterProvider
to the URLRewriter engine.
ParameterProvider
s are used
when encodeRedirectURL
and encodeURL
are called. They add global state parameters
like the session ID (for cookieless login) to URLs for links and
redirects.
provider
- the parameter provider to addURLRewriter.addParameterProvider(com.arsdigita.util.ParameterProvider)
public static void clearParameterProviders()
URLRewriter.clearParameterProviders()
public static Set getGlobalModels()
URLRewriter.getGlobalModels()
public static Set getGlobalParams(javax.servlet.http.HttpServletRequest req)
req
- the current request
public static String prepareURL(String url, javax.servlet.http.HttpServletRequest req)
url
- the target URL to prepare
public static String encodeURL(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String url)
req
- the current requestresp
- the current responseurl
- the target URL (for a link) to encode
URLRewriter
public static String getStaticURL()
String pathToImage = DispatcherHelper.getStaticURL() + "images/pic.gif"; Image img = new Image(pathToImage);
public static String getWebappContext()
public static void abortRequest()
AbortRequestSignal
- Error thrown
to abort current requestpublic static void setRequest(javax.servlet.http.HttpServletRequest r)
public static javax.servlet.http.HttpServletRequest getRequest()
public static void maybeCacheDisable(javax.servlet.http.HttpServletResponse response)
public static void cacheDisable(javax.servlet.http.HttpServletResponse response)
public static void forceCacheDisable(javax.servlet.http.HttpServletResponse response)
public static void maybeCacheForUser(javax.servlet.http.HttpServletResponse response)
public static void cacheForUser(javax.servlet.http.HttpServletResponse response)
public static void maybeCacheForUser(javax.servlet.http.HttpServletResponse response, int maxage)
maxage
- the max time in second until this expirespublic static void maybeCacheForUser(javax.servlet.http.HttpServletResponse response, Date expiry)
expiry
- the time at which to expirepublic static void cacheForUser(javax.servlet.http.HttpServletResponse response, int maxage)
maxage
- the max life of the response in secondspublic static void cacheForUser(javax.servlet.http.HttpServletResponse response, Date expiry)
expiry
- time at which to expirepublic static void maybeCacheForWorld(javax.servlet.http.HttpServletResponse response)
public static void cacheForWorld(javax.servlet.http.HttpServletResponse response)
public static void maybeCacheForWorld(javax.servlet.http.HttpServletResponse response, int maxage)
maxage
- the time in seconds until expirypublic static void maybeCacheForWorld(javax.servlet.http.HttpServletResponse response, Date expiry)
expiry
- the time at which it will expirepublic static void cacheForWorld(javax.servlet.http.HttpServletResponse response, int maxage)
maxage
- time in seconds until this expirespublic static void cacheForWorld(javax.servlet.http.HttpServletResponse response, Date expiry)
public static DispatcherConfig getConfig()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |