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 ms...@apache.org on 2002/04/28 23:40:53 UTC

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

mstover1    02/04/28 14:40:53

  Modified:    src_1/org/apache/jmeter/protocol/http/proxy
                        HttpRequestHdr.java Proxy.java ProxyControl.java
  Added:       src_1    MANIFEST
  Log:
  no message
  
  Revision  Changes    Path
  1.1                  jakarta-jmeter/src_1/MANIFEST
  
  Index: MANIFEST
  ===================================================================
  Manifest-Version: 1.0
  Main-Class: org.apache.jmeter.NewDriver
  
  
  
  1.6       +312 -310  jakarta-jmeter/src_1/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
  
  Index: HttpRequestHdr.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src_1/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HttpRequestHdr.java	26 Apr 2002 23:26:13 -0000	1.5
  +++ HttpRequestHdr.java	28 Apr 2002 21:40:53 -0000	1.6
  @@ -1,310 +1,312 @@
  -package org.apache.jmeter.protocol.http.proxy;
  -/****************************************
  - * File HttpRequestHdr.java
  - ***************************************/
  -import java.io.*;
  -import java.util.StringTokenizer;
  -
  -import java.util.*;
  -import java.net.*;
  -
  -import org.apache.jmeter.samplers.Entry;
  -import org.apache.jmeter.protocol.http.config.*;
  -import org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui;
  -import org.apache.jmeter.protocol.http.sampler.*;
  -
  -//
  -// Class:     HttpRequestHdr
  -// Abstract:  The headers of the client HTTP request.
  -//
  -
  -/****************************************
  - * !ToDo (Class description)
  - *
  - *@author    $Author: mstover1 $
  - *@created   $Date: 2002/04/26 23:26:13 $
  - *@version   $Revision: 1.5 $
  - ***************************************/
  -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();
  -
  -
  -
  -	/****************************************
  -	 * !ToDo (Field description)
  -	 ***************************************/
  -	public String postData = "";
  -
  -	static String CR = "\r\n";
  -
  -	private Map headers = new HashMap();
  -
  -
  -	/****************************************
  -	 * Parses a http header from a stream.
  -	 *
  -	 *@param in  The stream to parse.
  -	 *@return    Array of bytes from client.
  -	 ***************************************/
  -	public byte[] parse(InputStream in) throws IOException
  -	{
  -		boolean inHeaders = true;
  -		int readLength = 0;
  -		int dataLength = 0;
  -		String CR = "\r\n";
  -		boolean first = true;
  -		ByteArrayOutputStream clientRequest = new ByteArrayOutputStream();
  -		ByteArrayOutputStream line = new ByteArrayOutputStream();
  -		int x;
  -		while((inHeaders || readLength < dataLength) && ((x = in.read()) != -1))
  -		{
  -			line.write(x);
  -			clientRequest.write(x);
  -			if(inHeaders && (byte)x == (byte)'\n')
  -			{
  -				if(line.size() < 3)
  -				{
  -					inHeaders = false;
  -				}
  -				if(first)
  -				{
  -					parseFirstLine(line.toString());
  -					first = false;
  -				}
  -				else
  -				{
  -					dataLength = Math.max(parseLine(line.toString()),dataLength);
  -				}
  -				line.reset();
  -			}
  -			else if(!inHeaders)
  -			{
  -				readLength++;
  -			}
  -		}
  -		return clientRequest.toByteArray();
  -	}
  -
  -	public void parseFirstLine(String firstLine)
  -	{
  -		StringTokenizer tz = new StringTokenizer(firstLine);
  -		method = getToken(tz).toUpperCase();
  -		url = getToken(tz);
  -		version = getToken(tz);
  -	}
  -
  -	public int parseLine(String nextLine)
  -	{
  -		StringTokenizer tz;
  -		tz = new StringTokenizer(nextLine);
  -		String token = getToken(tz);
  -		// look for termination of HTTP command
  -		if(0 == token.length())
  -		{
  -			return 0;
  -		}
  -		else
  -		{
  -			String name = token.trim().substring(0,token.trim().length()-1);
  -			String value = getRemainder(tz);
  -			headers.put(name,value);
  -			if(name.equalsIgnoreCase("content-length"))
  -			{
  -				return Integer.parseInt(value);
  -			}
  -		}
  -		return 0;
  -	}
  -
  -	public HTTPSampler getSampler() throws MalformedURLException,IOException,ProtocolException
  -	{
  -		HttpTestSampleGui tempGui = new HttpTestSampleGui();
  -		tempGui.configure(createUrlConfig());
  -		return (HTTPSampler)tempGui.createTestElement();
  -	}
  -
  -	public String getContentType()
  -	{
  -		return (String)headers.get("Content-Type");
  -	}
  -
  -	private UrlConfig createUrlConfig()
  -	{
  -		UrlConfig urlConfig = UrlConfig.createConfig(getContentType());
  -		urlConfig.setDomain(serverName());
  -		urlConfig.setMethod(method);
  -		urlConfig.setPath(serverUrl());
  -		urlConfig.setName(urlConfig.getPath());
  -		urlConfig.setProtocol(url.substring(0, url.indexOf(":")));
  -		urlConfig.setPort(serverPort());
  -		urlConfig.parseArguments(postData);
  -		return urlConfig;
  -	 }
  -
  -	//
  -	// 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);
  -	}
  -
  -	/****************************************
  -	 * Returns the next token in a string
  -	 *
  -	 *@param tk  String that is partially tokenized.
  -	 *@return    !ToDo (Return description)
  -	 *@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.
  -	 *@return    !ToDo (Return description)
  -	 *@returns   The remainder
  -	 ***************************************/
  -	String getRemainder(StringTokenizer tk)
  -	{
  -		String str = "";
  -		if(tk.hasMoreTokens())
  -		{
  -			str = tk.nextToken();
  -		}
  -		while(tk.hasMoreTokens())
  -		{
  -			str += " " + tk.nextToken();
  -		}
  -
  -		return str;
  -	}
  -
  -	private String readPostData(Reader in) throws IOException
  -	{
  -		StringWriter string = new StringWriter();
  -		char[] buf = new char[4096];
  -		int x = 0;
  -		while((x = in.read(buf)) > 0)
  -		{
  -			string.write(buf, 0, x);
  -			if(!in.ready())
  -			{
  -				break;
  -			}
  -		}
  -		string.close();
  -		return string.toString().trim();
  -	}
  -
  -}
  +package org.apache.jmeter.protocol.http.proxy;
  +/****************************************
  + * File HttpRequestHdr.java
  + ***************************************/
  +import java.io.*;
  +import java.util.StringTokenizer;
  +
  +import java.util.*;
  +import java.net.*;
  +
  +import org.apache.jmeter.samplers.Entry;
  +import org.apache.jmeter.protocol.http.config.*;
  +import org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui;
  +import org.apache.jmeter.protocol.http.sampler.*;
  +import org.apache.jmeter.protocol.http.control.HeaderManager;
  +import org.apache.jmeter.protocol.http.control.Header;
  +
  +//
  +// Class:     HttpRequestHdr
  +// Abstract:  The headers of the client HTTP request.
  +//
  +
  +/****************************************
  + * !ToDo (Class description)
  + *
  + *@author    $Author: mstover1 $
  + *@created   $Date: 2002/04/28 21:40:53 $
  + *@version   $Revision: 1.6 $
  + ***************************************/
  +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();
  +
  +
  +
  +	/****************************************
  +	 * !ToDo (Field description)
  +	 ***************************************/
  +	public String postData = "";
  +
  +	static String CR = "\r\n";
  +
  +	private Map headers = new HashMap();
  +
  +
  +	/****************************************
  +	 * Parses a http header from a stream.
  +	 *
  +	 *@param in  The stream to parse.
  +	 *@return    Array of bytes from client.
  +	 ***************************************/
  +	public byte[] parse(InputStream in) throws IOException
  +	{
  +		boolean inHeaders = true;
  +		int readLength = 0;
  +		int dataLength = 0;
  +		String CR = "\r\n";
  +		boolean first = true;
  +		ByteArrayOutputStream clientRequest = new ByteArrayOutputStream();
  +		ByteArrayOutputStream line = new ByteArrayOutputStream();
  +		int x;
  +		while((inHeaders || readLength < dataLength) && ((x = in.read()) != -1))
  +		{
  +			line.write(x);
  +			clientRequest.write(x);
  +			if(inHeaders && (byte)x == (byte)'\n')
  +			{
  +				if(line.size() < 3)
  +				{
  +					inHeaders = false;
  +				}
  +				if(first)
  +				{
  +					parseFirstLine(line.toString());
  +					first = false;
  +				}
  +				else
  +				{
  +					dataLength = Math.max(parseLine(line.toString()),dataLength);
  +				}
  +				line.reset();
  +			}
  +			else if(!inHeaders)
  +			{
  +				readLength++;
  +			}
  +		}
  +		return clientRequest.toByteArray();
  +	}
  +
  +	public void parseFirstLine(String firstLine)
  +	{
  +		StringTokenizer tz = new StringTokenizer(firstLine);
  +		method = getToken(tz).toUpperCase();
  +		url = getToken(tz);
  +		version = getToken(tz);
  +	}
  +
  +	public int parseLine(String nextLine)
  +	{
  +		StringTokenizer tz;
  +		tz = new StringTokenizer(nextLine);
  +		String token = getToken(tz);
  +		// look for termination of HTTP command
  +		if(0 == token.length())
  +		{
  +			return 0;
  +		}
  +		else
  +		{
  +			String name = token.trim().substring(0,token.trim().length()-1);
  +			String value = getRemainder(tz);
  +			headers.put(name,value);
  +			if(name.equalsIgnoreCase("content-length"))
  +			{
  +				return Integer.parseInt(value);
  +			}
  +		}
  +		return 0;
  +	}
  +	
  +	public HeaderManager getHeaderManager()
  +	{
  +		HeaderManager manager = new HeaderManager();
  +		Iterator keys = headers.keySet().iterator();
  +		while(keys.hasNext())
  +		{
  +			String key = (String)keys.next();
  +			if(!key.equalsIgnoreCase("cookie"))
  +			{
  +				Header h = new Header(key,(String)headers.get(key));
  +				manager.add(h);
  +			}
  +		}
  +		manager.setName("Browser-derived headers");
  +		return  manager;
  +	}
  +
  +	public HTTPSampler getSampler() throws MalformedURLException,IOException,ProtocolException
  +	{
  +		HttpTestSampleGui tempGui = new HttpTestSampleGui();
  +		tempGui.configure(createUrlConfig());
  +		return (HTTPSampler)tempGui.createTestElement();
  +	}
  +
  +	public String getContentType()
  +	{
  +		return (String)headers.get("Content-Type");
  +	}
  +
  +	private UrlConfig createUrlConfig()
  +	{
  +		UrlConfig urlConfig = UrlConfig.createConfig(getContentType());
  +		urlConfig.setDomain(serverName());
  +		urlConfig.setMethod(method);
  +		urlConfig.setPath(serverUrl());
  +		urlConfig.setName(urlConfig.getPath());
  +		urlConfig.setProtocol(url.substring(0, url.indexOf(":")));
  +		urlConfig.setPort(serverPort());
  +		urlConfig.parseArguments(postData);
  +		return urlConfig;
  +	 }
  +
  +	//
  +	// 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);
  +	}
  +
  +	/****************************************
  +	 * Returns the next token in a string
  +	 *
  +	 *@param tk  String that is partially tokenized.
  +	 *@return    !ToDo (Return description)
  +	 *@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.
  +	 *@return    !ToDo (Return description)
  +	 *@returns   The remainder
  +	 ***************************************/
  +	String getRemainder(StringTokenizer tk)
  +	{
  +		String str = "";
  +		if(tk.hasMoreTokens())
  +		{
  +			str = tk.nextToken();
  +		}
  +		while(tk.hasMoreTokens())
  +		{
  +			str += " " + tk.nextToken();
  +		}
  +
  +		return str;
  +	}
  +
  +}
  
  
  
  1.5       +268 -329  jakarta-jmeter/src_1/org/apache/jmeter/protocol/http/proxy/Proxy.java
  
  Index: Proxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src_1/org/apache/jmeter/protocol/http/proxy/Proxy.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Proxy.java	26 Apr 2002 00:03:56 -0000	1.4
  +++ Proxy.java	28 Apr 2002 21:40:53 -0000	1.5
  @@ -1,329 +1,268 @@
  -/*
  - * ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - * notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - * notice, this list of conditions and the following disclaimer in
  - * the documentation and/or other materials provided with the
  - * distribution.
  - *
  - * 3. The end-user documentation included with the redistribution,
  - * if any, must include the following acknowledgment:
  - * "This product includes software developed by the
  - * Apache Software Foundation (http://www.apache.org/)."
  - * Alternately, this acknowledgment may appear in the software itself,
  - * if and wherever such third-party acknowledgments normally appear.
  - *
  - * 4. The names "Apache" and "Apache Software Foundation" and
  - * "Apache JMeter" must not be used to endorse or promote products
  - * derived from this software without prior written permission. For
  - * written permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - * "Apache JMeter", nor may "Apache" appear in their name, without
  - * prior written permission of the Apache Software Foundation.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - */
  -
  -package org.apache.jmeter.protocol.http.proxy;
  -
  -import java.net.*;
  -import java.io.*;
  -import java.util.*;
  -import org.apache.jmeter.protocol.http.config.UrlConfig;
  -import org.apache.jmeter.protocol.http.control.CookieManager;
  -import org.apache.jmeter.samplers.Entry;
  -import org.apache.jmeter.samplers.Sampler;
  -import org.apache.jmeter.samplers.SampleResult;
  -import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
  -
  -//
  -// Class:     Proxy
  -// Abstract:  Thread to handle one client request. get the requested
  -//            object from the web server or from the cache, and delivers
  -//            the bits to client.
  -//
  -/**
  - *  Description of the Class
  - *
  - *@author     mike
  - *@created    June 8, 2001
  - */
  -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;
  -
  -	CookieManager cookieManager;
  -
  -
  -	//
  -	// Public member methods
  -	//
  -
  -	//
  -	// Constructor
  -	//
  -	Proxy(Socket clientSocket, Cache CacheManager, Config configObject,ProxyControl target,
  -			CookieManager cookieManager)
  -	{
  -		//
  -		// Initialize member variables
  -		//
  -		this.cookieManager = cookieManager;
  -		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 = "";
  -		HttpURLConnection url;
  -		byte line[];
  -		HttpRequestHdr request = new HttpRequestHdr();
  -		HttpReplyHdr reply = new HttpReplyHdr();
  -		FileInputStream fileInputStream = null;
  -		FileOutputStream fileOutputStream = null;
  -		boolean TakenFromCache = false;
  -		boolean isCachable = false;
  -		try
  -		{
  -			byte[] clientRequest = request.parse(new BufferedInputStream(ClientSocket.getInputStream()));
  -			HTTPSampler sampler = request.getSampler();
  -			writeToClient(sampler.getDomain(),sampler.getPort(),new BufferedInputStream(
  -					new ByteArrayInputStream(clientRequest)),
  -					new BufferedOutputStream(ClientSocket.getOutputStream()));
  -			target.deliverSampler(sampler);
  -		}
  -		catch (UnknownHostException uhe)
  -		{
  -			System.out.println("Server Not Found.");
  -			try
  -			{
  -				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();
  -				}
  -				DataOutputStream out =
  -						new DataOutputStream(ClientSocket.getOutputStream());
  -				out.writeBytes(reply.formTimeout());
  -				out.flush();
  -			}
  -			catch (Exception uhe2)
  -			{
  -			}
  -		}
  -		finally
  -		{
  -			try
  -			{
  -				ClientSocket.close();
  -			}
  -			catch (Exception e)
  -			{
  -				e.printStackTrace();
  -			}
  -
  -		}
  -	}
  -
  -	public byte[] sampleServer(HTTPSampler sampler) throws IllegalAccessException,
  -			InstantiationException
  -	{
  -		SampleResult result = sampler.sample();
  -		return result.getResponseData();
  -	}
  -
  -
  -
  -	//
  -	// 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 writeToClient(String server,int serverPort,InputStream in,OutputStream out) throws IOException
  -	{
  -		BufferedInputStream serverIn = null;
  -		BufferedOutputStream serverOut = null;
  -		try
  -		{
  -			int x = 0;
  -			Socket toServer = new Socket(server,serverPort);
  -			serverOut = new BufferedOutputStream(toServer.getOutputStream());
  -			serverIn = new BufferedInputStream(toServer.getInputStream());
  -			while((x = in.read()) != -1)
  -			{
  -				serverOut.write(x);
  -			}
  -			serverOut.flush();
  -			while((x = serverIn.read()) != -1)
  -			{
  -				out.write(x);
  -			}
  -			out.flush();
  -		}
  -		catch(IOException e)
  -		{
  -			e.printStackTrace();
  -		}
  -		finally
  -		{
  -			try
  -			{
  -				in.close();
  -				out.close();
  -				serverIn.close();
  -				serverOut.close();
  -			}
  -			catch (Exception ex)
  -			{}
  -		}
  -	}
  -
  -
  -}
  -
  +/*
  + * ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + * notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + * notice, this list of conditions and the following disclaimer in
  + * the documentation and/or other materials provided with the
  + * distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + * if any, must include the following acknowledgment:
  + * "This product includes software developed by the
  + * Apache Software Foundation (http://www.apache.org/)."
  + * Alternately, this acknowledgment may appear in the software itself,
  + * if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + * "Apache JMeter" must not be used to endorse or promote products
  + * derived from this software without prior written permission. For
  + * written permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + * "Apache JMeter", nor may "Apache" appear in their name, without
  + * prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +package org.apache.jmeter.protocol.http.proxy;
  +import java.net.*;
  +import java.io.*;
  +import java.util.*;
  +import org.apache.jmeter.protocol.http.config.UrlConfig;
  +import org.apache.jmeter.protocol.http.control.CookieManager;
  +import org.apache.jmeter.samplers.Entry;
  +import org.apache.jmeter.samplers.Sampler;
  +import org.apache.jmeter.samplers.SampleResult;
  +import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
  +import org.apache.jmeter.testelement.TestElement;
  +//
  +// Class:     Proxy
  +// Abstract:  Thread to handle one client request. get the requested
  +//            object from the web server or from the cache, and delivers
  +//            the bits to client.
  +//
  +/**
  + *  Description of the Class
  + *
  + *@author     mike
  + *@created    June 8, 2001
  + */
  +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;
  +	CookieManager cookieManager;
  +	//
  +	// Public member methods
  +	//
  +	//
  +	// Constructor
  +	//
  +	Proxy(
  +		Socket clientSocket,
  +		Cache CacheManager,
  +		Config configObject,
  +		ProxyControl target,
  +		CookieManager cookieManager) {
  +		//
  +		// Initialize member variables
  +		//
  +		this.cookieManager = cookieManager;
  +		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 = "";
  +		HttpURLConnection url;
  +		byte line[];
  +		HttpRequestHdr request = new HttpRequestHdr();
  +		HttpReplyHdr reply = new HttpReplyHdr();
  +		FileInputStream fileInputStream = null;
  +		FileOutputStream fileOutputStream = null;
  +		boolean TakenFromCache = false;
  +		boolean isCachable = false;
  +		try {
  +			byte[] clientRequest =
  +				request.parse(new BufferedInputStream(
  +				ClientSocket.getInputStream()));
  +			HTTPSampler sampler = request.getSampler();
  +			writeToClient(
  +				sampler.getDomain(),
  +				sampler.getPort(),
  +				new BufferedInputStream(new ByteArrayInputStream(clientRequest)),
  +				new BufferedOutputStream(ClientSocket.getOutputStream()));
  +			target.deliverSampler(sampler,new TestElement[]{request.getHeaderManager()});
  +		} catch (UnknownHostException uhe) {
  +			System.out.println("Server Not Found.");
  +			try {
  +				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();
  +					}
  +				DataOutputStream out = new DataOutputStream(ClientSocket.getOutputStream());
  +				out.writeBytes(reply.formTimeout());
  +				out.flush();
  +			} catch (Exception uhe2) {}
  +		} finally {
  +			try {
  +				ClientSocket.close();
  +			} catch (Exception e) {
  +				e.printStackTrace();
  +			}
  +		}
  +	}
  +	public byte[] sampleServer(HTTPSampler sampler)
  +		throws IllegalAccessException, InstantiationException {
  +		SampleResult result = sampler.sample();
  +		return result.getResponseData();
  +	}
  +	//
  +	// 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 writeToClient(
  +		String server,
  +		int serverPort,
  +		InputStream in,
  +		OutputStream out)
  +		throws IOException {
  +		BufferedInputStream serverIn = null;
  +		BufferedOutputStream serverOut = null;
  +		try {
  +			int x = 0;
  +			Socket toServer = new Socket(server, serverPort);
  +			serverOut = new BufferedOutputStream(toServer.getOutputStream());
  +			serverIn = new BufferedInputStream(toServer.getInputStream());
  +			while ((x = in.read()) != -1) {
  +				serverOut.write(x);
  +			}
  +			serverOut.flush();
  +			while ((x = serverIn.read()) != -1) {
  +				out.write(x);
  +			}
  +			out.flush();
  +		} catch (IOException e) {
  +			e.printStackTrace();
  +		} finally {
  +			try {
  +				in.close();
  +				out.close();
  +				serverIn.close();
  +				serverOut.close();
  +			} catch (Exception ex) {}
  +		}
  +	}
  +}
  \ No newline at end of file
  
  
  
  1.3       +446 -434  jakarta-jmeter/src_1/org/apache/jmeter/protocol/http/proxy/ProxyControl.java
  
  Index: ProxyControl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src_1/org/apache/jmeter/protocol/http/proxy/ProxyControl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProxyControl.java	19 Apr 2002 02:08:49 -0000	1.2
  +++ ProxyControl.java	28 Apr 2002 21:40:53 -0000	1.3
  @@ -1,434 +1,446 @@
  -/*
  - * ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - * notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - * notice, this list of conditions and the following disclaimer in
  - * the documentation and/or other materials provided with the
  - * distribution.
  - *
  - * 3. The end-user documentation included with the redistribution,
  - * if any, must include the following acknowledgment:
  - * "This product includes software developed by the
  - * Apache Software Foundation (http://www.apache.org/)."
  - * Alternately, this acknowledgment may appear in the software itself,
  - * if and wherever such third-party acknowledgments normally appear.
  - *
  - * 4. The names "Apache" and "Apache Software Foundation" and
  - * "Apache JMeter" must not be used to endorse or promote products
  - * derived from this software without prior written permission. For
  - * written permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - * "Apache JMeter", nor may "Apache" appear in their name, without
  - * prior written permission of the Apache Software Foundation.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - */
  -
  -package org.apache.jmeter.protocol.http.proxy;
  -
  -import java.net.UnknownHostException;
  -import java.util.*;
  -import java.io.*;
  -
  -import junit.framework.TestCase;
  -
  -import org.apache.jmeter.config.*;
  -import org.apache.jmeter.threads.ThreadGroup;
  -import org.apache.jmeter.protocol.http.config.UrlConfig;
  -import org.apache.jmeter.protocol.http.config.gui.UrlConfigGui;
  -import org.apache.oro.text.regex.*;
  -import org.apache.jmeter.util.JMeterUtils;
  -import org.apache.jmeter.gui.*;
  -import org.apache.jmeter.gui.tree.*;
  -import org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui;
  -import org.apache.jmeter.exceptions.IllegalUserActionException;
  -import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
  -import org.apache.jmeter.testelement.TestElement;
  -import org.apache.jmeter.control.gui.LogicControllerGui;
  -import org.apache.jmeter.threads.gui.ThreadGroupGui;
  -
  -/************************************************************
  - *  Title: Apache JMeter Description: Copyright: Copyright (c) 2000 Company:
  - *  Apache Foundation
  - *
  - *@author     Michael Stover
  - *@created    $Date: 2002/04/19 02:08:49 $
  - *@version    1.0
  - ***********************************************************/
  -
  -public class ProxyControl extends ConfigTestElement implements Serializable
  -{
  -	Daemon server;
  -	private final int DEFAULT_PORT = 8080;
  -	transient Perl5Compiler compiler;
  -	transient Perl5Matcher matcher;
  -	public final static String PORT = "ProxyControlGui.port";
  -	public final static String EXCLUDE_LIST = "ProxyControlGui.exclude_list";
  -	public final static String INCLUDE_LIST = "ProxyControlGui.include_list";
  -
  -	/************************************************************
  -	 *  !ToDo (Constructor description)
  -	 ***********************************************************/
  -	public ProxyControl()
  -	{
  -		matcher = new Perl5Matcher();
  -		compiler = new Perl5Compiler();
  -		setPort(DEFAULT_PORT);
  -		setExcludeList(new LinkedList());
  -		setIncludeList(new LinkedList());
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo (Method description)
  -	 *
  -	 *@param  port  !ToDo (Parameter description)
  -	 ***********************************************************/
  -	public void setPort(int port)
  -	{
  -		this.setProperty(PORT, new Integer(port));
  -	}
  -
  -	public void setIncludeList(List list)
  -	{
  -		setProperty(INCLUDE_LIST,list);
  -	}
  -
  -	public void setExcludeList(List list)
  -	{
  -		setProperty(EXCLUDE_LIST,list);
  -	}
  -
  -	/************************************************************
  -	 *  !ToDoo (Method description)
  -	 *
  -	 *@return    !ToDo (Return description)
  -	 ***********************************************************/
  -	public String getClassLabel()
  -	{
  -		return JMeterUtils.getResString("proxy_title");
  -	}
  -
  -	/************************************************************
  -	 *  !ToDoo (Method description)
  -	 *
  -	 *@return    !ToDo (Return description)
  -	 ***********************************************************/
  -	public int getPort()
  -	{
  -		if (this.getProperty(PORT) instanceof String)
  -		{
  -			setPort(Integer.parseInt((String)getProperty(PORT)));
  -			return ((Integer)this.getProperty(PORT)).intValue();
  -		}
  -		else
  -		{
  -			return ((Integer)this.getProperty(PORT)).intValue();
  -		}
  -	}
  -
  -	/************************************************************
  -	 *  !ToDoo (Method description)
  -	 *
  -	 *@return    !ToDo (Return description)
  -	 ***********************************************************/
  -	public int getDefaultPort()
  -	{
  -		return DEFAULT_PORT;
  -	}
  -
  -	public Class getGuiClass()
  -	{
  -		return org.apache.jmeter.protocol.http.proxy.gui.ProxyControlGui.class;
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo (Method description)
  -	 *
  -	 *@return    !ToDo (Return description)
  -	 ***********************************************************/
  -	public Object clone()
  -	{
  -		ProxyControl clone = new ProxyControl();
  -		configureClone(clone);
  -		return clone;
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo
  -	 *
  -	 *@param  config  !ToDo
  -	 ***********************************************************/
  -	public void addConfigElement(ConfigElement config)
  -	{
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo (Method description)
  -	 ***********************************************************/
  -	public void startProxy()
  -	{
  -		try
  -		{
  -			server = new Daemon(getPort(), this);
  -			server.start();
  -		}
  -		catch (UnknownHostException e)
  -		{
  -			e.printStackTrace();
  -		}
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo
  -	 *
  -	 *@param  pattern  !ToDo
  -	 ***********************************************************/
  -	public void addExcludedPattern(String pattern)
  -	{
  -		getExcludePatterns().add(pattern);
  -	}
  -
  -	public List getExcludePatterns()
  -	{
  -		return (List)getProperty(EXCLUDE_LIST);
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo
  -	 *
  -	 *@param  pattern  !ToDo
  -	 ***********************************************************/
  -	public void addIncludedPattern(String pattern)
  -	{
  -		getIncludePatterns().add(pattern);
  -	}
  -
  -	public List getIncludePatterns()
  -	{
  -		return (List)getProperty(INCLUDE_LIST);
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo (Method description)
  -	 ***********************************************************/
  -	public void clearExcludedPatterns()
  -	{
  -		getExcludePatterns().clear();
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo (Method description)
  -	 ***********************************************************/
  -	public void clearIncludedPatterns()
  -	{
  -		getIncludePatterns().clear();
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo (Method description)
  -	 *
  -	 *@param  config  !ToDo (Parameter description)
  -	 ***********************************************************/
  -	public void deliverSampler(HTTPSampler sampler)
  -	{
  -		if (filterUrl(sampler))
  -		{
  -			placeConfigElement(sampler);
  -		}
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo (Method description)
  -	 ***********************************************************/
  -	public void stopProxy()
  -	{
  -		if (server != null)
  -		{
  -			server.stopServer();
  -		}
  -	}
  -
  -	private boolean filterUrl(HTTPSampler sampler)
  -	{
  -		boolean ok = false;
  -		if (getIncludePatterns().size() == 0)
  -		{
  -			ok = true;
  -		}
  -		else
  -		{
  -			ok = checkIncludes(sampler);
  -		}
  -		if (!ok)
  -		{
  -			return ok;
  -		}
  -		else
  -		{
  -			if (getExcludePatterns().size() == 0)
  -			{
  -				return ok;
  -			}
  -			else
  -			{
  -				ok = checkExcludes(sampler);
  -			}
  -		}
  -		return ok;
  -	}
  -
  -	private void placeConfigElement(HTTPSampler sampler)
  -	{
  -		TestElement urlConfig = null;
  -		JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
  -		List nodes = treeModel.getNodesOfType(LogicControllerGui.class);
  -		if(nodes.size() == 0)
  -		{
  -			nodes = treeModel.getNodesOfType(ThreadGroupGui.class);
  -		}
  -		Iterator iter = nodes.iterator();
  -		if (iter.hasNext())
  -		{
  -			JMeterTreeNode node = (JMeterTreeNode)iter.next();
  -			Enumeration enum = node.children();
  -			while(enum.hasMoreElements())
  -			{
  -				JMeterTreeNode subNode = (JMeterTreeNode)enum.nextElement();
  -				JMeterGUIComponent sample = (JMeterGUIComponent)subNode.getUserObject();
  -				if(sample instanceof UrlConfigGui)
  -				{
  -				}
  -			}
  -			if(urlConfig == null || (urlConfig.getProperty(HTTPSampler.DOMAIN) == null ||
  -					urlConfig.getProperty(HTTPSampler.DOMAIN).equals("") ||
  -					urlConfig.getProperty(HTTPSampler.DOMAIN).equals(sampler.getDomain())) &&
  -					(urlConfig.getProperty(HTTPSampler.PATH) == null ||
  -					urlConfig.getProperty(HTTPSampler.PATH).equals("/") ||
  -					urlConfig.getProperty(HTTPSampler.PATH).equals(sampler.getPath())))
  -			{
  -				if(urlConfig != null && urlConfig.getProperty(HTTPSampler.DOMAIN) != null &&
  -						!urlConfig.getProperty(HTTPSampler.DOMAIN).equals(""))
  -				{
  -					sampler.setDomain("");
  -				}
  -				if(urlConfig != null && urlConfig.getProperty(HTTPSampler.PATH) != null &&
  -						!urlConfig.getProperty(HTTPSampler.PATH).equals("/"))
  -				{
  -					sampler.setPath("");
  -				}
  -				HttpTestSampleGui test = new HttpTestSampleGui();
  -				test.configure(sampler);
  -				try
  -				{
  -					treeModel.addComponent(test,node);
  -				}
  -				catch(IllegalUserActionException e)
  -				{
  -					JMeterUtils.reportErrorToUser(e.getMessage());
  -				}
  -			}
  -		}
  -	}
  -
  -	private boolean checkIncludes(HTTPSampler sampler)
  -	{
  -		boolean ok = false;
  -		Iterator iter = getIncludePatterns().iterator();
  -		while (iter.hasNext())
  -		{
  -			String item = (String)iter.next();
  -			try
  -			{
  -				Pattern pattern = compiler.compile(item);
  -				ok = matcher.matches(sampler.getDomain() + sampler.getPath(), pattern);
  -			}
  -			catch (MalformedPatternException e)
  -			{
  -				JMeterUtils.reportErrorToUser("Bad Regular expression: " + item);
  -			}
  -			if (ok)
  -			{
  -				break;
  -			}
  -		}
  -		return ok;
  -	}
  -
  -	private boolean checkExcludes(HTTPSampler sampler)
  -	{
  -		boolean ok = true;
  -		Iterator iter = getExcludePatterns().iterator();
  -		while (iter.hasNext())
  -		{
  -			String item = (String)iter.next();
  -			try
  -			{
  -				Pattern pattern = compiler.compile(item);
  -				ok = ok && !matcher.matches(sampler.getDomain() + sampler.getPath(), pattern);
  -			}
  -			catch (MalformedPatternException e)
  -			{
  -				JMeterUtils.reportErrorToUser("Bad Regular expression: " + item);
  -			}
  -			if (!ok)
  -			{
  -				return ok;
  -			}
  -		}
  -		return ok;
  -	}
  -
  -	public static class Test extends TestCase
  -	{
  -		public Test(String name)
  -		{
  -			super(name);
  -		}
  -
  -		public void testFiltering() throws Exception
  -		{
  -			ProxyControl control = new ProxyControl();
  -			control.addIncludedPattern(".*\\.jsp");
  -			control.addExcludedPattern(".*apache.org.*");
  -			HTTPSampler sampler = new HTTPSampler();
  -			sampler.setDomain("jakarta.org");
  -			sampler.setPath("index.jsp");
  -			assertTrue(control.filterUrl(sampler));
  -			sampler.setDomain("www.apache.org");
  -			assertTrue(!control.filterUrl(sampler));
  -			sampler.setPath("header.gif");
  -			sampler.setDomain("jakarta.org");
  -			assertTrue(!control.filterUrl(sampler));
  -		}
  -	}
  -
  -}
  +/*
  + * ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + * notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + * notice, this list of conditions and the following disclaimer in
  + * the documentation and/or other materials provided with the
  + * distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + * if any, must include the following acknowledgment:
  + * "This product includes software developed by the
  + * Apache Software Foundation (http://www.apache.org/)."
  + * Alternately, this acknowledgment may appear in the software itself,
  + * if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + * "Apache JMeter" must not be used to endorse or promote products
  + * derived from this software without prior written permission. For
  + * written permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + * "Apache JMeter", nor may "Apache" appear in their name, without
  + * prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
  +package org.apache.jmeter.protocol.http.proxy;
  +
  +import java.net.UnknownHostException;
  +import java.util.*;
  +import java.io.*;
  +
  +import junit.framework.TestCase;
  +
  +import org.apache.jmeter.config.*;
  +import org.apache.jmeter.threads.ThreadGroup;
  +import org.apache.jmeter.protocol.http.config.UrlConfig;
  +import org.apache.jmeter.protocol.http.config.gui.UrlConfigGui;
  +import org.apache.oro.text.regex.*;
  +import org.apache.jmeter.util.JMeterUtils;
  +import org.apache.jmeter.gui.*;
  +import org.apache.jmeter.gui.tree.*;
  +import org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui;
  +import org.apache.jmeter.exceptions.IllegalUserActionException;
  +import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
  +import org.apache.jmeter.testelement.TestElement;
  +import org.apache.jmeter.protocol.http.control.HeaderManager;
  +import org.apache.jmeter.protocol.http.gui.HeaderPanel;
  +import org.apache.jmeter.control.gui.LogicControllerGui;
  +import org.apache.jmeter.threads.gui.ThreadGroupGui;
  +
  +/************************************************************
  + *  Title: Apache JMeter Description: Copyright: Copyright (c) 2000 Company:
  + *  Apache Foundation
  + *
  + *@author     Michael Stover
  + *@created    $Date: 2002/04/28 21:40:53 $
  + *@version    1.0
  + ***********************************************************/
  +
  +public class ProxyControl extends ConfigTestElement implements Serializable
  +{
  +	Daemon server;
  +	private final int DEFAULT_PORT = 8080;
  +	transient Perl5Compiler compiler;
  +	transient Perl5Matcher matcher;
  +	public final static String PORT = "ProxyControlGui.port";
  +	public final static String EXCLUDE_LIST = "ProxyControlGui.exclude_list";
  +	public final static String INCLUDE_LIST = "ProxyControlGui.include_list";
  +
  +	/************************************************************
  +	 *  !ToDo (Constructor description)
  +	 ***********************************************************/
  +	public ProxyControl()
  +	{
  +		matcher = new Perl5Matcher();
  +		compiler = new Perl5Compiler();
  +		setPort(DEFAULT_PORT);
  +		setExcludeList(new LinkedList());
  +		setIncludeList(new LinkedList());
  +	}
  +
  +	/************************************************************
  +	 *  !ToDo (Method description)
  +	 *
  +	 *@param  port  !ToDo (Parameter description)
  +	 ***********************************************************/
  +	public void setPort(int port)
  +	{
  +		this.setProperty(PORT, new Integer(port));
  +	}
  +
  +	public void setIncludeList(List list)
  +	{
  +		setProperty(INCLUDE_LIST,list);
  +	}
  +
  +	public void setExcludeList(List list)
  +	{
  +		setProperty(EXCLUDE_LIST,list);
  +	}
  +
  +	/************************************************************
  +	 *  !ToDoo (Method description)
  +	 *
  +	 *@return    !ToDo (Return description)
  +	 ***********************************************************/
  +	public String getClassLabel()
  +	{
  +		return JMeterUtils.getResString("proxy_title");
  +	}
  +
  +	/************************************************************
  +	 *  !ToDoo (Method description)
  +	 *
  +	 *@return    !ToDo (Return description)
  +	 ***********************************************************/
  +	public int getPort()
  +	{
  +		if (this.getProperty(PORT) instanceof String)
  +		{
  +			setPort(Integer.parseInt((String)getProperty(PORT)));
  +			return ((Integer)this.getProperty(PORT)).intValue();
  +		}
  +		else
  +		{
  +			return ((Integer)this.getProperty(PORT)).intValue();
  +		}
  +	}
  +
  +	/************************************************************
  +	 *  !ToDoo (Method description)
  +	 *
  +	 *@return    !ToDo (Return description)
  +	 ***********************************************************/
  +	public int getDefaultPort()
  +	{
  +		return DEFAULT_PORT;
  +	}
  +
  +	public Class getGuiClass()
  +	{
  +		return org.apache.jmeter.protocol.http.proxy.gui.ProxyControlGui.class;
  +	}
  +
  +	/************************************************************
  +	 *  !ToDo (Method description)
  +	 *
  +	 *@return    !ToDo (Return description)
  +	 ***********************************************************/
  +	public Object clone()
  +	{
  +		ProxyControl clone = new ProxyControl();
  +		configureClone(clone);
  +		return clone;
  +	}
  +
  +	/************************************************************
  +	 *  !ToDo
  +	 *
  +	 *@param  config  !ToDo
  +	 ***********************************************************/
  +	public void addConfigElement(ConfigElement config)
  +	{
  +	}
  +
  +	/************************************************************
  +	 *  !ToDo (Method description)
  +	 ***********************************************************/
  +	public void startProxy()
  +	{
  +		try
  +		{
  +			server = new Daemon(getPort(), this);
  +			server.start();
  +		}
  +		catch (UnknownHostException e)
  +		{
  +			e.printStackTrace();
  +		}
  +	}
  +
  +	/************************************************************
  +	 *  !ToDo
  +	 *
  +	 *@param  pattern  !ToDo
  +	 ***********************************************************/
  +	public void addExcludedPattern(String pattern)
  +	{
  +		getExcludePatterns().add(pattern);
  +	}
  +
  +	public List getExcludePatterns()
  +	{
  +		return (List)getProperty(EXCLUDE_LIST);
  +	}
  +
  +	/************************************************************
  +	 *  !ToDo
  +	 *
  +	 *@param  pattern  !ToDo
  +	 ***********************************************************/
  +	public void addIncludedPattern(String pattern)
  +	{
  +		getIncludePatterns().add(pattern);
  +	}
  +
  +	public List getIncludePatterns()
  +	{
  +		return (List)getProperty(INCLUDE_LIST);
  +	}
  +
  +	/************************************************************
  +	 *  !ToDo (Method description)
  +	 ***********************************************************/
  +	public void clearExcludedPatterns()
  +	{
  +		getExcludePatterns().clear();
  +	}
  +
  +	/************************************************************
  +	 *  !ToDo (Method description)
  +	 ***********************************************************/
  +	public void clearIncludedPatterns()
  +	{
  +		getIncludePatterns().clear();
  +	}
  +
  +	/************************************************************
  +	 *  !ToDo (Method description)
  +	 *
  +	 *@param  config  !ToDo (Parameter description)
  +	 ***********************************************************/
  +	public void deliverSampler(HTTPSampler sampler,TestElement[] subConfigs)
  +	{
  +		if (filterUrl(sampler))
  +		{
  +			placeConfigElement(sampler,subConfigs);
  +		}
  +	}
  +
  +	/************************************************************
  +	 *  !ToDo (Method description)
  +	 ***********************************************************/
  +	public void stopProxy()
  +	{
  +		if (server != null)
  +		{
  +			server.stopServer();
  +		}
  +	}
  +
  +	private boolean filterUrl(HTTPSampler sampler)
  +	{
  +		boolean ok = false;
  +		if (getIncludePatterns().size() == 0)
  +		{
  +			ok = true;
  +		}
  +		else
  +		{
  +			ok = checkIncludes(sampler);
  +		}
  +		if (!ok)
  +		{
  +			return ok;
  +		}
  +		else
  +		{
  +			if (getExcludePatterns().size() == 0)
  +			{
  +				return ok;
  +			}
  +			else
  +			{
  +				ok = checkExcludes(sampler);
  +			}
  +		}
  +		return ok;
  +	}
  +
  +	private void placeConfigElement(HTTPSampler sampler,TestElement[] subConfigs)
  +	{
  +		TestElement urlConfig = null;
  +		JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
  +		List nodes = treeModel.getNodesOfType(LogicControllerGui.class);
  +		if(nodes.size() == 0)
  +		{
  +			nodes = treeModel.getNodesOfType(ThreadGroupGui.class);
  +		}
  +		Iterator iter = nodes.iterator();
  +		if (iter.hasNext())
  +		{
  +			JMeterTreeNode node = (JMeterTreeNode)iter.next();
  +			Enumeration enum = node.children();
  +			while(enum.hasMoreElements())
  +			{
  +				JMeterTreeNode subNode = (JMeterTreeNode)enum.nextElement();
  +				JMeterGUIComponent sample = (JMeterGUIComponent)subNode.getUserObject();
  +				if(sample instanceof UrlConfigGui)
  +				{
  +				}
  +			}
  +			if(urlConfig == null || (urlConfig.getProperty(HTTPSampler.DOMAIN) == null ||
  +					urlConfig.getProperty(HTTPSampler.DOMAIN).equals("") ||
  +					urlConfig.getProperty(HTTPSampler.DOMAIN).equals(sampler.getDomain())) &&
  +					(urlConfig.getProperty(HTTPSampler.PATH) == null ||
  +					urlConfig.getProperty(HTTPSampler.PATH).equals("/") ||
  +					urlConfig.getProperty(HTTPSampler.PATH).equals(sampler.getPath())))
  +			{
  +				if(urlConfig != null && urlConfig.getProperty(HTTPSampler.DOMAIN) != null &&
  +						!urlConfig.getProperty(HTTPSampler.DOMAIN).equals(""))
  +				{
  +					sampler.setDomain("");
  +				}
  +				if(urlConfig != null && urlConfig.getProperty(HTTPSampler.PATH) != null &&
  +						!urlConfig.getProperty(HTTPSampler.PATH).equals("/"))
  +				{
  +					sampler.setPath("");
  +				}
  +				HttpTestSampleGui test = new HttpTestSampleGui();
  +				test.configure(sampler);
  +				try
  +				{
  +					JMeterTreeNode newNode = treeModel.addComponent(test,node);
  +					for(int i = 0;subConfigs != null && i < subConfigs.length;
  +							i++)
  +					{
  +						if(subConfigs[i] instanceof HeaderManager)
  +						{
  +							HeaderPanel comp = new HeaderPanel();
  +							comp.configure(subConfigs[i]);
  +							treeModel.addComponent(comp,newNode);
  +						}
  +					}
  +				}
  +				catch(IllegalUserActionException e)
  +				{
  +					JMeterUtils.reportErrorToUser(e.getMessage());
  +				}
  +			}
  +		}
  +	}
  +
  +	private boolean checkIncludes(HTTPSampler sampler)
  +	{
  +		boolean ok = false;
  +		Iterator iter = getIncludePatterns().iterator();
  +		while (iter.hasNext())
  +		{
  +			String item = (String)iter.next();
  +			try
  +			{
  +				Pattern pattern = compiler.compile(item);
  +				ok = matcher.matches(sampler.getDomain() + sampler.getPath(), pattern);
  +			}
  +			catch (MalformedPatternException e)
  +			{
  +				JMeterUtils.reportErrorToUser("Bad Regular expression: " + item);
  +			}
  +			if (ok)
  +			{
  +				break;
  +			}
  +		}
  +		return ok;
  +	}
  +
  +	private boolean checkExcludes(HTTPSampler sampler)
  +	{
  +		boolean ok = true;
  +		Iterator iter = getExcludePatterns().iterator();
  +		while (iter.hasNext())
  +		{
  +			String item = (String)iter.next();
  +			try
  +			{
  +				Pattern pattern = compiler.compile(item);
  +				ok = ok && !matcher.matches(sampler.getDomain() + sampler.getPath(), pattern);
  +			}
  +			catch (MalformedPatternException e)
  +			{
  +				JMeterUtils.reportErrorToUser("Bad Regular expression: " + item);
  +			}
  +			if (!ok)
  +			{
  +				return ok;
  +			}
  +		}
  +		return ok;
  +	}
  +
  +	public static class Test extends TestCase
  +	{
  +		public Test(String name)
  +		{
  +			super(name);
  +		}
  +
  +		public void testFiltering() throws Exception
  +		{
  +			ProxyControl control = new ProxyControl();
  +			control.addIncludedPattern(".*\\.jsp");
  +			control.addExcludedPattern(".*apache.org.*");
  +			HTTPSampler sampler = new HTTPSampler();
  +			sampler.setDomain("jakarta.org");
  +			sampler.setPath("index.jsp");
  +			assertTrue(control.filterUrl(sampler));
  +			sampler.setDomain("www.apache.org");
  +			assertTrue(!control.filterUrl(sampler));
  +			sampler.setPath("header.gif");
  +			sampler.setDomain("jakarta.org");
  +			assertTrue(!control.filterUrl(sampler));
  +		}
  +	}
  +
  +}
  
  
  

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