tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets InvokerServlet.java
Date Fri, 05 May 2000 05:59:10 GMT
craigmcc    00/05/04 22:59:09

  Modified:    proposals/catalina/src/conf server.xml web.xml
               proposals/catalina/src/share/org/apache/tomcat/core
                        ApplicationContext.java ApplicationDispatcher.java
                        StandardContext.java
               proposals/catalina/src/share/org/apache/tomcat/servlets
                        InvokerServlet.java
  Log:
  Correct mapping problem on request dispatchers that, among other things,
  messed up the invoker servlet.
  
  Revision  Changes    Path
  1.16      +3 -3      jakarta-tomcat/proposals/catalina/src/conf/server.xml
  
  Index: server.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/conf/server.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- server.xml	2000/05/03 22:58:21	1.15
  +++ server.xml	2000/05/05 05:59:07	1.16
  @@ -50,12 +50,12 @@
         <!-- Tomcat Examples Context -->
         <Context path="/examples" docBase="webapps/examples" debug="0">
           <Listener className="org.apache.tomcat.startup.ContextConfig"
  -	          debug="3"/>
  +	          debug="0"/>
           <Manager className="org.apache.tomcat.session.StandardManager"
  -	         checkInterval="15" maxActiveSessions="1000"
  +	         checkInterval="15" maxActiveSessions="100"
                    pathname="sessions/localhost_examples.sessions"/>
   	<Valve   className="org.apache.tomcat.security.HttpSecurityValve"
  -                 debug="2"/>
  +                 debug="0"/>
         </Context>
   
         <!-- Watchdog JSP Tests Context -->
  
  
  
  1.7       +1 -3      jakarta-tomcat/proposals/catalina/src/conf/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/conf/web.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- web.xml	2000/05/03 22:58:21	1.6
  +++ web.xml	2000/05/05 05:59:08	1.7
  @@ -42,7 +42,7 @@
       </init-param>
   -->
   <!--
  -    <load-on-startup>-2147483646</load-on-startup>
  +    <load-on-startup>3</load-on-startup>
   -->
     </servlet>
   
  @@ -441,5 +441,3 @@
   -->
   
   </web-app>
  -
  -
  
  
  
  1.7       +7 -5      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationContext.java
  
  Index: ApplicationContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationContext.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ApplicationContext.java	2000/05/01 01:53:53	1.6
  +++ ApplicationContext.java	2000/05/05 05:59:08	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationContext.java,v
1.6 2000/05/01 01:53:53 craigmcc Exp $
  - * $Revision: 1.6 $
  - * $Date: 2000/05/01 01:53:53 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationContext.java,v
