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/10/02 00:21:47 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util Counters.java
costin 00/10/01 15:21:47
Modified: src/share/org/apache/tomcat/context WorkDirInterceptor.java
src/share/org/apache/tomcat/core Container.java Context.java
ContextManager.java Handler.java Request.java
Response.java
src/share/org/apache/tomcat/request
AccountingInterceptor.java ReloadInterceptor.java
src/share/org/apache/tomcat/service/connector
Ajp12ConnectionHandler.java
src/share/org/apache/tomcat/startup EmbededTomcat.java
src/share/org/apache/tomcat/util Counters.java
Log:
- removed host and port from ContextManager. (since we support multiple
hosts).
- We now generate the temp dir with DEFAULT for the default host ( used
to be localhost%8080 ), and the name of the virtual host where set.
- Added "state" to Context ( it's not checked, but it's a start )
- commented the states for ContextManager
- made final what is final in ContextManager ( the extension mechanism
is interceptor, if you need something else it's better to fix the
interceptor than hack CM )
- moved doAuth* in request, where it's used ( no need to call container
intereptors via CM )
- made private all the fields in CM
- removed deprecated methods ( some of them ).
- moved code around in Request - group getter/setter, group by function
Remove unused/deprecated code.( a small part - there is still a lot)
Revision Changes Path
1.13 +2 -2 jakarta-tomcat/src/share/org/apache/tomcat/context/WorkDirInterceptor.java
Index: WorkDirInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/WorkDirInterceptor.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- WorkDirInterceptor.java 2000/09/26 04:58:24 1.12
+++ WorkDirInterceptor.java 2000/10/01 22:21:44 1.13
@@ -120,10 +120,10 @@
sb.append(File.separator);
String host=ctx.getHost();
if( host==null )
- sb.append(cm.getHostName() );
+ sb.append( "DEFAULT" );
else
sb.append( host );
- sb.append("_").append(cm.getPort());
+ // sb.append("_").append(cm.getPort());
sb.append(URLEncoder.encode( ctx.getPath() ));
ctx.setWorkDir( new File(sb.toString()));
1.37 +3 -1 jakarta-tomcat/src/share/org/apache/tomcat/core/Container.java
Index: Container.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Container.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- Container.java 2000/10/01 06:37:44 1.36
+++ Container.java 2000/10/01 22:21:44 1.37
@@ -67,6 +67,8 @@
import java.util.*;
import org.apache.tomcat.core.*;
+// XXX better names: Location, URLPattern,
+
/**
* A group of resources, with some common properties.
* Container is similar with Apache "dir_conf" structue.
@@ -493,7 +495,7 @@
// debug
- public static final int dL=4;
+ public static final int dL=0;
private void debug( String s ) {
System.out.println("Container: " + s );
}
1.125 +19 -0 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.124
retrieving revision 1.125
diff -u -r1.124 -r1.125
--- Context.java 2000/10/01 06:37:44 1.124
+++ Context.java 2000/10/01 22:21:44 1.125
@@ -128,6 +128,19 @@
*/
public static final String ATTRIB_REAL_CONTEXT="org.apache.tomcat.context";
+ /** Context is new, not even added to server. ContextManager is not
+ set, and most of the paths are not fixed
+ */
+ public static final int STATE_PRE_ADD=0;
+ /** Context was added to the server. Relative paths are fixed, based
+ on server base, and CM is set.
+ */
+ public static final int STATE_ADD=1;
+ /** Context is initialized and ready to serve. We have all mappings
+ and configs from web.xml.
+ */
+ public static final int STATE_INIT=2;
+
// -------------------- internal properties
// context "id"
private String path = "";
@@ -137,6 +150,8 @@
// Absolute path to docBase if file-system based
private String absPath;
+
+ private int state=STATE_PRE_ADD;
// internal state / related objects
private ContextManager contextM;
@@ -439,6 +454,10 @@
return defaultContainer;
}
+ public final int getState() {
+ return state;
+ }
+
// -------------------- Basic properties --------------------
/** Base URL for this context
1.142 +138 -251 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.141
retrieving revision 1.142
diff -u -r1.141 -r1.142
--- ContextManager.java 2000/10/01 06:37:45 1.141
+++ ContextManager.java 2000/10/01 22:21:44 1.142
@@ -200,14 +200,24 @@
public static final int ACCOUNTS=2;
// State
- public static final int STATE_INITIAL=0;
- public static final int STATE_INITIALIZED=1;
- public static final int STATE_STARTED=2;
- public static final int STATE_STOPED=3;
+ /** Server is not initialized
+ */
+ public static final int STATE_PRE_INIT=0;
+ /** Server was initialized, engineInit() was called.
+ addContext() can be called.
+ */
+ public static final int STATE_INIT=1;
+ /** Engine is running. All configured contexts are
+ initialized ( contextInit()), and requests can be served.
+ */
+ public static final int STATE_START=2;
+ /** Engine has stoped
+ */
+ public static final int STATE_STOP=3;
// -------------------- local variables --------------------
- private int state=STATE_INITIAL;
+ private int state=STATE_PRE_INIT;
/** Contexts managed by this server
*/
@@ -231,6 +241,7 @@
*/
private String installDir;
+ private Context rootContext;
private Container defaultContainer;
@@ -266,7 +277,7 @@
* It will tehn call initContext() for all the contexts (
* including those added by interceptors )
*/
- public void init() throws TomcatException {
+ public final void init() throws TomcatException {
if(debug>0 ) log( "Tomcat classpath = " +
System.getProperty( "java.class.path" ));
@@ -277,7 +288,7 @@
cI[i].engineInit( this );
}
- state=STATE_INITIALIZED;
+ state=STATE_INIT;
Enumeration existingCtxE=contextsV.elements();
while( existingCtxE.hasMoreElements() ) {
@@ -295,7 +306,7 @@
/** Remove all contexts.
* Call Intereptor.engineShutdown hooks.
*/
- public void shutdown() throws TomcatException {
+ public final void shutdown() throws TomcatException {
Enumeration enum = getContexts();
while (enum.hasMoreElements()) {
removeContext((Context)enum.nextElement());
@@ -307,22 +318,9 @@
}
}
- /**
- * Initializes this context to be able to accept requests. This action
- * will cause the context to load it's configuration information
- * from the webapp directory in the docbase.
- *
- * <p>This method must be called
- * before any requests are handled by this context. It will be called
- * after the context was added, typically when the engine starts
- * or after the admin adds a new context.
- */
- public void initContext( Context ctx ) throws TomcatException {
- }
-
/** Stop the context and release all resources.
*/
- public void shutdownContext( Context ctx ) throws TomcatException {
+ public final void shutdownContext( Context ctx ) throws TomcatException {
// XXX This is here by accident, it should be moved as part
// of a normal context interceptor that will handle all standard
// start/stop actions
@@ -352,7 +350,7 @@
* hooks, there is no need for special code here - in the worst
* case we should add a new hook
*/
- public void start() throws Exception {
+ public final void start() throws Exception {
// init contexts
Enumeration enum = getContexts();
while (enum.hasMoreElements()) {
@@ -371,12 +369,12 @@
}
// Note that contextInit() will triger other
- state=STATE_STARTED;
+ state=STATE_START;
}
/** Will stop all connectors
*/
- public void stop() throws Exception {
+ public final void stop() throws Exception {
shutdown();
}
@@ -393,11 +391,11 @@
* The "tomcat.home" system property is used if no explicit
* value is set.
*/
- public void setHome(String home) {
+ public final void setHome(String home) {
this.home=home;
}
- public String getHome() {
+ public final String getHome() {
return home;
}
@@ -409,53 +407,53 @@
* is used as default.
*
*/
- public String getInstallDir() {
+ public final String getInstallDir() {
return installDir;
}
- public void setInstallDir( String tH ) {
+ public final void setInstallDir( String tH ) {
installDir=tH;
}
/**
* WorkDir property - where all working files will be created
*/
- public void setWorkDir( String wd ) {
+ public final void setWorkDir( String wd ) {
if(debug>0) log("set work dir " + wd);
this.workDir=wd;
}
- public String getWorkDir() {
+ public final String getWorkDir() {
return workDir;
}
/** Sets the name of the class used for generating random numbers by the
* session id generator. By default this is <code>java.security.SecureRandom</code>.
*/
- public void setRandomClass(String randomClass) {
+ public final void setRandomClass(String randomClass) {
System.setProperty(RANDOM_CLASS_PROPERTY, randomClass);
}
- public String getRandomClass() {
+ public final String getRandomClass() {
String randomClass = System.getProperty(RANDOM_CLASS_PROPERTY);
return randomClass == null ? "java.security.SecureRandom" : randomClass;
}
/** Debug level
*/
- public void setDebug( int level ) {
+ public final void setDebug( int level ) {
if( level != debug )
log( "Setting debug level to " + level);
debug=level;
}
- public int getDebug() {
+ public final int getDebug() {
return debug;
}
// -------------------- Other properties --------------------
- public int getState() {
+ public final int getState() {
return state;
}
@@ -470,38 +468,63 @@
* it is configured to - for example trusted webapps
* may have tomcat internal classes in classpath.
*/
- public void setParentLoader( ClassLoader cl ) {
+ public final void setParentLoader( ClassLoader cl ) {
parentLoader=cl;
}
- public ClassLoader getParentLoader() {
+ public final ClassLoader getParentLoader() {
return parentLoader;
}
- public URL[] getServerClassPath() {
+ public final URL[] getServerClassPath() {
if( serverClassPath==null ) return new URL[0];
return serverClassPath;
}
- public void setServerClassPath( URL urls[] ) {
+ public final void setServerClassPath( URL urls[] ) {
serverClassPath=urls;
}
/** Default container
*/
- public Container getContainer() {
+ public final Container getContainer() {
return defaultContainer;
}
- public void setContainer(Container newDefaultContainer) {
+ public final void setContainer(Container newDefaultContainer) {
defaultContainer = newDefaultContainer;
}
+ /** Accounting support - various counters associated with the server
+ */
+ public final Counters getCounters() {
+ return cntr;
+ }
+
// -------------------- Contexts --------------------
+ /**
+ * Initializes this context to be able to accept requests. This action
+ * will cause the context to load it's configuration information
+ * from the webapp directory in the docbase.
+ *
+ * <p>This method must be called
+ * before any requests are handled by this context. It will be called
+ * after the context was added, typically when the engine starts
+ * or after the admin adds a new context.
+ */
+ public final void initContext( Context ctx ) throws TomcatException {
+ if( state!= STATE_PRE_INIT ) {
+ BaseInterceptor cI[]=getInterceptors(ctx.getContainer());
+ for( int i=0; i< cI.length; i++ ) {
+ cI[i].contextInit( ctx );
+ }
+ }
+ }
+
/** Return the list of contexts managed by this server
*/
- public Enumeration getContexts() {
+ public final Enumeration getContexts() {
return contextsV.elements();
}
@@ -510,7 +533,7 @@
*
* @param ctx context to be added.
*/
- public void addContext( Context ctx ) throws TomcatException {
+ public final void addContext( Context ctx ) throws TomcatException {
log("Adding context " + ctx.toString());
// Make sure context knows about its manager.
ctx.setContextManager( this );
@@ -519,12 +542,11 @@
// to deal with that ( either replace or throw an exception ).
contextsV.addElement( ctx );
- // XXX temporary workaround for the old SimpleMapper -
- // XXX hack - should be removed
- if( ctx.getHost() ==null ) contexts.put( ctx.getPath(), ctx );
-
- if( state == STATE_INITIAL )
+ if( ctx.getHost() == null && ctx.getPath().equals(""))
+ rootContext = ctx;
+
+ if( state == STATE_PRE_INIT )
return;
BaseInterceptor cI[]=getInterceptors(ctx.getContainer());
@@ -535,7 +557,7 @@
/** Shut down and removes a context from service
*/
- public void removeContext( Context context ) throws TomcatException {
+ public final void removeContext( Context context ) throws TomcatException {
if( context==null ) return;
log( "Removing context " + context.toString());
@@ -547,7 +569,6 @@
shutdownContext( context );
contextsV.removeElement(context);
- contexts.remove(context.getPath());
}
@@ -555,19 +576,19 @@
// The interceptors are handled per/container ( thanks to Nacho
// for this contribution ).
- public void addInterceptor( BaseInterceptor ri ) {
+ public final void addInterceptor( BaseInterceptor ri ) {
defaultContainer.addInterceptor(ri);
}
- public BaseInterceptor[] getInterceptors() {
+ public final BaseInterceptor[] getInterceptors() {
return defaultContainer.getInterceptors();
}
- public BaseInterceptor[] getInterceptors( Container ct ) {
+ public final BaseInterceptor[] getInterceptors( Container ct ) {
return ct.getInterceptors();
}
- public BaseInterceptor[] getInterceptors( Request req ,
+ public final BaseInterceptor[] getInterceptors( Request req ,
int hook_id)
{
Context ctx=req.getContext();
@@ -585,7 +606,7 @@
/** Prepare the req/resp pair for use in tomcat.
* Call it after you create the request/response objects
*/
- public void initRequest( Request req, Response resp ) {
+ public final void initRequest( Request req, Response resp ) {
// used to be done in service(), but there is no need to do it
// every time.
// We may add other special calls here.
@@ -601,7 +622,7 @@
* call this method to get it processed.
* XXX make sure the alghoritm is right, deal with response codes
*/
- public void service( Request req, Response res ) {
+ public final void service( Request req, Response res ) {
internalService( req, res );
// clean up
try {
@@ -655,8 +676,19 @@
}
String roles[]=req.getRequiredRoles();
- if(roles != null )
- status=doAuthorize( req, res, roles );
+ if(roles != null ) {
+ status=0;
+ BaseInterceptor reqI[]= req.getContext().getContainer().
+ getInterceptors(Container.H_authorize);
+
+ // Call all authorization callbacks.
+ for( int i=0; i< reqI.length; i++ ) {
+ status = reqI[i].authorize( req, res, roles );
+ if ( status != 0 ) {
+ break;
+ }
+ }
+ }
if( status > 200 ) {
if( debug > 0)
log("Authorize error " + req + " " + status);
@@ -675,7 +707,7 @@
* the Context. This is also used by Dispatcher and getResource -
* where the Context is already known.
*/
- public int processRequest( Request req ) {
+ public final int processRequest( Request req ) {
if(debug>9) log("Before processRequest(): "+req.toString());
int status=0;
@@ -710,7 +742,7 @@
*
* Note that session and all stuff will still be computed.
*/
- public Request createRequest( Context ctx, String urlPath ) {
+ public final Request createRequest( Context ctx, String urlPath ) {
// assert urlPath!=null
// deal with paths with parameters in it
@@ -738,7 +770,7 @@
/** Create a new sub-request, deal with query string
*/
- public Request createRequest( String urlPath ) {
+ public final Request createRequest( String urlPath ) {
String queryString=null;
int i = urlPath.indexOf("?");
int len=urlPath.length();
@@ -755,11 +787,34 @@
return lr;
}
- // -------------------- Error handling --------------------
+ /**
+ * Find a context by doing a sub-request and mapping the request
+ * against the active rules ( that means you could use a /~costin
+ * if a UserHomeInterceptor is present )
+ *
+ * The new context will be in the same virtual host as base.
+ *
+ */
+ public final Context getContext(Context base, String path) {
+ // XXX Servlet checks should be done in facade
+ if (! path.startsWith("/")) {
+ return null; // according to spec, null is returned
+ // if we can't return a servlet, so it's more probable
+ // servlets will check for null than IllegalArgument
+ }
+ // absolute path
+ Request lr=this.createRequest( path );
+ if( base.getHost() != null ) lr.setServerName( base.getHost() );
+ this.processRequest(lr);
+ return lr.getContext();
+ }
+
+ // -------------------- Error handling --------------------
+
/** Called for error-codes
*/
- public void handleStatus( Request req, Response res, int code ) {
+ public final void handleStatus( Request req, Response res, int code ) {
String errorPath=null;
Handler errorServlet=null;
@@ -769,7 +824,7 @@
res.setStatus(code);
Context ctx = req.getContext();
- if(ctx==null) ctx=getContext("");
+ if(ctx==null) ctx=rootContext;
// don't log normal cases ( redirect and need_auth ), they are not
// error
@@ -823,7 +878,7 @@
void handleError( Request req, Response res , Throwable t ) {
Context ctx = req.getContext();
if(ctx==null) {
- ctx=getContext("");
+ ctx=rootContext;
}
/** The exception must be available to the user.
@@ -897,7 +952,7 @@
errorServlet.service( req, res );
}
- public Handler getHandlerForPath( Context ctx, String path ) {
+ public final Handler getHandlerForPath( Context ctx, String path ) {
if( ! path.startsWith( "/" ) ) {
return ctx.getServletByName( path );
}
@@ -948,8 +1003,8 @@
public static final int REQ_RE_NOTE=0;
- String noteName[][]=new String[NOTE_COUNT][MAX_NOTES];
-
+ private String noteName[][]=new String[NOTE_COUNT][MAX_NOTES];
+
/** used to allow interceptors to set specific per/request, per/container
* and per/CM informations.
*
@@ -971,7 +1026,7 @@
* container or request.
* @param name the name of the note.
*/
- public synchronized int getNoteId( int noteType, String name )
+ public final synchronized int getNoteId( int noteType, String name )
throws TomcatException
{
// find if we already have a note with this name
@@ -991,28 +1046,28 @@
return noteId[noteType]++;
}
- public String getNoteName( int noteType, int noteId ) {
+ public final String getNoteName( int noteType, int noteId ) {
return noteName[noteType][noteId];
}
// -------------------- Per-server notes --------------------
- Object notes[]=new Object[MAX_NOTES];
-
- public void setNote( int pos, Object value ) {
+ private Object notes[]=new Object[MAX_NOTES];
+
+ public final void setNote( int pos, Object value ) {
notes[pos]=value;
}
- public Object getNote( int pos ) {
+ public final Object getNote( int pos ) {
return notes[pos];
}
// -------------------- Logging and debug --------------------
- Log loghelper = new Log("tc_log", "ContextManager");
+ private Log loghelper = new Log("tc_log", "ContextManager");
/**
* Get the Logger object that the context manager is writing to (necessary?)
**/
- public Logger getLogger() {
+ public final Logger getLogger() {
return loghelper.getLogger();
}
@@ -1020,19 +1075,19 @@
* So other classes can piggyback on the context manager's log
* stream, using Logger.Helper.setProxy()
**/
- public Log getLog() {
+ public final Log getLog() {
return loghelper;
}
/**
* Force this object to use the given Logger.
**/
- public void setLogger( Logger logger ) {
+ public final void setLogger( Logger logger ) {
log("!!!! setLogger: " + logger, Logger.DEBUG);
loghelper.setLogger(logger);
}
- public void addLogger(Logger l) {
+ public final void addLogger(Logger l) {
if (debug>20)
log("addLogger: " + l, new Throwable("trace"), Logger.DEBUG);
@@ -1064,183 +1119,15 @@
loghelper.log(msg, t, level);
}
- // -------------------- Accounting --------------------
- // XXX Can be implemented as note !
-
- public Counters getCounters() {
- return cntr;
- }
-
- // -------------------- DEPRECATED --------------------
- // XXX host and port are used only to construct a unique
- // work-dir for contexts, using them and the path
- // Since nobody sets them - I guess we can just drop them
- // anyway.
- // XXX ask and find if there is any other use!
- public static final String DEFAULT_HOSTNAME="localhost";
- public static final int DEFAULT_PORT=8080;
- String hostname;
- int port;
-
- /**
- * Sets the port number on which this server listens.
- *
- * @param port The new port number
- * @deprecated
- */
- public void setPort(int port) {
- if (debug>0) log("setPort", new Throwable("trace"));
- this.port=port;
- }
-
- /**
- * Gets the port number on which this server listens.
- * @deprecated
- */
- public int getPort() {
- if(port==0) port=DEFAULT_PORT;
- return port;
- }
-
- /**
- * Sets the virtual host name of this server.
- *
- * @param host The new virtual host name
- * @deprecated
- */
- public void setHostName( String host) {
- if (debug>0) log("setHostName", new Throwable("trace"));
- this.hostname=host;
- }
-
- /**
- * Gets the virtual host name of this server.
- * @deprecated
- */
- public String getHostName() {
- // if (debug>0) log("getHostName", new Throwable("trace"));
- if(hostname==null)
- hostname=DEFAULT_HOSTNAME;
- return hostname;
- }
- // -------------------- DEPRECATED --------------------
-
- /**
- * The set of Contexts associated with this ContextManager,
- * keyed by context paths.
- * @deprecated - the server shouldn't make any assumptions about
- * the key.
- */
- private Hashtable contexts = new Hashtable();
-
- /**
- * Gets a context by it's name, or <code>null</code> if there is
- * no such context.
- *
- * @param name Name of the requested context
- * @deprecated Use an external iterator to find the context that
- * matches your conditions.
- *
- */
- public Context getContext(String name) {
- // loghelper.log("getContext(String) is deprecated", new Throwable("trace"), Logger.DEBUG);
- return (Context)contexts.get(name);
- }
-
-
- /**
- * Find a context by doing a sub-request and mapping the request
- * against the active rules ( that means you could use a /~costin
- * if a UserHomeInterceptor is present )
- *
- * XXX I think this should be in ContextManager
- */
- public final Context getContext(Context base, String path) {
- // XXX Servlet checks should be done in facade
- if (! path.startsWith("/")) {
- return null; // according to spec, null is returned
- // if we can't return a servlet, so it's more probable
- // servlets will check for null than IllegalArgument
- }
- // absolute path
- Request lr=this.createRequest( path );
- if( base.getHost() != null ) lr.setServerName( base.getHost() );
- this.processRequest(lr);
- return lr.getContext();
- }
-
-
- /**
- * Shut down and removes a context from service.
- *
- * @param name Name of the Context to be removed
- * @deprecated Use removeContext( Context ).
- */
- public void removeContext(String name) throws TomcatException {
- loghelper.log("removeContext(String) is deprecated", new Throwable("trace"), Logger.DEBUG);
- Context context = (Context)contexts.get(name);
- removeContext( context);
- }
-
-
// -------------------- Hook support --------------------
- public void doReload( Request req, Context context )
- throws TomcatException
- {
- if( context==null ) return;
-
- if( debug>0 ) log( "Reloading context " + context.toString());
-
- BaseInterceptor cI[]=getInterceptors(context.getContainer());
- for( int i=0; i< cI.length; i++ ) {
- cI[i].reload( req, context );
- }
- }
-
-
- /** Call all authentication callbacks. If any of them is able to
- identify the user it will set the principal in req.
- */
- public int doAuthenticate( Request req, Response res ) {
- int status=0;
- BaseInterceptor reqI[]= req.getContext().getContainer().
- getInterceptors(Container.H_authenticate);
- for( int i=0; i< reqI.length; i++ ) {
- status=reqI[i].authenticate( req, res );
- if ( status != 0 ) {
- if( debug>0) log( "Authenticate status " + status );
- return status;
- }
- }
- return 0;
- }
- /** Call all authorization callbacks. The "require valid user" attributes
- are probably set during the mapping stage ( for efficiency), but it
- can be done here too.
- */
- public int doAuthorize( Request req, Response res, String roles[] ) {
- int status=0;
- BaseInterceptor reqI[]= req.getContext().getContainer().
- getInterceptors(Container.H_authorize);
-
- for( int i=0; i< reqI.length; i++ ) {
- status = reqI[i].authorize( req, res, roles );
- if ( status != 0 ) {
- if( debug>0) log( "Authorize status " + status );
- return status;
- }
- }
- return 0;
- }
-
-
/** Implement the write logic, calling the interceptors
- * and making sure the headers are sent before. This used to
+ * and making sure the headers are sent before. This used to
* be part of BufferedServletOutputStream, but it's better
* to have it here for all output streams.
+ * XXX XXX
*/
- public void doWrite(Request req, Response res, byte buf[], int off, int cnt )
+ public final void doWrite(Request req, Response res, byte buf[], int off, int cnt )
throws IOException
{
if (!res.isBufferCommitted()) {
1.19 +88 -82 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Handler.java 2000/10/01 06:37:45 1.18
+++ Handler.java 2000/10/01 22:21:44 1.19
@@ -59,7 +59,6 @@
package org.apache.tomcat.core;
import org.apache.tomcat.util.*;
-import org.apache.tomcat.util.log.*;
import java.io.*;
import java.net.*;
import java.util.*;
@@ -72,17 +71,19 @@
* @author costin@dnt.ro
*/
public class Handler {
- protected Context context;
- protected ContextManager contextM;
-
- protected String name;
-
- /** True if it can handle requests.
- 404 or error if not.
+ /** ServletWrapper counts. The accounting design is not
+ final, but all this is needed to tune up tomcat
+ ( and to understand and be able to implement a good
+ solution )
*/
- protected boolean initialized=false;
+ 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;
- Hashtable initArgs=null;
+ public static final int ACCOUNTS=6;
/** The servlet was declared in web.xml
*/
@@ -100,13 +101,32 @@
preferably in web.xml
*/
public static final int ORIGIN_ADMIN=4;
+
+ // -------------------- Properties --------------------
+ protected Context context;
+ protected ContextManager contextM;
+
+ protected String name;
+
+ /** True if it can handle requests.
+ 404 or error if not.
+ */
+ protected boolean initialized=false;
+ Hashtable initArgs=null;
+
+
// who creates the servlet definition
protected int origin;
+
protected boolean internal=false;
+
protected String path;
+
protected String servletClassName;
+
protected String servletName;
+
protected int loadOnStartup=-1;
protected boolean loadingOnStartup=false;
@@ -114,6 +134,10 @@
protected int debug=0;
protected String debugHead=null;
+ private Counters cntr=new Counters( ACCOUNTS );
+ private Object notes[]=new Object[ContextManager.MAX_NOTES];
+
+ // -------------------- Constructor --------------------
public Handler() {
}
@@ -121,7 +145,6 @@
public void setContext( Context context) {
this.context = context;
contextM=context.getContextManager();
- loghelper.setLogger(context.getLog().getLogger());
}
public Context getContext() {
@@ -143,6 +166,27 @@
this.name=servletName;
}
+ /** 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 void setOrigin( int origin ) {
+ this.origin=origin;
+ }
+
+ public int getOrigin() {
+ return origin;
+ }
+
+ /** Accounting
+ */
+ public final Counters getCounters() {
+ return cntr;
+ }
+
// -------------------- Common servlet attributes
public String getServletName() {
if(name!=null) return name;
@@ -215,14 +259,7 @@
}
}
- /** This method will be called when the handler
- is removed ( by admin or timeout ). Various handlers
- can implement this, but it can't be called from outside.
- ( the "guarded" doDestroy is public )
- */
- protected void doDestroy() throws Exception {
-
- }
+ // -------------------- Methods --------------------
/** Destroy a handler, and notify all the interested interceptors
*/
@@ -236,14 +273,6 @@
}
- /** Initialize the handler. Handler can override this
- method to initialize themself.
- The method must set initialised=true if successfull.
- */
- protected void doInit() throws Exception
- {
-
- }
/** Call the init method, and notify all interested listeners.
*/
@@ -259,15 +288,6 @@
}
}
- /** This is the actual content generator. Can't be called
- from outside.
- */
- protected void doService(Request req, Response res)
- throws Exception
- {
-
- }
-
/** Call the service method, and notify all listeners
*/
public void service(Request req, Response res)
@@ -318,20 +338,33 @@
contextM.handleError( req, res, t );
}
- // -------------------- Origin
- /** 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
+ // -------------------- Abstract methods --------------------
+
+ /** This method will be called when the handler
+ is removed ( by admin or timeout ). Various handlers
+ can implement this, but it can't be called from outside.
+ ( the "guarded" doDestroy is public )
*/
- public void setOrigin( int origin ) {
- this.origin=origin;
+ protected void doDestroy() throws Exception {
+
}
- public int getOrigin() {
- return origin;
+ /** Initialize the handler. Handler can override this
+ method to initialize themself.
+ The method must set initialised=true if successfull.
+ */
+ protected void doInit() throws Exception
+ {
+
+ }
+
+ /** This is the actual content generator. Can't be called
+ from outside.
+ */
+ protected void doService(Request req, Response res)
+ throws Exception
+ {
+
}
// -------------------- Debug --------------------
@@ -340,52 +373,25 @@
return name;
}
- Log loghelper = new Log("tc_log", this);
-
- public void setDebug( int d ) {
+ public final void setDebug( int d ) {
debug=d;
}
-
- protected void log( String s ) {
- loghelper.log(s);
- }
- protected void log( String s, Throwable t ) {
- loghelper.log(s, t);
+ protected final void log( String s ) {
+ context.log(s);
}
-
-
- // -------------------- Accounting --------------------
-
- /** ServletWrapper counts. The accounting design is not
- final, but all this is needed to tune up tomcat
- ( and to understand and be able to implement a good
- solution )
- */
- 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;
-
- private Counters cntr=new Counters( ACCOUNTS );
-
- public final Counters getCounters() {
- return cntr;
+ protected final void log( String s, Throwable t ) {
+ context.log(s, t);
}
- // -------------------- Notes
- Object notes[]=new Object[ContextManager.MAX_NOTES];
- public void setNote( int pos, Object value ) {
+ // -------------------- Notes --------------------
+ public final void setNote( int pos, Object value ) {
notes[pos]=value;
}
- public Object getNote( int pos ) {
+ public final Object getNote( int pos ) {
return notes[pos];
}
1.67 +247 -272 jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
Index: Request.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- Request.java 2000/10/01 06:37:45 1.66
+++ Request.java 2000/10/01 22:21:44 1.67
@@ -79,11 +79,27 @@
* @author Hans Bergsten [hans@gefionsoftware.com]
*/
public class Request {
+ public static final int ACC_PRE_CMAP=0;
+ public static final int ACC_PRE_RMAP=1;
+ public static final int ACC_POST_MAP=2;
+ public static final int ACC_PRE_SERVICE=3;
+ public static final int ACC_POST_SERVICE=4;
+ public static final int ACC_IN_OUT=5;
+ public static final int ACC_OUT_COUNT=6;
+
+ public static final int ACCOUNTS=7;
+
+ public static final String SESSIONID_FROM_COOKIE="cookie";
+ public static final String SESSIONID_FROM_URL="url";
+ public static final int MAX_INCLUDE=10;
+
/** Magic attribute that allows access to the real request from
* facade - for trusted applications
*/
public static final String ATTRIB_REAL_REQUEST="org.apache.tomcat.request";
+ // -------------------- properties --------------------
+
protected int serverPort;
protected String remoteAddr;
protected String remoteHost;
@@ -176,11 +192,14 @@
// Need to distinguish between null pathTranslated and
// lazy-computed pathTranlsated
protected boolean pathTranslatedIsSet=false;
+ protected Vector cookies = new Vector();
+ protected boolean didCookies;
- public static final String SESSIONID_FROM_COOKIE="cookie";
- public static final String SESSIONID_FROM_URL="url";
- public static final int MAX_INCLUDE=10;
-
+ private Object notes[]=new Object[ContextManager.MAX_NOTES];
+ // Accounting
+ private Counters cntr=new Counters(ACCOUNTS);
+
+ // -------------------- Constructor --------------------
public Request() {
headers = new MimeHeaders();
@@ -207,6 +226,32 @@
return contextM;
}
+ public Object getFacade() {
+ return requestFacade;
+ }
+
+ public void setFacade(Object facade ) {
+ requestFacade=facade;
+ }
+
+ public void setResponse(Response response) {
+ this.response = response;
+ }
+
+ public Response getResponse() {
+ return response;
+ }
+
+ public MimeHeaders getMimeHeaders() {
+ return headers;
+ }
+
+ public final Counters getCounters() {
+ return cntr;
+ }
+
+ // -------------------- Request data --------------------
+
public MessageBytes getSchemeMB() {
return schemeMB;
}
@@ -223,43 +268,42 @@
return method;
}
+ public void setMethod( String method ) {
+ this.method=method;
+ }
+
public String getRequestURI() {
return requestURI;
}
+
+ public void setRequestURI( String r ) {
+ this.requestURI=r;
+ }
- // XXX used by forward
public String getQueryString() {
return queryString;
}
+ public void setQueryString(String queryString) {
+ this.queryString = queryString;
+ }
+
public String getProtocol() {
return protocol;
}
+ public void setProtocol( String protocol ) {
+ this.protocol=protocol;
+ }
+
+
/** Return the server name. If none was set,
* extract it from the host header.
*
*/
public String getServerName() {
- if(serverName!=null) return serverName;
-
- String hostHeader = this.getHeader("host");
- if (hostHeader != null) {
- int i = hostHeader.indexOf(':');
- if (i > -1) {
- hostHeader = hostHeader.substring(0,i);
- }
- serverName=hostHeader;
- return serverName;
- }
-
- if( localHost != null ) {
- serverName = localHost;
- return serverName;
- }
- // default to localhost - and warn
- // log("No server name, defaulting to localhost");
- serverName="localhost";
+ if(serverName==null)
+ serverName=findServerName();
return serverName;
}
@@ -268,6 +312,52 @@
this.serverName = serverName;
}
+
+ public int getServerPort() {
+ return serverPort;
+ }
+
+ public String getRemoteAddr() {
+ return remoteAddr;
+ }
+
+ public String getRemoteHost() {
+ return remoteHost;
+ }
+
+ public void setPathInfo(String pathInfo) {
+ this.pathInfo = pathInfo;
+ }
+
+// // What's between context path and servlet name ( /servlet )
+// // A smart server may use arbitrary prefixes and rewriting
+// public String getServletPrefix() {
+// return null;
+// }
+
+ public void setServerPort(int serverPort ) {
+ this.serverPort=serverPort;
+ }
+
+ public void setRemoteAddr( String remoteAddr ) {
+ this.remoteAddr=remoteAddr;
+ }
+
+ public void setRemoteHost(String remoteHost) {
+ this.remoteHost=remoteHost;
+ }
+
+ public String getLocalHost() {
+ return localHost;
+ }
+
+ public void setLocalHost(String host) {
+ this.localHost = host;
+ }
+
+
+ // -------------------- Parameters --------------------
+
// XXX optimize for common case ( single params )
public String getParameter(String name ) {
String[] values = getParameterValues(name);
@@ -288,6 +378,12 @@
return parameters.keys();
}
+ // --------------------
+
+ public void setAuthType(String authType) {
+ this.authType = authType;
+ }
+
public String getAuthType() {
return authType;
}
@@ -298,6 +394,14 @@
return charEncoding;
}
+ public void setCharEncoding( String enc ) {
+ this.charEncoding=enc;
+ }
+
+ public void setContentLength( int len ) {
+ this.contentLength=len;
+ }
+
public int getContentLength() {
if( contentLength > -1 ) return contentLength;
@@ -316,6 +420,10 @@
return contentType;
}
+ public void setContentType( String type ) {
+ this.contentType=type;
+ }
+
/** All adapters that know the PT needs to call this method,
in order to set pathTranslatedIsSet, otherwise tomcat
@@ -365,6 +473,8 @@
if( notAuthenticated ) {
notAuthenticated=false;
+ // Call all authentication callbacks. If any of them is able to
+ // identify the user it will set the principal in req.
int status=0;
BaseInterceptor reqI[]= context.getContainer().
getInterceptors(Container.H_authenticate);
@@ -374,8 +484,6 @@
break;
}
}
-
- //contextM.doAuthenticate(this, response);
// context.log("Auth " + remoteUser );
}
return remoteUser;
@@ -419,53 +527,31 @@
String checkRoles[]=new String[1];
public boolean isUserInRole(String role) {
checkRoles[0]=role;
- int status=contextM.doAuthorize(this, response, checkRoles);
+
+ int status=0;
+ BaseInterceptor reqI[]= context.getContainer().
+ getInterceptors(Container.H_authorize);
+
+ // Call all authorization callbacks.
+ for( int i=0; i< reqI.length; i++ ) {
+ status = reqI[i].authorize( this, response, checkRoles );
+ if ( status != 0 ) {
+ break;
+ }
+ }
return status==0;
}
public String getServletPath() {
- // contextM.log( "GetServletPath " + servletPath );
return servletPath;
}
public void setServletPath(String servletPath) {
- // contextM.log( "SetServletPath " + servletPath );
this.servletPath = servletPath;
}
- // End hints
-
- // -------------------- Request methods ( high level )
- public Object getFacade() {
- // some requests are internal, and will never need a
- // facade - no need to create a new object unless needed.
-// if( requestFacade==null ) {
-// if( context==null ) {
-// // wrong request
-// // XXX the will go away after we remove the one-one relation between
-// // request and facades ( security, etc)
-// requestFacade = contextM.getContext("" ).getFacadeManager().createHttpServletRequestFacade(this );
-// return requestFacade;
-// }
-// requestFacade = context.getFacadeManager().createHttpServletRequestFacade(this);
-// }
- return requestFacade;
- }
-
- public void setFacade(Object facade ) {
- requestFacade=facade;
- }
-
- public void setResponse(Response response) {
- this.response = response;
- }
-
- public Response getResponse() {
- return response;
- }
-
// -------------------- Session --------------------
// GS - return the jvm load balance route
public String getJvmRoute() {
@@ -545,9 +631,6 @@
}
// -------------------- Cookies --------------------
- protected Vector cookies = new Vector();
- protected boolean didCookies;
-
public int getCookieCount() {
if( ! didCookies ) {
didCookies=true;
@@ -593,66 +676,27 @@
public void setContainer(Container container) {
this.container=container;
}
-
- /** The file - result of mapping the request ( using aliases and other
- * mapping rules. Usefull only for static resources.
- */
- public String getMappedPath() {
- return mappedPath;
- }
- public void setMappedPath( String m ) {
- mappedPath=m;
- }
+// /** The file - result of mapping the request ( using aliases and other
+// * mapping rules. Usefull only for static resources.
+// */
+// public String getMappedPath() {
+// return mappedPath;
+// }
- public void setRequestURI( String r ) {
- this.requestURI=r;
- }
+// public void setMappedPath( String m ) {
+// mappedPath=m;
+// }
public void setParameters( Hashtable h ) {
if(h!=null)
this.parameters=h;
- // XXX Should we override query parameters ??
}
public Hashtable getParameters() {
return parameters;
}
- public void setContentLength( int len ) {
- this.contentLength=len;
- }
-
- public void setContentType( String type ) {
- this.contentType=type;
- }
-
- public void setCharEncoding( String enc ) {
- this.charEncoding=enc;
- }
-
- public void setAuthType(String authType) {
- this.authType = authType;
- }
-
-
- public void setPathInfo(String pathInfo) {
- this.pathInfo = pathInfo;
- }
-
- /** Set query string - will be called by forward
- */
- public void setQueryString(String queryString) {
- // the query will be processed when getParameter() will be called.
- // Or - if you alredy have it parsed, call setParameters()
- this.queryString = queryString;
- }
-
-
- // XXX
- // the server name should be pulled from a server object of some
- // sort, not just set and got.
-
// -------------------- Attributes
public Object getAttribute(String name) {
@@ -660,11 +704,7 @@
if( value != null )
return value;
- // // allow access to FacadeManager for servlets
- // // ( this way you don't need to deal with init ).
- // if( name.equals(FacadeManager.FACADE_ATTRIBUTE)) {
- // return context.getAttribute( name );
- // }
+ // allow access to FacadeManager for servlets
if(name.equals(ATTRIB_REAL_REQUEST)) {
if( ! context.allowAttribute(name) ) return null;
return this;
@@ -688,7 +728,7 @@
}
// End Attributes
- // -------------------- Sub requests
+ // -------------------- Sub requests --------------------
/** If this is a sub-request, return the parent
*/
@@ -735,6 +775,14 @@
return getMimeHeaders().values(name);
}
+ public String getHeader(String name) {
+ return headers.getHeader(name);
+ }
+
+ public Enumeration getHeaderNames() {
+ return headers.names();
+ }
+
// -------------------- Utils - facade for RequestUtil
private void handleParameters() {
if(!didParameters) {
@@ -752,18 +800,93 @@
}
}
- // -------------------- End utils
- public void recycle() {
- if( requestFacade != null && context!=null ) {
- // context.getFacadeManager().recycle(this);
+
+ // -------------------- Computed fields --------------------
+
+ protected String findServerName() {
+ String hostHeader = this.getHeader("host");
+ if (hostHeader != null) {
+ int i = hostHeader.indexOf(':');
+ if (i > -1) {
+ hostHeader = hostHeader.substring(0,i);
+ }
+ serverName=hostHeader;
+ return serverName;
+ }
+
+ if( localHost != null ) {
+ serverName = localHost;
+ return serverName;
+ }
+ // default to localhost - and warn
+ // log("No server name, defaulting to localhost");
+ serverName="localhost";
+ return serverName;
+ }
+
+ // -------------------- For adapters --------------------
+
+ /** Fill in the buffer. This method is probably easier to implement than
+ previous.
+ This method should only be called from SerlvetInputStream implementations.
+ No need to implement it if your adapter implements ServletInputStream.
+ */
+ // you need to override this method if you want non-empty InputStream
+ public int doRead( byte b[], int off, int len ) throws IOException {
+ return -1; // not implemented - implement getInputStream
+ }
+
+
+ // This method must be removed and replaced with a real buffer !!!
+ byte b[]=new byte[1]; // read operations happen in the same thread.
+ // if needed, upper layer can synchronize ( well, 2 threads reading
+ // the input stream is not good anyway )
+
+ public int doRead() throws IOException {
+ byte []b = new byte[1];
+ int rc = doRead(b, 0, 1);
+
+ if(rc <= 0) {
+ return -1;
}
+ return b[0];
+ // ??
+ //return ((int)b[0]) & 0x000000FF;
+ }
+
+ // -------------------- debug --------------------
+
+ public String toString() {
+ StringBuffer sb=new StringBuffer();
+ sb.append( "R( ");
+ if( context!=null) {
+ sb.append( context.getPath() );
+ if( getServletPath() != null )
+ sb.append( " + " + getServletPath() + " + " + getPathInfo());
+ } else {
+ sb.append(getRequestURI());
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+
+ // -------------------- Per-Request "notes" --------------------
+
+ public final void setNote( int pos, Object value ) {
+ notes[pos]=value;
+ }
+
+ public final Object getNote( int pos ) {
+ return notes[pos];
+ }
+
+ // -------------------- Recycling --------------------
+ public void recycle() {
context = null;
attributes.clear();
parameters.clear();
cookies.removeAllElements();
- // requestURI = null;
- // queryString = null;
contentLength = -1;
contentType = null;
charEncoding = null;
@@ -795,7 +918,7 @@
remoteAddr="127.0.0.1";
remoteHost="localhost";
localHost="localhost";
- for( int i=0; i<ACCOUNTS; i++ ) accTable[i]=0;
+ cntr.recycle();
for( int i=0; i<ContextManager.MAX_NOTES; i++ ) notes[i]=null;
parent=null;
child=null;
@@ -803,7 +926,6 @@
notAuthenticated=true;
userRoles=null;
reqRoles=null;
- // in=null;
uriMB.recycle();
contextMB.recycle();
@@ -815,151 +937,4 @@
schemeMB.setString("http");
}
-
- public MimeHeaders getMimeHeaders() {
- return headers;
- }
-
- public String getHeader(String name) {
- return headers.getHeader(name);
- }
-
- public Enumeration getHeaderNames() {
- return headers.names();
- }
-
- // Bad design, use upper layer. We already have doRead()
-// public ServletInputStream getInputStream() throws IOException {
-// return getFacade().getInputStream();
-// }
-
- public int getServerPort() {
- return serverPort;
- }
-
- public String getRemoteAddr() {
- return remoteAddr;
- }
-
- public String getRemoteHost() {
- return remoteHost;
- }
-
- /** Fill in the buffer. This method is probably easier to implement than
- previous.
- This method should only be called from SerlvetInputStream implementations.
- No need to implement it if your adapter implements ServletInputStream.
- */
- // you need to override this method if you want non-empty InputStream
- public int doRead( byte b[], int off, int len ) throws IOException {
- return -1; // not implemented - implement getInputStream
- }
-
-
- // This method must be removed and replaced with a real buffer !!!
- public int doRead() throws IOException {
- byte []b = new byte[1];
- int rc = doRead(b, 0, 1);
-
- if(rc <= 0) {
- return -1;
- }
-
- return b[0];
- // ??
- //return ((int)b[0]) & 0x000000FF;
- }
-
- // -------------------- "cooked" info --------------------
- // Hints = return null if you don't know,
- // and Tom will find the value. You can also use the static
- // methods in Request
-
- // What's between context path and servlet name ( /servlet )
- // A smart server may use arbitrary prefixes and rewriting
- public String getServletPrefix() {
- return null;
- }
-
- public void setMethod( String method ) {
- this.method=method;
- }
-
- public void setProtocol( String protocol ) {
- this.protocol=protocol;
- }
-
- // 1 mime headers per request, you change the content of
- // MimeHeaders instead of replacing them.
- // public void setMimeHeaders( MimeHeaders headers ) {
- // this.headers=headers;
- // }
-
- public void setServerPort(int serverPort ) {
- this.serverPort=serverPort;
- }
-
- public void setRemoteAddr( String remoteAddr ) {
- this.remoteAddr=remoteAddr;
- }
-
- public void setRemoteHost(String remoteHost) {
- this.remoteHost=remoteHost;
- }
-
- public String getLocalHost() {
- return localHost;
- }
-
- public void setLocalHost(String host) {
- this.localHost = host;
- }
-
-
- public String toString() {
- StringBuffer sb=new StringBuffer();
- sb.append( "R( ");
- if( context!=null) {
- sb.append( context.getPath() );
- if( getServletPath() != null )
- sb.append( " + " + getServletPath() + " + " + getPathInfo());
- } else {
- sb.append(getRequestURI());
- }
- sb.append(")");
- return sb.toString();
- }
-
- // -------------------- Accounting --------------------
- // XXX Will be implemented as a note !
- public static final int ACC_PRE_CMAP=0;
- public static final int ACC_PRE_RMAP=1;
- public static final int ACC_POST_MAP=2;
- public static final int ACC_PRE_SERVICE=3;
- public static final int ACC_POST_SERVICE=4;
- public static final int ACC_IN_OUT=5;
- public static final int ACC_OUT_COUNT=6;
-
- public static final int ACCOUNTS=7;
- long accTable[]=new long[ACCOUNTS];
-
- public void setAccount( int pos, long value ) {
- accTable[pos]=value;
- }
-
- public long getAccount( int pos ) {
- return accTable[pos];
- }
-
- // -------------------- Per-Request "notes"
- Object notes[]=new Object[ContextManager.MAX_NOTES];
-
- public void setNote( int pos, Object value ) {
- notes[pos]=value;
- }
-
- public Object getNote( int pos ) {
- return notes[pos];
- }
-
}
1.40 +145 -178 jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
Index: Response.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- Response.java 2000/10/01 06:37:46 1.39
+++ Response.java 2000/10/01 22:21:45 1.40
@@ -75,71 +75,69 @@
* @author Hans Bergsten <ha...@gefionsoftware.com>
*/
public class Response {
+
public static final String DEFAULT_CONTENT_TYPE = "text/plain";
+
public static final String DEFAULT_CHAR_ENCODING = "8859_1";
+
public static final String LOCALE_DEFAULT="en";
+
public static final Locale DEFAULT_LOCALE=new Locale(LOCALE_DEFAULT, "");
-
+
+ // -------------------- fields --------------------
protected static StringManager sm =
StringManager.getManager("org.apache.tomcat.resources");
+ // associated request
protected Request request;
+
+ // facade
protected Object responseFacade;
- protected Vector userCookies = new Vector();
- protected String contentType = DEFAULT_CONTENT_TYPE;
- protected String contentLanguage = null;
- protected String characterEncoding = DEFAULT_CHAR_ENCODING;
- protected int contentLength = -1;
+ // Response components
protected int status = 200;
- private Locale locale = DEFAULT_LOCALE;
-
protected MimeHeaders headers = new MimeHeaders();
-
- // When getWriter is called on facade, both sos and writer are
- // set.
- // usingStream== ( sos!=null && writer ==null)
- // usingWriter== ( writer != null )
- // started == ( sos!=null )
- // protected ServletOutputStream sos;
- protected PrintWriter writer;
-
- protected boolean commited = false;
-
- // protected ByteBuffer bBuffer;
protected OutputBuffer oBuffer;
- // @deprecated
+ // state
+ protected boolean commited = false;
protected boolean usingStream = false;
protected boolean usingWriter = false;
- protected boolean started = false;
-
- boolean included=false;
+ protected boolean included=false;
+
+ //
+ protected String contentType = DEFAULT_CONTENT_TYPE;
+ protected String contentLanguage = null;
+ protected String characterEncoding = DEFAULT_CHAR_ENCODING;
+ protected int contentLength = -1;
+ private Locale locale = DEFAULT_LOCALE;
+
+ // -------------------- Constructor --------------------
public Response() {
}
+ // -------------------- --------------------
+
+ /** Init is called from CM when the object is added
+ to tomcat.
+ */
void init() {
- // init must be called from CM - we need req, etc.
oBuffer=new OutputBuffer( this );
}
public Object getFacade() {
-// if( responseFacade==null ) {
-// Context ctx= request.getContext();
-// if( ctx == null ) {
-// ctx=request.getContextManager().getContext("");
-// }
-// responseFacade = ctx.getFacadeManager().
-// createHttpServletResponseFacade(this);
-// }
return responseFacade;
}
+ /** Higher-level layer
+ */
public void setFacade(Object facade ) {
responseFacade=facade;
}
+ /** Associated request
+ */
public void setRequest(Request request) {
this.request = request;
}
@@ -147,8 +145,16 @@
public Request getRequest() {
return request;
}
+
+ public OutputBuffer getBuffer() {
+ return oBuffer;
+ }
+
+ public MimeHeaders getMimeHeaders() {
+ return headers;
+ }
- /* -------------------- */
+ // -------------------- State --------------------
// Included response behavior
public boolean isIncluded() {
@@ -157,54 +163,17 @@
public void setIncluded( boolean incl ) {
included= incl;
- if( incl ) {
- // included behavior, no header output,
- // no status change on errors.
- // XXX we can optimize a bit - replace headers with
- // an new Hashtable we can throw away.
- } else {
- // move back to normal behavior.
-
- }
}
- /** If the writer/output stream was requested
- */
- public boolean isStarted() {
- return started;
+ public int getStatus() {
+ return status;
}
- public void recycle() {
- userCookies.removeAllElements(); // XXX reuse !!!
- contentType = DEFAULT_CONTENT_TYPE;
- contentLanguage = null;
- locale = DEFAULT_LOCALE;
- characterEncoding = DEFAULT_CHAR_ENCODING;
- contentLength = -1;
- status = 200;
- usingWriter = false;
- usingStream = false;
- writer=null;
- started = false;
- commited = false;
- included=false;
- if ( oBuffer != null ) oBuffer.recycle();
- headers.clear();
- }
-
- public void finish() throws IOException {
- oBuffer.close();
- ContextManager cm=request.getContextManager();
- BaseInterceptor reqI[]= cm.
- getInterceptors(request, Container.H_afterBody);
-
- for( int i=0; i< reqI.length; i++ ) {
- reqI[i].afterBody( request, this );
- }
- }
-
- public boolean containsHeader(String name) {
- return headers.getHeader(name) != null;
+ /** Set the response status
+ */
+ public void setStatus( int status ) {
+ if( included ) return;
+ this.status=status;
}
public boolean isUsingStream() {
@@ -223,14 +192,53 @@
usingWriter=writer;
}
- public OutputBuffer getBuffer() {
- return oBuffer;
+ public boolean isBufferCommitted() {
+ return commited;
+ }
+
+ public void setBufferCommitted( boolean v ) {
+ this.commited=v;
}
+
+ // -------------------- Methods --------------------
+
+ public void reset() throws IllegalStateException {
+ // Force the PrintWriter to flush its data to the output
+ // stream before resetting the output stream
+ //
+ contentType = DEFAULT_CONTENT_TYPE;
+ locale = DEFAULT_LOCALE;
+ characterEncoding = DEFAULT_CHAR_ENCODING;
+ contentLength = -1;
+ status = 200;
+
+ // Reset the stream
+ if( commited ) {
+ String msg = sm.getString("servletOutputStreamImpl.reset.ise");
+ throw new IllegalStateException(msg);
+ }
+ oBuffer.reset();
+
+ // Clear the headers
+ if( ! included) headers.clear();
+ }
+ public void finish() throws IOException {
+ oBuffer.close();
+ ContextManager cm=request.getContextManager();
+ BaseInterceptor reqI[]= cm.
+ getInterceptors(request, Container.H_afterBody);
+
+ for( int i=0; i< reqI.length; i++ ) {
+ reqI[i].afterBody( request, this );
+ }
+ }
+
+
// -------------------- Headers --------------------
- public MimeHeaders getMimeHeaders() {
- return headers;
+ public boolean containsHeader(String name) {
+ return headers.getHeader(name) != null;
}
public void setHeader(String name, String value) {
@@ -281,81 +289,6 @@
return false;
}
- public int getBufferSize() {
- return oBuffer.getBufferSize();
- }
-
- public void setBufferSize(int size) throws IllegalStateException {
- // Force the PrintWriter to flush the data to the OutputStream.
- if (usingWriter == true && writer != null ) writer.flush();
- try{
- oBuffer.flushChars();
- }catch(IOException ex){
- ;
- }
- if( oBuffer.getBytesWritten() >0) {
- throw new IllegalStateException ( sm.getString("servletOutputStreamImpl.setbuffer.ise"));
- }
- oBuffer.setBufferSize( size );
- }
-
- /*
- * Methodname "isCommitted" already taken by Response class.
- */
- public boolean isBufferCommitted() {
- return commited;
- // return out.isCommitted();
- }
-
- public void setBufferCommitted( boolean v ) {
- this.commited=v;
- }
-
- public void reset() throws IllegalStateException {
- // Force the PrintWriter to flush its data to the output
- // stream before resetting the output stream
- //
- userCookies.removeAllElements(); // keep system (session) cookies
- contentType = DEFAULT_CONTENT_TYPE;
- locale = DEFAULT_LOCALE;
- characterEncoding = DEFAULT_CHAR_ENCODING;
- contentLength = -1;
- status = 200;
-
- // XXX XXX What happens here ? flush() on writer will flush
- // to client !!!!!!!!
- if (usingWriter == true && writer != null)
- writer.flush();
-
- // Reset the stream
- if( commited ) {
- String msg = sm.getString("servletOutputStreamImpl.reset.ise");
- throw new IllegalStateException(msg);
- }
- oBuffer.reset();
- // Clear the cookies and such
-
- // Clear the headers
- if( ! included) headers.clear();
- }
-
- // Reset the response buffer but not headers and cookies
- public void resetBuffer() throws IllegalStateException {
- if( usingWriter && writer != null )
- writer.flush();
-
- if( commited ) {
- String msg = sm.getString("servletOutputStreamImpl.reset.ise");
- throw new IllegalStateException(msg);
- }
- oBuffer.reset();
- }
-
- public void flushBuffer() throws IOException {
- oBuffer.flush();
- }
-
-
/** Signal that we're done with the headers, and body will follow.
* Any implementation needs to notify ContextManager, to allow
* interceptors to fix headers.
@@ -390,11 +323,48 @@
// No action..
}
+ // -------------------- Buffer --------------------
+
+ public int getBufferSize() {
+ return oBuffer.getBufferSize();
+ }
+
+ public void setBufferSize(int size) throws IllegalStateException {
+ // Force the PrintWriter to flush the data to the OutputStream.
+ // if (usingWriter == true && writer != null ) writer.flush();
+ try{
+ oBuffer.flushChars();
+ }catch(IOException ex){
+ ;
+ }
+ if( oBuffer.getBytesWritten() >0) {
+ throw new IllegalStateException ( sm.getString("servletOutputStreamImpl.setbuffer.ise"));
+ }
+ oBuffer.setBufferSize( size );
+ }
+
+
+ // Reset the response buffer but not headers and cookies
+ public void resetBuffer() throws IllegalStateException {
+
+ if( commited ) {
+ String msg = sm.getString("servletOutputStreamImpl.reset.ise");
+ throw new IllegalStateException(msg);
+ }
+ oBuffer.reset();
+ }
+
+ public void flushBuffer() throws IOException {
+ oBuffer.flush();
+ }
+
+
+ // -------------------- I18N --------------------
+
public Locale getLocale() {
return locale;
}
- // XXX XXX Need rewrite
public void setLocale(Locale locale) {
if (locale == null || included) {
return; // throw an exception?
@@ -444,17 +414,8 @@
return contentLength;
}
- public int getStatus() {
- return status;
- }
+ // -------------------- Extend --------------------
- /** Set the response status
- */
- public void setStatus( int status ) {
- if( included ) return;
- this.status=status;
- }
-
/** Write a chunk of bytes. Should be called only from ServletOutputStream implementations,
* No need to implement it if your adapter implements ServletOutputStream.
* Headers and status will be written before this method is exceuted.
@@ -467,16 +428,22 @@
// the rest of tomcat ( I'll do that - costin )
}
-
- /*
- Changes:
- - removed StringBuffer body. It was broken ( used DEFAULT_CHAR_ENCODING, the
- output is already bytes... ). No known usage, it's easy to create a
- response that stores the response.
-
- - replaced notIncluded with included, remove all ugly ! notIncluded
-
+ // --------------------
+
+ public void recycle() {
+ contentType = DEFAULT_CONTENT_TYPE;
+ contentLanguage = null;
+ locale = DEFAULT_LOCALE;
+ characterEncoding = DEFAULT_CHAR_ENCODING;
+ contentLength = -1;
+ status = 200;
+ usingWriter = false;
+ usingStream = false;
+ commited = false;
+ included=false;
+ if ( oBuffer != null ) oBuffer.recycle();
+ headers.clear();
+ }
- */
}
1.5 +11 -11 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AccountingInterceptor.java 2000/09/26 05:17:09 1.4
+++ AccountingInterceptor.java 2000/10/01 22:21:45 1.5
@@ -105,21 +105,21 @@
public int requestMap(Request request ) {
if( acc ) {
- request.setAccount( Request.ACC_PRE_RMAP, System.currentTimeMillis() );
+ request.getCounters().setCounter( Request.ACC_PRE_RMAP, System.currentTimeMillis() );
}
return 0;
}
public int contextMap( Request request ) {
if( acc ) {
- request.setAccount( Request.ACC_PRE_CMAP, System.currentTimeMillis() );
+ request.getCounters().setCounter( Request.ACC_PRE_CMAP, System.currentTimeMillis() );
}
return 0;
}
public int authenticate(Request request, Response response) {
if( acc ) {
- request.setAccount( Request.ACC_POST_MAP, System.currentTimeMillis() );
+ request.getCounters().setCounter( Request.ACC_POST_MAP, System.currentTimeMillis() );
}
return 0;
}
@@ -131,7 +131,7 @@
public int preService(Request request, Response response) {
if( acc ) {
- request.setAccount( Request.ACC_PRE_SERVICE, System.currentTimeMillis() );
+ request.getCounters().setCounter( Request.ACC_PRE_SERVICE, System.currentTimeMillis() );
}
return 0;
}
@@ -151,20 +151,20 @@
public int postService(Request request, Response response) {
if( acc ) {
- request.setAccount( Request.ACC_POST_SERVICE, System.currentTimeMillis() );
+ request.getCounters().setCounter( Request.ACC_POST_SERVICE, System.currentTimeMillis() );
- long t1=request.getAccount( Request.ACC_PRE_CMAP );
- long t2=request.getAccount( Request.ACC_PRE_RMAP );
- long t3=request.getAccount( Request.ACC_POST_MAP );
- long t4=request.getAccount( Request.ACC_PRE_SERVICE );
- long t5=request.getAccount( Request.ACC_POST_SERVICE );
+ long t1=request.getCounters().getCounter( Request.ACC_PRE_CMAP );
+ long t2=request.getCounters().getCounter( Request.ACC_PRE_RMAP );
+ long t3=request.getCounters().getCounter( Request.ACC_POST_MAP );
+ long t4=request.getCounters().getCounter( Request.ACC_PRE_SERVICE );
+ long t5=request.getCounters().getCounter( Request.ACC_POST_SERVICE );
long t21=t2-t1;
long t31=t3-t1;
long t54=t5-t4;
long t41=t4-t1;
- long tout=request.getAccount( Request.ACC_OUT_COUNT );
+ long tout=request.getCounters().getCounter( Request.ACC_OUT_COUNT );
StringBuffer sb=new StringBuffer();
// ContextMap, Map, Service, Pre-Service-Overhead
sb.append(t21).append(",");
1.7 +9 -1 jakarta-tomcat/src/share/org/apache/tomcat/request/ReloadInterceptor.java
Index: ReloadInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/ReloadInterceptor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ReloadInterceptor.java 2000/09/30 04:43:30 1.6
+++ ReloadInterceptor.java 2000/10/01 22:21:45 1.7
@@ -177,7 +177,15 @@
// send notification to all interceptors
// They may try to save up the state or take
// the right actions
- cm.doReload( request, ctx );
+
+
+ if( debug>0 ) log( "Reloading hooks for context " + ctx.toString());
+
+ // Call reload hook in context manager
+ BaseInterceptor cI[]=cm.getInterceptors(ctx.getContainer());
+ for( int i=0; i< cI.length; i++ ) {
+ cI[i].reload( request, ctx );
+ }
}
} catch( TomcatException ex) {
log( "Error reloading " + ex );
1.39 +5 -4 jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java
Index: Ajp12ConnectionHandler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- Ajp12ConnectionHandler.java 2000/09/29 07:01:27 1.38
+++ Ajp12ConnectionHandler.java 2000/10/01 22:21:46 1.39
@@ -239,10 +239,11 @@
// if("ROOT".equals( contextPath ) ) contextPath="";
if("ROOT".equalsIgnoreCase( contextPath ) ) contextPath=null;
if( doLog ) d("AJP: CP=" + contextPath);
-
- if( contextPath!= null )
- context=contextM.getContext( contextPath );
- if( doLog ) d("AJP: context=" + context );
+
+ // XXX That wasn't used afaik, need to do something in ajp13
+ // if( contextPath!= null )
+ // context=contextM.getContext( contextPath );
+ // if( doLog ) d("AJP: context=" + context );
servletName = readString(ajpin, null); //Servlet
if( doLog ) d("AJP: servlet=" + servletName );
1.29 +11 -3 jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java
Index: EmbededTomcat.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- EmbededTomcat.java 2000/10/01 06:37:50 1.28
+++ EmbededTomcat.java 2000/10/01 22:21:46 1.29
@@ -12,6 +12,9 @@
import java.security.*;
import java.util.*;
+// XXX XXX This started as a hack to integrate with J2EE,
+// need a major rewrite
+
/**
* Use this class to embed tomcat in your application.
* The order is important:
@@ -222,9 +225,14 @@
{
// We don't support virtual hosts in embeded tomcat
// ( it's not difficult, but can be done later )
- Context ctx=contextM.getContext( cpath );
- if( ctx==null ) return null;
- return ctx.getFacade();
+ Enumeration ctxE=contextM.getContexts();
+ while( ctxE.hasMoreElements() ) {
+ Context ctx=(Context)ctxE.nextElement();
+ // XXX check host too !
+ if( ctx.getPath().equals( cpath ))
+ return ctx.getFacade();
+ }
+ return null;
}
/** This will make the context available.
1.2 +3 -0 jakarta-tomcat/src/share/org/apache/tomcat/util/Counters.java
Index: Counters.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Counters.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Counters.java 2000/09/17 06:40:30 1.1
+++ Counters.java 2000/10/01 22:21:47 1.2
@@ -85,4 +85,7 @@
return accTable[pos];
}
+ public void recycle() {
+ for( int i=0; i<accTable.length; i++ ) accTable[i]=0;
+ }
}