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/WEB-INF/classes/params RDInclude.java ServletUtil.java InputStreamParams.java Params.java ParamsInputStream.java
Date Wed, 07 Feb 2001 06:49:39 GMT
costin      01/02/06 22:49:38

  Modified:    src/tests/webpages/WEB-INF test-tomcat.xml
               src/tests/webpages/WEB-INF/classes/params
                        InputStreamParams.java Params.java
                        ParamsInputStream.java
  Added:       src/tests/webpages/WEB-INF/classes/params RDInclude.java
                        ServletUtil.java
  Log:
  More work on testing the parameter handling.
  
  The final tests will cover:
  - POST + GET and the way the params are merged
  - The Body is read on getParameter ( and not before )
  - RequestDispatchers and the way params are merged and restored.
  - RequestDispatchers and the rule that the Body is read on the first
  getParameter ( this will probably fail with Tomcat3.2 )
  - Same tests for JSPs ( the tests for reading the Body will probably
  fail on 3.2 and if 3.3 is using JspServlet - since JspServlet does a
  getParameter that will automatically read the body )
  - the special case of jsp_compile ( the spec mentions that ?jsp_compile
  can be used - which is a special form of parameter, since it has no =)
  - also make sure that jsp_compile doesn't execute the jsp
  
  So far the tests found few bugs in reading input, I'll commit the fix
  tommorow.
  
  Revision  Changes    Path
  1.14      +78 -17    jakarta-tomcat/src/tests/webpages/WEB-INF/test-tomcat.xml
  
  Index: test-tomcat.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/tests/webpages/WEB-INF/test-tomcat.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- test-tomcat.xml	2001/01/31 02:05:54	1.13
  +++ test-tomcat.xml	2001/02/07 06:49:29	1.14
  @@ -16,7 +16,7 @@
           early tests.
       -->
   
  -     <property name="revision" value="$Revision: 1.13 $" />  
  +     <property name="revision" value="$Revision: 1.14 $" />  
        <property name="host" value="127.0.0.1" />
        <property name="port"     value="8080" />
        <property name="outputType"     value="text" />
  @@ -90,6 +90,82 @@
       
     </target>
   
  +  <!-- ==================== Parameters tests ==================== -->
  +
  +  <target name="params" depends="init">
  +      <gtest>
  +          <comment>Simple GET with parmeters</comment>
  +          <httpClient path="/test/servlet/params.Params?a=k&amp;c=l&amp;a=m"
