📄 standardwrapper.java
字号:
}
/**
* Set the context-relative URI of the JSP file for this servlet.
*
* @param jspFile JSP file URI
*/
public void setJspFile(String jspFile) {
String oldJspFile = this.jspFile;
this.jspFile = jspFile;
support.firePropertyChange("jspFile", oldJspFile, this.jspFile);
// Each jsp-file needs to be represented by its own JspServlet and
// corresponding JspMonitoring mbean, because it may be initialized
// with its own init params
isJspServlet = true;
}
/**
* Return the load-on-startup order value (negative value means
* load on first call).
*/
public int getLoadOnStartup() {
if (isJspServlet && loadOnStartup < 0) {
/*
* JspServlet must always be preloaded, because its instance is
* used during registerJMX (when registering the JSP
* monitoring mbean)
*/
return Integer.MAX_VALUE;
} else {
return (this.loadOnStartup);
}
}
/**
* Set the load-on-startup order value (negative value means
* load on first call).
*
* @param value New load-on-startup value
*/
public void setLoadOnStartup(int value) {
int oldLoadOnStartup = this.loadOnStartup;
this.loadOnStartup = value;
support.firePropertyChange("loadOnStartup",
new Integer(oldLoadOnStartup),
new Integer(this.loadOnStartup));
}
/**
* Set the load-on-startup order value from a (possibly null) string.
* Per the specification, any missing or non-numeric value is converted
* to a zero, so that this servlet will still be loaded at startup
* time, but in an arbitrary order.
*
* @param value New load-on-startup value
*/
public void setLoadOnStartupString(String value) {
try {
setLoadOnStartup(Integer.parseInt(value));
} catch (NumberFormatException e) {
setLoadOnStartup(0);
}
}
public String getLoadOnStartupString() {
return Integer.toString( getLoadOnStartup());
}
/**
* Return maximum number of instances that will be allocated when a single
* thread model servlet is used.
*/
public int getMaxInstances() {
return (this.maxInstances);
}
/**
* Set the maximum number of instances that will be allocated when a single
* thread model servlet is used.
*
* @param maxInstances New value of maxInstances
*/
public void setMaxInstances(int maxInstances) {
int oldMaxInstances = this.maxInstances;
this.maxInstances = maxInstances;
support.firePropertyChange("maxInstances", oldMaxInstances,
this.maxInstances);
}
/**
* Set the parent Container of this Wrapper, but only if it is a Context.
*
* @param container Proposed parent Container
*/
public void setParent(Container container) {
if ((container != null) &&
!(container instanceof Context))
throw new IllegalArgumentException
(sm.getString("standardWrapper.notContext"));
if (container instanceof StandardContext) {
swallowOutput = ((StandardContext)container).getSwallowOutput();
unloadDelay = ((StandardContext)container).getUnloadDelay();
}
super.setParent(container);
}
/**
* Return the run-as identity for this servlet.
*/
public String getRunAs() {
return (this.runAs);
}
/**
* Set the run-as identity for this servlet.
*
* @param runAs New run-as identity value
*/
public void setRunAs(String runAs) {
String oldRunAs = this.runAs;
this.runAs = runAs;
support.firePropertyChange("runAs", oldRunAs, this.runAs);
}
/**
* Return the fully qualified servlet class name for this servlet.
*/
public String getServletClass() {
return (this.servletClass);
}
/**
* Set the fully qualified servlet class name for this servlet.
*
* @param servletClass Servlet class name
*/
public void setServletClass(String servletClass) {
String oldServletClass = this.servletClass;
this.servletClass = servletClass;
support.firePropertyChange("servletClass", oldServletClass,
this.servletClass);
if (Constants.JSP_SERVLET_CLASS.equals(servletClass)) {
isJspServlet = true;
}
}
/**
* Set the name of this servlet. This is an alias for the normal
* <code>Container.setName()</code> method, and complements the
* <code>getServletName()</code> method required by the
* <code>ServletConfig</code> interface.
*
* @param name The new name of this servlet
*/
public void setServletName(String name) {
setName(name);
}
/**
* Return <code>true</code> if the servlet class represented by this
* component implements the <code>SingleThreadModel</code> interface.
*/
public boolean isSingleThreadModel() {
try {
loadServlet();
} catch (Throwable t) {
;
}
return (singleThreadModel);
}
/**
* Is this servlet currently unavailable?
*/
public boolean isUnavailable() {
if (available == 0L)
return (false);
else if (available <= System.currentTimeMillis()) {
available = 0L;
return (false);
} else
return (true);
}
/**
* Gets the names of the methods supported by the underlying servlet.
*
* This is the same set of methods included in the Allow response header
* in response to an OPTIONS request method processed by the underlying
* servlet.
*
* @return Array of names of the methods supported by the underlying
* servlet
*/
public String[] getServletMethods() throws ServletException {
Class servletClazz = loadServlet().getClass();
if (!javax.servlet.http.HttpServlet.class.isAssignableFrom(
servletClazz)) {
return DEFAULT_SERVLET_METHODS;
}
HashSet allow = new HashSet();
allow.add("TRACE");
allow.add("OPTIONS");
Method[] methods = getAllDeclaredMethods(servletClazz);
for (int i=0; methods != null && i<methods.length; i++) {
Method m = methods[i];
if (m.getName().equals("doGet")) {
allow.add("GET");
allow.add("HEAD");
} else if (m.getName().equals("doPost")) {
allow.add("POST");
} else if (m.getName().equals("doPut")) {
allow.add("PUT");
} else if (m.getName().equals("doDelete")) {
allow.add("DELETE");
}
}
String[] methodNames = new String[allow.size()];
return (String[]) allow.toArray(methodNames);
}
// --------------------------------------------------------- Public Methods
/**
* Execute a periodic task, such as reloading, etc. This method will be
* invoked inside the classloading context of this container. Unexpected
* throwables will be caught and logged.
*/
public void backgroundProcess() {
super.backgroundProcess();
if (!started)
return;
if (getServlet() != null && (getServlet() instanceof PeriodicEventListener)) {
((PeriodicEventListener) getServlet()).periodicEvent();
}
}
/**
* Extract the root cause from a servlet exception.
*
* @param e The servlet exception
*/
public static Throwable getRootCause(ServletException e) {
Throwable rootCause = e;
Throwable rootCauseCheck = null;
// Extra aggressive rootCause finding
int loops = 0;
do {
loops++;
rootCauseCheck = rootCause.getCause();
if (rootCauseCheck != null)
rootCause = rootCauseCheck;
} while (rootCauseCheck != null && (loops < 20));
return rootCause;
}
/**
* Refuse to add a child Container, because Wrappers are the lowest level
* of the Container hierarchy.
*
* @param child Child container to be added
*/
public void addChild(Container child) {
throw new IllegalStateException
(sm.getString("standardWrapper.notChild"));
}
/**
* Add a new servlet initialization parameter for this servlet.
*
* @param name Name of this initialization parameter to add
* @param value Value of this initialization parameter to add
*/
public void addInitParameter(String name, String value) {
synchronized (parameters) {
parameters.put(name, value);
}
fireContainerEvent("addInitParameter", name);
}
/**
* Add a new listener interested in InstanceEvents.
*
* @param listener The new listener
*/
public void addInstanceListener(InstanceListener listener) {
instanceSupport.addInstanceListener(listener);
}
/**
* Add a mapping associated with the Wrapper.
*
* @param mapping The new wrapper mapping
*/
public void addMapping(String mapping) {
synchronized (mappings) {
mappings.add(mapping);
}
fireContainerEvent("addMapping", mapping);
}
/**
* Add a new security role reference record to the set of records for
* this servlet.
*
* @param name Role name used within this servlet
* @param link Role name used within the web application
*/
public void addSecurityReference(String name, String link) {
synchronized (references) {
references.put(name, link);
}
fireContainerEvent("addSecurityReference", name);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -