You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/02/09 00:52:49 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util FileUtil.java
costin 00/02/08 15:52:49
Modified: src/share/org/apache/tomcat/context
BaseContextInterceptor.java DefaultCMSetter.java
src/share/org/apache/tomcat/core Context.java
ContextInterceptor.java ContextManager.java
src/share/org/apache/tomcat/util FileUtil.java
Removed: src/share/org/apache/tomcat/context
DefaultContextSetter.java
src/share/org/apache/tomcat/core JspWrapper.java
Log:
- Moved all "default" settings to DefaultCMSetter ( including default
Interceptors, etc). If a context doesn't have any explicit settings for
intreceptors - the defaults will be used.
It is still incomplete, but all hard-coding will happen in DefaultCMSetter
for "default" and in server.xml for "custom" setup.
- moved normPath in FileUtil ( from Context ) - it's a general utility.
- added notification for mapping add/remove in context interceptor
Revision Changes Path
1.2 +8 -0 jakarta-tomcat/src/share/org/apache/tomcat/context/BaseContextInterceptor.java
Index: BaseContextInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/BaseContextInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BaseContextInterceptor.java 2000/02/03 07:11:50 1.1
+++ BaseContextInterceptor.java 2000/02/08 23:52:46 1.2
@@ -98,6 +98,14 @@
return 0;
}
+ public int addMapping( Context ctx, String path, ServletWrapper servlet) {
+ return 0;
+ }
+
+
+ public int removeMapping( Context ctx, String path ) {
+ return 0;
+ }
}
1.3 +93 -1 jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java
Index: DefaultCMSetter.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultCMSetter.java 2000/01/30 04:22:45 1.2
+++ DefaultCMSetter.java 2000/02/08 23:52:46 1.3
@@ -70,7 +70,6 @@
import java.util.*;
import javax.servlet.http.*;
-
/**
* Check ContextManager and set defaults for non-set properties
*
@@ -111,4 +110,97 @@
return 0;
}
+
+ /** Called when a new context is added to the server.
+ *
+ * - Check it and set defaults for WorkDir, EngineHeader and SessionManager.
+ * If you don't like the defaults, set them in Context before adding it to the
+ * engine.
+ *
+ * - Set up defaults for context interceptors and session if nothing is set
+ */
+ public int addContext(ContextManager cm, Context ctx) {
+ // Make sure context knows about its manager.
+ ctx.setContextManager( cm );
+ setEngineHeader( ctx );
+
+ if( ctx.getWorkDir() == null)
+ setWorkDir(ctx);
+
+ // Set default session manager if none set
+ if( ctx.getSessionManager() == null )
+ ctx.setSessionManager(new org.apache.tomcat.session.StandardSessionManager());
+
+ // Alternative: org.apache.tomcat.session.ServerSessionManager.getManager();
+
+ // If no ContextInterceptors are set up use defaults
+ Enumeration enum=ctx.getContextInterceptors();
+ if( ! enum.hasMoreElements() ) {
+ // set up work dir ( attribute + creation )
+ ctx.addContextInterceptor(new WorkDirInterceptor());
+
+ // Read context's web.xml
+ // new WebXmlInterceptor().contextInit( this );
+ ctx.addContextInterceptor( new WebXmlReader());
+
+ // load initial servlets
+ ctx.addContextInterceptor(new LoadOnStartupInterceptor());
+ }
+
+ // XXX Loader properties - need to be set on loader!!
+ ctx.addClassPath("WEB-INF/classes");
+ ctx.addLibPath("WEB-INF/lib");
+
+ if(ctx.getLoader() == null) {
+ ctx.setLoader( new org.apache.tomcat.loader.ServletClassLoaderImpl(ctx));
+ }
+
+
+ return 0;
+ }
+
+ // -------------------- implementation
+ /** Encoded ContextManager.getWorkDir() + host + port + path
+ */
+ private void setWorkDir(Context ctx ) {
+ ContextManager cm=ctx.getContextManager();
+
+ StringBuffer sb=new StringBuffer();
+ sb.append(cm.getWorkDir());
+ sb.append(File.separator);
+ sb.append(cm.getHostName() );
+ sb.append("_").append(cm.getPort());
+ sb.append(URLEncoder.encode( ctx.getPath() ));
+
+ ctx.setWorkDir( new File(sb.toString()));
+ }
+
+ private void setEngineHeader(Context ctx) {
+ String engineHeader=ctx.getEngineHeader();
+
+ if( engineHeader==null) {
+ /*
+ * Whoever modifies this needs to check this modification is
+ * ok with the code in com.jsp.runtime.ServletEngine or talk
+ * to akv before you check it in.
+ */
+ // Default value for engine header
+ // no longer use core.properties - the configuration comes from
+ // server.xml or web.xml - no more properties.
+ StringBuffer sb=new StringBuffer();
+ sb.append(Constants.TOMCAT_NAME).append("/").append(Constants.TOMCAT_VERSION);
+ sb.append(" (").append(Constants.JSP_NAME).append(" ").append(Constants.JSP_VERSION);
+ sb.append("; ").append(Constants.SERVLET_NAME).append(" ");
+ sb.append(Constants.SERVLET_MAJOR).append(".").append(Constants.SERVLET_MINOR);
+ sb.append( "; Java " );
+ sb.append(System.getProperty("java.version")).append("; ");
+ sb.append(System.getProperty("os.name") + " ");
+ sb.append(System.getProperty("os.version") + " ");
+ sb.append(System.getProperty("os.arch") + "; java.vendor=");
+ sb.append(System.getProperty("java.vendor")).append(")");
+ engineHeader=sb.toString();
+ }
+ ctx.setEngineHeader( engineHeader );
+ }
+
}
1.40 +33 -56 jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
Index: Context.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- Context.java 2000/02/08 20:26:35 1.39
+++ Context.java 2000/02/08 23:52:47 1.40
@@ -120,18 +120,20 @@
private boolean isWARExpanded = false;
private boolean isWARValidated = false;
- // Class Loading
+ // Class Loading
+ // XXX Nobody sets it private ClassLoader classLoader;
private String classPath = ""; // classpath used by the classloader.
private Vector classPaths = new Vector();
private Vector libPaths = new Vector();
private ServletClassLoader servletLoader;
- private ClassLoader classLoader = null;
-
+
// Interceptors
private Vector initInterceptors = new Vector();
private Vector serviceInterceptors = new Vector();
private Vector destroyInterceptors = new Vector();
private RequestSecurityProvider rsProvider;
+
+ private Vector contextInterceptors = new Vector();
// Servlets loaded by this context( String->ServletWrapper )
private Hashtable servlets = new Hashtable();
@@ -357,7 +359,7 @@
// Real Path is the same as PathTranslated for a new request
Context base=this; // contextM.getContext("");
- Request req=contextM.createRequest( base , normPath(path) );
+ Request req=contextM.createRequest( base , FileUtil.normPath(path) );
contextM.processRequest(req);
String mappedPath = req.getMappedPath();
@@ -485,27 +487,20 @@
}
this.initialized = true;
- // Set defaults if not already there
- new DefaultContextSetter().contextInit( this );
-
- // set up work dir ( attribute + creation )
- new WorkDirInterceptor().contextInit( this );
+ for( int i=0; i< contextInterceptors.size(); i++ ) {
+ ((ContextInterceptor)contextInterceptors.elementAt(i)).contextInit( this );
+ }
+ }
- // Read context's web.xml
- // new WebXmlInterceptor().contextInit( this );
- new WebXmlReader().contextInit( this );
+ public void addContextInterceptor( ContextInterceptor ci) {
+ contextInterceptors.addElement( ci );
+ }
- // load initial servlets
- new LoadOnStartupInterceptor().contextInit( this );
+ public Enumeration getContextInterceptors() {
+ return contextInterceptors.elements();
}
public SessionManager getSessionManager() {
- if( sessionManager==null ) {
- // default - will change when a better one exists
- // sessionManager = org.apache.tomcat.session.ServerSessionManager.getManager();
- sessionManager =
- new org.apache.tomcat.session.StandardSessionManager();
- }
return sessionManager;
}
@@ -528,8 +523,10 @@
getSessionManager().removeSessions(this);
- new WorkDirInterceptor().contextShutdown(this);
-
+ for( int i=0; i< contextInterceptors.size(); i++ ) {
+ ((ContextInterceptor)contextInterceptors.elementAt(i)).contextShutdown( this );
+ }
+
System.out.println("Context: " + this + " down");
}
@@ -954,23 +951,27 @@
}
// -------------------- Class Loading --------------------
+
+ // XXX I have no ideea how it works !
+ // Used by JSP and loader
+ /** ClassLoader used to load this servlet.
+ */
public ClassLoader getClassLoader() {
- return this.classLoader;
- }
+ // Doesn't work: return (ClassLoader)servletLoader;
- public void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
+ // ClassLoader is allways null, nobody sets it
+ return null;
}
+
+ // public void setClassLoader(ClassLoader classLoader) {
+ // this.classLoader = classLoader;
+ // }
- void setLoader(ServletClassLoader loader ) {
+ public void setLoader(ServletClassLoader loader ) {
this.servletLoader=loader;
}
- ServletClassLoader getLoader() {
- if(servletLoader == null) {
- // XXX configurable option !!!
- servletLoader = new org.apache.tomcat.loader.ServletClassLoaderImpl(this);
- }
+ public ServletClassLoader getLoader() {
return servletLoader;
}
@@ -1021,28 +1022,4 @@
return "Ctx(" + path + "," + getDocBase() + ")";
// + " , " + getDocumentBase() + " ) ";
}
-
-
- // XXX Probably not needed, used by getRealPath()
- private String normPath( String path ) {
- int i = -1;
- // norm path
- if( path==null) {
- /*DEBUG*/ try {throw new Exception(); } catch(Exception ex) {ex.printStackTrace();}
- return "";
- }
- while ((i = path.indexOf('\\')) > -1) {
- String a = path.substring(0, i);
- String b = "";
-
- if (i < path.length() - 1) {
- b = path.substring(i + 1);
- }
-
- path = a + "/" + b;
- }
- return path;
- }
-
-
}
1.3 +12 -4 jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java
Index: ContextInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ContextInterceptor.java 2000/02/03 07:11:51 1.2
+++ ContextInterceptor.java 2000/02/08 23:52:47 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v 1.2 2000/02/03 07:11:51 costin Exp $
- * $Revision: 1.2 $
- * $Date: 2000/02/03 07:11:51 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v 1.3 2000/02/08 23:52:47 costin Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/02/08 23:52:47 $
*
* ====================================================================
*
@@ -86,5 +86,13 @@
/** Notify when a servlet is removed from context
*/
public int removeServlet( Context ctx, ServletWrapper sw);
-
+
+ /** Notify when a mapping is added to a context
+ */
+ public int addMapping( Context ctx, String path, ServletWrapper servlet);
+
+ /** Notify when a mapping is deleted from a context
+ */
+ public int removeMapping( Context ctx, String path );
+
}
1.34 +8 -4 jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
Index: ContextManager.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- ContextManager.java 2000/02/08 18:50:45 1.33
+++ ContextManager.java 2000/02/08 23:52:47 1.34
@@ -214,14 +214,18 @@
* @param ctx context to be added.
*/
public void addContext( Context ctx ) {
- // System.out.println("Add context ");
- ctx.setContextManager( this );
- // assert "valid path"
-
// it will replace existing context - it's better than
// IllegalStateException.
String path=ctx.getPath();
+ if( getContext( path ) != null ) {
+ removeContext(path);
+ }
+
+ // Set defaults for the context
+ new DefaultCMSetter().addContext( this, ctx );
+
if(debug>0) log(" adding " + ctx + " " + ctx.getPath() + " " + ctx.getDocBase());
+
contexts.put( path, ctx );
}
1.4 +28 -3 jakarta-tomcat/src/share/org/apache/tomcat/util/FileUtil.java
Index: FileUtil.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/FileUtil.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FileUtil.java 2000/01/12 06:35:21 1.3
+++ FileUtil.java 2000/02/08 23:52:49 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/FileUtil.java,v 1.3 2000/01/12 06:35:21 costin Exp $
- * $Revision: 1.3 $
- * $Date: 2000/01/12 06:35:21 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/FileUtil.java,v 1.4 2000/02/08 23:52:49 costin Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/02/08 23:52:49 $
*
* ====================================================================
*
@@ -165,4 +165,29 @@
return patchPath;
}
+
+
+ // Probably not needed, original code used by Context.getRealPath()
+ // XXX Find if it is duplicated, merge with the other "path" functions
+ public static String normPath( String path ) {
+ int i = -1;
+ // norm path
+ if( path==null) {
+ // Shouldn't happen, find out what is wrong
+ /*DEBUG*/ try {throw new Exception(); } catch(Exception ex) {ex.printStackTrace();}
+ return "";
+ }
+ while ((i = path.indexOf('\\')) > -1) {
+ String a = path.substring(0, i);
+ String b = "";
+
+ if (i < path.length() - 1) {
+ b = path.substring(i + 1);
+ }
+
+ path = a + "/" + b;
+ }
+ return path;
+ }
+
}