tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat/src/tests/webpages/dispatch forwParam.jsp
Date Sun, 26 Aug 2001 01:45:39 GMT
costin      01/08/25 18:45:39

  Added:       src/tests/webpages/WEB-INF build.xml
               src/tests/webpages/WEB-INF/classes LoadServlet.java
                        RequestDump.java
               src/tests/webpages/WEB-INF/classes/dispatch ForwardPI.java
               src/tests/webpages/dispatch forwParam.jsp
  Log:
  Added few more tests ( not automated yet ) for various bugs.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat/src/tests/webpages/WEB-INF/build.xml
  
  Index: build.xml
  ===================================================================
  <project name="webpages" default="main" basedir=".">
  <!--
    The values to customize for each application:
  
    appname: the name of the application ( "simple" ). Defaults to 
             project name, if set.
  
  
    Global properties you must set( can be set in jaxm.properties )
  
    servlet.jar: location of servlet.jar
  
    Other properties, with defaults:
  
    webapps.dir: directory where the app will be built. 
            Default to in-place ( very usefull if you create your app under webapps/ ).
  
    wars.dir: directory where the .war file will be constructed. 
              If not set, no war will be generated.
  
    compile.debug
    compile.deprecation
    compile.optimize: javac customization
  
    -->
    <property file="${user.home}/build.properties"/>   <!-- User local        -->
    <property file="${user.home}/.ant.properties"/>    <!-- User local        -->
    <property file="build.properties"/>                <!-- Component local   -->
    <property file="../../build.properties"/>          <!-- For all webapps -->
    <property file="../../../build.properties"/>             
   
    <property name="appname" value="${ant.project.name}"/>
  
    <property name="appdir" location=".."/>
  
    <property name="compile.debug" value="true" />
    <property name="compile.optimize" value="false" />
    <property name="compile.deprecation" value="false" />
  
    <!-- Classpath
    <fileset id="extra-classpath" dir="." >
    </fileset>
    -->
    <!-- ==================== Init targets ==================== -->
    <target name="init" depends="checks,build.dir.webapps,build.dir.local"
  	  description="Initialization and checkup" >
      <echo message="-------- Building ${appname} to ${build.dir} "/>
    </target>
    
    <target name="prepare.build" 
  	  if="webapps.dir"
  	  description="Preparing the webapp dir if not in-place" >
      <mkdir dir="${webapps.dir}/${appname}"/>
      <mkdir dir="${webapps.dir}/${appname}/WEB-INF"/>
      <mkdir dir="${webapps.dir}/${appname}/WEB-INF/lib"/>
      <mkdir dir="${webapps.dir}/${appname}/WEB-INF/src"/>
      <mkdir dir="${webapps.dir}/${appname}/WEB-INF/classes"/>
      <copy todir="${webapps.dir}/${appname}" >
        <fileset dir="${appdir}" />
      </copy>
    </target>
  
    <target name="prepare" depends="init,prepare.build">
      <mkdir dir="${build.dir}/${appname}/WEB-INF/lib"/>
      <mkdir dir="${build.dir}/${appname}/WEB-INF/classes"/>
      <mkdir dir="${appdir}/WEB-INF/lib"/>
    </target>
    
    <!-- ==================== Build ==================== -->
  
    <target name="main" depends="prepare,compile.src,compile.classes" />
  
    <target name="compile.src" if="src.available" >
      <javac srcdir="${appdir}/WEB-INF/src"
             destdir="${build.dir}/${appname}/WEB-INF/classes"
  	   debug="${compile.debug}"
  	   deprecation="${compile.deprecation}"
  	   optimize="${compile.optimize}">
        <classpath >
  	<pathelement location="${servlet.jar}" />
  	<fileset id="app-classpath" dir="${appdir}/WEB-INF/lib">
  	  <include name="*.jar" />
  	</fileset>
        </classpath>
      </javac>
      <copy todir="${build.dir}/${appname}/WEB-INF/classes">
        <fileset dir="${appdir}/WEB-INF/src">
  	<include name="**/*.properties" />
  	<include name="**/*.dtd" />
  	<include name="**/*.xml" />
        </fileset>
      </copy>
    </target>
  
    <target name="compile.classes" if="classes.available" >
      <javac srcdir="${appdir}/WEB-INF/classes"
             destdir="${build.dir}/${appname}/WEB-INF/classes"
  	   debug="${compile.debug}"
  	   deprecation="${compile.deprecation}"
  	   optimize="${compile.optimize}">
        <classpath >
  	<pathelement location="${servlet.jar}" />
  	<fileset id="app-classpath" dir="${appdir}/WEB-INF/lib">
  	  <include name="*.jar" />
  	</fileset>
        </classpath>
      </javac>
  
    </target>
  
    <!-- ==================== Cleanup & Packaging ==================== -->
  
    <target name="clean" depends="init">
      <delete dir="{build.dir}/${appname}/WEB-INF/classes"/>
    </target>
  
    <target name="war" 
  	  depends="main" 
  	  description="Creating the WAR file" 
  	  if="wars.dir" >
      <mkdir dir="${wars.dir}" />
      <jar jarfile="${wars.dir}/${appname}.war"
  	 basedir="${build.dir}/${appname}" >
        <include name="**"/>
      </jar>
    </target>
  
    <!-- ==================== Logic and Guessing ==================== -->
  
    <target name="checks" depends="set.available,check.appname,check.servlet" />
  
    <target name="set.available" >
      <!-- Environement check -->
      <property name="src.base" location="../.." />
      <available property="appname.correct" file="../../${appname}/WEB-INF/build.xml" />
      <available property="servlet.available" file="${servlet.jar}" />
      <available property="src.available" file="src" />
      <available property="classes.available" file="classes" />
    </target>
    
    <target name="check.servlet" unless="servlet.available" >
      <fail message="Servlet.jar not found at ${servlet.jar}, make sure servlet.jar is
