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/12/13 20:58:04 UTC
cvs commit: jakarta-tomcat/src/tests/webpages/jsp params.jsp
costin 00/12/13 11:58:04
Modified: src/facade22/org/apache/tomcat/facade ServletHandler.java
ServletInfo.java WebXmlReader.java
src/facade22/org/apache/tomcat/modules/facade22
JspInterceptor.java
src/share/org/apache/tomcat/context AutoSetup.java
ErrorHandler.java
src/share/org/apache/tomcat/core BaseInterceptor.java
Context.java Handler.java
src/share/org/apache/tomcat/modules/session SessionId.java
src/share/org/apache/tomcat/request AccessInterceptor.java
AccountingInterceptor.java InvokerInterceptor.java
Jdk12Interceptor.java StaticInterceptor.java
src/tests/webpages/WEB-INF web.xml
Added: src/tests/webpages/jsp params.jsp
Log:
One more step in Handler refactoring. We are very close, I think
Handler starts to be simple enough and ServletWrapper is now at least
readable ( that was one of the most complex parts of tomcat3).
In the process I also fixed a number of bugs ( it's amazing what you
find when the code is simpler ) and added few improvements on the
JspInterceptor ( now the main target for refactoring )
- added get/setModule - the handler is associated with an interceptor the
same way as in apache, etc. The interceptor creates the handler and sets
it ( properties, debug ) - Servlet22Interceptor and JspInterceptor are doing
this for servlets/jsps
- many fixes in JspInterceptor - the error handling had few problems,
same for reloading.
- changed JspInterceptor to use the same mechanism for reloading with
servlets - now expire checks are done periodically, not for each
request.
- started to simplify and better organize JspInterceptor
- fixed bugs related with jsps declared in web.xml
- added a small test for jsp declarations
- use a prefix for the names declared by JspInterceptor, to avoid
conflicts with web.xml names
- changed the Context logger to report the context path
- removed accounting from Handler - a better mechanism is needed, and
it's not a priority.
- that simplifies a lot the Handler, and make it possible and easy to
pass options using server.xml
- removed "origin" from handler - it's implied by Module
- removed Context from handler - it's used only in ServletHandler.
- Small hack in ServletInfo so that servlets declared by WebXmlReader will
have Servlet22Interceptor as "owner".
Revision Changes Path
1.3 +16 -2 jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletHandler.java
Index: ServletHandler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServletHandler.java 2000/12/12 22:32:54 1.2
+++ ServletHandler.java 2000/12/13 19:57:58 1.3
@@ -110,6 +110,7 @@
private String path;
protected Class servletClass;
protected Servlet servlet;
+ protected Context context;
// If init() fails, Handler.errorException will hold the reason.
// In the case of an UnavailableException, this field will hold
@@ -121,7 +122,7 @@
}
public String toString() {
- return "ServletHandler " + name + "(" + sw + ")";
+ return "ServletH " + name + "(" + sw + ")";
}
public void setServletInfo( ServletInfo sw ) {
@@ -137,6 +138,19 @@
return sw;
}
+ /**
+ */
+ public void setContext( Context context) {
+ this.context = context;
+ }
+
+ /** Return the context associated with the handler
+ */
+ public Context getContext() {
+ return context;
+ }
+
+
public void setServletClassName( String servletClassName) {
servlet=null; // reset the servlet, if it was set
servletClass=null;
@@ -394,7 +408,7 @@
if( state!= STATE_DISABLED ) {
init();
}
- if( state== STATE_DISABLED ) {
+ if( state== STATE_DISABLED || state==STATE_DELAYED_INIT ) {
// the init failed because of an exception
Exception ex=getErrorException();
// save error state on request and response
1.2 +19 -3 jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletInfo.java
Index: ServletInfo.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletInfo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServletInfo.java 2000/12/12 20:21:24 1.1
+++ ServletInfo.java 2000/12/13 19:57:58 1.2
@@ -115,16 +115,32 @@
}
public String toString() {
- return "SW " + handler.getName() + "(" + path + "/" +
+ return "SW (" + path + " CN=" +
handler.getServletClassName() + ")";
}
// -------------------- Configuration hook
-
/** This method can called to add the servlet to the web application.
* ( typlically used from the config - WebXmlReader ).
*/
- public void addServlet(Context ctx) throws TomcatException {
+ public void addServlet(Context ctx, WebXmlReader wxR)
+ throws TomcatException
+ {
+ // set the owner module for the servlet.
+ // Even if the servlets are defined in WebXmlReader, they should
+ // belong to Servlet22Interceptor. ( it's easy to set WebXmlReader,
+ // but it's more intuitive to set debug and options on Servlet22 )
+ BaseInterceptor mods[]=ctx.getContainer().getInterceptors();
+ for( int i=0; i<mods.length; i++ ) {
+ if( mods[i] instanceof Servlet22Interceptor ) {
+ handler.setModule( mods[i] );
+ break;
+ }
+ }
+ // if not found - then we don't have a Servlet22Interceptor.
+ // That means a configuration problem.
+ if( handler.getModule() == null )
+ throw new TomcatException("Can't find Servlet22Interceptor");
ctx.addServlet( handler );
handler.setContext( ctx );
}
1.8 +2 -1 jakarta-tomcat/src/facade22/org/apache/tomcat/facade/WebXmlReader.java
Index: WebXmlReader.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/WebXmlReader.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- WebXmlReader.java 2000/12/12 20:21:25 1.7
+++ WebXmlReader.java 2000/12/13 19:57:58 1.8
@@ -190,13 +190,14 @@
xh.addRule("web-app/servlet", xh.setParent( "setContext") ); // remove it from stack when done
// xh.addRule("web-app/servlet", xh.addChild("addServlet", "org.apache.tomcat.core.Handler") );
+ final WebXmlReader wxr=this;
xh.addRule("web-app/servlet", new XmlAction() {
public void end( SaxContext xctx)
throws Exception {
ServletInfo sw=(ServletInfo)
xctx.currentObject();
Context cctx=(Context)xctx.previousObject();
- sw.addServlet(cctx);
+ sw.addServlet(cctx, wxr);
}
}
);
1.16 +116 -64 jakarta-tomcat/src/facade22/org/apache/tomcat/modules/facade22/JspInterceptor.java
Index: JspInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/modules/facade22/JspInterceptor.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- JspInterceptor.java 2000/12/12 20:21:29 1.15
+++ JspInterceptor.java 2000/12/13 19:57:59 1.16
@@ -66,6 +66,7 @@
import org.apache.tomcat.util.log.*;
import org.apache.tomcat.util.*;
+import org.apache.tomcat.util.depend.*;
import org.apache.jasper.*;
import org.apache.jasper.Constants;
@@ -186,39 +187,66 @@
}
Context ctx= req.getContext();
+ DependManager dm=ctx.getDependManager();
+ if( dm==null ) {
+ dm=new DependManager();
+ ctx.setDependManager( dm );
+ }
// If this Wrapper was already used, we have all the info
JspInfo jspInfo=(JspInfo)wrapper.getNote( jspInfoNOTE );
if( jspInfo == null ) {
- if( debug > 0 ) log("New jsp page - no jspInfo ");
+ if( debug>0) log("Handler never processed " + wrapper );
+
jspInfo=new JspInfo(req);
- mapJspPage( req, jspInfo, jspInfo.uri, jspInfo.fullClassN);
- }
-
- if( debug > 3) {
- log( "Check if source is up-to-date " +
- jspInfo.jspSource + " " +
- jspInfo.jspSource.lastModified() + " "
- + jspInfo.compileTime );
+ if( "jsp".equals(wrapper.getName())) {
+ wrapper = mapJspPage( ctx, jspInfo );
+ }
+ wrapper.setNote( jspInfoNOTE, jspInfo );
+ dm.addDependency( jspInfo.expireCheck );
+ ((ServletHandler)wrapper).
+ setServletClassName( jspInfo.fullClassN );
+ req.setHandler( wrapper );
}
- if( jspInfo.jspSource.lastModified()
- > jspInfo.compileTime ) {
- //XXX destroy();
+ if( debug > 3)
+ log( "Check if source is up-to-date " + jspInfo.jspSource + " " +
+ jspInfo.jspSource.lastModified()+" "+ jspInfo.compileTime );
+
+ if( jspInfo.expireCheck.isExpired() ) {
+ //XXX old servlet - destroy();
// jump version number - the file needs to
// be recompiled, and we don't want a reload
if( debug > 0 ) log( "Before sync block " + jspInfo );
synchronized( jspInfo ) {
- // if( debug>0 )
- if( jspInfo.jspSource.lastModified()
- > jspInfo.compileTime ) {
+ // if still expired ( we may enter the sync block after
+ // another thread re-compiled )
+ if( jspInfo.expireCheck.isExpired() ) {
+ // reset the handler error, un-initialize the servlet
+ wrapper.setErrorException( null );
+ jspInfo.setCompileException( null );
+ wrapper.setState( Handler.STATE_ADDED );
+
if( debug > 0 ) log( "Compiling " + jspInfo );
-
+ // Move to the next class name
jspInfo.nextVersion();
+
compile( req, jspInfo );
- mapJspPage( req , jspInfo, jspInfo.uri,
- jspInfo.fullClassN);
+
+ // Update the class name in wrapper
+ ((ServletHandler)wrapper).
+ setServletClassName( jspInfo.fullClassN );
+
+ // set initial exception on the servlet if one is present
+ if ( jspInfo.isExceptionPresent() ) {
+ wrapper.
+ setErrorException(jspInfo.getCompileException());
+ wrapper.setState(Handler.STATE_DISABLED);
+ // until the jsp cahnges, when it'll be enabled again
+ }
+ jspInfo.expireCheck.setExpired( false );
+
}
}
}
@@ -226,57 +254,56 @@
return 0;
}
+ private static final String SERVLET_NAME_PREFIX="tomcat_jsp.";
+
/** Add an exact map that will avoid *.jsp mapping and intermediate
- * steps
+ * steps. It's equivalent with declaring
+ * <servlet-name>tomcat_jsp.uri</>
+ * <servlet-mapping><servlet-name>tomcat_jsp.uri</><url-pattern>uri</></>
*/
- void mapJspPage( Request req, JspInfo jspInfo,
- String servletName, String classN )
+ Handler mapJspPage( Context ctx, JspInfo jspInfo)
{
- Context ctx=req.getContext();
- Handler wrapper=null;
- String servletPath=servletName;
+ String uri=jspInfo.uri;
+ String servletName= SERVLET_NAME_PREFIX + uri;
+
+ log( "mapJspPage " + ctx + " " + jspInfo + " " + servletName + " " +
+ uri );
+
// add the mapping - it's a "invoker" map ( i.e. it
// can be removed to keep memory under control.
// The memory usage is smaller than JspSerlvet anyway, but
// can be further improved.
try {
- wrapper=ctx.getServletByName( servletName );
+ Handler wrapper=ctx.getServletByName( servletName );
+
// We may want to replace the class and reset it if changed
if( wrapper==null ) {
wrapper=new ServletHandler();
- wrapper.setContext(ctx);
+ wrapper.setModule( this );
+ ((ServletHandler)wrapper).setContext(ctx);
wrapper.setName(servletName);
- wrapper.setOrigin( Handler.ORIGIN_INVOKER );
((ServletHandler)wrapper).getServletInfo().
- setPath( servletPath );
+ setPath( uri );
ctx.addServlet( wrapper );
- ctx.addServletMapping( servletPath ,
- servletPath );
+ ctx.addServletMapping( uri ,
+ servletName );
if( debug > 0 )
- log( "Added mapping " + servletPath +
- " path=" + servletPath );
+ log( "Added mapping " + uri +
+ " path=" + servletName );
}
- ((ServletHandler)wrapper).setServletClassName( classN );
- wrapper.setNote( jspInfoNOTE, jspInfo );
- // set initial exception on the servlet if one is present
- if ( jspInfo.isExceptionPresent() ) {
- wrapper.setErrorException(jspInfo.getCompileException());
- wrapper.setState(Handler.STATE_DISABLED);
- }
+ return wrapper;
} catch( TomcatException ex ) {
- log("mapJspPage: request=" + req +
+ log("mapJspPage: ctx=" + ctx +
", jspInfo=" + jspInfo +
- ", servletName=" + servletName +
- ", classN=" + classN, ex);
- return ;
+ ", servletName=" + servletName, ex);
+ return null;
}
- req.setHandler( wrapper );
- if( debug>0) log("Handler " + wrapper);
}
+
/** Convert the .jsp file to a java file, then compile it to class
*/
void compile(Request req, JspInfo jspInfo ) {
@@ -302,10 +329,14 @@
// record time of attempted translate-and-compile
jspInfo.touch();
- synchronized ( this ) {
+ synchronized ( jspInfo ) {
compiler.compile();
}
-
+ if( debug > 0 ) {
+ File f = new File( mangler.getJavaFileName());
+ log( "Created file : " + f + " " + f.lastModified());
+
+ }
javac( createJavaCompiler( options ), ctxt, mangler );
if(debug>0)log( "Compiled to " + jspInfo.realClassPath );
@@ -345,13 +376,14 @@
String cp=System.getProperty("java.class.path")+ sep +
ctxt.getClassPath() + sep + ctxt.getOutputDir();
javac.setClasspath( cp );
- if( debug>0) log( "ClassPath " + cp);
+ if( debug>5) log( "ClassPath " + cp);
ByteArrayOutputStream out = new ByteArrayOutputStream (256);
javac.setOutputDir(ctxt.getOutputDir());
javac.setMsgOutput(out);
String javaFileName = mangler.getJavaFileName();
+ if( debug>0) log( "Compiling java file " + javaFileName);
/**
* Execute the compiler
*/
@@ -367,6 +399,7 @@
throw new JasperException("Unable to compile "
+ msg);
}
+ if( debug > 0 ) log("Compiled ok");
}
/** tool for customizing javac
@@ -415,11 +448,13 @@
*/
class JspInfo {
Request request;
-
- String uri; // path
+ String jspPath; // real jsp path - if the request URI is mapped to
+ // a named jsp.
+ String uri; // path from request URI
+
int version; // version
- int debug=0;
+ int debug=9;
String pkg;
String pkgDir;
String baseClassN;
@@ -436,13 +471,15 @@
long compileTime;// tstamp of last compile attemp
Exception compileException; // translation/compile exception
-
+ Dependency expireCheck=new Dependency();
+
JspInfo( Request req ) {
+ expireCheck.setLocal( true );
init( req );
}
public String toString() {
- return uri +" " + version;
+ return "JSPInfo: " + jspPath + " " + uri +" " + version;
}
/** Update compile time
@@ -519,22 +556,28 @@
compileException = null;
// String includeUri
// = (String) req.getAttribute(Constants.INC_SERVLET_PATH);
+ Handler w=req.getHandler();
uri=req.getServletPath();
+
+ if("jsp".equals( w.getName()))
+ jspPath=uri;
+ else
+ jspPath=((ServletHandler)w).getServletInfo().getPath();
Context ctx=req.getContext();
outputDir = ctx.getWorkDir().getAbsolutePath();
String jspFilePath=FileUtil.safePath( ctx.getAbsolutePath(),
- uri);
+ jspPath);
jspSource = new File(jspFilePath);
// extension
- int lastComp=uri.lastIndexOf( "/" );
+ int lastComp=jspPath.lastIndexOf( "/" );
String endUnproc=null;
if( lastComp > 0 ) {
// has package
- pkgDir=uri.substring( 1, lastComp );
- endUnproc=uri.substring( lastComp+1 );
+ pkgDir=jspPath.substring( 1, lastComp );
+ endUnproc=jspPath.substring( lastComp+1 );
} else {
- endUnproc=uri.substring( 1 );
+ endUnproc=jspPath.substring( 1 );
}
if( pkgDir!=null ) {
@@ -554,10 +597,10 @@
baseClassN=endUnproc;
}
// XXX insert "mangle" to make names safer
- if (pkgDir!=null)
- mapPath = outputDir + "/" + pkgDir + "/" + baseClassN + ".ver";
- else
- mapPath = outputDir + "/" + baseClassN + ".ver";
+ if (pkgDir!=null)
+ mapPath = outputDir + "/" + pkgDir + "/" + baseClassN + ".ver";
+ else
+ mapPath = outputDir + "/" + baseClassN + ".ver";
File mapFile=new File(mapPath);
if( mapFile.exists() ) {
@@ -570,11 +613,20 @@
updateVersionedPaths();
compileTime=0;
}
-
+
+ expireCheck.setOrigin( jspSource );
+ expireCheck.setTarget( this );
+ // if the file has been compiled before, we'll use the
+ // time of the compilation.
+ expireCheck.setLastModified( compileTime );
+ // update isExpired()
+ expireCheck.checkExpiry();
+
if( debug>0 )
log("uri=" + uri +
//" outputDir=" + outputDir +
- //" jspSource=" + jspSource +
+ " jspSource=" + jspSource +
+ " jspPath=" + jspPath +
" pkgDir=" + pkgDir +
" baseClassN=" + baseClassN +
" ext=" + ext +
1.19 +0 -4 jakarta-tomcat/src/share/org/apache/tomcat/context/AutoSetup.java
Index: AutoSetup.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/AutoSetup.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- AutoSetup.java 2000/11/02 00:43:48 1.18
+++ AutoSetup.java 2000/12/13 19:58:00 1.19
@@ -174,8 +174,4 @@
}
}
- public void setDebug( int i ) {
- debug=i;
- }
-
}
1.12 +17 -13 jakarta-tomcat/src/share/org/apache/tomcat/context/ErrorHandler.java
Index: ErrorHandler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/ErrorHandler.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ErrorHandler.java 2000/12/12 00:42:43 1.11
+++ ErrorHandler.java 2000/12/13 19:58:00 1.12
@@ -102,13 +102,13 @@
{
if( ctx.getHost() == null && ctx.getPath().equals(""))
rootContext = ctx;
- ctx.addServlet( new ExceptionHandler());
- ctx.addServlet( new StatusHandler());
+ ctx.addServlet( new ExceptionHandler(this));
+ ctx.addServlet( new StatusHandler(this));
// Default status handlers
- ctx.addServlet( new RedirectHandler());
+ ctx.addServlet( new RedirectHandler(this));
ctx.addErrorPage( "302", "tomcat.redirectHandler");
- ctx.addServlet( new NotFoundHandler());
+ ctx.addServlet( new NotFoundHandler(this));
ctx.addErrorPage( "404", "tomcat.notFoundHandler");
}
@@ -186,7 +186,7 @@
// has clicked "STOP"
// we need to log any other error - something may be
// broken if the error servlet has errors.
- ctx.log( "Error in errorServlet", ex);
+ ctx.log( "Error in default status handler", ex);
}
}
@@ -330,9 +330,10 @@
getManager("org.apache.tomcat.resources");
int sbNote=0;
- NotFoundHandler() {
- setOrigin( Handler.ORIGIN_INTERNAL );
+ NotFoundHandler(BaseInterceptor bi) {
+ // setOrigin( Handler.ORIGIN_INTERNAL );
name="tomcat.notFoundHandler";
+ setModule(bi);
}
public void doService(Request req, Response res)
@@ -382,9 +383,10 @@
getManager("org.apache.tomcat.resources");
int sbNote=0;
- ExceptionHandler() {
- setOrigin( Handler.ORIGIN_INTERNAL );
+ ExceptionHandler(BaseInterceptor bi) {
+ // setOrigin( Handler.ORIGIN_INTERNAL );
name="tomcat.exceptionHandler";
+ setModule( bi );
}
public void doService(Request req, Response res)
@@ -455,9 +457,10 @@
getManager("org.apache.tomcat.resources");
int sbNote=0;
- StatusHandler() {
- setOrigin( Handler.ORIGIN_INTERNAL );
+ StatusHandler(BaseInterceptor bi) {
+ //setOrigin( Handler.ORIGIN_INTERNAL );
name="tomcat.statusHandler";
+ setModule( bi );
}
// We don't want interceptors called for redirect
@@ -515,9 +518,10 @@
getManager("org.apache.tomcat.resources");
int sbNote=0;
- RedirectHandler() {
- setOrigin( Handler.ORIGIN_INTERNAL );
+ RedirectHandler(BaseInterceptor bi) {
+ //setOrigin( Handler.ORIGIN_INTERNAL );
name="tomcat.redirectHandler";
+ setModule( bi );
}
// We don't want interceptors called for redirect
1.30 +15 -7 jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java
Index: BaseInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- BaseInterceptor.java 2000/12/04 18:47:46 1.29
+++ BaseInterceptor.java 2000/12/13 19:58:00 1.30
@@ -409,16 +409,20 @@
// -------------------- Helpers --------------------
// Methods used in internal housekeeping
- public void setDebug( int d ) {
+ public final void setDebug( int d ) {
debug=d;
}
- public void setContextManager( ContextManager cm ) {
+ public final void setContextManager( ContextManager cm ) {
this.cm=cm;
this.ct=cm.getContainer();
loghelper.setLogger(cm.getLogger());
}
+ public final ContextManager getContextManager() {
+ return cm;
+ }
+
/** Called for context-level interceptors
*/
public void setContext( Context ctx ) {
@@ -428,23 +432,27 @@
loghelper.setLogger(ctx.getLog().getLogger());
}
- public void log( String s ) {
+ public final void log( String s ) {
loghelper.log(s);
}
- public void log( String s, Throwable t ) {
+ public final void log( String s, Throwable t ) {
loghelper.log(s, t);
}
- public void log( String s, int level ) {
+ public final void log( String s, int level ) {
loghelper.log(s, level);
}
- public void log( String s, Throwable t, int level ) {
+ public final void log( String s, Throwable t, int level ) {
loghelper.log(s, t, level);
}
- public int getDebug() {
+ public Log getLog() {
+ return loghelper;
+ }
+
+ public final int getDebug() {
return debug;
}
1.129 +6 -2 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.128
retrieving revision 1.129
diff -u -r1.128 -r1.129
--- Context.java 2000/12/12 00:42:44 1.128
+++ Context.java 2000/12/13 19:58:01 1.129
@@ -327,7 +327,8 @@
containers.put( path, map );
mappings.put( path, sw );
-
+ if( debug > 4 )
+ log( "Map " + path + " -> " + mappings.get(path));
}
/** Will add a new security constraint:
@@ -492,6 +493,7 @@
if( "/".equals(path) )
path="";
this.path = path;
+ loghelper.setLogPrefix("Ctx("+ path +") ");
}
/**
@@ -819,7 +821,7 @@
public final void addServlet(Handler wrapper)
throws TomcatException
{
- wrapper.setContext( this );
+ // wrapper.setContext( this );
wrapper.setState( Handler.STATE_ADDED );
String name=wrapper.getName();
@@ -828,6 +830,8 @@
log("Removing duplicate servlet " + name + " " + wrapper);
removeServletByName(name);
}
+ if( debug>5 ) log( "Adding servlet=" + name + "-> "
+ + wrapper);
servlets.put(name, wrapper);
}
1.29 +29 -81 jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java
Index: Handler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- Handler.java 2000/12/12 22:33:02 1.28
+++ Handler.java 2000/12/13 19:58:01 1.29
@@ -92,47 +92,6 @@
* @author Costin Manolache
*/
public class Handler {
- /** accounting - various informations we capture about servlet
- * execution.
- * // XXX Not implemented
- * @see org.apache.tomcat.util.Counters
- */
- public static final int ACC_LAST_ACCESSED=0;
- public static final int ACC_INVOCATION_COUNT=1;
- public static final int ACC_SERVICE_TIME=2;
- public static final int ACC_ERRORS=3;
- public static final int ACC_OVERHEAD=4;
- public static final int ACC_IN_INCLUDE=5;
-
- public static final int ACCOUNTS=6;
-
- // -------------------- Origin --------------------
- /** The handler is declared in a configuration file.
- */
- public static final int ORIGIN_WEB_XML=0;
- /** The handler is automatically added by an "invoker" interceptor,
- * that is able to add new servlets based on request
- */
- public static final int ORIGIN_INVOKER=1;
- /** The handler is automatically added by an interceptor that
- * implements a templating system.
- */
- public static final int ORIGIN_JSP=2;
- /** any tomcat-specific component that can
- register mappings that are "re-generable",
- i.e. can be recreated - the mapping can
- safely be removed.
- */
- public static final int ORIGIN_DYNAMIC=3;
- /** The handler was added by the admin interface, it should be saved
- * preferably in web.xml
- */
- public static final int ORIGIN_ADMIN=4;
-
- /** This handler is created internally by tomcat
- */
- public static final int ORIGIN_INTERNAL=5;
-
// -------------------- State --------------------
/** The handler is new, not part of any application.
@@ -159,22 +118,21 @@
public static final int STATE_DISABLED=4;
// -------------------- Properties --------------------
- protected Context context;
+ // the handler is part of a module
+ protected BaseInterceptor module;
+
protected ContextManager contextM;
protected String name;
protected int state=STATE_NEW;
- // who creates the servlet definition
- protected int origin;
-
protected Exception errorException=null;
// Debug
protected int debug=0;
protected Log logger=null;
- private Counters cntr=new Counters( ACCOUNTS );
+ private Counters cntr=new Counters(ContextManager.MAX_NOTES);
private Object notes[]=new Object[ContextManager.MAX_NOTES];
// -------------------- Constructor --------------------
@@ -184,23 +142,25 @@
public Handler() {
}
- /** A handler "belongs" to a single application ( many->one ).
- * We don't support handlers that spawn multiple Contexts -
- * the model is simpler because we can set the security constraints,
- * properties, etc on a application basis.
- */
- public final void setContext( Context context) {
- this.context = context;
- contextM=context.getContextManager();
- logger=context.getLog();
+ /** A handler is part of a module. The module can create a number
+ of handlers. Since the module is configurable, it can
+ also configure the handlers - including debug, etc.
+
+ The handler shares the same log file with the module ( it
+ can log to different logs, but the default for debug information
+ is shared with the other components of a module ).
+ */
+ public void setModule(BaseInterceptor module ) {
+ this.module=module;
+ contextM=module.getContextManager();
+ debug=module.getDebug();
+ logger=module.getLog();
}
- /** Return the context associated with the handler
- */
- public final Context getContext() {
- return context;
+ public BaseInterceptor getModule() {
+ return module;
}
-
+
// -------------------- configuration --------------------
public int getState() {
@@ -219,27 +179,6 @@
this.name=handlerName;
}
- /** Who created this servlet definition - default is 0, i.e. the
- * web.xml mapping. It can also be the Invoker, the admin ( by using a
- * web interface), JSP engine or something else.
- *
- * Tomcat can do special actions - for example remove non-used
- * mappings if the source is the invoker or a similar component
- */
- public final void setOrigin( int origin ) {
- this.origin=origin;
- }
-
- public final int getOrigin() {
- return origin;
- }
-
- /** Accounting information
- */
- public final Counters getCounters() {
- return cntr;
- }
-
// -------------------- Common servlet attributes
/** Sets an exception that relates to the ability of the
servlet to execute. An exception may be set by an
@@ -386,5 +325,14 @@
public final Object getNote( int pos ) {
return notes[pos];
}
+
+ /** Accounting information. Not implemented - it'll contain usefull
+ information like LAST_ACCESSED, INVOCATION_COUNT, SERVICE_TIME,
+ ERRROS, IN_INCLUDE, etc.
+ */
+ public final Counters getCounters() {
+ return cntr;
+ }
+
}
1.6 +0 -4 jakarta-tomcat/src/share/org/apache/tomcat/modules/session/SessionId.java
Index: SessionId.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/session/SessionId.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SessionId.java 2000/12/01 08:19:14 1.5
+++ SessionId.java 2000/12/13 19:58:02 1.6
@@ -101,10 +101,6 @@
public SessionId() {
}
- public void setContextManager( ContextManager cm ) {
- this.cm=cm;
- }
-
public void setNoCookies(boolean noCookies) {
this.noCookies = noCookies;
}
1.27 +13 -7 jakarta-tomcat/src/share/org/apache/tomcat/request/AccessInterceptor.java
Index: AccessInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/AccessInterceptor.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- AccessInterceptor.java 2000/12/12 00:42:48 1.26
+++ AccessInterceptor.java 2000/12/13 19:58:03 1.27
@@ -135,7 +135,9 @@
if(page==null || errorPage==null) {
ctx.log( "Form login without form pages, defaulting to basic "
+ page + " " + errorPage);
- ctx.addServlet( new BasicAuthHandler());
+ BasicAuthHandler baH=new BasicAuthHandler();
+ baH.setModule( this );
+ ctx.addServlet( baH );
ctx.addErrorPage( "401", "tomcat.basicAuthHandler");
return;
}
@@ -173,9 +175,11 @@
ctx.setFormErrorPage( errorPage );
FormAuthHandler formH=new FormAuthHandler();
- formH.setDebug(20);
+ formH.setModule( this );
ctx.addServlet( formH );
- ctx.addServlet( new FormSecurityCheckHandler() );
+ FormSecurityCheckHandler fscH=new FormSecurityCheckHandler();
+ fscH.setModule( this );
+ ctx.addServlet( fscH );
ctx.addErrorPage( "401", "tomcat.formAuthHandler");
// Add mapping for the POST handler
@@ -193,7 +197,9 @@
" to tomcat.formSecurityCheck for " +
page);
} else if( "BASIC".equals( login_type )) {
- ctx.addServlet( new BasicAuthHandler());
+ BasicAuthHandler baH=new BasicAuthHandler();
+ baH.setModule( this );
+ ctx.addServlet( baH );
ctx.addErrorPage( "401", "tomcat.basicAuthHandler");
} else {
// if unknown, leave the normal 404 error handler to deal
@@ -344,7 +350,7 @@
int sbNote=0;
BasicAuthHandler() {
- setOrigin( Handler.ORIGIN_INTERNAL );
+ // setOrigin( Handler.ORIGIN_INTERNAL );
name="tomcat.basicAuthHandler";
}
@@ -390,7 +396,7 @@
class FormAuthHandler extends Handler {
FormAuthHandler() {
- setOrigin( Handler.ORIGIN_INTERNAL );
+ // setOrigin( Handler.ORIGIN_INTERNAL );
name="tomcat.formAuthHandler";
}
@@ -447,7 +453,7 @@
class FormSecurityCheckHandler extends Handler {
FormSecurityCheckHandler() {
- setOrigin( Handler.ORIGIN_INTERNAL );
+ // setOrigin( Handler.ORIGIN_INTERNAL );
name="tomcat.formSecurityCheck";
}
1.6 +0 -8 jakarta-tomcat/src/share/org/apache/tomcat/request/AccountingInterceptor.java
Index: AccountingInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/AccountingInterceptor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AccountingInterceptor.java 2000/10/01 22:21:45 1.5
+++ AccountingInterceptor.java 2000/12/13 19:58:03 1.6
@@ -80,18 +80,10 @@
public AccountingInterceptor() {
}
- public void setDebug( int i ) {
- debug=i;
- }
-
public void setTrace( String file ) {
trace=file;
}
- public void setContextManager( ContextManager cm ) {
- this.cm=cm;
- }
-
/** Called when the ContextManger is started
*/
public void engineInit(ContextManager cm) throws TomcatException {
1.16 +1 -1 jakarta-tomcat/src/share/org/apache/tomcat/request/InvokerInterceptor.java
Index: InvokerInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/InvokerInterceptor.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- InvokerInterceptor.java 2000/12/08 23:18:48 1.15
+++ InvokerInterceptor.java 2000/12/13 19:58:03 1.16
@@ -151,7 +151,7 @@
// sw.setServletName(servletName);
// ctx.addServlet( sw );
// sw.setServletClass( servletName );
- sw.setOrigin( Handler.ORIGIN_INVOKER );
+ //sw.setOrigin( Handler.ORIGIN_INVOKER );
wrapper=sw;
if( debug > 0)
1.12 +0 -8 jakarta-tomcat/src/share/org/apache/tomcat/request/Jdk12Interceptor.java
Index: Jdk12Interceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/Jdk12Interceptor.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Jdk12Interceptor.java 2000/08/02 02:17:27 1.11
+++ Jdk12Interceptor.java 2000/12/13 19:58:03 1.12
@@ -76,14 +76,6 @@
public Jdk12Interceptor() {
}
- public void setContextManager( ContextManager cm ) {
- this.cm=cm;
- }
-
- public void setDebug( int i ) {
- debug=i;
- }
-
public void preServletInit( Context ctx, Handler sw )
throws TomcatException
{
1.27 +23 -9 jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java
Index: StaticInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- StaticInterceptor.java 2000/12/12 00:42:48 1.26
+++ StaticInterceptor.java 2000/12/13 19:58:03 1.27
@@ -106,13 +106,16 @@
{
FileHandler fileHandler=new FileHandler();
DirHandler dirHandler=new DirHandler();
+ fileHandler.setModule( this );
+ fileHandler.setContext( ctx );
fileHandler.setNoteId( realFileNote );
- dirHandler.setNoteId( realFileNote );
ctx.addServlet( fileHandler );
+
+ dirHandler.setNoteId( realFileNote );
+ dirHandler.setContext( ctx );
+ dirHandler.setModule( this );
if (listings)
ctx.addServlet( dirHandler );
- fileHandler.setDebug( debug );
- dirHandler.setDebug( debug );
}
public int requestMap(Request req) {
@@ -129,7 +132,8 @@
String absPath=FileUtil.safePath( ctx.getAbsolutePath(),
pathInfo);
- if( debug > 0 ) log( "RequestMap " + req + " " + absPath + " " + ctx.getAbsolutePath() );
+ if( debug > 0 ) log( "RequestMap " + req + " " + absPath + " " +
+ ctx.getAbsolutePath() );
if( absPath == null ) return 0;
String requestURI=req.requestURI().toString();
@@ -213,14 +217,19 @@
/** Serve the content of a file ( and nothing more !).
*
*/
-class FileHandler extends Handler {
+final class FileHandler extends Handler {
int realFileNote;
-
+ Context context;
+
FileHandler() {
- setOrigin( Handler.ORIGIN_INTERNAL );
+ // setOrigin( Handler.ORIGIN_INTERNAL );
name="tomcat.fileHandler";
}
+ public void setContext(Context ctx) {
+ this.context=ctx;
+ }
+
public void setNoteId( int n ) {
realFileNote=n;
}
@@ -322,13 +331,14 @@
/** HTML-display for directories ( and nothing more !).
* This is the handler for static resources of type "dir".
*/
-class DirHandler extends Handler {
+final class DirHandler extends Handler {
private static final String datePattern = "EEE, dd MMM yyyyy HH:mm z";
int realFileNote;
int sbNote=0;
+ Context context;
DirHandler() {
- setOrigin( Handler.ORIGIN_INTERNAL );
+ // setOrigin( Handler.ORIGIN_INTERNAL );
name="tomcat.dirHandler";
}
@@ -336,6 +346,10 @@
realFileNote=n;
}
+ public void setContext(Context ctx) {
+ this.context=ctx;
+ }
+
public void doService(Request req, Response res)
throws Exception
{
1.8 +88 -0 jakarta-tomcat/src/tests/webpages/WEB-INF/web.xml
Index: web.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/tests/webpages/WEB-INF/web.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- web.xml 2000/07/06 22:55:37 1.7
+++ web.xml 2000/12/13 19:58:04 1.8
@@ -37,6 +37,94 @@
requestMap.Servlet4
</servlet-class>
</servlet>
+
+ <servlet>
+ <servlet-name>
+ jspParams1
+ </servlet-name>
+ <jsp-file>
+ /jsp/params.jsp
+ </jsp-file>
+ <init-param>
+ <param-name>abc</param-name>
+ <param-value>def</param-value>
+ </init-param>
+ </servlet>
+ <servlet>
+ <servlet-name>
+ jspParams2.jsp
+ </servlet-name>
+ <jsp-file>
+ /jsp/params.jsp
+ </jsp-file>
+ <init-param>
+ <param-name>xyz</param-name>
+ <param-value>klm</param-value>
+ </init-param>
+ </servlet>
+ <servlet>
+ <servlet-name>
+ jspParams3
+ </servlet-name>
+ <jsp-file>
+ /jsp/params.jsp
+ </jsp-file>
+ <init-param>
+ <param-name>foo</param-name>
+ <param-value>bar</param-value>
+ </init-param>
+ <init-param>
+ <param-name>foo1</param-name>
+ <param-value>bar1</param-value>
+ </init-param>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>
+ jspParams1
+ </servlet-name>
+ <url-pattern>
+ /jsp/jspParams1
+ </url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>
+ jspParams1
+ </servlet-name>
+ <url-pattern>
+ /jsp/jspParams11
+ </url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>
+ jspParams2.jsp
+ </servlet-name>
+ <url-pattern>
+ /jsp/jspParams2
+ </url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>
+ jspParams2.jsp
+ </servlet-name>
+ <url-pattern>
+ /jsp/jspParams2.jsp
+ </url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>
+ jspParams3
+ </servlet-name>
+ <url-pattern>
+ /jsp/jspParams3
+ </url-pattern>
+ </servlet-mapping>
+
+
+
<servlet-mapping>
<servlet-name>
servlet1
1.1 jakarta-tomcat/src/tests/webpages/jsp/params.jsp
Index: params.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<h1> Jsp params: </h1>
<font size="4">
<%
javax.servlet.ServletConfig sc=getServletConfig();
java.util.Enumeration enum=sc.getInitParameterNames();
while( enum.hasMoreElements() ) {
String name=(String)enum.nextElement();
%>
Parameter <%= name %> = <%= sc.getInitParameter( name ) %>
<br>
<%
}
%>
</font>
</body>
</html>