/>
  +          <defaultMatcher returnCode="200" />
  +          <defaultMatcher responseMatch="a = [ k , m ]" />
  +          <defaultMatcher responseMatch="c = [ l ]"/>
  +      </gtest>
  +
  +      <gtest>
  +          <comment>Simple POST parmeters</comment>
  +          <httpClient path="/test/servlet/params.Params" 
  +		      method="POST">
  +             <header name="Content-Type" 
  +		     value="application/x-www-form-urlencoded" />
  +             <body>a=b&amp;c=d</body>
  +          </httpClient>
  +          <defaultMatcher returnCode="200" />
  +          <defaultMatcher  responseMatch="a = [ b ]"/>
  +          <defaultMatcher responseMatch="c = [ d ]"/>
  +      </gtest>
  +
  +      <gtest>
  +          <comment>POST and GET parameters</comment>
  +          <httpClient path="/test/servlet/params.Params?a=x&amp;m=n" 
  +		      method="POST">
  +             <header name="Content-Type" 
  +		     value="application/x-www-form-urlencoded" />
  +             <body>a=b&amp;c=d</body>
  +          </httpClient>
  +          <defaultMatcher returnCode="200" />
  +          <defaultMatcher  responseMatch="a = [ x , b ]"/>
  +          <defaultMatcher responseMatch="m = [ n ]"/>
  +          <defaultMatcher responseMatch="c = [ d ]"/>
  +      </gtest>
  +    
  +      <gtest>
  +          <comment>The POST data can't be read before getParameter</comment>
  +          <httpClient 
  +              path="/test/servlet/params.InputStreamParams?a=x&amp;m=n" 
  +              method="POST">
  +             <header name="Content-Type" 
  +		     value="application/x-www-form-urlencoded" />
  +             <body>a=b&amp;c=d</body>
  +          </httpClient>
  +          <defaultMatcher returnCode="200" />
  +          <defaultMatcher  responseMatch="a = [ x ]" />
  +          <defaultMatcher responseMatch="m = [ n ]"/>
  +          <defaultMatcher responseMatch="c = [ d ]"/>
  +      </gtest>
  +    
  +
  +  </target>
  +
  +  <!-- ==================== Init params tests ==================== -->
  +
  +  <target name="init-params" depends="init">
  +    <gtest  request="GET /test/servlet/servletParam1 HTTP/1.0"
  +           returnCode="${http.protocol} 200"
  +           goldenFile="${gdir}/servletParam1.txt"
  +    />
  +
  +    <gtest  request="GET /test/servlet/servletParam2 HTTP/1.0"
  +           returnCode="${http.protocol} 200"
  +           goldenFile="${gdir}/servletParam2.txt"
  +    />
  +
  +    <gtest  request="GET /test/servlet/ServletParam HTTP/1.0"
  +           returnCode="${http.protocol} 200"
  +           goldenFile="${gdir}/ServletParam.txt"
  +    />
  +  </target>
  +
  +
     <!-- ==================== Dispatch tests ==================== -->
       <target name="dispatch" depends="init">
         <gtest  description="SimpleInclude"
  @@ -455,21 +531,6 @@
              returnCode="${http.protocol} 200"
       />
   
  -    <gtest  request="GET /test/servlet/servletParam1 HTTP/1.0"
  -           returnCode="${http.protocol} 200"
  -           goldenFile="${gdir}/servletParam1.txt"
  -    />
  -
  -    <gtest  request="GET /test/servlet/servletParam2 HTTP/1.0"
  -           returnCode="${http.protocol} 200"
  -           goldenFile="${gdir}/servletParam2.txt"
  -    />
  -
  -    <gtest  request="GET /test/servlet/ServletParam HTTP/1.0"
  -           returnCode="${http.protocol} 200"
  -           goldenFile="${gdir}/ServletParam.txt"
  -    />
  -
       <gtest  request="GET /test/jsp/bigDeclaration.jsp HTTP/1.0"
              returnCode="${http.protocol} 200"
       />
  @@ -537,7 +598,7 @@
   
      <!-- ==================== Get tests ==================== -->
     
  -   <target name="get" depends="init">
  +   <target name="get" depends="init,init-params">
   
         <gtest description="First call to unavailable will fail, wait 10 sec"
   	     request="GET /test/servlet/Unavailable HTTP/1.0"
  
  
  
  1.2       +4 -27     jakarta-tomcat/src/tests/webpages/WEB-INF/classes/params/InputStreamParams.java
  
  Index: InputStreamParams.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/tests/webpages/WEB-INF/classes/params/InputStreamParams.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InputStreamParams.java	2001/02/06 06:53:32	1.1
  +++ InputStreamParams.java	2001/02/07 06:49:33	1.2
  @@ -1,4 +1,4 @@
  -package request;
  +package params;
   
   import java.io.*;
   import java.text.*;
  @@ -18,33 +18,10 @@
           response.setContentType("text/plain");
           PrintWriter out = response.getWriter();
   
  -	InputStream in=request.getInputStream();
  +	ServletUtil.printBody( request, out );
  +	out.flush();
   
  -	out.println("START BODY: " );
  -	int c;
  -	while( (c=in.read()) >= 0 ) {
  -	    out.write( (char)c );
  -	}
  -	out.println();
  -	out.println("END BODY");
  -
  -	// Now get parameters - only query should be available :-)
  -	Enumeration paramN=request.getParameterNames();
  -
  -	while( paramN.hasMoreElements() ) {
  -	    String name=(String)paramN.nextElement();
  -	    String all[]=request.getParameterValues(name);
  -
  -	    out.print(name);
  -	    out.print(" = [ " );
  -	    for( int i=0; i<all.length; i++ ) {
  -		if( i>0 ) out.print( " , ");
  -		out.print( all[i] );
  -	    }
  -	    out.println( " ]");
  -	    
  -	}
  -        out.println(request.getQueryString());
  +	ServletUtil.printParams( request, out );
       }
   
   }
  
  
  
  1.2       +2 -18     jakarta-tomcat/src/tests/webpages/WEB-INF/classes/params/Params.java
  
  Index: Params.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/tests/webpages/WEB-INF/classes/params/Params.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Params.java	2001/02/06 06:53:32	1.1
  +++ Params.java	2001/02/07 06:49:33	1.2
  @@ -1,4 +1,4 @@
  -package request;
  +package params;
   
   import java.io.*;
   import java.text.*;
  @@ -18,23 +18,7 @@
           response.setContentType("text/plain");
           PrintWriter out = response.getWriter();
   
  -	out.println("Request parameters: " );
  -	Enumeration paramN=request.getParameterNames();
  -
  -	while( paramN.hasMoreElements() ) {
  -	    String name=(String)paramN.nextElement();
  -	    String all[]=request.getParameterValues(name);
  -
  -	    out.print(name);
  -	    out.print(" = [ " );
  -	    for( int i=0; i<all.length; i++ ) {
  -		if( i>0 ) out.print( " , ");
  -		out.print( all[i] );
  -	    }
  -	    out.println( " ]");
  -	    
  -	}
  -        out.println(request.getQueryString());
  +	ServletUtil.printParams( request, out );
       }
   
   }
  
  
  
  1.2       +4 -28     jakarta-tomcat/src/tests/webpages/WEB-INF/classes/params/ParamsInputStream.java
  
  Index: ParamsInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/tests/webpages/WEB-INF/classes/params/ParamsInputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParamsInputStream.java	2001/02/06 06:53:32	1.1
  +++ ParamsInputStream.java	2001/02/07 06:49:34	1.2
  @@ -1,4 +1,4 @@
  -package request;
  +package params;
   
   import java.io.*;
   import java.text.*;
  @@ -17,35 +17,11 @@
       {
   	PrintWriter out = response.getWriter();
           response.setContentType("text/plain");
  -	Enumeration paramN=request.getParameterNames();
   
  -	while( paramN.hasMoreElements() ) {
  -	    String name=(String)paramN.nextElement();
  -	    String all[]=request.getParameterValues(name);
  +	ServletUtil.printParams( request, out );
  +	out.flush();
   
  -	    out.print(name);
  -	    out.print(" = [ " );
  -	    for( int i=0; i<all.length; i++ ) {
  -		if( i>0 ) out.print( " , ");
  -		out.print( all[i] );
  -	    }
  -	    out.println( " ]");
  -	    
  -	}
  -	
  -        out.println("QueryString= " + request.getQueryString());
  -
  -
  -	InputStream in=request.getInputStream();
  -
  -	out.println("START BODY: " );
  -	int c;
  -	while( (c=in.read()) >= 0 ) {
  -	    out.write( (char)c );
  -	}
  -	out.println();
  -	out.println("END BODY");
  -
  +	ServletUtil.printBody( request, out );
       }
   
   }
  
  
  
  1.1                  jakarta-tomcat/src/tests/webpages/WEB-INF/classes/params/RDInclude.java
  
  Index: RDInclude.java
  ===================================================================
  package params;
  
  import java.io.*;
  import java.text.*;
  import java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   *
   */
  public class RDInclude extends HttpServlet {
  
      public void service(HttpServletRequest request,
  			HttpServletResponse response)
          throws IOException, ServletException
      {
          response.setContentType("text/plain");
          PrintWriter out = response.getWriter();
  
  	out.println("RequestDispatcher view: ");
  	ServletUtil.printParams( request, out );
  
  	String uri="Params?a=b";
  	out.println("Calling RD.include for: " + uri);
  	RequestDispatcher rd=request.getRequestDispatcher(uri);
  
  	rd.include( request, response );
  
  	out.println("After include ");
  	ServletUtil.printParams( request, out );
  
  	uri="Params?a=c&d=e";
  	out.println("Calling RD.include for: " + uri);
  	rd=request.getRequestDispatcher(uri);
  
  	rd.include( request, response );
  	
  	out.println("After include ");
  	ServletUtil.printParams( request, out );
      }
  
  }
  
  
  
  
  
  
  1.1                  jakarta-tomcat/src/tests/webpages/WEB-INF/classes/params/ServletUtil.java
  
  Index: ServletUtil.java
  ===================================================================
  package params;
  
  import java.io.*;
  import java.text.*;
  import java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   *
   */
  public class ServletUtil {
  
  
      public static void printParams( HttpServletRequest request,
  				   PrintWriter out )
          throws IOException, ServletException
      {
  	Enumeration paramN=request.getParameterNames();
  	out.print( "Params = [");
  	
  	while( paramN.hasMoreElements() ) {
  	    String name=(String)paramN.nextElement();
  	    String all[]=request.getParameterValues(name);
  	    out.print(name);
  	    if( paramN.hasMoreElements()) out.print(" , ");
  	}
  	
  	out.println( " ]");
  
  	paramN=request.getParameterNames();
  
  	while( paramN.hasMoreElements() ) {
  	    String name=(String)paramN.nextElement();
  	    String all[]=request.getParameterValues(name);
  
  	    out.print(name);
  	    out.print(" = [ " );
  	    for( int i=0; i<all.length; i++ ) {
  		if( i>0 ) out.print( " , ");
  		out.print( all[i] );
  	    }
  	    out.println( " ]");
  	    
  	}
  	
          out.println("Query = " + request.getQueryString());
      }
  
      public static void printBody( HttpServletRequest request,
  				  PrintWriter out )
          throws IOException, ServletException
      {
  	InputStream in=request.getInputStream();
  	
  	out.println("START BODY: " );
  	int c;
  	while( (c=in.read()) >= 0 ) {
  	    out.write( (char)c );
  	}
  	out.println();
  	out.println("END BODY");
      }
  
  }
  
  
  
  
  
  

Mime
View raw message