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 Thu, 04 Apr 2002 17:24:16 GMT
rlubke      02/04/04 09:24:15

  Modified:    src/tools/org/apache/watchdog/task GTest.java
  Log:
  Fix for bugzilla 7406.
  
  GTest now uses Socket.getLocalAddress() to determine client hostname and IP.
  
  Revision  Changes    Path
  1.8       +45 -32    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- GTest.java	12 Feb 2002 15:11:54 -0000	1.7
  +++ GTest.java	4 Apr 2002 17:24:15 -0000	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-watchdog-4.0/src/tools/org/apache/watchdog/task/GTest.java,v
1.7 2002/02/12 15:11:54 rlubke Exp $ 
  - * $Revision: 1.7 $
  - * $Date: 2002/02/12 15:11:54 $
  + * $Header: /home/cvs/jakarta-watchdog-4.0/src/tools/org/apache/watchdog/task/GTest.java,v
1.8 2002/04/04 17:24:15 rlubke Exp $ 
  + * $Revision: 1.8 $
  + * $Date: 2002/04/04 17:24:15 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -90,6 +90,8 @@
   
       String prefix = "http";
       String host = "localhost";
  +    String localHost = null;
  +    String localIP = null;
       int port = 8080;
       int debug = 0;
   
  @@ -428,11 +430,22 @@
        *
        * @param s a <code>String</code> value in the form
        *          of METHOD PATH HTTP_VERSION
  -     * @exception Exception if an error occurs
        */
  -    public void setRequest ( String s ) throws Exception {
  +    public void setRequest ( String s ) {
  +        this.request = s;
  +    }
   
  -        this.request = replaceMarkers( s );
  +    /**
  +     * Private utility method to 'massage' a request string that
  +     * may or may not have replacement markers for the request parameters.
  +     *
  +     * @param req the request to manipulate
  +     * @param socket local socket.  Used to rebuild specified query strings.
  +     *
  +     * @exception Exception if an error occurs
  +     */
  +    private void rebuildRequest(String req, Socket socket) throws Exception {
  +        this.request = replaceMarkers(req, socket );
           String addressString = request.substring( request.indexOf( "/" ), request.indexOf(
"HTTP" ) ).trim();
   
           if ( addressString.indexOf( "?" ) > -1 ) {
  @@ -505,7 +518,7 @@
                   resultOut.write( ( "\n<testStrategy>" + testStrategy + "</testStrategy>\n"
).getBytes() );
               }
   
  -            dispatch( request, requestHeaders );
  +            dispatch(requestHeaders );
   
               boolean result = checkResponse( magnitude );
   
  @@ -893,14 +906,16 @@
        * <code>dispatch</code> sends the request and any
        * configured request headers to the target server.
        *
  -     * @param request a <code>String</code> value
        * @param requestHeaders a <code>HashMap</code> value
        */
  -    private void dispatch( String request, HashMap requestHeaders ) 
  +    private void dispatch( HashMap requestHeaders ) 
       throws Exception {
           // XXX headers are ignored
           Socket socket = new Socket( host, port );
   
  +        //socket obtained, rebuild the request.
  +        rebuildRequest(request, socket);
  +
           InputStream in = new CRBufferedInputStream( socket.getInputStream() );
   
           // Write the request
  @@ -1028,37 +1043,35 @@
        *
        * @param request An HTTP request. 
        */
  -     private String replaceMarkers( String request ) {
  +     private String replaceMarkers( String req, Socket socket ) {
           
           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";
  +        if (localIP == null || localHost == null) {
  +            InetAddress addr = socket.getLocalAddress(); 
  +            localHost = addr.getHostName();
  +            localIP = addr.getHostAddress();
           }
  +
  +        if (req.indexOf('|') > -1) {
  +            StringTokenizer tok = new StringTokenizer( request, "|" );
  +            StringBuffer sb = new StringBuffer( 50 );
           
  -        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 );
  +            while ( tok.hasMoreElements() ) {
  +                String token = tok.nextToken();
  +                if ( token.equals( CLIENT_IP ) ) {
  +                    sb.append( localIP );
  +                } else if ( token.equals( CLIENT_HOME ) ) {
  +                    sb.append( localHost );
  +                } else {
  +                    sb.append( token );
  +                }
               }
  +            return sb.toString(); 
  +        } else {
  +            return req;
           }
  -        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