| Method from org.apache.tomcat.core.Context Detail: |
public void addDestroyInterceptor(LifecycleInterceptor interceptor) {
destroyInterceptors.addElement(interceptor);
}
Adds an interceptor for destroy() method.
If Interceptors a, b and c are added to a context, the
implementation would guarantee the following call order:
(no matter what happens, for eg.Exceptions ??)
a.preInvoke(...)
b.preInvoke(...)
c.preInvoke(...)
destroy()
c.postInvoke(...)
b.postInvoke(...)
a.postInvoke(...) |
public void addInitInterceptor(LifecycleInterceptor interceptor) {
initInterceptors.addElement(interceptor);
}
Adds an interceptor for init() method.
If Interceptors a, b and c are added to a context, the
implementation would guarantee the following call order:
(no matter what happens, for eg.Exceptions ??)
a.preInvoke(...)
b.preInvoke(...)
c.preInvoke(...)
init()
c.postInvoke(...)
b.postInvoke(...)
a.postInvoke(...) |
public void addServiceInterceptor(ServiceInterceptor interceptor) {
serviceInterceptors.addElement(interceptor);
}
Adds an interceptor for service() method.
If Interceptors a, b and c are added to a context, the
implementation would guarantee the following call order:
(no matter what happens, for eg.Exceptions ??)
a.preInvoke(...)
b.preInvoke(...)
c.preInvoke(...)
service()
c.postInvoke(...)
b.postInvoke(...)
a.postInvoke(...) |
public void copyContext(Context context) {
this.container = context.getContainer();
this.serviceInterceptors = context.serviceInterceptors;
this.initInterceptors = context.initInterceptors;
this.destroyInterceptors = context.destroyInterceptors;
this.engineHeader = context.engineHeader;
this.classLoader = context.classLoader; // jsp class loader
this.attributes = context.attributes;
// just to save a little space
this.initializationParameters = context.initializationParameters;
this.contextFacade = context.contextFacade;
}
Copy the internals of a context. Enhydra 3.0 will create shadow contexts
used by any extra channels that point to the same app. These extra contexts
will share many of the internals of the base context. |
public Object getAttribute(String name) {
if (name.equals("org.apache.tomcat.jsp_classpath"))
return getClassPath();
else if(name.equals("org.apache.tomcat.classloader")) {
return this.container.getLoader();
}else {
Object o = attributes.get(name);
return attributes.get(name);
}
}
|
public Enumeration getAttributeNames() {
return attributes.keys();
}
|
public ClassLoader getClassLoader() {
return this.classLoader;
}
|
public String getClassPath() {
String cp = this.classPath.trim();
String servletLoaderClassPath =
this.container.getLoader().getClassPath();
if (servletLoaderClassPath != null &&
servletLoaderClassPath.trim().length() > 0) {
cp += ((cp.length() > 0) ? File.pathSeparator : "") +
servletLoaderClassPath;
}
return cp;
}
|
public Container getContainer() {
return container;
}
|
public String getDescription() {
return this.description;
}
|
Vector getDestroyInterceptors() {
return destroyInterceptors;
}
|
public URL getDocumentBase() {
return docBase;
}
|
public String getEngineHeader() {
return engineHeader;
}
|
public String getErrorPage(int errorCode) {
return getErrorPage(String.valueOf(errorCode));
}
|
public String getErrorPage(String errorCode) {
return (String)errorPages.get(errorCode);
}
|
ServletContextFacade getFacade() {
return contextFacade;
}
|
Vector getInitInterceptors() {
return initInterceptors;
}
|
public String getInitParameter(String name) {
return (String)initializationParameters.get(name);
}
|
public Enumeration getInitParameterNames() {
return initializationParameters.keys();
}
|
public LogChannel getLogChannel() {
return logChannel;
}
|
public MimeMap getMimeMap() {
return mimeTypes;
}
|
public String getPath() {
return path;
}
|
public RequestSecurityProvider getRequestSecurityProvider() {
return this.rsProvider;
}
|
Vector getServiceInterceptors() {
return serviceInterceptors;
}
|
public int getSessionTimeOut() {
return this.sessionTimeOut;
}
|
File getWARDir() {
return this.warDir;
}
|
public Enumeration getWelcomeFiles() {
return welcomeFiles.elements();
}
|
public File getWorkDir() {
return this.workDir;
}
|
public void handleRequest(Request request,
Response response) throws IOException {
// XXX
// make sure we are init'd or throw an illegal state exception
request.setContext(this);
request.setResponse(response);
// look for session id -- cookies only right now
/*
ServerSession session =
sessionManager.getServerSession(request, response, false);
if (session != null) {
session.accessed();
ApplicationSession appSession =
session.getApplicationSession(this, false);
if (appSession != null) {
appSession.accessed();
}
}
request.setServerSession(session); // may be null
*/
LookupResult result =
container.lookupServlet(request.getLookupPath());
request.setServletPath(result.getServletPath());
request.setPathInfo(result.getPathInfo());
if (result.getResolvedServlet() != null) {
request.setAttribute(Constants.Attribute.RESOLVED_SERVLET,
result.getResolvedServlet());
} else if (result.getMappedPath() != null) {
request.setAttribute(Constants.Attribute.RESOLVED_SERVLET,
result.getMappedPath());
} else {
request.removeAttribute(Constants.Attribute.RESOLVED_SERVLET);
}
result.getWrapper().handleRequest(request.getFacade(),
response.getFacade());
//ServletWrapper wrap = container.resolveServlet(request);
// XXX
// we want to be sure to handle any IOExceptions here
// and log 'em -- also an UnavailableExceptions would be
// trapped here.
//wrap.handleRequest(request.getFacade(), response.getFacade());
}
|
public synchronized void init() {
// check to see if we've already been init'd
if (this.initialized) {
String msg = sm.getString("context.init.alreadyinit");
throw new IllegalStateException(msg);
}
this.initialized = true;
if (this.docBase == null) {
//String msg = sm.getString("context.init.nodocbase");
//throw new IllegalStateException(msg);
// XXX
// for now we are going to pretend it doens't matter
}
// set up work dir attribute
if (this.workDir != null) {
setAttribute(Constants.Context.Attribute.WorkDir.Name,
this.workDir);
if (! this.workDir.exists()) {
this.workDir.mkdirs();
}
}
// expand WAR
URL servletBase = this.docBase;
if (docBase.getProtocol().equalsIgnoreCase(
Constants.Request.WAR)) {
if (isWARExpanded()) {
this.warDir = new File(getWorkDir(),
Constants.Context.WARExpandDir);
if (! this.warDir.exists()) {
this.warDir.mkdirs();
try {
WARUtil.expand(this.warDir, getDocumentBase());
} catch (MalformedURLException mue) {
} catch (IOException ioe) {
}
try {
servletBase = URLUtil.resolve(this.warDir.toString());
} catch (Exception e) {
}
}
}
}
this.container.setServletBase(servletBase);
for (int i = 0; i < Constants.Context.CLASS_PATHS.length; i++) {
this.container.addClassPath(Constants.Context.CLASS_PATHS[i]);
}
for (int i = 0; i < Constants.Context.LIB_PATHS.length; i++) {
this.container.addLibPath(Constants.Context.LIB_PATHS[i]);
}
// process base configuration
try {
Class webApplicationDescriptor = Class.forName(
"org.apache.tomcat.deployment.WebApplicationDescriptor");
InputStream is =
webApplicationDescriptor.getResourceAsStream(
org.apache.tomcat.deployment.Constants.ConfigFile);
String msg = sm.getString("context.getConfig.msg", "default");
logWrite(Logger.INFO,msg);
processWebApp(is, true);
} catch (Exception e) {
String msg = sm.getString("context.getConfig.e", "default");
logWrite(Logger.ERROR,msg,e);
}
// process webApp configuration
String s = docBase.toString();
if (docBase.getProtocol().equalsIgnoreCase(
Constants.Request.WAR)) {
if (s.endsWith("/")) {
s = s.substring(0, s.length() - 1);
}
s += "!/";
}
URL webURL = null;
try {
webURL = new URL(s + Constants.Context.ConfigFile);
InputStream is = webURL.openConnection().getInputStream();
String msg = sm.getString("context.getConfig.msg",
webURL.toString());
logWrite(Logger.INFO,msg);
processWebApp(is);
} catch (Exception e) {
String msg = sm.getString("context.getConfig.e",
(webURL != null) ? webURL.toString() : "not available");
// go silent on this one
// System.out.println(msg);
}
if (! this.isInvokerEnabled) {
// Put in a special "no invoker" that handles
// /servlet requests and explains why no servlet
// is being invoked
this.container.addServlet(Constants.Servlet.NoInvoker.Name,
Constants.Servlet.NoInvoker.Class);
this.container.addMapping(Constants.Servlet.NoInvoker.Name,
Constants.Servlet.NoInvoker.Map);
}
// load-on-startup
if (! loadableServlets.isEmpty()) {
loadServlets();
}
}
Initializes this context to take on requests. This action
will cause the context to load it's configuration information
from the webapp directory in the docbase.
This method may only be called once and must be called
before any requests are handled by this context. |
public boolean isDistributable() {
return this.isDistributable;
}
|
public boolean isInvokerEnabled() {
return isInvokerEnabled;
}
|
public boolean isWARExpanded() {
return this.isWARExpanded;
}
|
public boolean isWARValidated() {
return this.isWARValidated;
}
|
public boolean isWorkDirPersistent() {
return this.isWorkDirPersistent;
}
|
public void removeAttribute(String name) {
attributes.remove(name);
}
|
public void removeDestroyInterceptor(LifecycleInterceptor interceptor) {
destroyInterceptors.removeElement(interceptor);
}
Removes a destroy() Interceptor. |
public void removeInitInterceptor(LifecycleInterceptor interceptor) {
initInterceptors.removeElement(interceptor);
}
Removes an init() Interceptor. |
public void removeServiceInterceptor(ServiceInterceptor interceptor) {
serviceInterceptors.removeElement(interceptor);
}
Removes a service() Interceptor. |
public void setAttribute(String name,
Object object) {
attributes.put(name, object);
}
|
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
|
public void setClassPath(String classPath) {
if (this.classPath.trim().length() > 0) {
this.classPath += File.pathSeparator;
}
this.classPath += classPath;
}
|
public void setDescription(String description) {
this.description = description;
}
|
public void setDistributable(boolean isDistributable) {
this.isDistributable = isDistributable;
}
|
public void setDocumentBase(URL docBase) {
String file = docBase.getFile();
if (! file.endsWith("/")) {
try {
docBase = new URL(docBase.getProtocol(),
docBase.getHost(), docBase.getPort(), file + "/");
} catch (MalformedURLException mue) {
if (getLogChannel()!= null) {
getLogChannel().write(Logger.ERROR,"SHOULD NEVER HAPPEN: ",mue);
}
//System.out.println("SHOULD NEVER HAPPEN: " + mue);
}
}
this.docBase = docBase;
}
|
public void setInvokerEnabled(boolean isInvokerEnabled) {
this.isInvokerEnabled = isInvokerEnabled;
}
|
public void setIsWARExpanded(boolean isWARExpanded) {
this.isWARExpanded = isWARExpanded;
}
|
public void setIsWARValidated(boolean isWARValidated) {
this.isWARValidated = isWARValidated;
}
|
public void setLogChannel(LogChannel logChannel) {
this.logChannel = logChannel;
}
|
public void setPath(String path) {
this.path = path;
}
|
public void setRequestSecurityProvider(RequestSecurityProvider rsProvider) {
this.rsProvider = rsProvider;
}
|
public void setSessionTimeOut(int sessionTimeOut) {
this.sessionTimeOut = sessionTimeOut;
}
|
public void setWorkDir(String workDir,
boolean isWorkDirPersistent) {
File f = null;
try {
f = new File(workDir);
} catch (Exception e) {
}
setWorkDir(f, isWorkDirPersistent);
}
|
public void setWorkDir(File workDir,
boolean isWorkDirPersistent) {
this.isWorkDirPersistent = isWorkDirPersistent;
if (workDir == null) {
workDir = this.workDir;
}
if (! isWorkDirPersistent) {
clearDir(workDir);
}
this.workDir = workDir;
setAttribute(Constants.Attribute.WorkDirectory, this.workDir);
}
|
public void setupLoadableServlet(String name) {
Vector v = new Vector();
v.addElement(name);
loadableServlets.put(new Integer(0),v);
loadServlets();
}
Normally the loadable servlets are set within web.xml. If the context
is a wrapper for an enhydra app then the one and only servlet must be
started and init() called. The servlet is created by the ServletWrapper. |
public void shutdown() {
// shut down container
container.shutdown();
// shut down any sessions
sessionManager.removeApplicationSessions(this);
if (! isWorkDirPersistent) {
clearDir(workDir);
}
logWrite(Logger.INFO,"Context down.");
//System.out.println("Context: " + this + " down");
}
|