public class RequestForwarder extends CachedAction
CachedAction.OutputProvider
Modifier and Type | Field and Description |
---|---|
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> |
additionalParams |
protected java.lang.String |
destinationHost |
protected java.lang.String |
destinationPath |
protected int |
destinationPort |
protected java.lang.String |
destinationProtocol |
protected boolean |
forwardAllParams |
protected java.util.ArrayList<java.lang.String> |
forwardParams |
cache, caching, threadPool
actionParamKey, handledActions, httpHeaders, isDefaultAction, replacements, replacementsInitialized, servletModule
engine, initScript, persistentObjects, scriptManager, startScript, stopScript
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
RequestForwarder() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
doOutput(javax.servlet.http.HttpServletRequest req,
ModulesServlet.HttpMethod method,
java.lang.String action,
CachedAction.OutputProvider out,
User user)
Does the output that might be either cached or returned directly.
|
protected java.lang.String |
getCacheKey(javax.servlet.http.HttpServletRequest req,
ModulesServlet.HttpMethod method,
java.lang.String action)
Should return a string that uniquely identifies this request.
|
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> |
getSendParams(javax.servlet.http.HttpServletRequest req) |
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> settings)
Initialises the module.
|
protected java.lang.String |
makeSendParamString(javax.servlet.http.HttpServletRequest req) |
protected void |
returnOutput(java.io.InputStream cacheIn,
javax.servlet.http.HttpServletResponse resp)
Writes a page read from an input stream into an HTTP servlet response.
|
buildCacheKey, handleAction, readMetadata, start, stop, writeMetadata
addHandledAction, doReplacements, handleRequest, isHandleAction, setActionParamKey, setHttpHeaders
getScriptEngine
isInitialized, isRunning, requireLogging, toString
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> additionalParams
protected java.util.ArrayList<java.lang.String> forwardParams
protected boolean forwardAllParams
protected java.lang.String destinationProtocol
protected java.lang.String destinationHost
protected int destinationPort
protected java.lang.String destinationPath
public java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
Module
getDependencies
in interface Module
getDependencies
in class CachedAction
manager
- The module manager handling this module.ModuleException
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
Module
Initialises the module. After constructor, this is the first method called in the life cycle of a module. It should not perform anything time consuming or anything with notable outside side effects. It should only read the parameters and initialise the module so that it can later be started. Note that a module being initialised doesn't mean that it necessarily will ever be started.
A ModuleException may be thrown if something vital is missing from the parameters or they are not sensible. In some cases you may not want to throw an exception even if vital initialisation information is missing. If, for example, it is possible that the module is initialised in some other way between the init and the start method calls. A ModuleException may also be thrown at the start method if the module is still not initialised.
init
in interface Module
init
in class CachedAction
manager
- The module manager handling this module. You may keep a
reference to it if needed.ModuleException
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> getSendParams(javax.servlet.http.HttpServletRequest req)
protected java.lang.String makeSendParamString(javax.servlet.http.HttpServletRequest req)
protected void returnOutput(java.io.InputStream cacheIn, javax.servlet.http.HttpServletResponse resp) throws java.io.IOException
CachedAction
Writes a page read from an input stream into an HTTP servlet response. The input stream might be coming from a cached file, or directly from the doOutput method if caching is not in use. In any case, the contents of it need to be written to the response object. Note that any HTTP headers must be set before writing anything else.
If you used writeMetadata in doOutput, you have to override this method and use readMetadata correspondingly to read the metadata from the start of the stream. You can then, for example, set any HTTP headers you read from the metadata. After this, you can call this super implementation which will do the rest of the stream copying.
Make absolutely certain that the input stream is closed before returning from this method. Failing to do so may cause the caching service to become locked which can then lock the whole application. It is best to put the contents in a try-finally block and then call cacheIn.close in the finally part. Do this even if you call the super implementation as your code could possibly fail before reaching that part.
returnOutput
in class CachedAction
java.io.IOException
protected boolean doOutput(javax.servlet.http.HttpServletRequest req, ModulesServlet.HttpMethod method, java.lang.String action, CachedAction.OutputProvider out, User user) throws javax.servlet.ServletException, java.io.IOException
CachedAction
Does the output that might be either cached or returned directly. The OutputProvider is used to get the output stream where the output should be written. Before you get this stream, you may abort the action by returning false but after the output stream is retrieved, you are committed to outputting the page that then might be cached for future use. Therefore you should do all the preparations first, and only then get the output stream when you know that you will be able to output something sensible.
If you opened the output stream using the output provider, you must make sure that the stream is properly closed. It is best to place all your code after this in a try-finally block and close the stream in the finally part. Failing to do this may cause the caching service to become locked, which in turn could potentially lock the whole application.
doOutput
in class CachedAction
javax.servlet.ServletException
java.io.IOException
protected java.lang.String getCacheKey(javax.servlet.http.HttpServletRequest req, ModulesServlet.HttpMethod method, java.lang.String action)
CachedAction
getCacheKey
in class CachedAction
req
- The HTTP request which, result of which is to be cached.method
- The method of the HTTP request.action
- The parsed action parameter from the request.Copyright 2004-2015 Wandora Team