1.7 2000/05/05 05:59:08 craigmcc Exp $
  + * $Revision: 1.7 $
  + * $Date: 2000/05/05 05:59:08 $
    *
    * ====================================================================
    *
  @@ -91,7 +91,7 @@
    * associated with each instance of <code>StandardContext</code>.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.6 $ $Date: 2000/05/01 01:53:53 $
  + * @version $Revision: 1.7 $ $Date: 2000/05/05 05:59:08 $
    */
   
   final class ApplicationContext
  @@ -360,6 +360,7 @@
   	}
   	HttpRequestBase request = new HttpRequestBase();
   	request.setContext(context);
  +	request.setContextPath(context.getPath());
   	request.setRequestURI(contextPath + relativeURI);
   	request.setQueryString(queryString);
   	Wrapper wrapper = context.map(request, true);
  @@ -367,7 +368,8 @@
   	    return (null);
   
   	// Construct a RequestDispatcher to process this request
  -	HttpServletRequest hrequest = (HttpServletRequest) request.getRequest();
  +	HttpServletRequest hrequest =
  +	    (HttpServletRequest) request.getRequest();
   	ApplicationDispatcher dispatcher =
   	  new ApplicationDispatcher(wrapper,
   	  			    hrequest.getServletPath(),
  
  
  
  1.3       +88 -28    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java
  
  Index: ApplicationDispatcher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ApplicationDispatcher.java	2000/05/01 21:08:52	1.2
  +++ ApplicationDispatcher.java	2000/05/05 05:59:08	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v
1.2 2000/05/01 21:08:52 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/05/01 21:08:52 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v
1.3 2000/05/05 05:59:08 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/05/05 05:59:08 $
    *
    * ====================================================================
    *
  @@ -93,7 +93,7 @@
    * from this resource.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/05/01 21:08:52 $
  + * @version $Revision: 1.3 $ $Date: 2000/05/05 05:59:08 $
    */
   
   final class ApplicationDispatcher
  @@ -122,11 +122,14 @@
   	super();
   	this.wrapper = wrapper;
   	this.context = (Context) wrapper.getParent();
  -	this.logger = wrapper.getLogger();
   	this.servletPath = servletPath;
   	this.pathInfo = pathInfo;
   	this.queryString = queryString;
   
  +	if (debug >= 1)
  +	    log("servletPath=" + this.servletPath + ", pathInfo=" +
  +		this.pathInfo + ", queryString=" + queryString);
  +
       }
   
   
  @@ -140,9 +143,9 @@
   
   
       /**
  -     * The Logger we can use to log debugging messages.
  +     * The debugging detail level for this component.
        */
  -    private Logger logger = null;
  +    private int debug = 0;
   
   
       /**
  @@ -211,6 +214,8 @@
   
   	// Handle a non-HTTP forward by passing on the existing request and response
   	if ((hrequest == null) || (hresponse == null)) {
  +	    if (debug >= 1)
  +		log(" Non-HTTP Forward");
   	    try {
   		wrapper.invoke(srequest, sresponse);
   	    } catch (IOException e) {
  @@ -225,6 +230,8 @@
   
   	// Handle an HTTP named dispatcher forward (no wrapping is required)
           else if ((servletPath == null) && (pathInfo == null)) {
  +	    if (debug >= 1)
  +		log(" Named Dispatcher Forward");
   	    try {
   		wrapper.invoke(hrequest, hresponse);
   	    } catch (IOException e) {
  @@ -239,6 +246,22 @@
   
   	// Handle an HTTP path-based forward with no new query parameters
   	else if (queryString == null) {
  +	    if (debug >= 1)
  +		log(" Non-Wrapped Path Forward");
  +	    StringBuffer sb = new StringBuffer();
  +	    if (context.getPath() != null)
  +	        sb.append(context.getPath());
  +	    if (servletPath != null)
  +	        sb.append(servletPath);
  +	    if (pathInfo != null)
  +	        sb.append(pathInfo);
  +	    String requestURI = sb.toString();
  +	    hrequest.setRequestURI(requestURI);
  +	    hrequest.setServletPath(servletPath);
  +	    hrequest.setPathInfo(pathInfo);
  +	    // Keep original query string
  +	    if (debug >= 1)
  +		log(" requestURI=" + requestURI);
   	    try {
   		wrapper.invoke(hrequest, hresponse);
   	    } catch (IOException e) {
  @@ -254,6 +277,8 @@
   
   	// Handle an HTTP path-based dispatcher include with request wrapping
   	else {
  +	    if (debug >= 1)
  +		log(" Wrapped Path Forward");
   	    WrappedRequest wrequest = new WrappedRequest(hrequest, queryString);
   	    StringBuffer sb = new StringBuffer();
   	    if (context.getPath() != null)
  @@ -263,6 +288,8 @@
   	    if (pathInfo != null)
   	        sb.append(pathInfo);
   	    String requestURI = sb.toString();
  +	    if (debug >= 1)
  +		log(" requestURI=" + requestURI);
   	    wrequest.setRequestURI(requestURI);
   	    wrequest.setServletPath(servletPath);
   	    wrequest.setPathInfo(pathInfo);
  @@ -279,27 +306,6 @@
   	    }
   	}
   
  -
  -	// Flush and close the output stream or writer
  -	PrintWriter writer = null;
  -	try {
  -	    writer = response.getWriter();
  -	    try {
  -		writer.flush();
  -		writer.close();
  -	    } catch (Throwable t) {
  -		;
  -	    }
  -	} catch (IllegalStateException e) {
  -	    try {
  -		ServletOutputStream stream = response.getOutputStream();
  -		stream.flush();
  -		stream.close();
  -	    } catch (Throwable t) {
  -		;
  -	    }
  -	}
  -
       }
   
   
  @@ -332,6 +338,8 @@
   
   	// Handle a non-HTTP include by passing on the existing request and response
   	if ((hrequest == null) || (hresponse == null)) {
  +	    if (debug >= 1)
  +		log(" Non-HTTP Include");
   	    try {
   		wrapper.invoke(srequest, sresponse);
   	    } catch (IOException e) {
  @@ -347,6 +355,8 @@
   
   	// Handle an HTTP named dispatcher include (no wrapping is required)
   	if ((servletPath == null) && (pathInfo == null)) {
  +	    if (debug >= 1)
  +		log(" Named Dispatcher Include");
   	    try {
   		wrapper.invoke(hrequest, hresponse);
   	    } catch (IOException e) {
  @@ -361,6 +371,8 @@
   	}
   
   	// Handle an HTTP path-based dispatcher include (with request wrapping)
  +	if (debug >= 1)
  +	    log(" Wrapped Path Include");
   	WrappedRequest wrequest = new WrappedRequest(hrequest, queryString);
   	String contextPath = context.getPath();
   	StringBuffer sb = new StringBuffer();
  @@ -371,6 +383,8 @@
   	if (pathInfo != null)
   	    sb.append(pathInfo);
   	ServletRequest sr = wrequest.getRequest();
  +	if (debug >= 1)
  +	    log(" requestURI=" + sb.toString());
   	if (sb.length() > 0)
   	    sr.setAttribute("javax.servlet.include.request_uri", sb.toString());
   	if (contextPath != null)
  @@ -391,6 +405,52 @@
   	} catch (Throwable t) {
   	    throw new ServletException
   	      (sm.getString("applicationDispatcher.include.throw"), t);
  +	}
  +
  +    }
  +
  +
  +    // -------------------------------------------------------- Private Methods
  +
  +
  +    /**
  +     * Log a message on the Logger associated with our Context (if any)
  +     *
  +     * @param message Message to be logged
  +     */
  +    private void log(String message) {
  +
  +	Logger logger = null;
  +	if (context != null)
  +	    logger = context.getLogger();
  +	if (logger != null)
  +	    logger.log("ApplicationDispatcher[" + context.getPath() + "]: "
  +		       + message);
  +	else
  +	    System.out.println("ApplicationDispatcher[" + context.getPath()
  +			       + "]: " + message);
  +
  +    }
  +
  +
  +    /**
  +     * Log a message on the Logger associated with our Container (if any)
  +     *
  +     * @param message Message to be logged
  +     * @param throwable Associated exception
  +     */
  +    private void log(String message, Throwable throwable) {
  +
  +	Logger logger = null;
  +	if (context != null)
  +	    logger = context.getLogger();
  +	if (logger != null)
  +	    logger.log("ApplicationDispatcher[" + context.getPath() + "] "
  +		       + message, throwable);
  +	else {
  +	    System.out.println("ApplicationDispatcher[" + context.getPath()
  +			       + "]: " + message);
  +	    throwable.printStackTrace(System.out);
   	}
   
       }
  
  
  
  1.17      +12 -10    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java
  
  Index: StandardContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- StandardContext.java	2000/05/03 22:58:24	1.16
  +++ StandardContext.java	2000/05/05 05:59:08	1.17
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java,v
1.16 2000/05/03 22:58:24 craigmcc Exp $
  - * $Revision: 1.16 $
  - * $Date: 2000/05/03 22:58:24 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java,v
