You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/02/08 19:50:47 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/core Context.java ContextManager.java JspWrapper.java RequestImpl.java ServletConfigImpl.java ServletWrapper.java
costin 00/02/08 10:50:47
Modified: . build.xml
src/share/org/apache/tomcat/context AutoSetup.java
LoadOnStartupInterceptor.java
WebXmlInterceptor.java
src/share/org/apache/tomcat/core Context.java
ContextManager.java JspWrapper.java
RequestImpl.java ServletConfigImpl.java
ServletWrapper.java
Log:
- Moved the JSP "load-on-startup" hack in LoadOnStartupInterceptor.
Still a hack, but no longer in core.
- As a result we can remove JSPWrapper. We still have a special case
for JSP pages, but it will be easy to fix ( i.e. have JSP engine set
the generated servlet wrapper after the first invocation - or another
way to avoid a RD )
- Fixed getPathTranslated() ( regression after cleanup )
- added "deprecated" comments in Context, many methods will go
- added few more debug lines, will probably be removed for release
or replaced with if(debug). Time the initialization ( the new web.xml
and server.xml reader will be 2x faster )
- servlet initParam are set on ServletWrapper instead of Context.
Revision Changes Path
1.28 +1 -1 jakarta-tomcat/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/build.xml,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- build.xml 2000/02/07 07:51:20 1.27
+++ build.xml 2000/02/08 18:50:42 1.28
@@ -28,7 +28,7 @@
<!-- include ant, it is used for testing and will be used for
configuration and few other tasks -->
- <copydir src="${ant.home}/bin" dest="${tomcat.build}/bin"/>
+ <copydir src="${ant.home}/src/bin" dest="${tomcat.build}/bin"/>
<copyfile src="${ant.home}/lib/xml.jar" dest="${tomcat.build}/lib/xml.jar"/>
<copyfile src="${ant.home}/lib/ant.jar" dest="${tomcat.build}/lib/ant.jar"/>
1.2 +4 -1 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AutoSetup.java 2000/01/29 05:51:28 1.1
+++ AutoSetup.java 2000/02/08 18:50:43 1.2
@@ -126,9 +126,10 @@
// Current code supports only one level, we
// need to decide an encoding scheme for multi-level
String path="/" + name; // decode(name)
-
+ // System.out.println("XXX : " + path );
if( path.equals("/ROOT") )
path="";
+
if( cm.getContext(path) == null ) {
// if no explicit set up
System.out.println("Automatic addContext( " + path + ", webapps/" + name + ")");
@@ -137,6 +138,8 @@
ctx.setPath(path);
ctx.setDocBase( "webapps/" + name);
cm.addContext(ctx);
+ } else {
+ //System.out.println("Already set up: " + path + " " + cm.getContext(path));
}
1.4 +57 -3 jakarta-tomcat/src/share/org/apache/tomcat/context/LoadOnStartupInterceptor.java
Index: LoadOnStartupInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/LoadOnStartupInterceptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LoadOnStartupInterceptor.java 2000/02/03 07:11:50 1.3
+++ LoadOnStartupInterceptor.java 2000/02/08 18:50:43 1.4
@@ -68,6 +68,7 @@
import java.net.*;
import java.util.*;
import javax.servlet.http.*;
+import javax.servlet.*;
/**
@@ -77,10 +78,15 @@
*/
public class LoadOnStartupInterceptor extends BaseContextInterceptor implements ContextInterceptor {
private static StringManager sm =StringManager.getManager("org.apache.tomcat.context");
+ int debug=0;
public LoadOnStartupInterceptor() {
}
-
+
+ public void setDebug( int i ) {
+ debug=i;
+ }
+
public int contextInit(Context ctx) {
init(ctx);
Vector orderedKeys = new Vector();
@@ -121,12 +127,15 @@
String servletName = (String)sOnLevel.nextElement();
ServletWrapper result = ctx.getServletByName(servletName);
- ctx.log("Loading " + key + " " + servletName );
+ if( debug > 0 ) ctx.log("Loading " + key + " " + servletName );
if(result==null)
System.out.println("Warning: we try to load an undefined servlet " + servletName);
else {
try {
- result.loadServlet();
+ if( result.getPath() != null )
+ loadJsp( ctx, result );
+ else
+ result.loadServlet();
} catch (Exception ee) {
String msg = sm.getString("context.loadServlet.e",
servletName);
@@ -138,6 +147,51 @@
return OK;
}
+ void loadJsp( Context context, ServletWrapper result ) throws Exception {
+ // A Jsp initialized in web.xml -
+
+ // Log ( since I never saw this code called, let me know if it does
+ // for you )
+ System.out.println("Initializing JSP with JspWrapper");
+
+ // Ugly code to trick JSPServlet into loading this.
+
+ // XXX XXX XXX
+ // core shouldn't depend on a particular connector!
+ // need to find out what this code does!
+
+ // XXX XXX find a better way !!!
+ // RequestAdapterImpl reqA=new RequestAdapterImpl();
+ // ResponseAdapterImpl resA=new ResponseAdapterImpl();
+ String path=result.getPath();
+ RequestImpl request = new RequestImpl();
+ ResponseImpl response = new ResponseImpl();
+ request.recycle();
+ response.recycle();
+
+ // request.setRequestAdapter( reqA );
+ // response.setResponseAdapter( resA );
+
+ request.setResponse(response);
+ response.setRequest(request);
+
+ String requestURI = path + "?jsp_precompile=true";
+
+ request.setRequestURI(context.getPath() + path);
+ request.setQueryString( Constants.JSP.Directive.Compile.Name + "=" +
+ Constants.JSP.Directive.Compile.Value );
+
+ request.setContext(context);
+ request.getSession(true);
+
+ RequestDispatcher rd = context.getRequestDispatcher(requestURI);
+
+ try {
+ rd.forward(request.getFacade(), response.getFacade());
+ } catch (ServletException se) {
+ } catch (IOException ioe) {
+ }
+ }
// --------------------
// Old logic from Context - probably something cleaner can replace it.
1.8 +2 -1 jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlInterceptor.java
Index: WebXmlInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlInterceptor.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- WebXmlInterceptor.java 2000/02/03 07:11:50 1.7
+++ WebXmlInterceptor.java 2000/02/08 18:50:43 1.8
@@ -82,7 +82,7 @@
}
public int contextInit(Context ctx) {
- System.out.println("Context(" + ctx.getPath() + "): " + ctx.getDocBase());
+ // System.out.println("Context(" + ctx.getPath() + "): " + ctx.getDocBase());
// process base configuration
WebApplicationReader webXmlReader=new WebApplicationReader();
@@ -96,6 +96,7 @@
} catch (Exception e) {
String msg = sm.getString("context.getConfig.e",ctx.getPath() + " " + ctx.getDocBase());
System.out.println(msg);
+ e.printStackTrace();
}
return 0;
}
1.38 +48 -8 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.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- Context.java 2000/02/03 07:11:51 1.37
+++ Context.java 2000/02/08 18:50:44 1.38
@@ -215,6 +215,7 @@
return isInvokerEnabled;
}
+
public void setInvokerEnabled(boolean isInvokerEnabled) {
this.isInvokerEnabled = isInvokerEnabled;
}
@@ -492,6 +493,7 @@
// Read context's web.xml
new WebXmlInterceptor().contextInit( this );
+ // new WebXmlReader().contextInit( this );
// load initial servlets
new LoadOnStartupInterceptor().contextInit( this );
@@ -548,9 +550,15 @@
return (String)initializationParameters.get(name);
}
+ /** @deprecated use addInitParameter
+ */
public void setInitParameter( String name, String value ) {
initializationParameters.put(name, value );
}
+
+ public void addInitParameter( String name, String value ) {
+ initializationParameters.put(name, value );
+ }
public Enumeration getInitParameterNames() {
return initializationParameters.keys();
@@ -604,6 +612,10 @@
this.description = description;
}
+ public void setIcon( String icon ) {
+
+ }
+
public boolean isDistributable() {
return this.isDistributable;
}
@@ -648,14 +660,17 @@
}
// --------------------
+
/** Add a jsp to the "pre-defined" list ( used by web.xml )
+ * @deprecated Create a Wrapper and use add Servlet
*/
public void addJSP(String name, String path, String description) {
// XXX
// check for duplicates!
- JspWrapper wrapper = new JspWrapper(this);
+ // JspWrapper wrapper = new JspWrapper(this);
+ ServletWrapper wrapper = new ServletWrapper(this);
wrapper.setServletName(name);
wrapper.setServletDescription(description);
@@ -683,6 +698,7 @@
return (servlets.containsKey(name));
}
+ // XXX use external iterator
/** Remove all servlets with a specific class name
*/
void removeServletByClassName(String className) {
@@ -704,6 +720,8 @@
}
}
+ /** @deprecated use getServletByPath or getJsp
+ */
public boolean containsJSP(String path) {
Enumeration enum = servlets.keys();
@@ -711,8 +729,8 @@
String key = (String)enum.nextElement();
ServletWrapper sw = (ServletWrapper)servlets.get(key);
- if( (sw instanceof JspWrapper ) &&
- path.equals( ((JspWrapper)sw).getPath()))
+ // if( (sw instanceof JspWrapper ) &&
+ if( path.equals( (sw).getPath()))
return true;
}
return false;
@@ -722,25 +740,29 @@
* Called only by deployment descriptor - to deal with
* duplicated mappings -
* XXX Find out if we really need that - it can be avoided!
+ * @deprecated Use removeServlet and findServletByPath or ByName
*/
public void removeJSP(String path) {
Enumeration enum = servlets.keys();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
ServletWrapper sw = (ServletWrapper)servlets.get(key);
- if( (sw instanceof JspWrapper ) &&
- path.equals( ((JspWrapper)sw).getPath()))
+ // if( (sw instanceof JspWrapper ) &&
+ if(path.equals( (sw).getPath()))
removeServlet( sw );
}
}
+ /** @deprecated use the method of servletWrapper
+ */
public void setServletInitParams(String name, Hashtable initParams) {
ServletWrapper wrapper = (ServletWrapper)servlets.get(name);
if (wrapper != null) {
wrapper.setInitArgs(initParams);
}
}
-
+
+ // XXX only one mapping, the mapper should do it's own optimizations
/**
* Maps a named servlet to a particular path or extension.
* If the named servlet is unregistered, it will be added
@@ -826,11 +848,14 @@
pathMappedServlets.remove(mapping);
}
+ // XXX replace with getServlet()
public ServletWrapper getServletByName(String servletName) {
return (ServletWrapper)servlets.get(servletName);
}
- // className==name for servlets loaded by invoker
+ /** @deprecated Create a ServletWrapper and add it.
+ This allows you to set other Wrapper properties
+ */
public ServletWrapper loadServlet(String servletClassName) {
// XXX
// check for duplicates!
@@ -853,7 +878,7 @@
* and instantiated using the given class name.
*
* Called to add a new servlet from web.xml
- *
+ * @deprecated use addServlet(ServletWrapper)
*/
public void addServlet(String name, String className,
String description) {
@@ -873,6 +898,17 @@
servlets.put(name, wrapper);
}
+ public void addServlet(ServletWrapper wrapper) {
+ String name=wrapper.getServletName();
+ // System.out.println("Adding servlet " + name + " " + wrapper);
+ // check for duplicates
+ if (servlets.get(name) != null) {
+ removeServletByClassName(name); // XXX XXX why?
+ removeServletByName(name);
+ }
+ servlets.put(name, wrapper);
+ }
+
private void removeServlet(ServletWrapper sw) {
if (prefixMappedServlets.contains(sw)) {
Enumeration enum = prefixMappedServlets.keys();
@@ -991,6 +1027,10 @@
private String normPath( String path ) {
int i = -1;
// norm path
+ if( path==null) {
+ /*DEBUG*/ try {throw new Exception(); } catch(Exception ex) {ex.printStackTrace();}
+ return "";
+ }
while ((i = path.indexOf('\\')) > -1) {
String a = path.substring(0, i);
String b = "";
1.33 +4 -2 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.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- ContextManager.java 2000/02/03 23:05:26 1.32
+++ ContextManager.java 2000/02/08 18:50:45 1.33
@@ -90,7 +90,6 @@
int debug=0;
private Vector requestInterceptors = new Vector();
- private Vector contextLifecycleInterceptors = new Vector();
/**
* The set of Contexts associated with this ContextManager,
@@ -138,6 +137,7 @@
public void init() throws TomcatException {
+ long time=System.currentTimeMillis();
(new AutoSetup()).handleContextManagerInit(this);
// Initialize and check Context Manager
(new DefaultCMSetter()).handleContextManagerInit(this);
@@ -148,7 +148,9 @@
Context context = getContext((String)enum.nextElement());
context.init();
}
+ System.out.println("Init time " + ( System.currentTimeMillis() - time ));
+
// After all context are configured, we can generate Apache configs
org.apache.tomcat.task.ApacheConfig apacheConfig=new org.apache.tomcat.task.ApacheConfig();
apacheConfig.execute( this );
@@ -212,7 +214,7 @@
* @param ctx context to be added.
*/
public void addContext( Context ctx ) {
- // System.out.println("Add context ");
+ // System.out.println("Add context ");
ctx.setContextManager( this );
// assert "valid path"
1.4 +3 -13 jakarta-tomcat/src/share/org/apache/tomcat/core/JspWrapper.java
Index: JspWrapper.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/JspWrapper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JspWrapper.java 2000/02/01 22:53:31 1.3
+++ JspWrapper.java 2000/02/08 18:50:45 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/JspWrapper.java,v 1.3 2000/02/01 22:53:31 costin Exp $
- * $Revision: 1.3 $
- * $Date: 2000/02/01 22:53:31 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/JspWrapper.java,v 1.4 2000/02/08 18:50:45 costin Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/02/08 18:50:45 $
*
* ====================================================================
*
@@ -180,13 +180,6 @@
RequestDispatcher rd = request.getRequestDispatcher(requestURI);
try {
- // Watch out, ugly code ahead...
- // We need to do a forward or include here, but we can't
- // easily determine which. So we try a forward, and if
- // there's an IllegalStateException thrown, then we know
- // we should have tried an include, so we do the include.
- // It's so ugly I have to giggle.
- // All this to support dispatching to named JSPs!
if (! response.getRealResponse().isStarted())
rd.forward(request, response);
else
@@ -199,10 +192,7 @@
ioe.printStackTrace();
response.sendError(404);
}
-
return;
- // I have no ideea how it works - but the code should be
- // equivalent with the original in ServletWrapper.
}
}
}
1.15 +8 -5 jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java
Index: RequestImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- RequestImpl.java 2000/02/03 23:05:27 1.14
+++ RequestImpl.java 2000/02/08 18:50:45 1.15
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v 1.14 2000/02/03 23:05:27 costin Exp $
- * $Revision: 1.14 $
- * $Date: 2000/02/03 23:05:27 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v 1.15 2000/02/08 18:50:45 costin Exp $
+ * $Revision: 1.15 $
+ * $Date: 2000/02/08 18:50:45 $
*
* ====================================================================
*
@@ -243,8 +243,11 @@
// the real path for this ( i.e. the URI ).
// Check the PATH_TRANSLATED specs before changing!
- if( pathTranslated==null)
- pathTranslated=context.getRealPath( getPathInfo() );
+ if( pathTranslated==null) {
+ String path=getPathInfo();
+ if(path==null) path="";
+ pathTranslated=context.getRealPath( path );
+ }
return pathTranslated;
}
1.3 +10 -3 jakarta-tomcat/src/share/org/apache/tomcat/core/ServletConfigImpl.java
Index: ServletConfigImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletConfigImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServletConfigImpl.java 2000/01/11 20:43:02 1.2
+++ ServletConfigImpl.java 2000/02/08 18:50:45 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletConfigImpl.java,v 1.2 2000/01/11 20:43:02 costin Exp $
- * $Revision: 1.2 $
- * $Date: 2000/01/11 20:43:02 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletConfigImpl.java,v 1.3 2000/02/08 18:50:45 costin Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/02/08 18:50:45 $
*
* ====================================================================
*
@@ -84,6 +84,13 @@
private Hashtable initArgs;
private String servletName = null;
private String servletClassName = null;
+
+ ServletConfigImpl() {
+ }
+
+ void setContext( Context ctx ) {
+ context=ctx;
+ }
ServletConfigImpl(Context context) {
this.context = context;
1.17 +71 -8 jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java
Index: ServletWrapper.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ServletWrapper.java 2000/02/03 07:11:52 1.16
+++ ServletWrapper.java 2000/02/08 18:50:46 1.17
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.16 2000/02/03 07:11:52 costin Exp $
- * $Revision: 1.16 $
- * $Date: 2000/02/03 07:11:52 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.17 2000/02/08 18:50:46 costin Exp $
+ * $Revision: 1.17 $
+ * $Date: 2000/02/08 18:50:46 $
*
* ====================================================================
*
@@ -93,7 +93,10 @@
protected ServletConfigImpl config;
protected Servlet servlet;
protected Class servletClass;
-
+
+ // Jsp pages
+ private String path = null;
+
// optional informations
protected String description = null;
@@ -106,9 +109,18 @@
int loadOnStartup=0;
+ public ServletWrapper() {
+ config = new ServletConfigImpl();
+ }
+
ServletWrapper(Context context) {
+ config = new ServletConfigImpl();
+ setContext( context );
+ }
+
+ public void setContext( Context context) {
this.context = context;
- config = new ServletConfigImpl(context);
+ config.setContext( context );
}
protected Context getContext() {
@@ -119,6 +131,10 @@
loadOnStartup=level;
}
+ public void setLoadOnStartUp( String level ) {
+ loadOnStartup=new Integer(level).intValue();
+ }
+
public int getLoadOnStartUp() {
return loadOnStartup;
}
@@ -131,15 +147,23 @@
return config.getServletName();
}
- void setServletName(String servletName) {
+ public void setServletName(String servletName) {
config.setServletName(servletName);
}
+ public String getPath() {
+ return this.path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
String getServletDescription() {
return this.description;
}
- void setServletDescription(String description) {
+ public void setServletDescription(String description) {
this.description = description;
}
@@ -152,6 +176,19 @@
config.setServletClassName(servletClassName);
}
+
+ Hashtable initArgs=null;
+
+ public void addInitParam( String name, String value ) {
+ if( initArgs==null) {
+ initArgs=new Hashtable();
+ config.setInitArgs( initArgs );
+ }
+ initArgs.put( name, value );
+ }
+
+ /** @deprecated
+ */
void setInitArgs(Hashtable initArgs) {
config.setInitArgs(initArgs);
}
@@ -202,10 +239,36 @@
}
}
+ // XXX XXX need to go directly to Jsp API
+ public void handleJspRequest(final HttpServletRequestFacade request,
+ final HttpServletResponseFacade response)
+ throws IOException
+ {
+ // "Special" JSP
+ String requestURI = path + request.getPathInfo();
+ RequestDispatcher rd = request.getRequestDispatcher(requestURI);
+
+ try {
+ if (! response.getRealResponse().isStarted())
+ rd.forward(request, response);
+ else
+ rd.include(request, response);
+
+ } catch (ServletException se) {
+ se.printStackTrace();
+ response.sendError(404);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ response.sendError(404);
+ }
+ return;
+ }
+
public void handleRequest(final HttpServletRequestFacade request,
final HttpServletResponseFacade response)
throws IOException
{
+ if( path != null ) handleJspRequest( request, response );
synchronized (this) {
if (servlet == null) {
try {
@@ -441,7 +504,7 @@
}
public String toString() {
- String toS="Wrapper(";
+ String toS="Wrapper(" + config.getServletName() + " ";
if( servlet!=null ) toS=toS+ "S:" + servlet.getClass().getName();
else toS= toS + servletClassName;
return toS + ")";
Apache 1.3.9 with Tomcat 3.0
Posted by Angel Gomez <al...@ibernet.com>.
I´ve installed Red Hat Linux 6.1 with Apache 1.3.9, but I couldn´t configure Tomcat 3.0 with the listener of Apache 1.3.9. Separatly their
do work well. How to tell apache to use the tomcat ?
Angel.
Thanks.