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/08/14 19:49:22 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util SessionUtil.java
costin 00/08/14 10:49:21
Modified: src/etc server.xml
src/share/org/apache/tomcat/context WorkDirInterceptor.java
src/share/org/apache/tomcat/core Constants.java Context.java
ContextManager.java FacadeManager.java
Response.java
src/share/org/apache/tomcat/facade
HttpServletRequestFacade.java
ServletInputStreamFacade.java ServletWrapper.java
SimpleFacadeManager.java
src/share/org/apache/tomcat/util SessionUtil.java
Log:
- removed dead code, small cosmetic changes ( incl. few more comments).
- removed Constants that are no longer used.
Moved ATTRIB constants in the Context ( where get is called ) - first to insure
consistency and also to be able to document them ( comments ).
- same for Response defaults, session defaults.
Also planed: move ServerName/version to ContextManager ( wich is the actual
server ), and remove Constants. All constants should be defined in the component
where they belong ( request attributes in request, context attributes in context,
etc). This allows us to keep the code in sync in the future.
Revision Changes Path
1.35 +5 -1 jakarta-tomcat/src/etc/server.xml
Index: server.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/etc/server.xml,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- server.xml 2000/07/27 23:08:17 1.34
+++ server.xml 2000/08/14 17:49:08 1.35
@@ -4,6 +4,10 @@
<!-- Debug low-level events in XmlMapper startup -->
<xmlmapper:debug level="0" />
+ <!-- This config is used for JDK1.1
+ server2.xml will be used for JDK1.2
+ -->
+
<!--
Logging:
@@ -247,7 +251,7 @@
in the webapps dir and read/write in the workdir.
-->
- <Context path="/examples"
+ <Context path="/examples"
docBase="webapps/examples"
debug="0"
reloadable="true" >
1.10 +0 -3 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- WorkDirInterceptor.java 2000/07/11 03:48:41 1.9
+++ WorkDirInterceptor.java 2000/08/14 17:49:10 1.10
@@ -98,9 +98,6 @@
log("Creating work dir " + ctx.getWorkDir());
ctx.getWorkDir().mkdirs();
}
- ctx.setAttribute(Constants.ATTRIB_WORKDIR1, ctx.getWorkDir());
- ctx.setAttribute(Constants.ATTRIB_WORKDIR , ctx.getWorkDir());
-
if ( cleanWorkDir ) {
clearDir(ctx.getWorkDir() );
}
1.24 +0 -51 jakarta-tomcat/src/share/org/apache/tomcat/core/Constants.java
Index: Constants.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Constants.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Constants.java 2000/07/10 13:46:10 1.23
+++ Constants.java 2000/08/14 17:49:12 1.24
@@ -76,56 +76,5 @@
public static final int SERVLET_MAJOR = 2;
public static final int SERVLET_MINOR = 2;
- public static final String INVOKER_SERVLET_NAME = "invoker";
- public static final String DEFAULT_SERVLET_NAME = "default";
-
- public static final String ATTRIB_WORKDIR1 = "sun.servlet.workdir";
- public static final String ATTRIB_WORKDIR = "javax.servlet.context.tempdir";
-
- // ProtectionDomain defined for use by JSP's in a Context
- // when using a SecurityManager
- public static final String ATTRIB_JSP_ProtectionDomain = "tomcat.context.jsp.protection_domain";
-
- public static final String SESSION_COOKIE_NAME = "JSESSIONID";
- public static final String SESSION_PARAMETER_NAME = "jsessionid";
-
- public static final String Package = "org.apache.tomcat.core";
- public static final int RequestURIMatchRecursion = 5;
- public static final String WORK_DIR = "work";
-
- public static final String LOCALE_DEFAULT="en";
-
- public static final String ATTRIBUTE_RequestURI =
- "javax.servlet.include.request_uri";
- public static final String ATTRIBUTE_ServletPath =
- "javax.servlet.include.servlet_path";
- public static final String ATTRIBUTE_PathInfo =
- "javax.servlet.include.path_info";
- public static final String ATTRIBUTE_QueryString =
- "javax.servlet.include.query_string";
- public static final String ATTRIBUTE_Dispatch =
- "javax.servlet.dispatch.request_uri";
- public static final String ATTRIBUTE_ERROR_EXCEPTION_TYPE =
- "javax.servlet.error.exception_type";
- public static final String ATTRIBUTE_ERROR_MESSAGE =
- "javax.servlet.error.message";
- public static final String ATTRIBUTE_RESOLVED_SERVLET =
- "org.apache.tomcat.servlet.resolved";
-
- public static final String WEB_XML_PublicId =
- "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN";
- public static final String WEB_XML_Resource =
- "/org/apache/tomcat/deployment/web.dtd";
-
- public static final String HTML = "text/html";
-
- public static final String DEFAULT_CONTENT_TYPE = "text/plain";
public static final String DEFAULT_CHAR_ENCODING = "8859_1";
-
-
- // deprecated
- public static final String[] MASKED_DIR = {
- "META-INF","WEB-INF"
- };
-
}
1.108 +38 -1 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.107
retrieving revision 1.108
diff -u -r1.107 -r1.108
--- Context.java 2000/08/11 21:19:57 1.107
+++ Context.java 2000/08/14 17:49:12 1.108
@@ -99,6 +99,23 @@
* @author Gal Shachor shachor@il.ibm.com
*/
public class Context implements LogAware {
+ // Proprietary attribute names for contexts - defined
+ // here so we can document them.
+
+ /** Private tomcat attribute names
+ */
+ public static final String ATTRIB_PREFIX="org.apache.tomcat";
+
+ /** Workdir - a place where the servlets are allowed to write
+ */
+ public static final String ATTRIB_WORKDIR="org.apache.tomcat.workdir";
+
+ /** This attribute will return the real context ( org.apache.tomcat.core.Context).
+ * Only "trusted" applications will get the value. Null if the application
+ * is not trusted.
+ */
+ public static final String ATTRIB_REAL_CONTEXT="org.apache.tomcat.context";
+
// -------------------- internal properties
// context "id"
private String path = "";
@@ -364,11 +381,27 @@
return initializationParameters.keys();
}
+
+ /** Workdir attribute - XXX is it specified anyway ?
+ */
+ public static final String ATTRIB_WORKDIR1 = "javax.servlet.context.tempdir";
+ // XXX deprecated, is anyone in the world using it ?
+ public static final String ATTRIB_WORKDIR2 = "sun.servlet.workdir";
+
public Object getAttribute(String name) {
- if (name.startsWith("org.apache.tomcat")) {
+ // deprecated
+ if( name.equals( ATTRIB_WORKDIR1 ) )
+ return getWorkDir();
+ if( name.equals( ATTRIB_WORKDIR2 ) )
+ return getWorkDir();
+
+
+ if (name.startsWith( ATTRIB_PREFIX )) {
// XXX XXX XXX XXX Security - servlets may get too much access !!!
// right now we don't check because we need JspServlet to
// be able to access classloader and classpath
+ if( name.equals( ATTRIB_WORKDIR ) )
+ return getWorkDir();
if (name.equals("org.apache.tomcat.jsp_classpath")) {
String separator = System.getProperty("path.separator", ":");
@@ -385,6 +418,10 @@
}
if(name.equals("org.apache.tomcat.classloader")) {
return this.getClassLoader();
+ }
+ if(name.equals(ATTRIB_REAL_CONTEXT)) {
+ if( ! allowAttribute(name) ) return null;
+ return this;
}
if( name.equals(FacadeManager.FACADE_ATTRIBUTE)) {
if( ! allowAttribute(name) ) return null;
1.115 +4 -3 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.114
retrieving revision 1.115
diff -u -r1.114 -r1.115
--- ContextManager.java 2000/08/13 02:04:12 1.114
+++ ContextManager.java 2000/08/14 17:49:12 1.115
@@ -1037,7 +1037,8 @@
/** Note id counters. Synchronized access is not necesarily needed
* ( the initialization is in one thread ), but anyway we do it
*/
- private int noteId[]=new int[4];
+ public static final int NOTE_COUNT=5;
+ private int noteId[]=new int[NOTE_COUNT];
/** Maximum number of notes supported
*/
@@ -1048,10 +1049,10 @@
public static final int CONTAINER_NOTE=1;
public static final int REQUEST_NOTE=2;
public static final int HANDLER_NOTE=3;
-
+
public static final int REQ_RE_NOTE=0;
- String noteName[][]=new String[4][MAX_NOTES];
+ String noteName[][]=new String[NOTE_COUNT][MAX_NOTES];
/** used to allow interceptors to set specific per/request, per/container
* and per/CM informations.
1.5 +7 -4 jakarta-tomcat/src/share/org/apache/tomcat/core/FacadeManager.java
Index: FacadeManager.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/FacadeManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FacadeManager.java 2000/08/02 02:17:10 1.4
+++ FacadeManager.java 2000/08/14 17:49:13 1.5
@@ -88,17 +88,20 @@
public ServletContext createServletContextFacade(Context ctx);
+ public Context getRealContext( ServletContext ctx );
+
+ public Request getRealRequest( HttpServletRequest req );
+
+
+
public HttpServletRequest createHttpServletRequestFacade(Request req);
public HttpServletResponse createHttpServletResponseFacade(Response res);
- public ServletConfig createServletConfig(Handler sw);
- public void recycle( Request req );
- public Request getRealRequest( HttpServletRequest req );
- public Context getRealContext( ServletContext ctx );
+ public void recycle( Request req );
}
1.28 +15 -19 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.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Response.java 2000/08/12 04:55:46 1.27
+++ Response.java 2000/08/14 17:49:13 1.28
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.27 2000/08/12 04:55:46 costin Exp $
- * $Revision: 1.27 $
- * $Date: 2000/08/12 04:55:46 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.28 2000/08/14 17:49:13 costin Exp $
+ * $Revision: 1.28 $
+ * $Date: 2000/08/14 17:49:13 $
*
* ====================================================================
*
@@ -82,17 +82,21 @@
* @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";
+
protected static StringManager sm =
StringManager.getManager("org.apache.tomcat.resources");
- static final Locale DEFAULT_LOCALE=new Locale(Constants.LOCALE_DEFAULT, "");
+ static final Locale DEFAULT_LOCALE=new Locale(LOCALE_DEFAULT, "");
protected Request request;
protected HttpServletResponse responseFacade;
protected Vector userCookies = new Vector();
- protected String contentType = Constants.DEFAULT_CONTENT_TYPE;
+ protected String contentType = DEFAULT_CONTENT_TYPE;
protected String contentLanguage = null;
- protected String characterEncoding = Constants.DEFAULT_CHAR_ENCODING;
+ protected String characterEncoding = DEFAULT_CHAR_ENCODING;
protected String sessionId;
protected int contentLength = -1;
protected int status = 200;
@@ -124,14 +128,6 @@
StringBuffer body=null;
public Response() {
- // if( useBuffer ) {
- // bBuffer=new ByteBuffer();
- // bBuffer.setParent( this );
- // out=null;
- // } else {
- // out=new BufferedServletOutputStream();
- // out.setResponse( this );
- // }
}
void init() {
@@ -186,10 +182,10 @@
public void recycle() {
userCookies.removeAllElements(); // XXX reuse !!!
- contentType = Constants.DEFAULT_CONTENT_TYPE;
+ contentType = DEFAULT_CONTENT_TYPE;
contentLanguage = null;
locale = DEFAULT_LOCALE;
- characterEncoding = Constants.DEFAULT_CHAR_ENCODING;
+ characterEncoding = DEFAULT_CHAR_ENCODING;
contentLength = -1;
status = 200;
usingWriter = false;
@@ -440,9 +436,9 @@
// stream before resetting the output stream
//
userCookies.removeAllElements(); // keep system (session) cookies
- contentType = Constants.DEFAULT_CONTENT_TYPE;
+ contentType = DEFAULT_CONTENT_TYPE;
locale = DEFAULT_LOCALE;
- characterEncoding = Constants.DEFAULT_CHAR_ENCODING;
+ characterEncoding = DEFAULT_CHAR_ENCODING;
contentLength = -1;
status = 200;
@@ -637,7 +633,7 @@
if( body==null)
body=new StringBuffer();
body.append(new String(buffer, pos, count,
- Constants.DEFAULT_CHAR_ENCODING) );
+ DEFAULT_CHAR_ENCODING) );
}
public StringBuffer getBody() {
1.10 +8 -23 jakarta-tomcat/src/share/org/apache/tomcat/facade/HttpServletRequestFacade.java
Index: HttpServletRequestFacade.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/facade/HttpServletRequestFacade.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HttpServletRequestFacade.java 2000/08/11 21:20:08 1.9
+++ HttpServletRequestFacade.java 2000/08/14 17:49:17 1.10
@@ -82,8 +82,8 @@
* @author Costin Manolache
*/
final class HttpServletRequestFacade implements HttpServletRequest {
- // Use the strings from core
- private static StringManager sm = StringManager.getManager("org.apache.tomcat.resources");
+ private static StringManager sm =
+ StringManager.getManager("org.apache.tomcat.resources");
private Request request;
@@ -117,6 +117,12 @@
Request getRealRequest() {
return request;
}
+
+ /** Not public - is called only from FacadeManager
+ */
+ void setRequest( Request req ) {
+ request=req;
+ }
// -------------------- Public facade methods --------------------
public Object getAttribute(String name) {
@@ -194,19 +200,11 @@
}
usingStream = true;
- //if( isFacade!=null) return isFacade;
- //if( request.getInputBuffer() != null ) {
- //isFacade=new ServletInputStreamFacade();
- //isFacade.setRequest( request );
if( ! isFacadeInitialized ) {
isFacade.prepare();
isFacadeInitialized=true;
}
return isFacade;
- // }
-
- // old mechanism
- // return request.getInputStream();
}
/** Adapter: Tomcat Request doesn't deal with header to int conversion.
@@ -279,15 +277,6 @@
}
usingReader = true;
- // // old mechanism
- // if( isFacade==null && request.getInputBuffer() == null )
- // return request.getReader();
-
- // New mechanism, based on exposed Buffers
- // if( isFacade == null ) {
- // isFacade=new ServletInputStreamFacade();
- // }
-
if( reader != null ) return reader; // method already called
if( ! isFacadeInitialized ) {
@@ -295,10 +284,6 @@
isFacadeInitialized=true;
}
- // isFacade.setRequest( request );
-
- // from RequestUtil. Note that InputStreamFacade
- // provide contentLength limiting
// XXX provide recycleable objects
String encoding = request.getCharacterEncoding();
if (encoding == null) {
1.5 +0 -5 jakarta-tomcat/src/share/org/apache/tomcat/facade/ServletInputStreamFacade.java
Index: ServletInputStreamFacade.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/facade/ServletInputStreamFacade.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ServletInputStreamFacade.java 2000/07/31 02:35:16 1.4
+++ ServletInputStreamFacade.java 2000/08/14 17:49:18 1.5
@@ -78,7 +78,6 @@
private int limit = -1;
private Request reqA;
- // private ByteBuffer inBuffer;
ServletInputStreamFacade() {
}
@@ -93,7 +92,6 @@
void setRequest(Request reqA ) {
this.reqA=reqA;
- // inBuffer=reqA.getInputBuffer();
}
void recycle() {
@@ -104,12 +102,10 @@
* use the old method.
*/
private int doRead() throws IOException {
- // if( inBuffer!=null ) return inBuffer.read();
return reqA.doRead();
}
private int doRead(byte[] b, int off, int len) throws IOException {
- // if( inBuffer!=null ) return inBuffer.read(b,off,len);
return reqA.doRead(b,off,len);
}
@@ -152,7 +148,6 @@
public int readLine(byte[] b, int off, int len) throws IOException {
- // no changes - the default implementation is good
return super.readLine(b, off, len);
}
}
1.2 +21 -3 jakarta-tomcat/src/share/org/apache/tomcat/facade/ServletWrapper.java
Index: ServletWrapper.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/facade/ServletWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServletWrapper.java 2000/08/02 03:50:31 1.1
+++ ServletWrapper.java 2000/08/14 17:49:18 1.2
@@ -117,7 +117,7 @@
public void setContext( Context context) {
super.setContext( context );
isReloadable=context.getReloadable();
- configF = context.getFacadeManager().createServletConfig( this );
+ configF = new ServletConfigImpl(this);
}
public String toString() {
@@ -384,13 +384,31 @@
protected void doService(Request req, Response res)
throws Exception
{
+ // Get facades - each req have one facade per context
+ // the facade itself is very light.
+
+ // For big servers ( with >100s of webapps ) we can
+ // use a pool or other technique. Right now there
+ // are many other ( much more expensive ) resources
+ // associated with contexts ( like the session thread)
+
+ // XXX
+ HttpServletRequest reqF= req.getFacade();//new HttpServletRequestFacade( req );
+ HttpServletResponse resF= res.getFacade();//new HttpServletResponseFacade( res );
+ doService( reqF, resF );
+
+ }
+
+ protected void doService(HttpServletRequest req, HttpServletResponse res)
+ throws Exception
+ {
// We are initialized and fine
if (servlet instanceof SingleThreadModel) {
synchronized(servlet) {
- servlet.service(req.getFacade(), res.getFacade());
+ servlet.service(req, res);
}
} else {
- servlet.service(req.getFacade(), res.getFacade());
+ servlet.service(req, res);
}
}
1.6 +0 -7 jakarta-tomcat/src/share/org/apache/tomcat/facade/SimpleFacadeManager.java
Index: SimpleFacadeManager.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/facade/SimpleFacadeManager.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SimpleFacadeManager.java 2000/08/02 02:17:26 1.5
+++ SimpleFacadeManager.java 2000/08/14 17:49:18 1.6
@@ -164,12 +164,5 @@
return realSctx;
}
-
- public ServletConfig createServletConfig(Handler sw) {
- // if( sw.getContext() != ctx ) return null;
- return new ServletConfigImpl((ServletWrapper)sw);
- }
-
-
}
1.7 +10 -9 jakarta-tomcat/src/share/org/apache/tomcat/util/SessionUtil.java
Index: SessionUtil.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SessionUtil.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SessionUtil.java 2000/07/05 20:02:44 1.6
+++ SessionUtil.java 2000/08/14 17:49:19 1.7
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SessionUtil.java,v 1.6 2000/07/05 20:02:44 alex Exp $
- * $Revision: 1.6 $
- * $Date: 2000/07/05 20:02:44 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SessionUtil.java,v 1.7 2000/08/14 17:49:19 costin Exp $
+ * $Revision: 1.7 $
+ * $Date: 2000/08/14 17:49:19 $
*
* ====================================================================
*
@@ -67,7 +67,6 @@
import javax.servlet.http.Cookie;
import org.apache.tomcat.core.*;
-import org.apache.tomcat.core.Constants;
/**
@@ -75,10 +74,12 @@
* <code>Session</code> implementations.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.6 $ $Date: 2000/07/05 20:02:44 $
+ * @version $Revision: 1.7 $ $Date: 2000/08/14 17:49:19 $
*/
public final class SessionUtil {
+ public static final String SESSION_COOKIE_NAME = "JSESSIONID";
+ public static final String SESSION_PARAMETER_NAME = "jsessionid";
// ------------------------------------------------------- Static Variables
@@ -103,7 +104,7 @@
*/
public static Cookie createCookie(Request req, String id) {
- Cookie cookie = new Cookie(Constants.SESSION_COOKIE_NAME, id);
+ Cookie cookie = new Cookie(SESSION_COOKIE_NAME, id);
String serverName = req.getServerName();
if (serverName != null)
cookie.setDomain(serverName);
@@ -193,7 +194,7 @@
if (cookies == null)
return (null);
for (int i = 0; i < cookies.length; i++) {
- if (Constants.SESSION_COOKIE_NAME.equals(cookies[i].getName()))
+ if (SESSION_COOKIE_NAME.equals(cookies[i].getName()))
return (cookies[i].getValue());
}
return (null);
@@ -212,7 +213,7 @@
public static String parseSessionId(String uri) {
// Search for the required match string in the URI
- String match = ";" + Constants.SESSION_PARAMETER_NAME + "=";
+ String match = ";" + SESSION_PARAMETER_NAME + "=";
int m = uri.indexOf(match);
if (m < 0)
return (null);
@@ -263,7 +264,7 @@
else
buf.append(url.substring(0, question));
buf.append(';');
- buf.append(Constants.SESSION_PARAMETER_NAME);
+ buf.append(SESSION_PARAMETER_NAME);
buf.append('=');
buf.append(id);
if (question >= 0)