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/core DummyContainer.java
Date Fri, 21 Apr 2000 22:00:26 GMT
craigmcc    00/04/21 15:00:25

  Added:       proposals/catalina/src/share/org/apache/tomcat/core
                        DummyContainer.java
  Log:
  Add a dummy implementation of Container that returns "snoop" type output from
  a request passed to invoke().  This will be useful in debugging Connector
  implementations.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/DummyContainer.java
  
  Index: DummyContainer.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/DummyContainer.java,v
1.1 2000/04/21 22:00:25 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/04/21 22:00:25 $
   *
   * ====================================================================
   *
   * 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.core;
  
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Enumeration;
  import java.util.Locale;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.tomcat.Container;
  import org.apache.tomcat.Request;
  import org.apache.tomcat.Response;
  
  /**
   * Dummy container implementation that simply returns "snoop" type information
   * about an incoming Request.  This can be used to test and debug Connector
   * implementations.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/04/21 22:00:25 $
   */
  
  public final class DummyContainer
  extends ContainerBase {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * Should we output debugging information to System.out? (0=No, >0=Yes)
       */
      private int debug = 1;
  
  
      /**
       * Descriptive information about this implementation.
       */
      private static final String info =
        "org.apache.tomcat.core.DummyContainer/1.0";
  
  
      // ------------------------------------------------------------- Properties
  
      /**
       * Return the debug level for this Container.
       */
      public int getDebug() {
  
          return (debug);
  
      }
  
  
      /**
       * Set the debug level for this Container.
       *
       * @param debug New debug level
       */
      public void setDebug(int debug) {
  
          this.debug = debug;
  
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Return descriptive information about this Container implementation and
       * the corresponding version number, in the format
       * <code>&lt;description&gt;/&lt;version&gt;</code>.
       */
      public String getInfo() {
  
  	return (info);
  
      }
  
  
      /**
       * Process the specified Request, to produce the corresponding Response,
       * by invoking the first Valve in our pipeline (if any), or the basic
       * Valve otherwise.
       *
       * @param request Request to be processed
       * @param response Response to be produced
       *
       * @exception IllegalStateException if neither a pipeline or a basic
       *  Valve have been configured for this Container
       * @exception IOException if an input/output error occurred while
       *  processing
       * @exception ServletException if a ServletException was thrown
       *  while processing this request
       */
      public void invoke(Request request, Response response)
  	throws IOException, ServletException {
  
  	if (debug >= 0)
  	    System.out.println("DummyContainer.invoke() started");
  
  	ServletRequest sreq = request.getRequest();
  	HttpServletRequest hreq = null;
  	if (request.getRequest() instanceof HttpServletRequest)
  	    hreq = (HttpServletRequest) request.getRequest();
  	PrintWriter writer = response.getResponse().getWriter();
  
  	// Generate HTML page header
  	writer.println("<head>");
  	writer.println("<title>DummyContainer Output</title>");
  	writer.println("</head>");
  	writer.println("<body bgcolor=\"white\">");
  
  	// Document the properties of the Request itself
  	writer.println("<h1>Request Properties</h1>");
  	writer.println("<ul>");
  	writer.println("<li><b>connector</b> = " + request.getConnector());
  	writer.println("<li><b>context</b> = " + request.getContext());
  	writer.println("<li><b>info</b> = " + request.getInfo());
  	writer.println("</ul>");
  	writer.println("<hr>");
  
  	// Document the properties of the ServletRequest
  	writer.println("<h1>ServletRequest Properties</h1>");
  	writer.println("<ul>");
  	Enumeration attrs = sreq.getAttributeNames();
  	while (attrs.hasMoreElements()) {
   	    String attr = (String) attrs.nextElement();
  	    writer.println("<li><b>attribute</b> " + attr + " = " +
  			   sreq.getAttribute(attr));
  	}
  	writer.println("<li><b>characterEncoding</b> = " +
  		       sreq.getCharacterEncoding());
  	writer.println("<li><b>contentLength</b> = " +
  		       sreq.getContentLength());
  	writer.println("<li><b>contentType</b> = " +
  		       sreq.getContentType());
  	Enumeration locales = sreq.getLocales();
  	while (locales.hasMoreElements()) {
  	    Locale locale = (Locale) locales.nextElement();
  	    writer.println("<li><b>locale</b> = " + locale);
  	}
  	Enumeration params = sreq.getParameterNames();
  	while (params.hasMoreElements()) {
  	    String param = (String) params.nextElement();
  	    writer.println("<li><b>parameter</b> " + param + " = " +
  			   sreq.getParameter(param));  // FIXME - values
  	}
  	writer.println("<ul><b>protocol</b> = " + sreq.getProtocol());
  	writer.println("<ul><b>remoteAddr</b> = " + sreq.getRemoteAddr());
  	writer.println("<ul><b>remoteHost</b> = " + sreq.getRemoteHost());
  	writer.println("<ul><b>scheme</b> = " + sreq.getScheme());
  	writer.println("<ul><b>serverName</b> = " + sreq.getServerName());
  	writer.println("<ul><b>serverPort</b> = " + sreq.getServerPort());
  	writer.println("<ul><b>isSecure</b> = " + sreq.isSecure());
  	writer.println("</ul>");
  	writer.println("<hr>");
  
  	// Document the properties of the HttpServletRequest if present
  	if (hreq != null) {
  	    writer.println("<h1>HttpServletRequest Properties</h1>");
  	    writer.println("<ul>");
  	    writer.println("<li><b>authType</b> = " + hreq.getAuthType());
  	    writer.println("<li><b>contextPath</b> = " +
  			   hreq.getContextPath());
  	    Cookie cookies[] = hreq.getCookies();
  	    for (int i = 0; i < cookies.length; i++)
  	        writer.println("<li><b>cookie</b> " + cookies[i].getName() +
  			       " = " + cookies[i].getValue());
  	    Enumeration headers = hreq.getHeaderNames();
  	    while (headers.hasMoreElements()) {
  	        String header = (String) headers.nextElement();
  		writer.println("<li><b>header</b> " + header + " = " +
  			       hreq.getHeader(header));
  	    }
  	    writer.println("<li><b>method</b> = " + hreq.getMethod());
  	    writer.println("<li><b>pathInfo</b> = " + hreq.getPathInfo());
  	    writer.println("<li><b>pathTranslated</b> = " +
  			   hreq.getPathTranslated());
  	    writer.println("<li><b>queryString</b> = " +
  			   hreq.getQueryString());
  	    writer.println("<li><b>remoteUser</b> = " +
  			   hreq.getRemoteUser());
  	    writer.println("<li><b>requestURI</b> = " +
  			   hreq.getRequestURI());
  	    writer.println("<li><b>userPrincipal</b> = " +
  			   hreq.getUserPrincipal());
  	    writer.println("</ul>");
  	    writer.println("<hr>");
  	}
  
  	// Generate HTML page footer and flush the output
  	writer.println("</body>");
  	writer.println("</html>");
  	writer.flush();
  	writer.close();
  
  	if (debug >= 0)
  	    System.out.println("DummyContainer.invoke() finished");
  
  
      }
  
  
  }
  
  
  

Mime
View raw message