set" />
    </target>
  
    <target name="check.appname" unless="appname.correct" >
      <fail message="Appname not set, couldn't find ${appname} in ${src.base}" />
    </target>
    
    <target name="build.dir.webapps" if="webapps.dir" >
      <property name="build.dir" value="${webapps.dir}" />
    </target>
  
    <target name="build.dir.local" unless="webapps.dir" >
      <property name="build.dir" location="../.." />
    </target>
  
  </project>
  
  
  
  1.1                  jakarta-tomcat/src/tests/webpages/WEB-INF/classes/LoadServlet.java
  
  Index: LoadServlet.java
  ===================================================================
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  public class LoadServlet extends HttpServlet {
    public LoadServlet() {};
  
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {
      int num = (int) (java.lang.Math.random()*10000);
      int stop = (int) (java.lang.Math.random()*10000);
  
      java.io.PrintWriter pw = response.getWriter();
      pw.println("Lines = " + num + " " + stop);
      for (int i = 1;  i < num;  i++) {
        if (i == stop) {
          throw new ServletException("num = " + num + ", stop = " + stop);
        }
        pw.println("  Line " + i);
      }
    } 
  
    private class Loader implements Runnable {
      int num;
      public Loader(int pNum) { num = pNum; }
      public void run() {
        java.net.URL url;
        try {
          url = new java.net.URL("http://127.0.0.1:8080/test/servlet/LoadServlet?num=" + num);
        } catch (java.net.MalformedURLException e) {
          throw new NullPointerException();
        }
        int ok = 0;
        int ownErrors = 0;
        for (int i = 0;  ;  i++) {
          try {
            if (i % 100 == 100) {
              System.out.println("Thread " + num + " = " + i + ", ownErrors = " + ownErrors
+ ", ok = " + ok);
            }
            int stop = (int) (java.lang.Math.random()*40000);
            java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(url.openStream()));
            for (int j = 0;  ; j++) {
              String line = br.readLine();
              if (line == null) {
                break;
              }
              if (j == stop) {
                ++ownErrors;
                throw new NullPointerException();
              }
            }
            ++ok;
          } catch (Exception e) {
          }
        }
      }
    }
  
    public void run() {
      for (int i = 0;  i < 10;  i++) {
        Thread t = new Thread(new Loader(i));
        t.start();
      }
    }
  
    public static void main(String[] args) throws Exception {
      (new LoadServlet()).run();
    }
  }
  
  
  
  1.1                  jakarta-tomcat/src/tests/webpages/WEB-INF/classes/RequestDump.java
  
  Index: RequestDump.java
  ===================================================================
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Enumeration;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   *
   *
   * @author James Duncan Davidson <duncan@eng.sun.com>
   * @author Jason Hunter <jch@eng.sun.com>
   */
  public class RequestDump extends HttpServlet {
  
      public void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException
      {
  	doGet( request, response );
      }
      
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException
      {
  	dumpRequest(this, request, response );
      }
      
      public static void dumpRequest(HttpServlet servlet, HttpServletRequest request, HttpServletResponse
response)
          throws ServletException, IOException
      {
          PrintWriter out = response.getWriter();
          response.setContentType("text/html");
  	Enumeration enum, names, e;
  
  	ServletContext context=servlet.getServletContext();
          out.println();
          out.println("<h2>Request info</h2>");
  
  	out.println("<table border='1' id='req.info'>");
  
          out.println("<tr><td>Servlet Name</td><td>" + servlet.getServletName()
+ "</td></tr>");
          out.println("<tr><td>Protocol</td><td>" + request.getProtocol()
+ "</td></tr>");
          out.println("<tr><td>Scheme</td><td>" + request.getScheme()
+ "</td></tr>");
          out.println("<tr><td>Server Name</td><td>" + request.getServerName()
+ "</td></tr>");
          out.println("<tr><td>Server Port</td><td>" + request.getServerPort()
+ "</td></tr>");
          out.println("<tr><td>Server Info</td><td>" + context.getServerInfo()
+ "</td></tr>");
          out.println("<tr><td>Remote Addr</td><td>" + request.getRemoteAddr()
+ "</td></tr>");
          out.println("<tr><td>Remote Host</td><td>" + request.getRemoteHost()
+ "</td></tr>");
          out.println("<tr><td>Character Encoding</td><td>" + request.getCharacterEncoding()
+ "</td></tr>");
          out.println("<tr><td>Content Length</td><td>" + request.getContentLength()
+ "</td></tr>");
          out.println("<tr><td>Content Type</td><td>"+ request.getContentType()
+ "</td></tr>");
          out.println("<tr><td>Locale</td><td>"+ request.getLocale()
+ "</td></tr>");
          out.println("<tr><td>Default Response Buffer</td><td>"+
response.getBufferSize() + "</td></tr>");
          out.println("<tr><td>Request Is Secure</td><td>" + request.isSecure()
+ "</td></tr>");
          out.println("<tr><td>Auth Type</td><td>" + request.getAuthType()
+ "</td></tr>");
          out.println("<tr><td>HTTP Method</td><td>" + request.getMethod()
+ "</td></tr>");
          out.println("<tr><td>Remote User</td><td>" + request.getRemoteUser()
+ "</td></tr>");
          out.println("<tr><td>Request URI</td><td>" + request.getRequestURI()
+ "</td></tr>");
          out.println("<tr><td>Context Path</td><td>" + request.getContextPath()
+ "</td></tr>");
          out.println("<tr><td>Servlet Path</td><td>" + request.getServletPath()
+ "</td></tr>");
          out.println("<tr><td>Path Info</td><td>" + request.getPathInfo()
+ "</td></tr>");
  	out.println("<tr><td>Path Trans</td><td>" + request.getPathTranslated()
+ "</td></tr>");
          out.println("<tr><td>Query String</td><td>" + request.getQueryString()
+ "</td></tr>");
  
  	HttpSession session = request.getSession(false);
  	if( session!=null ) {
  	    out.println("<tr><td>Requested Session Id</td><td>" +
                      request.getRequestedSessionId() + "</td></tr>");
  	    out.println("<tr><td>Current Session Id</td><td>" + session.getId()
+ "</td></tr>");
  	    out.println("<tr><td>Session Created Time</td><td>" + session.getCreationTime()
+ "</td></tr>");
  	    out.println("<tr><td>Session Last Accessed Time</td><td>" +
  			session.getLastAccessedTime() + "</td></tr>");
  	    out.println("<tr><td>Session Max Inactive Interval Seconds</td><td>"
+
  			session.getMaxInactiveInterval() + "</td></tr>");
  	}
  
  	out.println("</table>");
  	
          out.println("<h2>Parameters</h2>");
  
  	out.println("<table border='1' id='req.params'>");
          e = request.getParameterNames();
          while (e.hasMoreElements()) {
              String key = (String)e.nextElement();
              String[] values = request.getParameterValues(key);
              out.print("<tr><td>" + key + "</td><td>");
              for(int i = 0; i < values.length; i++) {
                  out.print("<span>" + values[i] + "</span> ");
              }
              out.println("</td></tr>");
          }
          out.println("</table>");
  
          out.println("<h2>Headers</h2>");
  	out.println("<table border='1' id='req.headers'>");
  	e = request.getHeaderNames();
  	while (e.hasMoreElements()) {
              String key = (String)e.nextElement();
              String value = request.getHeader(key);
  	    out.println("<tr><td>" + key + "</td><td>" + value + "</td></tr>"
);
          }
  	out.println("</table>");
  
          out.println("<h2>Cookies</h2>");
  	out.println("<table border='1' id='req.cookies'>");
          Cookie[] cookies = request.getCookies();
          for (int i = 0; i < cookies.length; i++) {
              Cookie cookie = cookies[i];
  	    out.println("<tr><td>" + cookie.getName() + "</td><td>" + cookie.getValue()
+ "</td></tr>" );
          }
  	out.println("</table>");
  
  	if( session != null ) {
  	    out.println("<h2>Session</h2>");
  	    out.println("<table border='1' id='req.cookies'>");
  	    names = session.getAttributeNames();
  	    while (names.hasMoreElements()) {
  		String name = (String) names.nextElement();
  		out.println("<tr><td>" + name + "</td><td>" +
  			    session.getAttribute(name) + "</td></tr>" );
  	    }
  	    out.println("</table>");
  	}
  	
          out.println("<h2>Request attributes</h2>");
  	out.println("<table border='1' id='req.attributes'>");
  	e = request.getAttributeNames();
          while (e.hasMoreElements()) {
              String key = (String)e.nextElement();
              Object value = request.getAttribute(key);
  	    out.println("<tr><td>" + key + "</td><td>" + value + "</td></tr>"
); 
          }
  	out.println("</table>");
  
  	out.println("<h2>Context attributes:</h2>");
  	out.println("<table border='1' id='ctx.attributes'>");
  	enum = context.getAttributeNames();
  	while (enum.hasMoreElements()) {
  	    String key = (String)enum.nextElement();
              Object value = context.getAttribute(key);
  	    out.println("<tr><td>" + key + "</td><td>" + value + "</td></tr>"
); 
  	}
  	out.println("</table>");
  	
  
  	out.println("<h2>Servlet init parameters</h2>");
  	out.println("<table border='1' id='servlet.init.params'>");
  	e = servlet.getInitParameterNames();
  	while (e.hasMoreElements()) {
  	    String key = (String)e.nextElement();
  	    String value = servlet.getInitParameter(key);
  	    out.println("<tr><td>" + key + "</td><td>" + value + "</td></tr>"
); 
  	}
  	out.println("</table>");
  
  	out.println("<h2>Context init parameters</h2>");
  	out.println("<table border='1' id='ctx.init.params'>");
  
  	enum = context.getInitParameterNames();
  	while (enum.hasMoreElements()) {
  	    String key = (String)enum.nextElement();
              Object value = context.getInitParameter(key);
  	    out.println("<tr><td>" + key + "</td><td>" + value + "</td></tr>"
); 
  	}
  	out.println("</table>");
  
  
      }
  }
  
  
  
  
  1.1                  jakarta-tomcat/src/tests/webpages/WEB-INF/classes/dispatch/ForwardPI.java
  
  Index: ForwardPI.java
  ===================================================================
  /*
   * $Id: ForwardPI.java,v 1.1 2001/08/26 01:45:39 costin Exp $
   */
  
  
  package dispatch;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.io.*;
  
  import RequestDump;
  
  /**
   * Test FORWARD with a path info
   *
   */
  public class ForwardPI extends HttpServlet {
  
      public void doGet(HttpServletRequest req, HttpServletResponse res)
          throws ServletException, IOException
      {
  	req.setAttribute("originalPI", req.getPathInfo());
  	RequestDispatcher rd = getServletContext().getRequestDispatcher("/servlet/RequestDump");
  	rd.forward(req, res);
      }
  
  }
  
  
  
  
  
  
  1.1                  jakarta-tomcat/src/tests/webpages/dispatch/forwParam.jsp
  
  Index: forwParam.jsp
  ===================================================================
  <%
    String workListID="foo";
    String wiID="bar";
    String action="open";
  
  %>
  
  <jsp:forward page = "/servlet/RequestDump" >
    <jsp:param name = "workList.id"       value = "<%= workListID %>" />
    <jsp:param name = "workItem.id"       value = "<%= wiID %>" />
    <jsp:param name = "open.content"      value = "<%= action.equals( \"open\" ) ? \"true\"
: \"false\" %>" />
  </jsp:forward>
  
  

Mime
View raw message