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/watchdog/task GTest.java
Date Mon, 11 Feb 2002 20:52:24 GMT
rlubke      02/02/11 12:52:24

  Modified:    src/tools/org/apache/watchdog/task GTest.java
  Log:
   - added support to replace |client.host| and |client.ip| markers in a request
     string.
  
  Revision  Changes    Path
  1.4       +45 -15    jakarta-watchdog-4.0/src/tools/org/apache/watchdog/task/GTest.java
  
  Index: GTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-watchdog-4.0/src/tools/org/apache/watchdog/task/GTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GTest.java	10 Feb 2002 16:34:33 -0000	1.3
  +++ GTest.java	11 Feb 2002 20:52:24 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-watchdog-4.0/src/tools/org/apache/watchdog/task/GTest.java,v
1.3 2002/02/10 16:34:33 rlubke Exp $ 
  - * $Revision: 1.3 $
  - * $Date: 2002/02/10 16:34:33 $
  + * $Header: /home/cvs/jakarta-watchdog-4.0/src/tools/org/apache/watchdog/task/GTest.java,v
1.4 2002/02/11 20:52:24 rlubke Exp $ 
  + * $Revision: 1.4 $
  + * $Date: 2002/02/11 20:52:24 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -432,7 +432,7 @@
        */
       public void setRequest ( String s ) throws Exception {
   
  -        this.request = s;
  +        this.request = replaceMarkers( s );
           String addressString = request.substring( request.indexOf( "/" ), request.indexOf(
"HTTP" ) ).trim();
   
           if ( addressString.indexOf( "?" ) > -1 ) {
  @@ -916,17 +916,6 @@
               }
           }
   
  -	// replace any occurances of |host.ip| found in the
  -        // query string with the IP of the client host
  -	int startIdx = request.indexOf( "|h" );
  -        int endIdx = request.indexOf( "p|" );
  -	if ( startIdx > -1 && endIdx > -1 ) {
  -	    String start = request.substring( 0, startIdx );
  -            String stop  = request.substring( endIdx + 2 );
  -	    String inetAddr =  InetAddress.getByName( host ).getHostAddress();
  -	    request = start + inetAddr + stop;
  -        }
  -	    
           if ( debug > 0 ) {
               System.out.println( " REQUEST: " + request );
           }
  @@ -1014,6 +1003,47 @@
   	        socket = null;
   	    }
       }
  +
  +    /**
  +     * Replaces any |client.ip| and |client.host| parameter marks
  +     * with the host and IP values of the host upon which Watchdog
  +     * is running.
  +     *
  +     * @param request An HTTP request. 
  +     */
  +     private String replaceMarkers( String request ) {
  +        
  +        final String CLIENT_IP = "client.ip";
  +        final String CLIENT_HOME = "client.host";
  +
  +        StringTokenizer tok = new StringTokenizer( request, "|" );
  +        StringBuffer sb = new StringBuffer( 50 );
  +        InetAddress addr = null;
  +        String host = null;
  +        String ip = null;
  +        try {
  +            addr = InetAddress.getLocalHost(); 
  +            host = addr.getHostName();
  +            ip = addr.getHostAddress();
  +        } catch ( UnknownHostException nshe ) {
  +            System.out.println( " [WARNING] Unable to determine local host and IP address.
 Defaulting to localhost" );
  +            host = "localhost";
  +            ip = "127.0.0.1";
  +        }
  +        
  +        while ( tok.hasMoreElements() ) {
  +            String token = tok.nextToken();
  +            if ( token.equals( CLIENT_IP ) ) {
  +                sb.append( ip );
  +            } else if ( token.equals( CLIENT_HOME ) ) {
  +                sb.append( host );
  +            } else {
  +                sb.append( token );
  +            }
  +        }
  +        return sb.toString();
  +    }
  +            
   
       
       /**
  
  
  

--
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