jakarta-watchdog-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rlu...@apache.org
Subject cvs commit: jakarta-watchdog-4.0/src/tools/org/apache/tomcat/task GTest.java
Date Tue, 29 Jan 2002 17:06:32 GMT
rlubke      02/01/29 09:06:32

  Modified:    src/tools/org/apache/tomcat/task GTest.java
  Log:
   - Per section 19.6.1.1 of RFC 2616, GTest will now send a Host header
     on every request.
   - general clean up of request code.
  
  Revision  Changes    Path
  1.18      +64 -69    jakarta-watchdog-4.0/src/tools/org/apache/tomcat/task/GTest.java
  
  Index: GTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-watchdog-4.0/src/tools/org/apache/tomcat/task/GTest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- GTest.java	24 Jan 2002 17:49:10 -0000	1.17
  +++ GTest.java	29 Jan 2002 17:06:32 -0000	1.18
  @@ -330,7 +330,7 @@
           StringTokenizer tok = new StringTokenizer( s, "|" );
           while ( tok.hasMoreElements() ) {
               String header = (String) tok.nextElement();
  -            getHeaderDetails( header, expectHeaders, false );
  +            setHeaderDetails( header, expectHeaders, false );
           }
       }
   
  @@ -344,7 +344,7 @@
        */
       public void setUnexpectedHeaders( String s ) {
           this.unexpectedHeaders = new HashMap();
  -        getHeaderDetails( s, unexpectedHeaders, false );
  +        setHeaderDetails( s, unexpectedHeaders, false );
       }
   
       public void setNested( String s ) {
  @@ -416,7 +416,7 @@
           StringTokenizer tok = new StringTokenizer( s, "|" );
           while ( tok.hasMoreElements() ) {
               String header = (String) tok.nextElement();
  -            getHeaderDetails( header, requestHeaders, true );
  +            setHeaderDetails( header, requestHeaders, true );
           }
       }
   
  @@ -831,82 +831,76 @@
   
           OutputStream out = new BufferedOutputStream( 
                                  socket.getOutputStream() );
  -        StringBuffer reqbuf = new StringBuffer( 128 ); 
  -        try {
  -            if ( debug > 0 ) {
  -                System.out.println( " REQUEST: " + request );
  -            }
  -            reqbuf.append( request );
  -            reqbuf.append( CRLF );
  +        StringBuffer reqbuf = new StringBuffer( 128 );
   
  -            // Now sending any specified request headers
  -            if ( !requestHeaders.isEmpty() ) {
  -                Iterator iter = requestHeaders.keySet().iterator();
  -		
  -                while ( iter.hasNext() ) {
  -                    String headerKey = ( String ) iter.next();
  -		            ArrayList values = (ArrayList) requestHeaders.get( headerKey );
  -		            String[] value = (String[]) values.toArray( new String[ values.size() ] );
  -		            for ( int i = 0; i < value.length; i++ ) {
  -			            reqbuf.append( headerKey );
  -			            reqbuf.append( ": " );
  -			            reqbuf.append( value[ i ] );
  -                        reqbuf.append( CRLF );
  -			            if ( debug > 0 ) {
  -			                System.out.println( " REQUEST HEADER: " + headerKey + ": " + value[
i ] );
  -			            }
  -		            }
  -                }
  -            }
  +        // set the Host header
  +        setHeaderDetails( "Host:" + host, requestHeaders, true );
   
  -            if ( testSession != null ) {
  -                cookieController = ( CookieController ) sessionHash.get( testSession );
  -
  -                if ( cookieController != null ) {
  -
  -                    String releventCookieString = cookieController.applyRelevantCookies(
requestURL );
  -
  -                    if ( ( releventCookieString != null ) && ( !releventCookieString.trim().equals(
"" ) ) ) {
  -                        reqbuf.append( "Cookie: " );
  -                        reqbuf.append( releventCookieString );
  -                        reqbuf.append( CRLF );
  +        // set the Content-Length header
  +        if ( content != null ) {
  +            setHeaderDetails( "Content-Length:" + content.length(),
  +                              requestHeaders, true );
  +        }
   
  -                        if ( debug > 0 ) {
  -                            System.out.println( " Sending Cookie Header:: Cookie: " + releventCookieString
);
  -                        }
  -                    }
  +        // set the Cookie header
  +        if ( testSession != null ) {
  +            cookieController = ( CookieController ) sessionHash.get( testSession );
  +
  +            if ( cookieController != null ) {
  +
  +                String releventCookieString = cookieController.applyRelevantCookies( requestURL
);
  +
  +                if ( ( releventCookieString != null ) && ( !releventCookieString.trim().equals(
"" ) ) ) {
  +                    setHeaderDetails( "Cookie:" + releventCookieString, requestHeaders,
true );
                   }
               }
  +        }
   
  -            /*
  +        if ( debug > 0 ) {
  +            System.out.println( " REQUEST: " + request );
  +        }
  +        reqbuf.append( request ).append( CRLF );;
   
  -            if ( ( testSession != null ) && ( sessionHash.get( testSession ) !=
null ) ) {
  -                System.out.println("Sending Session Id : " + (String)sessionHash.get( testSession
) );
  -                pw.println("JSESSIONID:" + (String)sessionHash.get( testSession) );
  +        // append all rquest headers 
  +        if ( !requestHeaders.isEmpty() ) {
  +            Iterator iter = requestHeaders.keySet().iterator();
  +		
  +            while ( iter.hasNext() ) {
  +                String headerKey = ( String ) iter.next();
  +		        ArrayList values = (ArrayList) requestHeaders.get( headerKey );
  +		        String[] value = (String[]) values.toArray( new String[ values.size() ] );
  +		        for ( int i = 0; i < value.length; i++ ) {
  +			        reqbuf.append( headerKey ).append( ": " ).append( value[ i ] ).append( CRLF
);
  +			        if ( debug > 0 ) {
  +			            System.out.println( " REQUEST HEADER: " + headerKey + ": " + value[ i ]
);
  +			        }
  +		        }
               }
  +        }
   
  -            */
  +        /*
   
  -            if ( content != null ) {
  -                int length = content.length();
  -                if ( debug > 0 ) {
  -                    System.out.println( " REQUEST HEADER: Content-Length: " + length );
  -                }
  -                reqbuf.append( "Content-Length: " );
  -                reqbuf.append( length );
  -                reqbuf.append( CRLF );
  -            }
  +        if ( ( testSession != null ) && ( sessionHash.get( testSession ) != null
) ) {
  +            System.out.println("Sending Session Id : " + (String)sessionHash.get( testSession
) );
  +            pw.println("JSESSIONID:" + (String)sessionHash.get( testSession) );
  +        }
   
  -            if ( request.indexOf( "HTTP/1." ) > -1 ) {
  -                reqbuf.append( "" );
  -                reqbuf.append( CRLF );
  -            }
  +        */
   
  -            if ( content != null ) {
  -                reqbuf.append( content );
  -                // XXX no CRLF at the end -see HTTP specs!
  -            }
  -            byte[] reqbytes = reqbuf.toString().getBytes();
  +        if ( request.indexOf( "HTTP/1." ) > -1 ) {
  +            reqbuf.append( "" ).append( CRLF );
  +        }
  +
  +        // append request content 
  +        if ( content != null ) {
  +            reqbuf.append( content );
  +            // XXX no CRLF at the end -see HTTP specs!
  +        }
  +        
  +        byte[] reqbytes = reqbuf.toString().getBytes();
  +
  +        try {
  +            // write the request
               out.write( reqbytes, 0, reqbytes.length );
               out.flush();
               reqbuf = null;
  @@ -918,6 +912,7 @@
   	        }
           }
   
  +        // read the response
           try {
     
   	        responseLine = read( in );
  @@ -1113,7 +1108,7 @@
       }
   
       /**
  -     * <code>getHeaderDetails</code> Wrapper method for parseHeader.
  +     * <code>setHeaderDetails</code> Wrapper method for parseHeader.
        * Allows easy addition of headers to the specified
        * HashMap
        *
  @@ -1122,7 +1117,7 @@
        * @param isRequest a <code>boolean</code> indicating if the passed Header

        *                  HashMap is for request headers
        */
  -    private void getHeaderDetails( String line, HashMap headerHash, boolean isRequest )
{
  +    private void setHeaderDetails( String line, HashMap headerHash, boolean isRequest )
{
           StringTokenizer stk = new StringTokenizer( line, "##" );
   
           while ( stk.hasMoreElements( ) ) {
  
  
  

--
To unsubscribe, e-mail:   <mailto:watchdog-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:watchdog-dev-help@jakarta.apache.org>


Mime
View raw message