You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/05/01 23:08:53 UTC
cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets SnoopAllServlet.java InvokerServlet.java
craigmcc 00/05/01 14:08:53
Modified: proposals/catalina/src/share/org/apache/tomcat/core
ApplicationDispatcher.java
proposals/catalina/src/share/org/apache/tomcat/servlets
InvokerServlet.java
Added: proposals/catalina/src/share/org/apache/tomcat/servlets
SnoopAllServlet.java
Log:
Correct bugs in the "invoker" servlet, and have it use the new
RequestDispatcher implementation. Now, if you invoke
http://localhost:8080/servlet/org.apache.tomcat.servlets/SnoopAllServlet
you will get the following path element values:
context path = "" (i.e. zero-length string)
servlet path = "/servlet/org.apache.tomcat.servlets/SnoopAllServlet
path info = null string
Revision Changes Path
1.2 +21 -6 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ApplicationDispatcher.java 2000/05/01 01:53:54 1.1
+++ ApplicationDispatcher.java 2000/05/01 21:08:52 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v 1.1 2000/05/01 01:53:54 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/05/01 01:53:54 $
+ * $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 $
*
* ====================================================================
*
@@ -93,7 +93,7 @@
* from this resource.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/05/01 01:53:54 $
+ * @version $Revision: 1.2 $ $Date: 2000/05/01 21:08:52 $
*/
final class ApplicationDispatcher
@@ -223,7 +223,7 @@
}
}
- // Handle an HTTP named dispatcher include (no wrapping is required)
+ // Handle an HTTP named dispatcher forward (no wrapping is required)
else if ((servletPath == null) && (pathInfo == null)) {
try {
wrapper.invoke(hrequest, hresponse);
@@ -237,7 +237,22 @@
}
}
- // Handle an HTTP path-based dispatcher include (with request wrapping)
+ // Handle an HTTP path-based forward with no new query parameters
+ else if (queryString == null) {
+ try {
+ wrapper.invoke(hrequest, hresponse);
+ } catch (IOException e) {
+ throw e;
+ } catch (ServletException e) {
+ throw e;
+ } catch (Throwable t) {
+ throw new ServletException
+ (sm.getString("applicationDispatcher.forward.throw"), t);
+ }
+ }
+
+
+ // Handle an HTTP path-based dispatcher include with request wrapping
else {
WrappedRequest wrequest = new WrappedRequest(hrequest, queryString);
StringBuffer sb = new StringBuffer();
1.2 +17 -35 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InvokerServlet.java 2000/04/29 23:20:33 1.1
+++ InvokerServlet.java 2000/05/01 21:08:53 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/InvokerServlet.java,v 1.1 2000/04/29 23:20:33 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/04/29 23:20:33 $
+ * $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 $
*
* ====================================================================
*
@@ -97,7 +97,7 @@
* in the web application deployment descriptor.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/04/29 23:20:33 $
+ * @version $Revision: 1.2 $ $Date: 2000/05/01 21:08:53 $
*/
public final class InvokerServlet
@@ -211,8 +211,7 @@
context = (Context) wrapper.getParent();
if (debug > 0)
- log("InvokerServlet.init: Associated with Context '" +
- context.getPath() + "'");
+ log("init: Associated with Context '" + context.getPath() + "'");
}
@@ -239,13 +238,12 @@
// Identify the class name of the servlet we want
if (debug > 0)
- log("InvokerServlet.serveRequest: Serving request " +
- request.getMethod() + " " + request.getRequestURI());
+ log("serveRequest: Serving request " + request.getMethod() +
+ " " + request.getRequestURI());
String pathInfo = request.getPathInfo();
if (pathInfo == null) {
if (debug > 0)
- log("InvokerServlet.serveRequest: Invalid pathInfo '" +
- pathInfo + "'");
+ log("serveRequest: Invalid pathInfo '" + pathInfo + "'");
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
request.getRequestURI());
return;
@@ -261,11 +259,11 @@
pathInfo = "";
}
String name = "org.apache.tomcat.INVOKER." + servletClass;
- String path = request.getServletPath() + "/" + servletClass;
+ String pattern = request.getServletPath() + "/" + servletClass + "/*";
Wrapper wrapper = null;
if (debug > 0)
- log("InvokerServlet.serveRequest: Creating wrapper for '" +
- servletClass + "'");
+ log("serveRequest: Creating wrapper for '" + servletClass +
+ "' with mapping '" + pattern + "'");
try {
Class wrapperClassObject = Class.forName(wrapperClass);
wrapper = (Wrapper) wrapperClassObject.newInstance();
@@ -273,37 +271,21 @@
wrapper.setLoadOnStartup(0);
wrapper.setServletClass(servletClass);
context.addChild(wrapper);
- context.addServletMapping(path, name);
+ context.addServletMapping(pattern, name);
} catch (Throwable t) {
- log("InvokerServlet.serveRequest", t);
+ log("serveRequest", t);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
// Pass this request on to the newly created wrapper
- // FIXME - use RequestDispatcher.forward() when available
+ String dispatcherPath =
+ request.getServletPath() + "/" + servletClass + pathInfo;
if (debug > 0)
- log("InvokerServlet.serveRequest: Forwarding to servlet");
- try {
- HttpRequest hrequest = (HttpRequest) request;
- HttpResponse hresponse = (HttpResponse) response;
- hrequest.setServletPath(path);
- if (pathInfo.length() > 0)
- hrequest.setPathInfo(pathInfo);
- else
- hrequest.setPathInfo(null);
- wrapper.invoke(hrequest, hresponse);
- } catch (ClassCastException e) {
- log("InvokerServlet.serveRequest", e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- return;
- }
- /*
+ log("serveRequest: Forwarding to '" + dispatcherPath + "'");
RequestDispatcher rd =
- getServletContext().getRequestDispatcher(path + pathInfo);
+ getServletContext().getRequestDispatcher(dispatcherPath);
rd.forward(request, response);
- */
-
}
1.1 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/SnoopAllServlet.java
Index: SnoopAllServlet.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/SnoopAllServlet.java,v 1.1 2000/05/01 21:08:53 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/05/01 21:08:53 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet to dump everything that is known in the current request object
* into an HTML page.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/05/01 21:08:53 $
*/
public final class SnoopAllServlet
extends HttpServlet {
/**
* Process a GET request for the specified resource.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet-specified error occurs
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
// Generate HTML page header
writer.println("<head>");
writer.println("<title>SnoopAllServlet Output</title>");
writer.println("</head>");
writer.println("<body bgcolor=\"white\">");
// Document the properties from ServletRequest
writer.println("<h1>ServletRequest Properties</h1>");
writer.println("<ul>");
Enumeration attrs = request.getAttributeNames();
while (attrs.hasMoreElements()) {
String attr = (String) attrs.nextElement();
writer.println("<li><b>attribute</b> " + attr + " = " +
request.getAttribute(attr));
}
writer.println("<li><b>characterEncoding</b> = " +
request.getCharacterEncoding());
writer.println("<li><b>contentLength</b> = " +
request.getContentLength());
writer.println("<li><b>contentType</b> = " +
request.getContentType());
Enumeration locales = request.getLocales();
while (locales.hasMoreElements()) {
Locale locale = (Locale) locales.nextElement();
writer.println("<li><b>locale</b> = " + locale);
}
Enumeration params = request.getParameterNames();
while (params.hasMoreElements()) {
String param = (String) params.nextElement();
String values[] = request.getParameterValues(param);
for (int i = 0; i < values.length; i++)
writer.println("<li><b>parameter</b> " + param + " = " +
values[i]);
}
writer.println("<li><b>protocol</b> = " + request.getProtocol());
writer.println("<li><b>remoteAddr</b> = " + request.getRemoteAddr());
writer.println("<li><b>remoteHost</b> = " + request.getRemoteHost());
writer.println("<li><b>scheme</b> = " + request.getScheme());
writer.println("<li><b>secure</b> = " + request.isSecure());
writer.println("<li><b>serverName</b> = " + request.getServerName());
writer.println("<li><b>serverPort</b> = " + request.getServerPort());
writer.println("</ul>");
writer.println("<hr>");
// Document the properties from HttpServletRequest
writer.println("<h1>HttpServletRequest Properties</h1>");
writer.println("<ul>");
writer.println("<li><b>authType</b> = " + request.getAuthType());
writer.println("<li><b>contextPath</b> = " +
request.getContextPath());
Cookie cookies[] = request.getCookies();
for (int i = 0; i < cookies.length; i++)
writer.println("<li><b>cookie</b> " + cookies[i].getName() +
" = " + cookies[i].getValue());
Enumeration headers = request.getHeaderNames();
while (headers.hasMoreElements()) {
String header = (String) headers.nextElement();
writer.println("<li><b>header</b> " + header + " = " +
request.getHeader(header));
}
writer.println("<li><b>method</b> = " + request.getMethod());
writer.println("<li><b>pathInfo</b> = " + request.getPathInfo());
writer.println("<li><b>pathTranslated</b> = " +
request.getPathTranslated());
writer.println("<li><b>queryString</b> = " +
request.getQueryString());
writer.println("<li><b>remoteUser</b> = " +
request.getRemoteUser());
writer.println("<li><b>requestedSessionId</b> = " +
request.getRequestedSessionId());
writer.println("<li><b>requestedSessionIdFromCookie</b> = " +
request.isRequestedSessionIdFromCookie());
writer.println("<li><b>requestedSessionIdFromURL</b> = " +
request.isRequestedSessionIdFromURL());
writer.println("<li><b>requestURI</b> = " +
request.getRequestURI());
writer.println("<li><b>servletPath</b> = " +
request.getServletPath());
writer.println("<li><b>userPrincipal</b> = " +
request.getUserPrincipal());
writer.println("</ul>");
writer.println("<hr>");
// Generate HTML page footer
writer.println("</body>");
writer.println("</html>");
}
/**
* Process a POST request for the specified resource.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet-specified error occurs
*/
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
doGet(request, response);
}
}