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 2001/07/24 00:26:15 UTC

cvs commit: jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy Config.java Daemon.java

mstover1    01/07/23 15:26:15

  Modified:    .        build.xml
               bin      jmeter.bat
               src/org/apache/jmeter/protocol/http/parser HtmlParser.java
               src/org/apache/jmeter/protocol/http/proxy Config.java
                        Daemon.java
  Added:       src/org/apache/jmeter/protocol/http/parser FormElement.java
                        HtmlForm.java
  Log:
  Refactoring Proxy server.
  Fixing jmeter.bat
  New HTML parsing tools
  
  Revision  Changes    Path
  1.31      +1 -0      jakarta-jmeter/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/build.xml,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- build.xml	2001/07/14 19:51:05	1.30
  +++ build.xml	2001/07/23 22:26:15	1.31
  @@ -86,6 +86,7 @@
   				<exclude name="**/*.orig"/>
   				<exclude name="org/apache/jmeter/protocol/http/util/SSLStaticProvider.java" unless="jsse.present"/>
   				<exclude name="org/apache/jmeter/visualizers/MailerVisualizer.java" unless="javamail.complete"/>
  +				<exclude name="org/apache/jmeter/reporters/MailerResultCollector.java" unless="javamail.complete"/>
   				<classpath refid="classpath"/>
   		  </javac>
   	 </target>
  
  
  
  1.15      +1 -2      jakarta-jmeter/bin/jmeter.bat
  
  Index: jmeter.bat
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/bin/jmeter.bat,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- jmeter.bat	2001/07/23 21:00:05	1.14
  +++ jmeter.bat	2001/07/23 22:26:15	1.15
  @@ -11,5 +11,4 @@
   IF "%5" EQU "-f" set PROP=%6
   IF "%5" EQU "-h" set HOST=-Dhttp.proxyHost=%6 -Dhttps.proxyHost=%6
   IF "%5" EQU "-p" set PORT=-Dhttp.proxyPort=%6 -Dhttps.proxyPort=%6
  -java -cp %CLASSPATH%;../lib/xerces.jar;ApacheJMeter.jar;../lib/Tidy.jar;../lib/log4j-core.jar %HOST% %PORT% 
  -org.apache.jmeter.NewDriver %PROP%
  +java -cp %CLASSPATH%;../lib/xerces.jar;ApacheJMeter.jar;../lib/Tidy.jar;../lib/log4j-core.jar %HOST% %PORT% org.apache.jmeter.NewDriver %PROP%
  
  
  
  1.6       +446 -317  jakarta-jmeter/src/org/apache/jmeter/protocol/http/parser/HtmlParser.java
  
  Index: HtmlParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/parser/HtmlParser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HtmlParser.java	2001/06/27 02:28:43	1.5
  +++ HtmlParser.java	2001/07/23 22:26:15	1.6
  @@ -1,317 +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.parser;
  -import java.net.*;
  -
  -import java.util.*;
  -import org.apache.jmeter.config.*;
  -
  -import org.apache.jmeter.control.ResponseParser;
  -import org.apache.jmeter.protocol.http.config.UrlConfig;
  -import org.apache.jmeter.samplers.Entry;
  -import org.apache.jmeter.util.JMeterUtils;
  -
  -import org.apache.oro.text.regex.*;
  -/************************************************************
  - *  Title: Description: Copyright: Copyright (c) 2001 Company:
  - *
  - *@author     Michael Stover
  - *@created    June 14, 2001
  - *@version    1.0
  - ***********************************************************/
  -
  -public class HtmlParser implements ResponseParser
  -{
  -	Collection parsedConfigs;
  -	Perl5Compiler compiler;
  -	Random random = new Random();
  -	List hrefPatterns;
  -	private int compilerOptions = Perl5Compiler.CASE_INSENSITIVE_MASK |
  -			Perl5Compiler.MULTILINE_MASK | Perl5Compiler.READ_ONLY_MASK;
  -
  -	/************************************************************
  -	 *  Constructor for the HtmlParser object
  -	 ***********************************************************/
  -	public HtmlParser()
  -	{
  -		compiler = new Perl5Compiler();
  -		hrefPatterns = new LinkedList();
  -	}
  -
  -	/************************************************************
  -	 *  Gets the ClassLabel attribute of the HtmlParser object
  -	 *
  -	 *@return    The ClassLabel value
  -	 ***********************************************************/
  -	public String getClassLabel()
  -	{
  -		/************************************************************
  -		 *@todo:    Implement this org.apache.jmeter.control.ResponseParser method
  -		 ***********************************************************/
  -		throw new java.lang.UnsupportedOperationException("Method getClassLabel() not yet implemented.");
  -	}
  -
  -	/************************************************************
  -	 *  Give a current HTML page, an Entry object, and the current URL object, this
  -	 *  method will find a link within the html page that matches the Entry, and will
  -	 *  modify the Entry object to be equivalent to that link.  Both anchors and
  -	 *  form links will be processed in the HTML page.
  -	 *
  -	 *@param  entry                          Description of Parameter
  -	 *@param  currentResponse                Description of Parameter
  -	 *@param  currentContext                 Description of Parameter
  -	 *@exception  MalformedPatternException  Description of Exception
  -	 ***********************************************************/
  -	public void modifyEntry(Entry entry, String currentResponse, Object currentContext) throws MalformedPatternException
  -	{
  -		if(entryIrrelevant(entry))
  -		{
  -			return;
  -		}
  -		UrlConfig config = (UrlConfig)entry.getConfigElement(
  -				org.apache.jmeter.protocol.http.config.UrlConfig.class);
  -		List sections;
  -		if(config.getMethod().equals(config.GET))
  -		{
  -			sections = getRelevantSections(extractAnchors(currentResponse, (URL)currentContext),
  -					config.getPath());
  -			if(sections.size() > 0)
  -			{
  -				modifyAnchorEntry(config, (URL)sections.get(random.nextInt(sections.size())));
  -			}
  -		}
  -		else if(config.getMethod().equals(config.POST))
  -		{
  -			sections = getRelevantSections(extractForms(currentResponse),
  -					config.getPath());
  -		}
  -	}
  -
  -
  -	private List getRelevantSections(Collection anchors, String pattern) throws MalformedPatternException
  -	{
  -		List relevantAnchors = new LinkedList();
  -		Iterator iter = anchors.iterator();
  -		while(iter.hasNext())
  -		{
  -			URL item = (URL)iter.next();
  -			try
  -			{
  -				if(isMatch(pattern, item.toString()))
  -				{
  -					relevantAnchors.add(item);
  -				}
  -			}
  -			catch(MalformedPatternException e)
  -			{
  -				System.out.println("malformed pattern = " + pattern.toString());
  -			}
  -		}
  -		return relevantAnchors;
  -	}
  -
  -	private boolean isMatch(String configPath, String section) throws MalformedPatternException
  -	{
  -		Perl5Matcher matcher = new Perl5Matcher();
  -		Pattern pattern = compiler.compile(configPath);
  -		return matcher.contains(section, pattern);
  -	}
  -
  -	private String extractLinkText(String anchor)
  -	{
  -		String tempVersion = anchor.toLowerCase();
  -		int start = tempVersion.indexOf("href=") + 5;
  -		int end;
  -		if(start == -1)
  -		{
  -			return "";
  -		}
  -		if(tempVersion.charAt(start) == '"')
  -		{
  -			start++;
  -			end = tempVersion.indexOf('"', start);
  -		}
  -		else
  -		{
  -			end = findFirst(anchor, ' ', '>', start);
  -		}
  -		return anchor.substring(start, end);
  -	}
  -
  -	private void modifyAnchorEntry(UrlConfig config, URL url)
  -	{
  -		config.setDomain(url.getHost());
  -		config.setPort(url.getPort());
  -		config.setProtocol(url.getProtocol());
  -		config.setPath(url.getPath());
  -		String query = url.getQuery();
  -		String[] args = JMeterUtils.split(query, "&");
  -		for(int i = 0; i < args.length; i++)
  -		{
  -			int index = args[i].indexOf("=");
  -			config.addArgument(args[i].substring(0, index),
  -					args[i].substring(index + 1));
  -		}
  -	}
  -
  -	private int findFirst(String search, char one, char two, int start)
  -	{
  -		int end1 = search.indexOf(one, start);
  -		int end2 = search.indexOf(two, start);
  -		if(end1 == -1)
  -		{
  -			return end2;
  -		}
  -		else if(end2 == -1)
  -		{
  -			return end1;
  -		}
  -		else
  -		{
  -			return Math.min(end1, end2);
  -		}
  -	}
  -
  -	private Collection extractAnchors(String html, URL context)
  -	{
  -		Collection sections = new LinkedList();
  -		int index = 0;
  -		while((index = extractAnchor(html, index, sections, context)) < html.length())
  -		{
  -			;
  -		}
  -		return sections;
  -	}
  -
  -	private int extractAnchor(String html, int index, Collection sections, URL context)
  -	{
  -		String tempVersion = html.toLowerCase();
  -		int anchorStart = tempVersion.indexOf("<a", index);
  -		if(anchorStart == -1)
  -		{
  -			return html.length();
  -		}
  -		int anchorEnd = tempVersion.indexOf("</a>", anchorStart) + "</a>".length();
  -		sections.add(createUrlFromAnchor(extractLinkText(html.substring(anchorStart, anchorEnd)),
  -				context));
  -		return anchorEnd;
  -	}
  -
  -	private Collection extractForms(String html)
  -	{
  -		Collection sections = new LinkedList();
  -		int index = 0;
  -		while((index = extractForm(html, index, sections)) < html.length())
  -		{
  -			;
  -		}
  -		return sections;
  -	}
  -
  -	private int extractForm(String html, int index, Collection sections)
  -	{
  -		String tempVersion = html.toLowerCase();
  -		int formStart = tempVersion.indexOf("<form", index);
  -		if(formStart == -1)
  -		{
  -			return html.length();
  -		}
  -		int formEnd = tempVersion.indexOf("</form>", formStart) + "</form>".length();
  -		//sections.add(createUrlConfigFromForm(extractFormElements(html.substring(formStart, formEnd))));
  -		return formEnd;
  -	}
  -
  -
  -	private boolean entryIrrelevant(Entry entry)
  -	{
  -		UrlConfig config = (UrlConfig)entry.getConfigElement(
  -				org.apache.jmeter.protocol.http.config.UrlConfig.class);
  -		if(config == null)
  -		{
  -			return true;
  -		}
  -		return false;
  -	}
  -
  -	private URL createUrlFromAnchor(String parsedUrlString, URL context)
  -	{
  -		URL url = null;
  -		if(parsedUrlString.startsWith("/"))
  -		{
  -			parsedUrlString = context.getProtocol() + "://" + context.getHost() + parsedUrlString;
  -		}
  -		else if(parsedUrlString.startsWith(".."))
  -		{
  -			parsedUrlString = context.getProtocol() + "://" + context.getHost() +
  -					context.getPath().substring(0,context.getPath().substring(0, context.getPath().lastIndexOf("/")).lastIndexOf("/")) +
  -					parsedUrlString.substring(2);
  -		}
  -		else if(!parsedUrlString.toLowerCase().startsWith("http"))
  -		{
  -			parsedUrlString = context.getProtocol() + "://" + context.getHost() +
  -					context.getPath().substring(0, context.getPath().lastIndexOf("/")) +
  -					"/" + parsedUrlString;
  -		}
  -		try
  -		{
  -			url = new URL(parsedUrlString);
  -		}
  -		catch(MalformedURLException e)
  -		{
  -			e.printStackTrace();
  -		}
  -		return url;
  -	}
  -}
  +/*
  + * ====================================================================
  + * 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.parser;
  +
  +import java.net.*;
  +
  +
  +import java.util.*;
  +
  +import org.apache.jmeter.config.*;
  +
  +
  +import org.apache.jmeter.control.ResponseParser;
  +
  +import org.apache.jmeter.protocol.http.config.UrlConfig;
  +
  +import org.apache.jmeter.samplers.Entry;
  +
  +import org.apache.jmeter.util.JMeterUtils;
  +
  +
  +import org.apache.oro.text.regex.*;
  +
  +/************************************************************
  + *  Title: Description: Copyright: Copyright (c) 2001 Company:
  + *
  + *@author     Michael Stover
  + *@created    June 14, 2001
  + *@version    1.0
  + ***********************************************************/
  +
  +
  +public class HtmlParser implements ResponseParser
  +{
  +
  +	Collection parsedConfigs;
  +
  +	Perl5Compiler compiler;
  +
  +	Random random = new Random();
  +
  +	List hrefPatterns;
  +
  +	private int compilerOptions = Perl5Compiler.CASE_INSENSITIVE_MASK |
  +			Perl5Compiler.MULTILINE_MASK | Perl5Compiler.READ_ONLY_MASK;
  +
  +
  +	/************************************************************
  +	 *  Constructor for the HtmlParser object
  +	 ***********************************************************/
  +
  +	public HtmlParser()
  +	{
  +
  +		compiler = new Perl5Compiler();
  +
  +		hrefPatterns = new LinkedList();
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the ClassLabel attribute of the HtmlParser object
  +	 *
  +	 *@return    The ClassLabel value
  +	 ***********************************************************/
  +
  +	public String getClassLabel()
  +	{
  +
  +		/************************************************************
  +		 *@todo:    Implement this org.apache.jmeter.control.ResponseParser method
  +		 ***********************************************************/
  +
  +		throw new java.lang.UnsupportedOperationException("Method getClassLabel() not yet implemented.");
  +	}
  +
  +
  +	/************************************************************
  +	 *  Give a current HTML page, an Entry object, and the current URL object, this
  +	 *  method will find a link within the html page that matches the Entry, and
  +	 *  will modify the Entry object to be equivalent to that link. Both anchors
  +	 *  and form links will be processed in the HTML page.
  +	 *
  +	 *@param  entry                          Description of Parameter
  +	 *@param  currentResponse                Description of Parameter
  +	 *@param  currentContext                 Description of Parameter
  +	 *@exception  MalformedPatternException  Description of Exception
  +	 ***********************************************************/
  +
  +	public void modifyEntry(Entry entry, String currentResponse, Object currentContext) throws MalformedPatternException
  +	{
  +		if(entryIrrelevant(entry))
  +		{
  +			return;
  +		}
  +		UrlConfig config = (UrlConfig)entry.getConfigElement(
  +				org.apache.jmeter.protocol.http.config.UrlConfig.class);
  +		List sections;
  +		if(config.getMethod().equals(config.GET))
  +		{
  +			sections = getRelevantSections(extractAnchors(currentResponse, (URL)currentContext),
  +					config.getPath());
  +			if(sections.size() > 0)
  +			{
  +				modifyAnchorEntry(config, (URL)sections.get(random.nextInt(sections.size())));
  +			}
  +		}
  +		else if(config.getMethod().equals(config.POST))
  +		{
  +			sections = getRelevantSections(extractForms(currentResponse),
  +					config.getPath());
  +		}
  +	}
  +
  +	private List getRelevantSections(Collection anchors, String pattern) throws MalformedPatternException
  +	{
  +		List relevantAnchors = new LinkedList();
  +		Iterator iter = anchors.iterator();
  +		while(iter.hasNext())
  +		{
  +			URL item = (URL)iter.next();
  +			try
  +			{
  +				if(isMatch(pattern, item.toString()))
  +				{
  +					relevantAnchors.add(item);
  +				}
  +			}
  +			catch(MalformedPatternException e)
  +			{
  +				System.out.println("malformed pattern = " + pattern.toString());
  +			}
  +		}
  +		return relevantAnchors;
  +	}
  +
  +
  +	private boolean isMatch(String configPath, String section) throws MalformedPatternException
  +	{
  +
  +		Perl5Matcher matcher = new Perl5Matcher();
  +
  +		Pattern pattern = compiler.compile(configPath);
  +
  +		return matcher.contains(section, pattern);
  +	}
  +
  +
  +	private String extractLinkText(String anchor)
  +	{
  +
  +		String tempVersion = anchor.toLowerCase();
  +
  +		int start = tempVersion.indexOf("href=") + 5;
  +
  +		int end;
  +
  +		if(start == -1)
  +		{
  +
  +			return "";
  +		}
  +
  +		if(tempVersion.charAt(start) == '"')
  +		{
  +
  +			start++;
  +
  +			end = tempVersion.indexOf('"', start);
  +
  +		}
  +
  +		else
  +		{
  +
  +			end = findFirst(anchor, ' ', '>', start);
  +
  +		}
  +
  +		return anchor.substring(start, end);
  +	}
  +
  +
  +	private void modifyAnchorEntry(UrlConfig config, URL url)
  +	{
  +
  +		config.setDomain(url.getHost());
  +
  +		config.setPort(url.getPort());
  +
  +		config.setProtocol(url.getProtocol());
  +
  +		config.setPath(url.getPath());
  +
  +		String query = url.getQuery();
  +
  +		String[] args = JMeterUtils.split(query, "&");
  +
  +		for(int i = 0; i < args.length; i++)
  +		{
  +
  +			int index = args[i].indexOf("=");
  +
  +			config.addArgument(args[i].substring(0, index),
  +					args[i].substring(index + 1));
  +
  +		}
  +
  +	}
  +
  +
  +	private int findFirst(String search, char one, char two, int start)
  +	{
  +
  +		int end1 = search.indexOf(one, start);
  +
  +		int end2 = search.indexOf(two, start);
  +
  +		if(end1 == -1)
  +		{
  +
  +			return end2;
  +		}
  +
  +		else if(end2 == -1)
  +		{
  +
  +			return end1;
  +		}
  +
  +		else
  +		{
  +
  +			return Math.min(end1, end2);
  +		}
  +
  +	}
  +
  +
  +	private Collection extractAnchors(String html, URL context)
  +	{
  +
  +		Collection sections = new LinkedList();
  +
  +		int index = 0;
  +
  +		while((index = extractAnchor(html, index, sections, context)) < html.length())
  +		{
  +
  +			;
  +
  +		}
  +
  +		return sections;
  +	}
  +
  +
  +	private int extractAnchor(String html, int index, Collection sections, URL context)
  +	{
  +
  +		String tempVersion = html.toLowerCase();
  +
  +		int anchorStart = tempVersion.indexOf("<a", index);
  +
  +		if(anchorStart == -1)
  +		{
  +
  +			return html.length();
  +		}
  +
  +		int anchorEnd = tempVersion.indexOf("</a>", anchorStart) + "</a>".length();
  +
  +		sections.add(createUrlFromAnchor(extractLinkText(html.substring(anchorStart, anchorEnd)),
  +				context));
  +
  +		return anchorEnd;
  +	}
  +
  +
  +	private Collection extractForms(String html)
  +	{
  +
  +		Collection sections = new LinkedList();
  +
  +		int index = 0;
  +
  +		while((index = extractForm(html, index, sections)) < html.length())
  +		{
  +
  +			;
  +
  +		}
  +
  +		return sections;
  +	}
  +
  +
  +	private int extractForm(String html, int index, Collection sections)
  +	{
  +
  +		String tempVersion = html.toLowerCase();
  +
  +		int formStart = tempVersion.indexOf("<form", index);
  +
  +		if(formStart == -1)
  +		{
  +
  +			return html.length();
  +		}
  +
  +		int formEnd = tempVersion.indexOf("</form>", formStart) + "</form>".length();
  +		String action = html.substring(formStart,formEnd).toLowerCase();
  +		action = action.substring(action.indexOf("action=")+6);
  +		if(action.charAt(0) == '"')
  +		{
  +			action = action.substring(1,action.indexOf("\"",1));
  +		}
  +		else
  +		{
  +			action = action.substring(0,this.findFirst(action,'>',' ',1));
  +		}
  +		sections.add(new HtmlForm(action,HtmlForm.extractFormElements(html.substring(formStart, formEnd))));
  +		return formEnd;
  +	}
  +
  +
  +
  +	private boolean entryIrrelevant(Entry entry)
  +	{
  +
  +		UrlConfig config = (UrlConfig)entry.getConfigElement(
  +				org.apache.jmeter.protocol.http.config.UrlConfig.class);
  +
  +		if(config == null)
  +		{
  +
  +			return true;
  +		}
  +
  +		return false;
  +	}
  +
  +
  +	private URL createUrlFromAnchor(String parsedUrlString, URL context)
  +	{
  +
  +		URL url = null;
  +
  +		if(parsedUrlString.startsWith("/"))
  +		{
  +
  +			parsedUrlString = context.getProtocol() + "://" + context.getHost() + parsedUrlString;
  +
  +		}
  +
  +		else if(parsedUrlString.startsWith(".."))
  +		{
  +
  +			parsedUrlString = context.getProtocol() + "://" + context.getHost() +
  +					context.getPath().substring(0, context.getPath().substring(0, context.getPath().lastIndexOf("/")).lastIndexOf("/")) +
  +					parsedUrlString.substring(2);
  +
  +		}
  +
  +		else if(!parsedUrlString.toLowerCase().startsWith("http"))
  +		{
  +
  +			parsedUrlString = context.getProtocol() + "://" + context.getHost() +
  +					context.getPath().substring(0, context.getPath().lastIndexOf("/")) +
  +					"/" + parsedUrlString;
  +
  +		}
  +
  +		try
  +		{
  +
  +			url = new URL(parsedUrlString);
  +
  +		}
  +
  +		catch(MalformedURLException e)
  +		{
  +
  +			e.printStackTrace();
  +
  +		}
  +
  +		return url;
  +	}
  +
  +}
  +
  
  
  
  1.1                  jakarta-jmeter/src/org/apache/jmeter/protocol/http/parser/FormElement.java
  
  Index: FormElement.java
  ===================================================================
  package org.apache.jmeter.protocol.http.parser;
  
  /************************************************************
   *  Title: Description: Copyright: Copyright (c) 2001 Company:
   *
   *@author
   *@created    June 16, 2001
   *@version    1.0
   ***********************************************************/
  
  public class FormElement
  {
  	private boolean multipleAllowed;
  	private String name;
  	private java.util.List possibleValues;
  	private java.util.List defaultValues;
  
  	/************************************************************
  	 *  Constructor for the FormElement object
  	 ***********************************************************/
  	public FormElement()
  	{
  	}
  
  	/************************************************************
  	 *  Sets the MultipleAllowed attribute of the FormElement object
  	 *
  	 *@param  newMultipleAllowed  The new MultipleAllowed value
  	 ***********************************************************/
  	public void setMultipleAllowed(boolean newMultipleAllowed)
  	{
  		multipleAllowed = newMultipleAllowed;
  	}
  
  	/************************************************************
  	 *  Sets the Name attribute of the FormElement object
  	 *
  	 *@param  newName  The new Name value
  	 ***********************************************************/
  	public void setName(String newName)
  	{
  		name = newName;
  	}
  
  	/************************************************************
  	 *  Sets the PossibleValues attribute of the FormElement object
  	 *
  	 *@param  newPossibleValues  The new PossibleValues value
  	 ***********************************************************/
  	public void setPossibleValues(java.util.List newPossibleValues)
  	{
  		possibleValues = newPossibleValues;
  	}
  
  	/************************************************************
  	 *  Sets the DefaultValues attribute of the FormElement object
  	 *
  	 *@param  newDefaultValues  The new DefaultValues value
  	 ***********************************************************/
  	public void setDefaultValues(java.util.List newDefaultValues)
  	{
  		defaultValues = newDefaultValues;
  	}
  
  	/************************************************************
  	 *  Gets the MultipleAllowed attribute of the FormElement object
  	 *
  	 *@return    The MultipleAllowed value
  	 ***********************************************************/
  	public boolean isMultipleAllowed()
  	{
  		return multipleAllowed;
  	}
  
  	/************************************************************
  	 *  Gets the Name attribute of the FormElement object
  	 *
  	 *@return    The Name value
  	 ***********************************************************/
  	public String getName()
  	{
  		return name;
  	}
  
  	/************************************************************
  	 *  Gets the PossibleValues attribute of the FormElement object
  	 *
  	 *@return    The PossibleValues value
  	 ***********************************************************/
  	public java.util.List getPossibleValues()
  	{
  		return possibleValues;
  	}
  
  	/************************************************************
  	 *  Gets the DefaultValues attribute of the FormElement object
  	 *
  	 *@return    The DefaultValues value
  	 ***********************************************************/
  	public java.util.List getDefaultValues()
  	{
  		return defaultValues;
  	}
  
  }
  
  
  
  1.1                  jakarta-jmeter/src/org/apache/jmeter/protocol/http/parser/HtmlForm.java
  
  Index: HtmlForm.java
  ===================================================================
  package org.apache.jmeter.protocol.http.parser;
  
  import java.util.*;
  
  /************************************************************
   *  Title: Description: Copyright: Copyright (c) 2001 Company:
   *
   *@author
   *@created    June 29, 2001
   *@version    1.0
   ***********************************************************/
  
  class HtmlForm
  {
  
  	/************************************************************
  	 *  Constructor for the HtmlForm object
  	 ***********************************************************/
  	public HtmlForm()
  	{
  	}
  
  	/************************************************************
  	 *  Give the action string and a list of FormElement objects to create
  	 *  the new HtmlForm, to be used by the HtmlParser.
  	 *
  	 *@param  action        Description of Parameter
  	 *@param  formElements  Description of Parameter
  	 ***********************************************************/
  	public HtmlForm(String action, Collection formElements)
  	{
  	}
  
  	public static Collection extractFormElements(String formString)
  	{
  		return Collections.EMPTY_LIST;
  	}
  }
  
  
  
  1.2       +930 -426  jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/Config.java
  
  Index: Config.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/Config.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Config.java	2001/06/14 00:28:20	1.1
  +++ Config.java	2001/07/23 22:26:15	1.2
  @@ -1,426 +1,930 @@
  -package org.apache.jmeter.protocol.http.proxy;
  -/******************************************************************
  -*** File Config.java
  -***
  -***/
  -
  -import java.util.*;
  -import java.net.*;
  -import java.io.*;
  -
  -
  -//
  -// Class:     Config
  -// Abstract:  Configurable parameters of the proxy. This class is
  -//            used by both the applet and the proxy.
  -//
  -
  -class Config
  -{
  -	//
  -	// Member variables
  -	//
  -	String jmxScriptDir;
  -	 private boolean  isFatherProxy;
  -	 private String   fatherProxyHost;
  -	 private int      fatherProxyPort;
  -	 private String[] deniedHosts;
  -	 private String   password;
  -	private boolean  isCaching;  // enable/disable caching
  -	private long 	 cacheSize;  // cache size in bytes
  -	 private boolean  cleanCache;
  -	 private String[] cacheMasks;
  -
  -	 private long     filesCached;
  -	 private long     bytesCached;
  -	 private long     bytesFree;
  -	 private long     hits;
  -	 private long     misses;
  -
  -	 private final int defaultProxyPort = 8080;
  -	 private final String defaultPassword = "admin";
  -	 private final long defaultCacheSize = 1000000;
  -
  -	private String adminPath;
  -	private int    adminPort;
  -
  -	private String localHost;
  -	private String localIP;
  -
  -	private boolean isAppletContext;
  -	private String  separator = " ";
  -	private String proxyMachineNameAndPort;
  -
  -
  -	//
  -	// Member methods
  -	//
  -
  -	//
  -	// Constructor
  -	//
  -	Config()
  -	{
  -		filesCached = 0;
  -		bytesCached = 0;
  -		bytesFree = cacheSize;
  -		hits = 0;
  -		misses = 0;
  -
  -		reset();
  -	}
  -
  -	public void setJmxScriptDir(String filename)
  -	{
  -		jmxScriptDir = filename;
  -		File file = new File(System.getProperty("user.dir")+File.separator+jmxScriptDir);
  -		file.mkdirs();
  -	}
  -
  -	public String getJmxScriptDir()
  -	{
  -		return jmxScriptDir;
  -	}
  -
  -	//
  -	// Re-initialize
  -	//
  -	public void reset()
  -	{
  -		  isFatherProxy = false;
  -		  fatherProxyHost = "wwwproxy.ac.il";
  -		  fatherProxyPort = defaultProxyPort;
  -		  password = defaultPassword;
  -		isCaching = true;
  -		cacheSize = defaultCacheSize;
  -		  cleanCache = false;
  -
  -		deniedHosts = new String[0];
  -		cacheMasks = new String[0];
  -	}
  -
  -
  -	//
  -	// Set/get methods
  -	//
  -
  -	// Set if we are in the applet or in the proxy
  -	public void setIsAppletContext(boolean b)
  -	{
  -		isAppletContext = b;
  -	}
  -
  -	public void setProxyMachineNameAndPort(String s)
  -	{
  -		proxyMachineNameAndPort = s;
  -	}
  -
  -	public String getProxyMachineNameAndPort()
  -	{
  -		return proxyMachineNameAndPort;
  -	}
  -
  -	public int getAdminPort()
  -	{
  -		return adminPort;
  -	}
  -
  -	public void setAdminPort(int port)
  -	{
  -		adminPort = port;
  -	}
  -
  -	public void setAdminPath(String path)
  -	{
  -		adminPath = path;
  -	}
  -
  -	public String getAdminPath()
  -	{
  -		return adminPath;
  -	}
  -
  -	public void setLocalHost(String host)
  -	{
  -		localHost = host;
  -	}
  -
  -	public String getLocalHost()
  -	{
  -		return localHost;
  -	}
  -
  -	public void setLocalIP(String ip)
  -	{
  -		localIP = ip;
  -	}
  -
  -	public String getLocalIP()
  -	{
  -		return localIP;
  -	}
  -
  -	boolean getIsCaching()
  -	{
  -		return isCaching;
  -	}
  -
  -	public synchronized void setIsCaching(boolean caching)
  -	{
  -		isCaching = caching;
  -	}
  -
  -	public synchronized long getCacheSize()
  -	{
  -		return cacheSize;
  -	}
  -	public synchronized void setCacheSize(long size)
  -	{
  -		cacheSize = size;
  -	}
  -
  -	 public boolean getIsFatherProxy()
  -	 {
  -		  return isFatherProxy;
  -	 }
  -
  -	 public synchronized void setIsFatherProxy(boolean fatherProxy)
  -	 {
  -		  isFatherProxy  = fatherProxy;
  -	 }
  -
  -	 public String getFatherProxyHost()
  -	 {
  -		  return fatherProxyHost;
  -	 }
  -
  -	 public synchronized void setFatherProxyHost(String host)
  -	 {
  -		  fatherProxyHost = host;
  -	 }
  -
  -	 public int getFatherProxyPort()
  -	 {
  -		  return fatherProxyPort;
  -	 }
  -
  -	 public synchronized void setFatherProxyPort(int port)
  -	 {
  -		  fatherProxyPort = port;
  -	 }
  -
  -	 public String[] getDeniedHosts()
  -	 {
  -		  return deniedHosts;
  -	 }
  -
  -	 public synchronized void setDeniedHosts(String[] hosts)
  -	 {
  -		  deniedHosts = hosts;
  -	 }
  -
  -	 public String getPassword()
  -	 {
  -		  return password;
  -	 }
  -
  -	 public synchronized void setPassword(String newPassword)
  -	 {
  -		  password = newPassword;
  -	 }
  -
  -	 public boolean getCleanCache()
  -	 {
  -		  return cleanCache;
  -	 }
  -
  -	 public synchronized void setCleanCache(boolean clean)
  -	 {
  -		  cleanCache = clean;
  -	 }
  -
  -	 public String[] getCacheMasks()
  -	 {
  -		  return cacheMasks;
  -	 }
  -
  -	 public synchronized void setCacheMasks(String[] masks)
  -	 {
  -		  cacheMasks = masks;
  -	 }
  -
  -	 public long getFilesCached()
  -	 {
  -		  return filesCached;
  -	 }
  -
  -	 public synchronized void increaseFilesCached()
  -	 {
  -		  filesCached++;
  -	 }
  -
  -	 public synchronized void decreaseFilesCached()
  -	 {
  -		  filesCached--;
  -	 }
  -
  -	public synchronized void setFilesCached(long number)
  -	{
  -		filesCached = number;
  -	}
  -
  -	 public long getBytesCached()
  -	 {
  -		  return bytesCached;
  -	 }
  -
  -	 public synchronized void setBytesCached(long number)
  -	 {
  -		  bytesCached = number;
  -	 }
  -
  -	 public long getBytesFree()
  -	 {
  -		  return cacheSize - bytesCached;
  -	 }
  -
  -	 public long getHits()
  -	 {
  -		  return hits;
  -	 }
  -
  -	 public synchronized void increaseHits()
  -	 {
  -		  hits++;
  -	 }
  -
  -	public synchronized void setHits(long number)
  -	{
  -		hits = number;
  -	}
  -
  -	 public long getMisses()
  -	 {
  -		  return misses;
  -	 }
  -
  -	 public synchronized void increaseMisses()
  -	 {
  -		  misses++;
  -	 }
  -
  -	public synchronized void setMisses(long number)
  -	{
  -		misses = number;
  -	}
  -
  -	 public double getHitRatio()
  -	 {
  -		  if ((hits + misses)==0)
  -				return 0;
  -		  else
  -				return 100*hits / (hits + misses);
  -	 }
  -
  -
  -	//
  -	// Construct a string with all parameters
  -	//
  -	public synchronized String toString()
  -	{
  -		int i;
  -		String s = "";
  -		s += isFatherProxy + separator;
  -		  s += fatherProxyHost.equals("") ? "NULL" : fatherProxyHost;
  -		  s +=                    separator +
  -		  fatherProxyPort       + separator;
  -
  -		  s += deniedHosts.length + separator;
  -		  for (i=0; i<deniedHosts.length; i++)
  -				s += deniedHosts[i] + separator;
  -
  -		  s +=
  -		  password              + separator +
  -		isCaching             + separator +
  -		cacheSize             + separator +
  -		  cleanCache            + separator;
  -
  -		  s += cacheMasks.length + separator;
  -		  for (i=0; i<cacheMasks.length; i++)
  -				s += cacheMasks[i] + separator;
  -
  -		  s+= proxyMachineNameAndPort + separator;
  -
  -		s +=
  -		  filesCached           + separator +
  -		  bytesCached           + separator +
  -		  bytesFree             + separator +
  -		  hits                  + separator +
  -		  misses                + separator +
  -		"\n";
  -		return s;
  -	}
  -
  -	//
  -	// Set parameters according to a string (that was sent by applet)
  -	//
  -	public synchronized void parse(String config)
  -	{
  -		System.out.println("Parsing administrator request...");
  -		int size,i;
  -		StringTokenizer s = new StringTokenizer(config,separator);
  -
  -		  isFatherProxy       = s.nextToken().equals("true");
  -		System.out.println("Use father proxy = "+isFatherProxy);
  -		  fatherProxyHost     = s.nextToken();
  -		  if(fatherProxyHost.equals("NULL"))
  -			  fatherProxyHost = "";
  -		System.out.println("Father proxy name = "+fatherProxyHost);
  -
  -		  fatherProxyPort     = Integer.parseInt(s.nextToken());
  -		System.out.println("Father proxy port = "+fatherProxyPort);
  -
  -		  size = Integer.parseInt(s.nextToken());
  -		  deniedHosts = new String[size];
  -		  for (i=0; i<size; i++)
  -		{
  -				deniedHosts[i] = s.nextToken();
  -			System.out.println("Deny access to "+deniedHosts[i]);
  -		}
  -
  -		  password            = s.nextToken();
  -		System.out.println("password = "+password);
  -		isCaching           = s.nextToken().equals("true");
  -		System.out.println("Caching = "+isCaching);
  -		cacheSize           = Long.parseLong(s.nextToken());
  -		System.out.println("Cache size = "+cacheSize);
  -		  cleanCache          = s.nextToken().equals("true");
  -		System.out.println("Do cache clean up = "+cleanCache);
  -
  -		  size = Integer.parseInt(s.nextToken());
  -		  cacheMasks = new String[size];
  -		  for (i=0; i<size; i++)
  -		{
  -				cacheMasks[i] = s.nextToken();
  -			System.out.println("Don't cache "+cacheMasks[i]);
  -		}
  -
  -		  proxyMachineNameAndPort = s.nextToken();
  -
  -		if (isAppletContext)
  -		{
  -			filesCached         = Long.parseLong(s.nextToken());
  -			bytesCached         = Long.parseLong(s.nextToken());
  -			bytesFree           = Long.parseLong(s.nextToken());
  -			hits                = Long.parseLong(s.nextToken());
  -			misses              = Long.parseLong(s.nextToken());
  -		}
  -
  -		//
  -		// Update bytesFree to reflect the change in cache size.
  -		// Note that free bytes can be below min free level now.
  -		//
  -		bytesFree = cacheSize - bytesCached;
  -	}
  -}
  -
  +package org.apache.jmeter.protocol.http.proxy;
  +
  +import java.io.*;
  +
  +import java.net.*;
  +
  +/************************************************************
  + *  File Config.java
  + ***********************************************************/
  +
  +
  +import java.util.*;
  +
  +
  +
  +//
  +
  +// Class:     Config
  +
  +// Abstract:  Configurable parameters of the proxy. This class is
  +
  +//            used by both the applet and the proxy.
  +
  +//
  +
  +
  +/************************************************************
  + *  Description of the Class
  + *
  + *@author     default
  + *@created    June 29, 2001
  + ***********************************************************/
  +class Config
  +{
  +
  +	//
  +
  +	// Member variables
  +
  +	//
  +
  +	String jmxScriptDir;
  +
  +	private boolean isFatherProxy;
  +
  +	private String fatherProxyHost;
  +
  +	private int fatherProxyPort;
  +
  +	private String[] deniedHosts;
  +
  +	private String password;
  +
  +	private boolean isCaching;
  +	// enable/disable caching
  +
  +	private long cacheSize;
  +	// cache size in bytes
  +
  +	private boolean cleanCache;
  +
  +	private String[] cacheMasks;
  +
  +
  +	private long filesCached;
  +
  +	private long bytesCached;
  +
  +	private long bytesFree;
  +
  +	private long hits;
  +
  +	private long misses;
  +
  +
  +	private final int defaultProxyPort = 8080;
  +
  +	private final String defaultPassword = "admin";
  +
  +	private final long defaultCacheSize = 1000000;
  +
  +
  +	private String adminPath;
  +
  +	private int adminPort;
  +
  +
  +	private String localHost;
  +
  +	private String localIP;
  +
  +
  +	private boolean isAppletContext;
  +
  +	private String separator = " ";
  +
  +	private String proxyMachineNameAndPort;
  +
  +
  +
  +	//
  +
  +	// Member methods
  +
  +	//
  +
  +
  +	//
  +
  +	// Constructor
  +
  +	//
  +
  +	Config()
  +	{
  +
  +		filesCached = 0;
  +
  +		bytesCached = 0;
  +
  +		bytesFree = cacheSize;
  +
  +		hits = 0;
  +
  +		misses = 0;
  +
  +
  +		reset();
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the JmxScriptDir attribute of the Config object
  +	 *
  +	 *@param  filename  The new JmxScriptDir value
  +	 ***********************************************************/
  +	public void setJmxScriptDir(String filename)
  +	{
  +
  +		jmxScriptDir = filename;
  +
  +		File file = new File(System.getProperty("user.dir") + File.separator + jmxScriptDir);
  +
  +		file.mkdirs();
  +
  +	}
  +
  +
  +
  +	//
  +
  +	// Set/get methods
  +
  +	//
  +
  +
  +	// Set if we are in the applet or in the proxy
  +
  +	/************************************************************
  +	 *  Sets the IsAppletContext attribute of the Config object
  +	 *
  +	 *@param  b  The new IsAppletContext value
  +	 ***********************************************************/
  +	public void setIsAppletContext(boolean b)
  +	{
  +
  +		isAppletContext = b;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the ProxyMachineNameAndPort attribute of the Config object
  +	 *
  +	 *@param  s  The new ProxyMachineNameAndPort value
  +	 ***********************************************************/
  +	public void setProxyMachineNameAndPort(String s)
  +	{
  +
  +		proxyMachineNameAndPort = s;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the AdminPort attribute of the Config object
  +	 *
  +	 *@param  port  The new AdminPort value
  +	 ***********************************************************/
  +	public void setAdminPort(int port)
  +	{
  +
  +		adminPort = port;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the AdminPath attribute of the Config object
  +	 *
  +	 *@param  path  The new AdminPath value
  +	 ***********************************************************/
  +	public void setAdminPath(String path)
  +	{
  +
  +		adminPath = path;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the LocalHost attribute of the Config object
  +	 *
  +	 *@param  host  The new LocalHost value
  +	 ***********************************************************/
  +	public void setLocalHost(String host)
  +	{
  +
  +		localHost = host;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the LocalIP attribute of the Config object
  +	 *
  +	 *@param  ip  The new LocalIP value
  +	 ***********************************************************/
  +	public void setLocalIP(String ip)
  +	{
  +
  +		localIP = ip;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the IsCaching attribute of the Config object
  +	 *
  +	 *@param  caching  The new IsCaching value
  +	 ***********************************************************/
  +	public synchronized void setIsCaching(boolean caching)
  +	{
  +
  +		isCaching = caching;
  +
  +	}
  +
  +	/************************************************************
  +	 *  Sets the CacheSize attribute of the Config object
  +	 *
  +	 *@param  size  The new CacheSize value
  +	 ***********************************************************/
  +	public synchronized void setCacheSize(long size)
  +	{
  +
  +		cacheSize = size;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the IsFatherProxy attribute of the Config object
  +	 *
  +	 *@param  fatherProxy  The new IsFatherProxy value
  +	 ***********************************************************/
  +	public synchronized void setIsFatherProxy(boolean fatherProxy)
  +	{
  +
  +		isFatherProxy = fatherProxy;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the FatherProxyHost attribute of the Config object
  +	 *
  +	 *@param  host  The new FatherProxyHost value
  +	 ***********************************************************/
  +	public synchronized void setFatherProxyHost(String host)
  +	{
  +
  +		fatherProxyHost = host;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the FatherProxyPort attribute of the Config object
  +	 *
  +	 *@param  port  The new FatherProxyPort value
  +	 ***********************************************************/
  +	public synchronized void setFatherProxyPort(int port)
  +	{
  +
  +		fatherProxyPort = port;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the DeniedHosts attribute of the Config object
  +	 *
  +	 *@param  hosts  The new DeniedHosts value
  +	 ***********************************************************/
  +	public synchronized void setDeniedHosts(String[] hosts)
  +	{
  +
  +		deniedHosts = hosts;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the Password attribute of the Config object
  +	 *
  +	 *@param  newPassword  The new Password value
  +	 ***********************************************************/
  +	public synchronized void setPassword(String newPassword)
  +	{
  +
  +		password = newPassword;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the CleanCache attribute of the Config object
  +	 *
  +	 *@param  clean  The new CleanCache value
  +	 ***********************************************************/
  +	public synchronized void setCleanCache(boolean clean)
  +	{
  +
  +		cleanCache = clean;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the CacheMasks attribute of the Config object
  +	 *
  +	 *@param  masks  The new CacheMasks value
  +	 ***********************************************************/
  +	public synchronized void setCacheMasks(String[] masks)
  +	{
  +
  +		cacheMasks = masks;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the FilesCached attribute of the Config object
  +	 *
  +	 *@param  number  The new FilesCached value
  +	 ***********************************************************/
  +	public synchronized void setFilesCached(long number)
  +	{
  +
  +		filesCached = number;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the BytesCached attribute of the Config object
  +	 *
  +	 *@param  number  The new BytesCached value
  +	 ***********************************************************/
  +	public synchronized void setBytesCached(long number)
  +	{
  +
  +		bytesCached = number;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the Hits attribute of the Config object
  +	 *
  +	 *@param  number  The new Hits value
  +	 ***********************************************************/
  +	public synchronized void setHits(long number)
  +	{
  +
  +		hits = number;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Sets the Misses attribute of the Config object
  +	 *
  +	 *@param  number  The new Misses value
  +	 ***********************************************************/
  +	public synchronized void setMisses(long number)
  +	{
  +
  +		misses = number;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the JmxScriptDir attribute of the Config object
  +	 *
  +	 *@return    The JmxScriptDir value
  +	 ***********************************************************/
  +	public String getJmxScriptDir()
  +	{
  +
  +		return jmxScriptDir;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the ProxyMachineNameAndPort attribute of the Config object
  +	 *
  +	 *@return    The ProxyMachineNameAndPort value
  +	 ***********************************************************/
  +	public String getProxyMachineNameAndPort()
  +	{
  +
  +		return proxyMachineNameAndPort;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the AdminPort attribute of the Config object
  +	 *
  +	 *@return    The AdminPort value
  +	 ***********************************************************/
  +	public int getAdminPort()
  +	{
  +
  +		return adminPort;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the AdminPath attribute of the Config object
  +	 *
  +	 *@return    The AdminPath value
  +	 ***********************************************************/
  +	public String getAdminPath()
  +	{
  +
  +		return adminPath;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the LocalHost attribute of the Config object
  +	 *
  +	 *@return    The LocalHost value
  +	 ***********************************************************/
  +	public String getLocalHost()
  +	{
  +
  +		return localHost;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the LocalIP attribute of the Config object
  +	 *
  +	 *@return    The LocalIP value
  +	 ***********************************************************/
  +	public String getLocalIP()
  +	{
  +
  +		return localIP;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the CacheSize attribute of the Config object
  +	 *
  +	 *@return    The CacheSize value
  +	 ***********************************************************/
  +	public synchronized long getCacheSize()
  +	{
  +
  +		return cacheSize;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the IsFatherProxy attribute of the Config object
  +	 *
  +	 *@return    The IsFatherProxy value
  +	 ***********************************************************/
  +	public boolean getIsFatherProxy()
  +	{
  +
  +		return isFatherProxy;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the FatherProxyHost attribute of the Config object
  +	 *
  +	 *@return    The FatherProxyHost value
  +	 ***********************************************************/
  +	public String getFatherProxyHost()
  +	{
  +
  +		return fatherProxyHost;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the FatherProxyPort attribute of the Config object
  +	 *
  +	 *@return    The FatherProxyPort value
  +	 ***********************************************************/
  +	public int getFatherProxyPort()
  +	{
  +
  +		return fatherProxyPort;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the DeniedHosts attribute of the Config object
  +	 *
  +	 *@return    The DeniedHosts value
  +	 ***********************************************************/
  +	public String[] getDeniedHosts()
  +	{
  +
  +		return deniedHosts;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the Password attribute of the Config object
  +	 *
  +	 *@return    The Password value
  +	 ***********************************************************/
  +	public String getPassword()
  +	{
  +
  +		return password;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the CleanCache attribute of the Config object
  +	 *
  +	 *@return    The CleanCache value
  +	 ***********************************************************/
  +	public boolean getCleanCache()
  +	{
  +
  +		return cleanCache;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the CacheMasks attribute of the Config object
  +	 *
  +	 *@return    The CacheMasks value
  +	 ***********************************************************/
  +	public String[] getCacheMasks()
  +	{
  +
  +		return cacheMasks;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the FilesCached attribute of the Config object
  +	 *
  +	 *@return    The FilesCached value
  +	 ***********************************************************/
  +	public long getFilesCached()
  +	{
  +
  +		return filesCached;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the BytesCached attribute of the Config object
  +	 *
  +	 *@return    The BytesCached value
  +	 ***********************************************************/
  +	public long getBytesCached()
  +	{
  +
  +		return bytesCached;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the BytesFree attribute of the Config object
  +	 *
  +	 *@return    The BytesFree value
  +	 ***********************************************************/
  +	public long getBytesFree()
  +	{
  +
  +		return cacheSize - bytesCached;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the Hits attribute of the Config object
  +	 *
  +	 *@return    The Hits value
  +	 ***********************************************************/
  +	public long getHits()
  +	{
  +
  +		return hits;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the Misses attribute of the Config object
  +	 *
  +	 *@return    The Misses value
  +	 ***********************************************************/
  +	public long getMisses()
  +	{
  +
  +		return misses;
  +	}
  +
  +
  +	/************************************************************
  +	 *  Gets the HitRatio attribute of the Config object
  +	 *
  +	 *@return    The HitRatio value
  +	 ***********************************************************/
  +	public double getHitRatio()
  +	{
  +
  +		if((hits + misses) == 0)
  +		{
  +
  +			return 0;
  +		}
  +
  +		else
  +		{
  +
  +			return 100 * hits / (hits + misses);
  +		}
  +
  +	}
  +
  +
  +	//
  +
  +	// Re-initialize
  +
  +	//
  +
  +	/************************************************************
  +	 *  Description of the Method
  +	 ***********************************************************/
  +	public void reset()
  +	{
  +
  +		isFatherProxy = false;
  +
  +		fatherProxyHost = "wwwproxy.ac.il";
  +
  +		fatherProxyPort = defaultProxyPort;
  +
  +		password = defaultPassword;
  +
  +		isCaching = true;
  +
  +		cacheSize = defaultCacheSize;
  +
  +		cleanCache = false;
  +
  +
  +		deniedHosts = new String[0];
  +
  +		cacheMasks = new String[0];
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Description of the Method
  +	 ***********************************************************/
  +	public synchronized void increaseFilesCached()
  +	{
  +
  +		filesCached++;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Description of the Method
  +	 ***********************************************************/
  +	public synchronized void decreaseFilesCached()
  +	{
  +
  +		filesCached--;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Description of the Method
  +	 ***********************************************************/
  +	public synchronized void increaseHits()
  +	{
  +
  +		hits++;
  +
  +	}
  +
  +
  +	/************************************************************
  +	 *  Description of the Method
  +	 ***********************************************************/
  +	public synchronized void increaseMisses()
  +	{
  +
  +		misses++;
  +
  +	}
  +
  +
  +
  +	//
  +
  +	// Construct a string with all parameters
  +
  +	//
  +
  +	/************************************************************
  +	 *  Description of the Method
  +	 *
  +	 *@return    Description of the Returned Value
  +	 ***********************************************************/
  +	public synchronized String toString()
  +	{
  +
  +		int i;
  +
  +		String s = "";
  +
  +		s += isFatherProxy + separator;
  +
  +		s += fatherProxyHost.equals("") ? "NULL" : fatherProxyHost;
  +
  +		s += separator +
  +				fatherProxyPort + separator;
  +
  +
  +		s += deniedHosts.length + separator;
  +
  +		for(i = 0; i < deniedHosts.length; i++)
  +		{
  +
  +			s += deniedHosts[i] + separator;
  +		}
  +
  +
  +		s +=
  +				password + separator +
  +				isCaching + separator +
  +				cacheSize + separator +
  +				cleanCache + separator;
  +
  +
  +		s += cacheMasks.length + separator;
  +
  +		for(i = 0; i < cacheMasks.length; i++)
  +		{
  +
  +			s += cacheMasks[i] + separator;
  +		}
  +
  +
  +		s += proxyMachineNameAndPort + separator;
  +
  +
  +		s +=
  +				filesCached + separator +
  +				bytesCached + separator +
  +				bytesFree + separator +
  +				hits + separator +
  +				misses + separator +
  +				"\n";
  +
  +		return s;
  +	}
  +
  +
  +	//
  +
  +	// Set parameters according to a string (that was sent by applet)
  +
  +	//
  +
  +	/************************************************************
  +	 *  Description of the Method
  +	 *
  +	 *@param  config  Description of Parameter
  +	 ***********************************************************/
  +	public synchronized void parse(String config)
  +	{
  +
  +		System.out.println("Parsing administrator request...");
  +
  +		int size;
  +
  +		int i;
  +
  +		StringTokenizer s = new StringTokenizer(config, separator);
  +
  +
  +		isFatherProxy = s.nextToken().equals("true");
  +
  +		System.out.println("Use father proxy = " + isFatherProxy);
  +
  +		fatherProxyHost = s.nextToken();
  +
  +		if(fatherProxyHost.equals("NULL"))
  +		{
  +
  +			fatherProxyHost = "";
  +		}
  +
  +		System.out.println("Father proxy name = " + fatherProxyHost);
  +
  +
  +		fatherProxyPort = Integer.parseInt(s.nextToken());
  +
  +		System.out.println("Father proxy port = " + fatherProxyPort);
  +
  +
  +		size = Integer.parseInt(s.nextToken());
  +
  +		deniedHosts = new String[size];
  +
  +		for(i = 0; i < size; i++)
  +		{
  +
  +			deniedHosts[i] = s.nextToken();
  +
  +			System.out.println("Deny access to " + deniedHosts[i]);
  +
  +		}
  +
  +
  +		password = s.nextToken();
  +
  +		System.out.println("password = " + password);
  +
  +		isCaching = s.nextToken().equals("true");
  +
  +		System.out.println("Caching = " + isCaching);
  +
  +		cacheSize = Long.parseLong(s.nextToken());
  +
  +		System.out.println("Cache size = " + cacheSize);
  +
  +		cleanCache = s.nextToken().equals("true");
  +
  +		System.out.println("Do cache clean up = " + cleanCache);
  +
  +
  +		size = Integer.parseInt(s.nextToken());
  +
  +		cacheMasks = new String[size];
  +
  +		for(i = 0; i < size; i++)
  +		{
  +
  +			cacheMasks[i] = s.nextToken();
  +
  +			System.out.println("Don't cache " + cacheMasks[i]);
  +
  +		}
  +
  +
  +		proxyMachineNameAndPort = s.nextToken();
  +
  +
  +		if(isAppletContext)
  +		{
  +
  +			filesCached = Long.parseLong(s.nextToken());
  +
  +			bytesCached = Long.parseLong(s.nextToken());
  +
  +			bytesFree = Long.parseLong(s.nextToken());
  +
  +			hits = Long.parseLong(s.nextToken());
  +
  +			misses = Long.parseLong(s.nextToken());
  +
  +		}
  +
  +
  +		//
  +
  +		// Update bytesFree to reflect the change in cache size.
  +
  +		// Note that free bytes can be below min free level now.
  +
  +		//
  +
  +		bytesFree = cacheSize - bytesCached;
  +
  +	}
  +
  +
  +	boolean getIsCaching()
  +	{
  +
  +		return isCaching;
  +	}
  +
  +}
  +
  +
  
  
  
  1.2       +156 -140  jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/Daemon.java
  
  Index: Daemon.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/proxy/Daemon.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Daemon.java	2001/06/14 00:28:20	1.1
  +++ Daemon.java	2001/07/23 22:26:15	1.2
  @@ -1,140 +1,156 @@
  -package org.apache.jmeter.protocol.http.proxy;
  -/******************************************************************
  -*** File Daemon.java
  -***
  -***/
  -
  -import java.net.*;
  -import java.io.*;
  -
  -
  -//
  -// Class:     Daemon
  -// Abstract:  Web daemon thread. creates main socket on port 8080
  -//            and listens on it forever. For each client request,
  -//            creates proxy thread to handle the request.
  -//
  -public class Daemon extends Thread
  -{
  -	//
  -	// Member variables
  -	//
  -	static ServerSocket MainSocket = null;
  -	 static Cache cache = null;
  -	static Config config;
  -	static String adminPath;
  -
  -	final static int defaultDaemonPort = 8080;
  -	final static int maxDaemonPort = 65536;
  -
  -
  -	//
  -	// Member methods
  -	//
  -
  -	// Application starts here
  -	public static void main(String args[])
  -	{
  -		int daemonPort;
  -
  -		// Parse command line
  -		switch (args.length)
  -		{
  -			case 0: daemonPort = defaultDaemonPort;
  -					break;
  -
  -			case 1: try
  -					{
  -						daemonPort = Integer.parseInt(args[0]);
  -					}
  -					catch (NumberFormatException e)
  -					{
  -						System.out.println("Error: Invalid daemon port");
  -						return;
  -					}
  -					if (daemonPort > maxDaemonPort)
  -					{
  -						System.out.println("Error: Invalid daemon port");
  -						return;
  -					}
  -					break;
  -
  -			default:System.out.println("Usage: Proxy [daemon port]");
  -					return;
  -		}
  -
  -
  -
  -		try
  -		{
  -			// Create the Cache Manager and Configuration objects
  -			System.out.println("Initializing...");
  -			System.out.print("Creating Config Object...");
  -			config = new Config();
  -			config.setIsAppletContext(false);
  -			config.setLocalHost(InetAddress.getLocalHost().getHostName());
  -			String tmp = InetAddress.getLocalHost().toString();
  -			config.setLocalIP(tmp.substring(tmp.indexOf('/')+1));
  -			config.setProxyMachineNameAndPort(InetAddress.getLocalHost().getHostName()+":"+daemonPort);
  -			config.setJmxScriptDir("proxy_script");
  -			File adminDir = new File("Applet");
  -			config.setAdminPath(adminDir.getAbsolutePath());
  -			System.out.println("OK");
  -
  -			System.out.print("Creating Cache Manager...");
  -			cache = new Cache(config);
  -			System.out.println("OK");
  -
  -			// Start the admin thread
  -			System.out.print("Creating Admin Thread...");
  -			Admin adminThd = new Admin(config,cache);
  -			adminThd.start();
  -			System.out.println(" port " + config.getAdminPort() + " OK");
  -
  -			// Create main socket
  -				System.out.print("Creating Daemon Socket...");
  -			MainSocket = new ServerSocket(daemonPort);
  -			System.out.println(" port " + daemonPort + " OK");
  -
  -			if (config.getIsFatherProxy())
  -			{
  -				System.out.println("Using Father Proxy "+
  -					config.getFatherProxyHost()+
  -					":"+config.getFatherProxyPort()+" .");
  -			}
  -			else
  -			{
  -				System.out.println("Not Using Father Proxy .");
  -			}
  -			System.out.println("Proxy up and running!");
  -
  -			// Main loop
  -			while (true)
  -			{
  -				// Listen on main socket
  -				Socket ClientSocket = MainSocket.accept();
  -
  -				// Pass request to new proxy thread
  -				Proxy thd = new Proxy(ClientSocket,cache,config);
  -				thd.start();
  -			}
  -
  -		}
  -
  -		catch (Exception e)
  -		{}
  -
  -		finally
  -		{
  -			try
  -			{
  -				MainSocket.close();
  -			}
  -			catch (Exception exc)
  -			{
  -			}
  -		}
  -	}
  -}
  -
  -
  +package org.apache.jmeter.protocol.http.proxy;
  +
  +import java.io.*;
  +
  +/************************************************************
  + *  File Daemon.java
  + ***********************************************************/
  +import java.net.*;
  +//
  +// Class:     Daemon
  +// Abstract:  Web daemon thread. creates main socket on port 8080
  +//            and listens on it forever. For each client request,
  +//            creates proxy thread to handle the request.
  +//
  +/************************************************************
  + *  Description of the Class
  + *
  + *@author     default
  + *@created    June 29, 2001
  + ***********************************************************/
  +public class Daemon extends Thread
  +{
  +	//
  +	// Member variables
  +	//
  +	static ServerSocket MainSocket = null;
  +	static Cache cache = null;
  +	static Config config;
  +	static String adminPath;
  +	final static int defaultDaemonPort = 8080;
  +	final static int maxDaemonPort = 65536;
  +	private int daemonPort;
  +
  +	public Daemon()
  +	{
  +	}
  +
  +	public Daemon(int port) throws UnknownHostException
  +	{
  +		configureProxy(port);
  +	}
  +
  +	/************************************************************
  +	 *  Description of the Method
  +	 *
  +	 *@param  daemonPort  Description of Parameter
  +	 ***********************************************************/
  +	public void configureProxy(int daemonPort) throws UnknownHostException
  +	{
  +		this.daemonPort = daemonPort;
  +		// Create the Cache Manager and Configuration objects
  +		System.out.println("Initializing...");
  +		System.out.print("Creating Config Object...");
  +		config = new Config();
  +		config.setIsAppletContext(false);
  +		config.setLocalHost(InetAddress.getLocalHost().getHostName());
  +		String tmp = InetAddress.getLocalHost().toString();
  +		config.setLocalIP(tmp.substring(tmp.indexOf('/') + 1));
  +		config.setProxyMachineNameAndPort(InetAddress.getLocalHost().getHostName() + ":" + daemonPort);
  +		config.setJmxScriptDir("proxy_script");
  +		File adminDir = new File("Applet");
  +		config.setAdminPath(adminDir.getAbsolutePath());
  +		System.out.println("OK");
  +		System.out.print("Creating Cache Manager...");
  +		cache = new Cache(config);
  +		System.out.println("OK");
  +	}
  +
  +	//
  +	// Member methods
  +	//
  +
  +	// Application starts here
  +	/************************************************************
  +	 *  Description of the Method
  +	 *
  +	 *@param  args  Description of Parameter
  +	 ***********************************************************/
  +	public static void main(String args[])
  +	{
  +		int daemonPort;
  +		// Parse command line
  +		switch (args.length)
  +		{
  +			case 0:
  +				daemonPort = defaultDaemonPort;
  +				break;
  +			case 1:
  +				try
  +				{
  +					daemonPort = Integer.parseInt(args[0]);
  +				}
  +				catch(NumberFormatException e)
  +				{
  +					System.out.println("Error: Invalid daemon port");
  +					return;
  +				}
  +				if(daemonPort > maxDaemonPort)
  +				{
  +					System.out.println("Error: Invalid daemon port");
  +					return;
  +				}
  +				break;
  +			default:
  +				System.out.println("Usage: Proxy [daemon port]");
  +				return;
  +		}
  +		Daemon demon = new Daemon();
  +		try
  +		{
  +			demon.configureProxy(daemonPort);
  +		}
  +		catch(UnknownHostException e)
  +		{
  +			System.out.println("Unknown host");
  +			System.exit(-1);
  +		}
  +		demon.start();
  +	}
  +
  +	/************************************************************
  +	 *  Main processing method for the Daemon object
  +	 ***********************************************************/
  +	public void run()
  +	{
  +		try
  +		{
  +			System.out.print("Creating Daemon Socket...");
  +			MainSocket = new ServerSocket(daemonPort);
  +			System.out.println(" port " + daemonPort + " OK");
  +			System.out.println("Proxy up and running!");
  +			while(true)
  +			{
  +				// Listen on main socket
  +				Socket ClientSocket = MainSocket.accept();
  +				// Pass request to new proxy thread
  +				Proxy thd = new Proxy(ClientSocket, cache, config);
  +				thd.start();
  +			}
  +		}
  +		catch(Exception e)
  +		{
  +		}
  +		finally
  +		{
  +			try
  +			{
  +				MainSocket.close();
  +			}
  +			catch(Exception exc)
  +			{
  +			}
  +		}
  +	}
  +}
  +
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org