Fields Summary |
---|
private static com.sun.org.apache.commons.logging.Log | log |
private ServletContext | contextcontext of the enclosing servlet |
private String | webAppRootDirreal file system directory of the enclosing servlet's web app |
private String | contextPathcontext path of enclosing servlet |
protected String | pathInfopathInfo for the current request |
private String | servletPathservlet URI of the enclosing servlet |
protected Hashtable | envderived process environment |
protected String | commandcommand to be invoked |
protected boolean | validwhether or not this object is valid or not |
protected int | debugthe debugging detail level for this instance. |
protected File | workingDirectoryprocess' desired working directory |
Constructors Summary |
---|
public ProcessEnvironment(HttpServletRequest req, ServletContext context)Creates a ProcessEnvironment and derives the necessary environment,
working directory, command, etc.
this(req, context, 0);
|
public ProcessEnvironment(HttpServletRequest req, ServletContext context, int debug)Creates a ProcessEnvironment and derives the necessary environment,
working directory, command, etc.
this.debug = debug;
setupFromContext(context);
setupFromRequest(req);
this.valid = deriveProcessEnvironment(req);
log(this.getClass().getName() + "() ctor, debug level " + debug);
|
Methods Summary |
---|
protected java.lang.String | blanksToString(java.lang.String couldBeBlank, java.lang.String subForBlanks)Converts blank strings to another string
return (("".equals(couldBeBlank) || couldBeBlank == null) ?
subForBlanks : couldBeBlank);
|
protected boolean | deriveProcessEnvironment(javax.servlet.http.HttpServletRequest req)Constructs the Process environment to be supplied to the invoked
process. Defines an environment no environment variables.
Should be overriden by subclasses to perform useful setup.
Hashtable envp = new Hashtable();
command = getCommand();
if (command != null) {
workingDirectory = new
File(command.substring(0,
command.lastIndexOf(File.separator)));
envp.put("X_TOMCAT_COMMAND_PATH", command); //for kicks
}
this.env = envp;
return true;
|
public java.lang.String | getCommand()Gets derived command string
return command;
|
public javax.servlet.ServletContext | getContext()
return context;
|
public java.lang.String | getContextPath()
return contextPath;
|
public java.util.Hashtable | getEnvironment()Gets process' environment
return env;
|
public java.lang.String | getServletPath()
return servletPath;
|
public java.lang.String | getWebAppRootDir()Gets the root directory of the web application to which this process\
belongs
return webAppRootDir;
|
public java.io.File | getWorkingDirectory()Gets this process' derived working directory
return workingDirectory;
|
public boolean | isValid()Gets validity status
return valid;
|
protected void | log(java.lang.String s)
if (log.isDebugEnabled())
log.debug(s);
|
protected java.lang.String | nullsToBlanks(java.lang.String s)Converts null strings to blank strings ("")
return nullsToString(s, "");
|
protected java.lang.String | nullsToString(java.lang.String couldBeNull, java.lang.String subForNulls)Converts null strings to another string
return (couldBeNull == null ? subForNulls : couldBeNull);
|
protected java.lang.String | setCommand(java.lang.String command)Sets the desired command string
return command;
|
public java.util.Hashtable | setEnvironment(java.util.Hashtable env)Sets process' environment
this.env = env;
return this.env;
|
protected void | setupFromContext(javax.servlet.ServletContext context)Uses the ServletContext to set some process variables
this.context = context;
this.webAppRootDir = context.getRealPath("/");
|
protected void | setupFromRequest(javax.servlet.http.HttpServletRequest req)Uses the HttpServletRequest to set most process variables
this.contextPath = req.getContextPath();
this.pathInfo = req.getPathInfo();
this.servletPath = req.getServletPath();
|
public java.lang.String | toString()Print important process environment information in an
easy-to-read HTML table
StringBuffer sb = new StringBuffer();
sb.append("<TABLE border=2>");
sb.append("<tr><th colspan=2 bgcolor=grey>");
sb.append("ProcessEnvironment Info</th></tr>");
sb.append("<tr><td>Debug Level</td><td>");
sb.append(debug);
sb.append("</td></tr>");
sb.append("<tr><td>Validity:</td><td>");
sb.append(isValid());
sb.append("</td></tr>");
if (isValid()) {
Enumeration envk = env.keys();
while (envk.hasMoreElements()) {
String s = (String)envk.nextElement();
sb.append("<tr><td>");
sb.append(s);
sb.append("</td><td>");
sb.append(blanksToString((String)env.get(s),
"[will be set to blank]"));
sb.append("</td></tr>");
}
}
sb.append("<tr><td colspan=2><HR></td></tr>");
sb.append("<tr><td>Derived Command</td><td>");
sb.append(nullsToBlanks(command));
sb.append("</td></tr>");
sb.append("<tr><td>Working Directory</td><td>");
if (workingDirectory != null) {
sb.append(workingDirectory.toString());
}
sb.append("</td></tr>");
sb.append("</TABLE><p>end.");
return sb.toString();
|