You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by bl...@apache.org on 2001/10/31 18:23:02 UTC

cvs commit: jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy Admin.java HttpRequestHdr.java Proxy.java

bloritsch    01/10/31 09:23:02

  Modified:    src/org/apache/jmeter/protocol/http/proxy Admin.java
                        HttpRequestHdr.java Proxy.java
  Log:
  Remove all deprecation warnings
  
  Revision  Changes    Path
  1.3       +109 -109  jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/Admin.java
  
  Index: Admin.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/Admin.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Admin.java	2001/07/26 00:34:48	1.2
  +++ Admin.java	2001/10/31 17:23:01	1.3
  @@ -15,114 +15,114 @@
   
   public class Admin extends Thread
   {
  -	//
  -	// Member variables
  -	//
  -
  -	ServerSocket adminSocket = null;
  -	Socket appletSocket = null;
  -	String passwordCandidate = null;
  -	DataInputStream in = null;
  -	DataOutputStream out = null;
  -	Config config = null;
  -	Cache cache;
  -
  -
  -	//
  -	// Public methods
  -	//
  -
  -	//
  -	// Constructor
  -	//
  -	Admin(Config configObject, Cache cacheManager)
  -	{
  -		try
  -		{
  -			config = configObject;
  -			cache = cacheManager;
  -			adminSocket = new ServerSocket(0);
  -			config.setAdminPort(adminSocket.getLocalPort());
  -		}
  -		catch (IOException e)
  -		{
  -			System.out.println("Error opening admin socket");
  -		}
  -	}
  -
  -
  -	//
  -	// Handle communications with remote administrator
  -	//
  -	public void run()
  -	{
  -		while(true)
  -		{
  -			try
  -			{
  -				appletSocket = adminSocket.accept();
  -				in = new DataInputStream(appletSocket.getInputStream());
  -				out = new DataOutputStream(appletSocket.getOutputStream());
  -
  -				do
  -				{
  -					// Read password candidate sent by applet
  -					String passwordCandidate = in.readLine();
  -
  -					// Send applet ack/nack on password
  -					if (config.getPassword().equals(passwordCandidate))
  -					{
  -						out.writeBytes("ACCEPT\n");
  -						break;
  -					}
  -					else
  -					{
  -						out.writeBytes("REJECT\n");
  -					}
  -					out.flush();
  -				}
  -				while (true);
  -
  -				//
  -				// Password is OK, so let's send the administrator the
  -				// parameters values and read his new values
  -				//
  -				while(true)
  -				{
  -					out.writeBytes(config.toString());
  -					out.flush();
  -
  -					config.parse(in.readLine());
  -					System.out.println("Configuration changed by administrator.");
  -
  -					// Administrator wants to clean the cache
  -					if (config.getCleanCache())
  -					{
  -						cache.clean();
  -						config.setCleanCache(false); //no need to clean again
  -					}
  -				}
  -			}
  -			catch (Exception e)
  -			{
  -				//
  -				// This line was reached because the administrator closed
  -				// the connection with the proxy. That's fine, we are now
  -				// available for another administrator to log in.
  -				//
  -				System.out.println("Connection with administrator closed.");
  -			}
  -			finally
  -			{
  -				try
  -				{
  -					out.close();
  -					in.close();
  -				}
  -				catch(Exception exc)
  -				{}
  -			}
  -		}//while
  -	}
  +    //
  +    // Member variables
  +    //
  +
  +    ServerSocket adminSocket = null;
  +    Socket appletSocket = null;
  +    String passwordCandidate = null;
  +    BufferedReader in = null;
  +    DataOutputStream out = null;
  +    Config config = null;
  +    Cache cache;
  +
  +
  +    //
  +    // Public methods
  +    //
  +
  +    //
  +    // Constructor
  +    //
  +    Admin(Config configObject, Cache cacheManager)
  +    {
  +        try
  +        {
  +            config = configObject;
  +            cache = cacheManager;
  +            adminSocket = new ServerSocket(0);
  +            config.setAdminPort(adminSocket.getLocalPort());
  +        }
  +        catch (IOException e)
  +        {
  +            System.out.println("Error opening admin socket");
  +        }
  +    }
  +
  +
  +    //
  +    // Handle communications with remote administrator
  +    //
  +    public void run()
  +    {
  +        while(true)
  +        {
  +            try
  +            {
  +                appletSocket = adminSocket.accept();
  +                in = new BufferedReader(new InputStreamReader(new DataInputStream(appletSocket.getInputStream())));
  +                out = new DataOutputStream(appletSocket.getOutputStream());
  +
  +                do
  +                {
  +                    // Read password candidate sent by applet
  +                    String passwordCandidate = in.readLine();
  +
  +                    // Send applet ack/nack on password
  +                    if (config.getPassword().equals(passwordCandidate))
  +                    {
  +                        out.writeBytes("ACCEPT\n");
  +                        break;
  +                    }
  +                    else
  +                    {
  +                        out.writeBytes("REJECT\n");
  +                    }
  +                    out.flush();
  +                }
  +                while (true);
  +
  +                //
  +                // Password is OK, so let's send the administrator the
  +                // parameters values and read his new values
  +                //
  +                while(true)
  +                {
  +                    out.writeBytes(config.toString());
  +                    out.flush();
  +
  +                    config.parse(in.readLine());
  +                    System.out.println("Configuration changed by administrator.");
  +
  +                    // Administrator wants to clean the cache
  +                    if (config.getCleanCache())
  +                    {
  +                        cache.clean();
  +                        config.setCleanCache(false); //no need to clean again
  +                    }
  +                }
  +            }
  +            catch (Exception e)
  +            {
  +                //
  +                // This line was reached because the administrator closed
  +                // the connection with the proxy. That's fine, we are now
  +                // available for another administrator to log in.
  +                //
  +                System.out.println("Connection with administrator closed.");
  +            }
  +            finally
  +            {
  +                try
  +                {
  +                    out.close();
  +                    in.close();
  +                }
  +                catch(Exception exc)
  +                {}
  +            }
  +        }//while
  +    }
   }
   
  
  
  
  1.3       +324 -322  jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
  
  Index: HttpRequestHdr.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpRequestHdr.java	2001/07/26 00:34:48	1.2
  +++ HttpRequestHdr.java	2001/10/31 17:23:02	1.3
  @@ -6,6 +6,8 @@
   
   import java.io.InputStream;
   import java.io.DataInputStream;
  +import java.io.BufferedReader;
  +import java.io.InputStreamReader;
   import java.util.StringTokenizer;
   
   //
  @@ -16,76 +18,76 @@
   public class HttpRequestHdr
   {
   
  -	/**
  -	 * Http Request method. Such as get or post.
  -	 */
  -	public  String method = new String();
  -
  -	/**
  -	 * The requested url. The universal resource locator that
  -	 * hopefully uniquely describes the object or service the
  -	 * client is requesting.
  -	 */
  -	public String url   = new String();
  -
  -	/**
  -	 * Version of http being used. Such as HTTP/1.0
  -	 */
  -	public String version           = new String();
  -
  -	/**
  -	 * The client's browser's name.
  -	 */
  -	public String userAgent         = new String();
  -
  -	/**
  -	 * The requesting documents that contained the url link.
  -	 */
  -	public String referer           = new String();
  -
  -	/**
  -	 * A internet address date of the remote copy.
  -	 */
  -	public String ifModifiedSince   = new String();
  -
  -	/**
  -	 * A list of mime types the client can accept.
  -	 */
  -	public String accept            = new String();
  -
  -	/**
  -	 * The clients authorization. Don't belive it.
  -	 */
  -
  -	public String authorization     = new String();
  -	/**
  -	 * The type of content following the request header.
  -	 * Normally there is no content and this is blank, however
  -	 * the post method usually does have a content and a content
  -	 * length.
  -	 */
  -	public String contentType       = new String();
  -	/**
  -	 * The length of the content following the header. Usually
  -	 * blank.
  -	 */
  -	public int    contentLength     = -1;
  -	/**
  -	 * The content length of a remote copy of the requested object.
  -	 */
  -	public int    oldContentLength  = -1;
  -	/**
  -	 * Anything in the header that was unrecognized by this class.
  -	 */
  -	public String unrecognized      = new String();
  -	/**
  -	 * Indicates that no cached versions of the requested object are
  -	 * to be sent. Usually used to tell proxy not to send a cached copy.
  -	 * This may also effect servers that are front end for data bases.
  -	 */
  -	public boolean pragmaNoCache    = false;
  +    /**
  +     * Http Request method. Such as get or post.
  +     */
  +    public  String method = new String();
  +
  +    /**
  +     * The requested url. The universal resource locator that
  +     * hopefully uniquely describes the object or service the
  +     * client is requesting.
  +     */
  +    public String url   = new String();
  +
  +    /**
  +     * Version of http being used. Such as HTTP/1.0
  +     */
  +    public String version           = new String();
  +
  +    /**
  +     * The client's browser's name.
  +     */
  +    public String userAgent         = new String();
  +
  +    /**
  +     * The requesting documents that contained the url link.
  +     */
  +    public String referer           = new String();
  +
  +    /**
  +     * A internet address date of the remote copy.
  +     */
  +    public String ifModifiedSince   = new String();
  +
  +    /**
  +     * A list of mime types the client can accept.
  +     */
  +    public String accept            = new String();
  +
  +    /**
  +     * The clients authorization. Don't belive it.
  +     */
  +
  +    public String authorization     = new String();
  +    /**
  +     * The type of content following the request header.
  +     * Normally there is no content and this is blank, however
  +     * the post method usually does have a content and a content
  +     * length.
  +     */
  +    public String contentType       = new String();
  +    /**
  +     * The length of the content following the header. Usually
  +     * blank.
  +     */
  +    public int    contentLength     = -1;
  +    /**
  +     * The content length of a remote copy of the requested object.
  +     */
  +    public int    oldContentLength  = -1;
  +    /**
  +     * Anything in the header that was unrecognized by this class.
  +     */
  +    public String unrecognized      = new String();
  +    /**
  +     * Indicates that no cached versions of the requested object are
  +     * to be sent. Usually used to tell proxy not to send a cached copy.
  +     * This may also effect servers that are front end for data bases.
  +     */
  +    public boolean pragmaNoCache    = false;
   
  -	static String CR ="\r\n";
  +    static String CR ="\r\n";
   
   
   /**
  @@ -95,260 +97,260 @@
    * @return    true if parsing sucsessfull.
    */
   public boolean parse(InputStream In)
  -	{
  -		 String CR ="\r\n";
  +    {
  +         String CR ="\r\n";
   
  -		 /*
  -		  * Read by lines
  -		  */
  -		 DataInputStream lines;
  -		 StringTokenizer tz;
  -		 try
  -		{
  -			  lines = new DataInputStream(In);
  -			  tz = new StringTokenizer(lines.readLine());
  -		 }
  -		catch (Exception e)
  -		{
  -			  return false;
  -		 }
  -
  -		 /*
  -		  * HTTP COMMAND LINE < <METHOD==get> <URL> <HTTP_VERSION> >
  -		  */
  -		 method = getToken(tz).toUpperCase();
  -		 url    = getToken(tz);
  -		 version= getToken(tz);
  -
  -		 while (true)
  -		{
  -			  try
  -			{
  -					tz = new StringTokenizer(lines.readLine());
  -			  }
  -			catch (Exception e)
  -			{
  -					return false;
  -			  }
  -			  String Token = getToken(tz);
  -
  -			  // look for termination of HTTP command
  -			  if (0 == Token.length())
  -					break;
  -
  -			  if (Token.equalsIgnoreCase("USER-AGENT:")) {
  -					// line =<User-Agent: <Agent Description>>
  -					userAgent = getRemainder(tz);
  -			  } else if (Token.equalsIgnoreCase("ACCEPT:")) {
  -					// line=<Accept: <Type>/<Form>
  -					// examp: Accept image/jpeg
  -					accept += " " + getRemainder(tz);
  -
  -			  } else if (Token.equalsIgnoreCase("REFERER:")) {
  -					// line =<Referer: <URL>>
  -					referer = getRemainder(tz);
  -
  -			  } else if (Token.equalsIgnoreCase("PRAGMA:")) {
  -					// Pragma: <no-cache>
  -					Token = getToken(tz);
  -
  -					if (Token.equalsIgnoreCase("NO-CACHE"))
  -						 pragmaNoCache = true;
  -					else
  -						 unrecognized += "Pragma:" + Token + " "
  -							  +getRemainder(tz) +"\n";
  -			  } else if (Token.equalsIgnoreCase("AUTHORIZATION:")) {
  -					// Authenticate: Basic UUENCODED
  -					authorization=  getRemainder(tz);
  -
  -			  } else if (Token.equalsIgnoreCase("IF-MODIFIED-SINCE:")) {
  -					// line =<If-Modified-Since: <http date>
  -					// *** Conditional GET replaces HEAD method ***
  -					String str = getRemainder(tz);
  -				  int index = str.indexOf(";");
  -				  if (index == -1) {
  -						 ifModifiedSince  =str;
  -					} else {
  -						 ifModifiedSince  =str.substring(0,index);
  -
  -						index = str.indexOf("=");
  -						if (index != -1) {
  -							 str = str.substring(index+1);
  -							 oldContentLength =Integer.parseInt(str);
  -						}
  -				  }
  -			  } else if (Token.equalsIgnoreCase("CONTENT-LENGTH:")) {
  -					Token = getToken(tz);
  -					contentLength =Integer.parseInt(Token);
  -			  } else if (Token.equalsIgnoreCase("CONTENT-TYPE:")) {
  -					contentType = getRemainder(tz);
  -			  } else {
  -					unrecognized += Token + " " + getRemainder(tz) + CR;
  -			  }
  -		 }
  -		 return true;
  -	}
  -
  -	/*
  -	 * Rebuilds the header in a string
  -	 * @returns      The header in a string.
  -	 */
  -	public String toString(boolean sendUnknowen) {
  -		 String Request;
  -
  -		 if (0 == method.length())
  -				method = "GET";
  -
  -		 Request = method +" "+ url + " HTTP/1.0" + CR;
  -
  -		 if (0 < userAgent.length())
  -			  Request +="User-Agent:" + userAgent + CR;
  -
  -		 if (0 < referer.length())
  -			  Request+= "Referer:"+ referer  + CR;
  -
  -		 if (pragmaNoCache)
  -			  Request+= "Pragma: no-cache" + CR;
  -
  -		 if (0 < ifModifiedSince.length())
  -			  Request+= "If-Modified-Since: " + ifModifiedSince + CR;
  -
  -		 // ACCEPT TYPES //
  -		 if (0 < accept.length())
  -			  Request += "Accept: " + accept + CR;
  -		 else
  -			  Request += "Accept: */"+"* \r\n";
  -
  -		 if (0 < contentType.length())
  -			  Request += "Content-Type: " + contentType   + CR;
  -
  -		 if (0 < contentLength)
  -			  Request += "Content-Length: " + contentLength + CR;
  -
  -
  -		 if (0 != authorization.length())
  -			  Request += "Authorization: " + authorization + CR;
  -
  -		 if (sendUnknowen) {
  -			  if (0 != unrecognized.length())
  -					Request += unrecognized;
  -		 }
  -
  -		 Request += CR;
  -
  -		 return Request;
  -	}
  -
  -
  -	/**
  -	 * (Re)builds the header in a string.
  -	 *
  -	 * @returns      The header in a string.
  -	 */
  -	public String toString() {
  -		 return toString(true);
  -	}
  -
  -	/**
  -	 *  Returns the next token in a string
  -	 *
  -	 * @param   tk String that is partially tokenized.
  -	 * @returns The remainder
  -	 */
  -	String  getToken(StringTokenizer tk){
  -		 String str ="";
  -		 if  (tk.hasMoreTokens())
  -			  str =tk.nextToken();
  -		 return str;
  -	}
  -
  -	/**
  -	 *  Returns the remainder of a tokenized string
  -	 *
  -	 * @param   tk String that is partially tokenized.
  -	 * @returns The remainder
  -	 */
  -	String  getRemainder(StringTokenizer tk){
  -		 String str ="";
  -		 if  (tk.hasMoreTokens())
  -			  str =tk.nextToken();
  -		 while (tk.hasMoreTokens()){
  -			  str +=" " + tk.nextToken();
  -		 }
  -		 return str;
  -	}
  -
  -		//
  -	// Parsing Methods
  -	//
  -
  -	 /**
  -	  * Find the //server.name from an url.
  -	  *
  -	  * @return Servers internet name
  -	  */
  -	 public String serverName()
  -	{
  -		  // chop to "server.name:x/thing"
  -		  String str = url;
  -		  int i = str.indexOf("//");
  -		  if (i< 0) return "";
  -		  str = str.substring(i+2);
  -
  -		  // chop to  server.name:xx
  -		  i = str.indexOf("/");
  -		  if (0 < i) str = str.substring(0,i);
  -
  -		  // chop to server.name
  -		  i = str.indexOf(":");
  -		  if (0 < i) str = str.substring(0,i);
  -
  -		  return str;
  -	 }
  -
  -	 /**
  -	  * Find the :PORT form http://server.ect:PORT/some/file.xxx
  -	  *
  -	  * @return Servers internet name
  -	  */
  -	 public int serverPort()
  -	{
  -		  String str = url;
  -		  // chop to "server.name:x/thing"
  -		  int i = str.indexOf("//");
  -		  if (i< 0) return 80;
  -		  str = str.substring(i+2);
  -
  -		  // chop to  server.name:xx
  -		  i = str.indexOf("/");
  -		  if (0 < i) str = str.substring(0,i);
  -
  -		  // chop XX
  -		  i = str.indexOf(":");
  -		  if (0 < i)
  -		{
  -				return Integer.parseInt(str.substring(i+1).trim());
  -		  }
  -
  -		  return 80;
  -	 }
  -
  -	 /**
  -	  * Find the /some/file.xxxx form http://server.ect:PORT/some/file.xxx
  -	  *
  -	  * @return the deproxied url
  -	  */
  -	 public String serverUrl()
  -	{
  -		  String str = url;
  -		  int i = str.indexOf("//");
  -		  if (i< 0) return str;
  -
  -		  str = str.substring(i+2);
  -		  i = str.indexOf("/");
  -		  if (i< 0) return str;
  +         /*
  +          * Read by lines
  +          */
  +         BufferedReader lines;
  +         StringTokenizer tz;
  +         try
  +        {
  +              lines = new BufferedReader(new InputStreamReader(new DataInputStream(In)));
  +              tz = new StringTokenizer(lines.readLine());
  +         }
  +        catch (Exception e)
  +        {
  +              return false;
  +         }
  +
  +         /*
  +          * HTTP COMMAND LINE < <METHOD==get> <URL> <HTTP_VERSION> >
  +          */
  +         method = getToken(tz).toUpperCase();
  +         url    = getToken(tz);
  +         version= getToken(tz);
  +
  +         while (true)
  +        {
  +              try
  +            {
  +                    tz = new StringTokenizer(lines.readLine());
  +              }
  +            catch (Exception e)
  +            {
  +                    return false;
  +              }
  +              String Token = getToken(tz);
  +
  +              // look for termination of HTTP command
  +              if (0 == Token.length())
  +                    break;
  +
  +              if (Token.equalsIgnoreCase("USER-AGENT:")) {
  +                    // line =<User-Agent: <Agent Description>>
  +                    userAgent = getRemainder(tz);
  +              } else if (Token.equalsIgnoreCase("ACCEPT:")) {
  +                    // line=<Accept: <Type>/<Form>
  +                    // examp: Accept image/jpeg
  +                    accept += " " + getRemainder(tz);
  +
  +              } else if (Token.equalsIgnoreCase("REFERER:")) {
  +                    // line =<Referer: <URL>>
  +                    referer = getRemainder(tz);
  +
  +              } else if (Token.equalsIgnoreCase("PRAGMA:")) {
  +                    // Pragma: <no-cache>
  +                    Token = getToken(tz);
  +
  +                    if (Token.equalsIgnoreCase("NO-CACHE"))
  +                         pragmaNoCache = true;
  +                    else
  +                         unrecognized += "Pragma:" + Token + " "
  +                              +getRemainder(tz) +"\n";
  +              } else if (Token.equalsIgnoreCase("AUTHORIZATION:")) {
  +                    // Authenticate: Basic UUENCODED
  +                    authorization=  getRemainder(tz);
  +
  +              } else if (Token.equalsIgnoreCase("IF-MODIFIED-SINCE:")) {
  +                    // line =<If-Modified-Since: <http date>
  +                    // *** Conditional GET replaces HEAD method ***
  +                    String str = getRemainder(tz);
  +                  int index = str.indexOf(";");
  +                  if (index == -1) {
  +                         ifModifiedSince  =str;
  +                    } else {
  +                         ifModifiedSince  =str.substring(0,index);
  +
  +                        index = str.indexOf("=");
  +                        if (index != -1) {
  +                             str = str.substring(index+1);
  +                             oldContentLength =Integer.parseInt(str);
  +                        }
  +                  }
  +              } else if (Token.equalsIgnoreCase("CONTENT-LENGTH:")) {
  +                    Token = getToken(tz);
  +                    contentLength =Integer.parseInt(Token);
  +              } else if (Token.equalsIgnoreCase("CONTENT-TYPE:")) {
  +                    contentType = getRemainder(tz);
  +              } else {
  +                    unrecognized += Token + " " + getRemainder(tz) + CR;
  +              }
  +         }
  +         return true;
  +    }
  +
  +    /*
  +     * Rebuilds the header in a string
  +     * @returns      The header in a string.
  +     */
  +    public String toString(boolean sendUnknowen) {
  +         String Request;
  +
  +         if (0 == method.length())
  +                method = "GET";
  +
  +         Request = method +" "+ url + " HTTP/1.0" + CR;
  +
  +         if (0 < userAgent.length())
  +              Request +="User-Agent:" + userAgent + CR;
  +
  +         if (0 < referer.length())
  +              Request+= "Referer:"+ referer  + CR;
  +
  +         if (pragmaNoCache)
  +              Request+= "Pragma: no-cache" + CR;
  +
  +         if (0 < ifModifiedSince.length())
  +              Request+= "If-Modified-Since: " + ifModifiedSince + CR;
  +
  +         // ACCEPT TYPES //
  +         if (0 < accept.length())
  +              Request += "Accept: " + accept + CR;
  +         else
  +              Request += "Accept: */"+"* \r\n";
  +
  +         if (0 < contentType.length())
  +              Request += "Content-Type: " + contentType   + CR;
  +
  +         if (0 < contentLength)
  +              Request += "Content-Length: " + contentLength + CR;
  +
  +
  +         if (0 != authorization.length())
  +              Request += "Authorization: " + authorization + CR;
  +
  +         if (sendUnknowen) {
  +              if (0 != unrecognized.length())
  +                    Request += unrecognized;
  +         }
  +
  +         Request += CR;
  +
  +         return Request;
  +    }
  +
  +
  +    /**
  +     * (Re)builds the header in a string.
  +     *
  +     * @returns      The header in a string.
  +     */
  +    public String toString() {
  +         return toString(true);
  +    }
  +
  +    /**
  +     *  Returns the next token in a string
  +     *
  +     * @param   tk String that is partially tokenized.
  +     * @returns The remainder
  +     */
  +    String  getToken(StringTokenizer tk){
  +         String str ="";
  +         if  (tk.hasMoreTokens())
  +              str =tk.nextToken();
  +         return str;
  +    }
  +
  +    /**
  +     *  Returns the remainder of a tokenized string
  +     *
  +     * @param   tk String that is partially tokenized.
  +     * @returns The remainder
  +     */
  +    String  getRemainder(StringTokenizer tk){
  +         String str ="";
  +         if  (tk.hasMoreTokens())
  +              str =tk.nextToken();
  +         while (tk.hasMoreTokens()){
  +              str +=" " + tk.nextToken();
  +         }
  +         return str;
  +    }
  +
  +        //
  +    // Parsing Methods
  +    //
  +
  +     /**
  +      * Find the //server.name from an url.
  +      *
  +      * @return Servers internet name
  +      */
  +     public String serverName()
  +    {
  +          // chop to "server.name:x/thing"
  +          String str = url;
  +          int i = str.indexOf("//");
  +          if (i< 0) return "";
  +          str = str.substring(i+2);
  +
  +          // chop to  server.name:xx
  +          i = str.indexOf("/");
  +          if (0 < i) str = str.substring(0,i);
  +
  +          // chop to server.name
  +          i = str.indexOf(":");
  +          if (0 < i) str = str.substring(0,i);
  +
  +          return str;
  +     }
  +
  +     /**
  +      * Find the :PORT form http://server.ect:PORT/some/file.xxx
  +      *
  +      * @return Servers internet name
  +      */
  +     public int serverPort()
  +    {
  +          String str = url;
  +          // chop to "server.name:x/thing"
  +          int i = str.indexOf("//");
  +          if (i< 0) return 80;
  +          str = str.substring(i+2);
  +
  +          // chop to  server.name:xx
  +          i = str.indexOf("/");
  +          if (0 < i) str = str.substring(0,i);
  +
  +          // chop XX
  +          i = str.indexOf(":");
  +          if (0 < i)
  +        {
  +                return Integer.parseInt(str.substring(i+1).trim());
  +          }
  +
  +          return 80;
  +     }
  +
  +     /**
  +      * Find the /some/file.xxxx form http://server.ect:PORT/some/file.xxx
  +      *
  +      * @return the deproxied url
  +      */
  +     public String serverUrl()
  +    {
  +          String str = url;
  +          int i = str.indexOf("//");
  +          if (i< 0) return str;
  +
  +          str = str.substring(i+2);
  +          i = str.indexOf("/");
  +          if (i< 0) return str;
   
  -		  return str.substring(i);
  -	 }
  +          return str.substring(i);
  +     }
   
   }
  
  
  
  1.6       +348 -348  jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/Proxy.java
  
  Index: Proxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/Proxy.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Proxy.java	2001/10/07 16:46:50	1.5
  +++ Proxy.java	2001/10/31 17:23:02	1.6
  @@ -75,353 +75,353 @@
    */
   public class Proxy extends Thread
   {
  -	//
  -	// Member variables
  -	//
  -	Socket ClientSocket = null;
  -	// Socket to client
  -	Socket SrvrSocket = null;
  -	// Socket to web server
  -	Cache cache = null;
  -	// Static cache manager object
  -	String localHostName = null;
  -	// Local machine name
  -	String localHostIP = null;
  -	// Local machine IP address
  -	String adminPath = null;
  -	// Path of admin applet
  -	Config config = null;
  -	// Config object
  -	UrlConfig urlConfig = null;
  -	// UrlConfig object for saving test cases
  -	ProxyControl target;
  -
  -
  -	//
  -	// Public member methods
  -	//
  -
  -	//
  -	// Constructor
  -	//
  -	Proxy(Socket clientSocket, Cache CacheManager, Config configObject,ProxyControl target)
  -	{
  -		//
  -		// Initialize member variables
  -		//
  -		this.target = target;
  -		config = configObject;
  -		ClientSocket = clientSocket;
  -		cache = CacheManager;
  -		localHostName = config.getLocalHost();
  -		localHostIP = config.getLocalIP();
  -		adminPath = config.getAdminPath();
  -	}
  -
  -
  -	//
  -	// run - Main work is done here:
  -	//
  -	/**
  -	 *  Main processing method for the Proxy object
  -	 */
  -	public void run()
  -	{
  -		String serverName = "";
  -		URL url;
  -
  -		byte line[];
  -		HttpRequestHdr request = new HttpRequestHdr();
  -		HttpReplyHdr reply = new HttpReplyHdr();
  -		FileInputStream fileInputStream = null;
  -		FileOutputStream fileOutputStream = null;
  -		boolean TakenFromCache = false;
  -		boolean isCachable = false;
  -
  -		try
  -		{
  -			//
  -			// Read HTTP Request from client
  -			//
  -			request.parse(ClientSocket.getInputStream());
  -			createUrlConfig(request);
  -			config.increaseFilesCached();
  -			url = new URL(request.url);
  -			System.out.println("Request = " + url);
  -
  -			//
  -			// Send Web page with applet to administrator
  -			//
  -			if (url.getFile().equalsIgnoreCase("/admin") &&
  -					(url.getHost().equalsIgnoreCase(localHostName) ||
  -					url.getHost().equalsIgnoreCase(localHostIP)))
  -			{
  -				sendAppletWebPage();
  -				return;
  -			}
  -
  -			//
  -			// Send Applet Files to administrator
  -			//
  -			if ((url.getHost().equalsIgnoreCase(localHostName) ||
  -					url.getHost().equalsIgnoreCase(localHostIP)))
  -			{
  -				sendAppletClass(url.getFile());
  -				return;
  -			}
  -
  -			//
  -			// Check if accessing the URL is allowed by administrator
  -			//
  -			String[] denied = config.getDeniedHosts();
  -			for (int i = 0; i < denied.length; i++)
  -			{
  -				if (url.toString().indexOf(denied[i]) != -1)
  -				{
  -					System.out.println("Access not allowed...");
  -					DataOutputStream out =
  -							new DataOutputStream(ClientSocket.getOutputStream());
  -					out.writeBytes(reply.formNotAllowed());
  -					out.flush();
  -					ClientSocket.close();
  -					return;
  -				}
  -			}
  -
  -			serverName = url.getHost();
  -			System.out.println("Miss! Forwarding to server " +
  -					serverName + "...");
  -			config.increaseMisses();
  -			SrvrSocket = new Socket(request.serverName(),
  -					request.serverPort());
  -			request.url = request.serverUrl();
  -
  -			DataOutputStream srvOut =
  -					new DataOutputStream(SrvrSocket.getOutputStream());
  -
  -			//
  -			// Send the url to web server (or father proxy)
  -			//
  -			srvOut.writeBytes(request.toString(true));
  -			srvOut.flush();
  -
  -			//
  -			// Send data to server (needed for post method)
  -			//
  -			StringBuffer buff = new StringBuffer();
  -			int readValue;
  -			for (int i = 0; i < request.contentLength; i++)
  -			{
  -				readValue = ClientSocket.getInputStream().read();
  -				buff.append((char)readValue);
  -				SrvrSocket.getOutputStream().write(readValue);
  -			}
  -			SrvrSocket.getOutputStream().flush();
  -			urlConfig.parseArguments(buff.toString());
  -			target.deliverUrlConfig(urlConfig);
  -
  -			// Third, check reply headers (we must read first
  -			//         line of headers for that).
  -			DataInputStream Din =
  -					new DataInputStream(SrvrSocket.getInputStream());
  -			DataOutputStream Dout =
  -					new DataOutputStream(ClientSocket.getOutputStream());
  -			String str = Din.readLine();
  -			StringTokenizer s = new StringTokenizer(str);
  -			String retCode = s.nextToken();
  -			// first token is HTTP protocol
  -			retCode = s.nextToken();
  -			// second is return code
  -
  -			//
  -			// First line was read - send it to client and cache it
  -			//
  -			String tempStr = new String(str + "\r\n");
  -			Dout.writeBytes(tempStr);
  -
  -			//
  -			// Read next lines in reply header, send them to
  -			// client and cache them
  -			//
  -			if (str.length() > 0)
  -			{
  -				while (true)
  -				{
  -					str = Din.readLine();
  -					tempStr = new String(str + "\r\n");
  -
  -					// Send bits to client
  -					Dout.writeBytes(tempStr);
  -
  -					if (str.length() <= 0)
  -					{
  -						break;
  -					}
  -				}
  -			}
  -			Dout.flush();
  -
  -			//
  -			// With the HTTP reply body do:
  -			//   (1) Send it to client.
  -			//   (2) Cache it.
  -			//
  -			InputStream in = SrvrSocket.getInputStream();
  -			OutputStream out = ClientSocket.getOutputStream();
  -
  -			byte data[] = new byte[2000];
  -			int count;
  -			while ((count = in.read(data)) > 0)
  -			{
  -				// Send bits to client
  -				out.write(data, 0, count);
  -			}
  -			out.flush();
  -		}
  -
  -		catch (UnknownHostException uhe)
  -		{
  -			//
  -			// Requested Server could not be located
  -			//
  -			System.out.println("Server Not Found.");
  -
  -			try
  -			{
  -				// Notify client that server not found
  -				DataOutputStream out =
  -						new DataOutputStream(ClientSocket.getOutputStream());
  -				out.writeBytes(reply.formServerNotFound());
  -				out.flush();
  -			}
  -			catch (Exception uhe2)
  -			{
  -			}
  -		}
  -
  -		catch (Exception e)
  -		{
  -			e.printStackTrace();
  -			try
  -			{
  -				if (TakenFromCache)
  -				{
  -					fileInputStream.close();
  -				}
  -				else if (isCachable)
  -				{
  -					fileOutputStream.close();
  -				}
  -
  -				// Notify client that internal error accured in proxy
  -				DataOutputStream out =
  -						new DataOutputStream(ClientSocket.getOutputStream());
  -				out.writeBytes(reply.formTimeout());
  -				out.flush();
  -
  -			}
  -			catch (Exception uhe2)
  -			{
  -			}
  -		}
  -
  -		finally
  -		{
  -			try
  -			{
  -				ClientSocket.getOutputStream().flush();
  -				ClientSocket.close();
  -			}
  -			catch (Exception e)
  -			{
  -			}
  -		}
  -	}
  -
  -
  -	//
  -	// Private methods
  -	//
  -
  -	//
  -	// Send to administrator web page containing reference to applet
  -	//
  -	private void sendAppletWebPage()
  -	{
  -		System.out.println("Sending the applet...");
  -		String page = "";
  -		try
  -		{
  -			File appletHtmlPage = new File(config.getAdminPath() +
  -					File.separator + "Admin.html");
  -			BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(appletHtmlPage)));
  -
  -			String s = null;
  -
  -			while ((s = in.readLine()) != null)
  -			{
  -				page += s;
  -			}
  -
  -			page = page.substring(0, page.indexOf("PORT")) +
  -					config.getAdminPort() +
  -					page.substring(page.indexOf("PORT") + 4);
  -
  -			in.close();
  -			DataOutputStream out = new DataOutputStream(ClientSocket.getOutputStream());
  -			out.writeBytes(page);
  -			out.flush();
  -			out.close();
  -		}
  -		catch (Exception e)
  -		{
  -			System.out.println("Error: can't open applet html page");
  -		}
  -
  -	}
  -
  -
  -	//
  -	// Send the applet to administrator
  -	//
  -	private void sendAppletClass(String className)
  -	{
  -		try
  -		{
  -			byte data[] = new byte[2000];
  -			int count;
  -			HttpReplyHdr reply = new HttpReplyHdr();
  -			File appletFile = new File(adminPath + File.separatorChar + className);
  -			long length = appletFile.length();
  -
  -			FileInputStream in = new FileInputStream(appletFile);
  -			DataOutputStream out = new DataOutputStream(ClientSocket.getOutputStream());
  -
  -			out.writeBytes(reply.formOk("application/octet-stream", length));
  -
  -			while (-1 < (count = in.read(data)))
  -			{
  -				out.write(data, 0, count);
  -			}
  -			out.flush();
  -			in.close();
  -			out.close();
  -		}
  -		catch (Exception e)
  -		{
  -		}
  -	}
  -
  -	private void createUrlConfig(HttpRequestHdr request)
  -	{
  -		System.out.println("Everything = " + request.toString(true));
  -		urlConfig = UrlConfig.createConfig(request.contentType);
  -		urlConfig.setDomain(request.serverName());
  -		urlConfig.setMethod(request.method);
  -		urlConfig.setPath(request.serverUrl());
  -		urlConfig.setName(urlConfig.getPath());
  -		urlConfig.setProtocol(request.url.substring(0, request.url.indexOf(":")));
  -		urlConfig.setPort(request.serverPort());
  +    //
  +    // Member variables
  +    //
  +    Socket ClientSocket = null;
  +    // Socket to client
  +    Socket SrvrSocket = null;
  +    // Socket to web server
  +    Cache cache = null;
  +    // Static cache manager object
  +    String localHostName = null;
  +    // Local machine name
  +    String localHostIP = null;
  +    // Local machine IP address
  +    String adminPath = null;
  +    // Path of admin applet
  +    Config config = null;
  +    // Config object
  +    UrlConfig urlConfig = null;
  +    // UrlConfig object for saving test cases
  +    ProxyControl target;
  +
  +
  +    //
  +    // Public member methods
  +    //
  +
  +    //
  +    // Constructor
  +    //
  +    Proxy(Socket clientSocket, Cache CacheManager, Config configObject,ProxyControl target)
  +    {
  +        //
  +        // Initialize member variables
  +        //
  +        this.target = target;
  +        config = configObject;
  +        ClientSocket = clientSocket;
  +        cache = CacheManager;
  +        localHostName = config.getLocalHost();
  +        localHostIP = config.getLocalIP();
  +        adminPath = config.getAdminPath();
  +    }
  +
  +
  +    //
  +    // run - Main work is done here:
  +    //
  +    /**
  +     *  Main processing method for the Proxy object
  +     */
  +    public void run()
  +    {
  +        String serverName = "";
  +        URL url;
  +
  +        byte line[];
  +        HttpRequestHdr request = new HttpRequestHdr();
  +        HttpReplyHdr reply = new HttpReplyHdr();
  +        FileInputStream fileInputStream = null;
  +        FileOutputStream fileOutputStream = null;
  +        boolean TakenFromCache = false;
  +        boolean isCachable = false;
  +
  +        try
  +        {
  +            //
  +            // Read HTTP Request from client
  +            //
  +            request.parse(ClientSocket.getInputStream());
  +            createUrlConfig(request);
  +            config.increaseFilesCached();
  +            url = new URL(request.url);
  +            System.out.println("Request = " + url);
  +
  +            //
  +            // Send Web page with applet to administrator
  +            //
  +            if (url.getFile().equalsIgnoreCase("/admin") &&
  +                    (url.getHost().equalsIgnoreCase(localHostName) ||
  +                    url.getHost().equalsIgnoreCase(localHostIP)))
  +            {
  +                sendAppletWebPage();
  +                return;
  +            }
  +
  +            //
  +            // Send Applet Files to administrator
  +            //
  +            if ((url.getHost().equalsIgnoreCase(localHostName) ||
  +                    url.getHost().equalsIgnoreCase(localHostIP)))
  +            {
  +                sendAppletClass(url.getFile());
  +                return;
  +            }
  +
  +            //
  +            // Check if accessing the URL is allowed by administrator
  +            //
  +            String[] denied = config.getDeniedHosts();
  +            for (int i = 0; i < denied.length; i++)
  +            {
  +                if (url.toString().indexOf(denied[i]) != -1)
  +                {
  +                    System.out.println("Access not allowed...");
  +                    DataOutputStream out =
  +                            new DataOutputStream(ClientSocket.getOutputStream());
  +                    out.writeBytes(reply.formNotAllowed());
  +                    out.flush();
  +                    ClientSocket.close();
  +                    return;
  +                }
  +            }
  +
  +            serverName = url.getHost();
  +            System.out.println("Miss! Forwarding to server " +
  +                    serverName + "...");
  +            config.increaseMisses();
  +            SrvrSocket = new Socket(request.serverName(),
  +                    request.serverPort());
  +            request.url = request.serverUrl();
  +
  +            DataOutputStream srvOut =
  +                    new DataOutputStream(SrvrSocket.getOutputStream());
  +
  +            //
  +            // Send the url to web server (or father proxy)
  +            //
  +            srvOut.writeBytes(request.toString(true));
  +            srvOut.flush();
  +
  +            //
  +            // Send data to server (needed for post method)
  +            //
  +            StringBuffer buff = new StringBuffer();
  +            int readValue;
  +            for (int i = 0; i < request.contentLength; i++)
  +            {
  +                readValue = ClientSocket.getInputStream().read();
  +                buff.append((char)readValue);
  +                SrvrSocket.getOutputStream().write(readValue);
  +            }
  +            SrvrSocket.getOutputStream().flush();
  +            urlConfig.parseArguments(buff.toString());
  +            target.deliverUrlConfig(urlConfig);
  +
  +            // Third, check reply headers (we must read first
  +            //         line of headers for that).
  +            BufferedReader Din = new BufferedReader( new InputStreamReader(
  +                    new DataInputStream(SrvrSocket.getInputStream())));
  +            DataOutputStream Dout =
  +                    new DataOutputStream(ClientSocket.getOutputStream());
  +            String str = Din.readLine();
  +            StringTokenizer s = new StringTokenizer(str);
  +            String retCode = s.nextToken();
  +            // first token is HTTP protocol
  +            retCode = s.nextToken();
  +            // second is return code
  +
  +            //
  +            // First line was read - send it to client and cache it
  +            //
  +            String tempStr = new String(str + "\r\n");
  +            Dout.writeBytes(tempStr);
  +
  +            //
  +            // Read next lines in reply header, send them to
  +            // client and cache them
  +            //
  +            if (str.length() > 0)
  +            {
  +                while (true)
  +                {
  +                    str = Din.readLine();
  +                    tempStr = new String(str + "\r\n");
  +
  +                    // Send bits to client
  +                    Dout.writeBytes(tempStr);
  +
  +                    if (str.length() <= 0)
  +                    {
  +                        break;
  +                    }
  +                }
  +            }
  +            Dout.flush();
  +
  +            //
  +            // With the HTTP reply body do:
  +            //   (1) Send it to client.
  +            //   (2) Cache it.
  +            //
  +            InputStream in = SrvrSocket.getInputStream();
  +            OutputStream out = ClientSocket.getOutputStream();
  +
  +            byte data[] = new byte[2000];
  +            int count;
  +            while ((count = in.read(data)) > 0)
  +            {
  +                // Send bits to client
  +                out.write(data, 0, count);
  +            }
  +            out.flush();
  +        }
  +
  +        catch (UnknownHostException uhe)
  +        {
  +            //
  +            // Requested Server could not be located
  +            //
  +            System.out.println("Server Not Found.");
  +
  +            try
  +            {
  +                // Notify client that server not found
  +                DataOutputStream out =
  +                        new DataOutputStream(ClientSocket.getOutputStream());
  +                out.writeBytes(reply.formServerNotFound());
  +                out.flush();
  +            }
  +            catch (Exception uhe2)
  +            {
  +            }
  +        }
  +
  +        catch (Exception e)
  +        {
  +            e.printStackTrace();
  +            try
  +            {
  +                if (TakenFromCache)
  +                {
  +                    fileInputStream.close();
  +                }
  +                else if (isCachable)
  +                {
  +                    fileOutputStream.close();
  +                }
  +
  +                // Notify client that internal error accured in proxy
  +                DataOutputStream out =
  +                        new DataOutputStream(ClientSocket.getOutputStream());
  +                out.writeBytes(reply.formTimeout());
  +                out.flush();
  +
  +            }
  +            catch (Exception uhe2)
  +            {
  +            }
  +        }
  +
  +        finally
  +        {
  +            try
  +            {
  +                ClientSocket.getOutputStream().flush();
  +                ClientSocket.close();
  +            }
  +            catch (Exception e)
  +            {
  +            }
  +        }
  +    }
  +
  +
  +    //
  +    // Private methods
  +    //
  +
  +    //
  +    // Send to administrator web page containing reference to applet
  +    //
  +    private void sendAppletWebPage()
  +    {
  +        System.out.println("Sending the applet...");
  +        String page = "";
  +        try
  +        {
  +            File appletHtmlPage = new File(config.getAdminPath() +
  +                    File.separator + "Admin.html");
  +            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(appletHtmlPage)));
  +
  +            String s = null;
  +
  +            while ((s = in.readLine()) != null)
  +            {
  +                page += s;
  +            }
  +
  +            page = page.substring(0, page.indexOf("PORT")) +
  +                    config.getAdminPort() +
  +                    page.substring(page.indexOf("PORT") + 4);
  +
  +            in.close();
  +            DataOutputStream out = new DataOutputStream(ClientSocket.getOutputStream());
  +            out.writeBytes(page);
  +            out.flush();
  +            out.close();
  +        }
  +        catch (Exception e)
  +        {
  +            System.out.println("Error: can't open applet html page");
  +        }
  +
  +    }
  +
  +
  +    //
  +    // Send the applet to administrator
  +    //
  +    private void sendAppletClass(String className)
  +    {
  +        try
  +        {
  +            byte data[] = new byte[2000];
  +            int count;
  +            HttpReplyHdr reply = new HttpReplyHdr();
  +            File appletFile = new File(adminPath + File.separatorChar + className);
  +            long length = appletFile.length();
  +
  +            FileInputStream in = new FileInputStream(appletFile);
  +            DataOutputStream out = new DataOutputStream(ClientSocket.getOutputStream());
  +
  +            out.writeBytes(reply.formOk("application/octet-stream", length));
  +
  +            while (-1 < (count = in.read(data)))
  +            {
  +                out.write(data, 0, count);
  +            }
  +            out.flush();
  +            in.close();
  +            out.close();
  +        }
  +        catch (Exception e)
  +        {
  +        }
  +    }
  +
  +    private void createUrlConfig(HttpRequestHdr request)
  +    {
  +        System.out.println("Everything = " + request.toString(true));
  +        urlConfig = UrlConfig.createConfig(request.contentType);
  +        urlConfig.setDomain(request.serverName());
  +        urlConfig.setMethod(request.method);
  +        urlConfig.setPath(request.serverUrl());
  +        urlConfig.setName(urlConfig.getPath());
  +        urlConfig.setProtocol(request.url.substring(0, request.url.indexOf(":")));
  +        urlConfig.setPort(request.serverPort());
   
  -	}
  +    }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>