1.17 2000/05/05 05:59:08 craigmcc Exp $
  + * $Revision: 1.17 $
  + * $Date: 2000/05/05 05:59:08 $
    *
    * ====================================================================
    *
  @@ -92,7 +92,7 @@
    * requests directed to a particular servlet.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.16 $ $Date: 2000/05/03 22:58:24 $
  + * @version $Revision: 1.17 $ $Date: 2000/05/05 05:59:08 $
    */
   
   public final class StandardContext
  @@ -1102,7 +1102,9 @@
   	    ((HttpServletRequest) request.getRequest()).getRequestURI();
   	String relativeURI = requestURI.substring(contextPath.length());
   	if (debug > 0)
  -	    log("Mapping relative URI '" + relativeURI + "'");
  +	    log("Mapping contextPath='" + contextPath +
  +		"' with requestURI='" + requestURI +
  +		"' and relativeURI='" + relativeURI + "'");
   
   	// Apply the standard request URI mapping rules from the specification
   	Wrapper wrapper = null;
  @@ -1129,19 +1131,19 @@
   		log("  Trying prefix match");
   	    servletPath = relativeURI;
   	    while (true) {
  -		int slash = servletPath.lastIndexOf("/");
  -		if (slash < 0)
  -		    break;
  -		servletPath = servletPath.substring(0, slash);
   		name = (String) servletMappings.get(servletPath + "/*");
   		if (name != null)
   		    wrapper = (Wrapper) findChild(name);
  -		if (wrapper != null) {
  + 		if (wrapper != null) {
   		    pathInfo = relativeURI.substring(servletPath.length());
   		    if (pathInfo.length() == 0)
   			pathInfo = null;
   		    break;
   		}
  +		int slash = servletPath.lastIndexOf("/");
  +		if (slash < 0)
  +		    break;
  +		servletPath = servletPath.substring(0, slash);
   	    }
   	}
   
  
  
  
  1.3       +9 -6      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/InvokerServlet.java
  
  Index: InvokerServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/InvokerServlet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InvokerServlet.java	2000/05/01 21:08:53	1.2
  +++ InvokerServlet.java	2000/05/05 05:59:09	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/InvokerServlet.java,v
1.2 2000/05/01 21:08:53 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/05/01 21:08:53 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/InvokerServlet.java,v
1.3 2000/05/05 05:59:09 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/05/05 05:59:09 $
    *
    * ====================================================================
    *
  @@ -97,7 +97,7 @@
    * in the web application deployment descriptor.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/05/01 21:08:53 $
  + * @version $Revision: 1.3 $ $Date: 2000/05/05 05:59:09 $
    */
   
   public final class InvokerServlet
  @@ -279,8 +279,11 @@
           }
   
   	// Pass this request on to the newly created wrapper
  -	String dispatcherPath =
  -	    request.getServletPath() + "/" + servletClass + pathInfo;
  +	StringBuffer sb = new StringBuffer(request.getServletPath());
  +	sb.append("/");
  +	sb.append(servletClass);
  +	sb.append(pathInfo);
  +	String dispatcherPath = sb.toString();
   	if (debug > 0)
   	    log("serveRequest:  Forwarding to '" + dispatcherPath + "'");
   	RequestDispatcher rd =
  
  
  

Mime
View raw message