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 se...@apache.org on 2007/03/19 00:26:44 UTC

svn commit: r519733 - in /jakarta/jmeter/branches/rel-2-2: bin/ src/core/org/apache/jmeter/resources/ src/core/org/apache/jmeter/util/ src/protocol/http/org/apache/jmeter/protocol/http/proxy/ src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/...

Author: sebb
Date: Sun Mar 18 16:26:42 2007
New Revision: 519733

URL: http://svn.apache.org/viewvc?view=rev&rev=519733
Log:
Bug 41880 - Add content-type filtering to HTTP Proxy Server

Removed:
    jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/util/HttpClientSSLProtocolSocketFactory.java
Modified:
    jakarta/jmeter/branches/rel-2-2/bin/jmeter.properties
    jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages.properties
    jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_de.properties
    jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_es.properties
    jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_fr.properties
    jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_ja.properties
    jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_no.properties
    jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_zh_TW.properties
    jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java
    jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java
    jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java
    jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml

Modified: jakarta/jmeter/branches/rel-2-2/bin/jmeter.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/bin/jmeter.properties?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/bin/jmeter.properties (original)
+++ jakarta/jmeter/branches/rel-2-2/bin/jmeter.properties Sun Mar 18 16:26:42 2007
@@ -302,6 +302,11 @@
 # Apache HTTPClient:
 #jmeter.httpsampler=HTTPSampler2
 
+# Default content-type include filter to use
+#proxy.content_type_include=text/html|text/plain|text/xml
+# Default content-type exclude filter to use
+#proxy.content_type_exclude=image/.*|text/css|application/.*
+
 #---------------------------------------------------------------------------
 # JMeter Proxy configuration
 #---------------------------------------------------------------------------

Modified: jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages.properties?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages.properties Sun Mar 18 16:26:42 2007
@@ -272,6 +272,7 @@
 invalid_mail=Error occurred sending the e-mail
 invalid_mail_address=One or more invalid e-mail addresses detected
 invalid_mail_server=Problem contacting the e-mail server (see JMeter log file)
+invalid_variables=Invalid variables
 iteration_counter_arg_1=TRUE, for each user to have own counter, FALSE for a global counter
 iterator_num=Loop Count\:
 jar_file=Jar Files
@@ -481,8 +482,8 @@
 path_extension_choice=Path Extension (use ";" as separator)
 path_extension_dont_use_equals=Do not use equals in path extension (Intershop Enfinity compatibility)
 path_extension_dont_use_questionmark=Do not use questionmark in path extension (Intershop Enfinity compatibility)
-patterns_to_exclude=Patterns to Exclude
-patterns_to_include=Patterns to Include
+patterns_to_exclude=URL Patterns to Exclude
+patterns_to_include=URL Patterns to Include
 pkcs12_desc=PKCS 12 Key (*.p12)
 port=Port\:
 property_as_field_label={0}\:
@@ -503,13 +504,18 @@
 provider_url=Provider URL
 proxy_assertions=Add Assertions
 proxy_cl_error=If specifying a proxy server, host and port must be given
+proxy_content_type_exclude=Exclude\:
+proxy_content_type_filter=Content-type filter
+proxy_content_type_include=Include\:
 proxy_headers=Capture HTTP Headers
 proxy_httpsspoofing=Attempt https Spoofing
 proxy_regex=Regex matching
+proxy_sampler_settings=HTTP Sampler settings
+proxy_sampler_type=Type\:
 proxy_separators=Add Separators
 proxy_target=Target Controller\:
+proxy_test_plan_content=Test plan content
 proxy_title=HTTP Proxy Server
-proxy_usekeepalive=Set Keep-Alive
 ramp_up=Ramp-Up Period (in seconds)\:
 random_control_title=Random Controller
 random_order_control_title=Random Order Controller

Modified: jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_de.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_de.properties?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_de.properties (original)
+++ jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_de.properties Sun Mar 18 16:26:42 2007
@@ -115,8 +115,8 @@
 paste=Einf\u00FCgen
 paste_insert=Als Eintrag einf\u00FCgen
 path_extension_choice=Path Erweiterung (benutze ";" als Trennzeichen)
-patterns_to_exclude=Muster zum ausschliessen
-patterns_to_include=Muster zum einschliessen
+patterns_to_exclude=URL Muster zum ausschliessen
+patterns_to_include=URL Muster zum einschliessen
 protocol=Protokol\:
 proxy_cl_error=Wenn Sie einen Proxy Server spezifizieren, m\u00FCssen Sie den Host und Port angeben
 random_control_title=Zufalls Kontroller

Modified: jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_es.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_es.properties?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_es.properties (original)
+++ jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_es.properties Sun Mar 18 16:26:42 2007
@@ -394,8 +394,8 @@
 path_extension_choice=Extensi\u00F3n de Path (utilice ";" como separador)
 path_extension_dont_use_equals=No utilice el signo igual en la extensi\u00F3n del path (compatibilidad con Intershop Enfinity)
 path_extension_dont_use_questionmark=No utilice el signo interrogaci\u00F3n en la extensi\u00F3n del path (compatibilidad con Intershop Enfinity)
-patterns_to_exclude=Patrones a Excluir
-patterns_to_include=Patrones a Incluir
+patterns_to_exclude=URL Patrones a Excluir
+patterns_to_include=URL Patrones a Incluir
 pkcs12_desc=Clave PKCS (*.p12)
 port=Puerto\:
 property_default_param=Valor por defecto
@@ -417,7 +417,6 @@
 proxy_separators=A\u00F1adir Separadores
 proxy_target=Controlador Objetivo\:
 proxy_title=Servidor Proxy HTTP
-proxy_usekeepalive=Establecer Keep-Alive
 ramp_up=Periodo de Subida (en segundos)\:
 random_control_title=Controlador Random
 random_order_control_title=Controlador Random Order

Modified: jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_fr.properties?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_fr.properties Sun Mar 18 16:26:42 2007
@@ -299,8 +299,8 @@
 path=Chemin\:
 path_extension_choice=Extension Chamin (utiliser ";" comme separateur)
 path_extension_dont_use_equals=Ne pas utiliser \u00E9gale dans l'extension de chemin (Intershop Enfinity compatibility)
-patterns_to_exclude=Motifs \u00E0 Exclure
-patterns_to_include=Motifs \u00E0 Inclure
+patterns_to_exclude=URL Motifs \u00E0 Exclure
+patterns_to_include=URL Motifs \u00E0 Inclure
 property_default_param=Valeur par d\u00E9faut
 property_edit=Editer
 property_editor.value_is_invalid_message=Le texte que vous venez d'entrer n'a pas une valeur valide pour cette propri\u00E9t\u00E9.\nLa propri\u00E9t\u00E9 va revenir \u00E0 sa valeur pr\u00E9c\u00E9dente.

Modified: jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_ja.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_ja.properties?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_ja.properties (original)
+++ jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_ja.properties Sun Mar 18 16:26:42 2007
@@ -302,7 +302,6 @@
 proxy_separators=\u30BB\u30D1\u30EC\u30FC\u30BF\u306E\u8FFD\u52A0
 proxy_target=\u5BFE\u8C61\u3068\u306A\u308B\u30B3\u30F3\u30C8\u30ED\u30FC\u30E9\:
 proxy_title=HTTP \u30D7\u30ED\u30AD\u30B7\u30B5\u30FC\u30D0
-proxy_usekeepalive=Keep-Alive\u3092\u8A2D\u5B9A
 ramp_up=Ramp-Up \u671F\u9593 (\u79D2)\:
 random_control_title=\u4E71\u6570\u30B3\u30F3\u30C8\u30ED\u30FC\u30E9
 random_order_control_title=\u30E9\u30F3\u30C0\u30E0\u9806\u5E8F\u30B3\u30F3\u30C8\u30ED\u30FC\u30E9

Modified: jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_no.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_no.properties?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_no.properties (original)
+++ jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_no.properties Sun Mar 18 16:26:42 2007
@@ -87,8 +87,8 @@
 paramtable=Send parametre med foresp\u00F8rselen\:
 password=Passord
 path=Sti\:
-patterns_to_exclude=M\u00F8nster \u00E5 ekskludere
-patterns_to_include=M\u00F8nster \u00E5 inkludere
+patterns_to_exclude=URL M\u00F8nster \u00E5 ekskludere
+patterns_to_include=URL M\u00F8nster \u00E5 inkludere
 protocol=Protokoll\:
 proxy_title=HTTP proxy server
 ramp_up=Oppstartsperiode (i sekunder)\:

Modified: jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_zh_TW.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_zh_TW.properties?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_zh_TW.properties (original)
+++ jakarta/jmeter/branches/rel-2-2/src/core/org/apache/jmeter/resources/messages_zh_TW.properties Sun Mar 18 16:26:42 2007
@@ -417,7 +417,6 @@
 proxy_separators=\u589E\u52A0\u5206\u9694
 proxy_target=\u76EE\u6A19\u63A7\u5236\u5668
 proxy_title=HTTP \u4EE3\u7406\u4F3A\u670D\u5668
-proxy_usekeepalive=\u4FDD\u6301\u9023\u7DDA
 ramp_up=\u555F\u52D5\u5EF6\u9072(\u79D2)
 random_control_title=\u96A8\u6A5F\u63A7\u5236\u5668
 random_order_control_title=\u96A8\u6A5F\u9806\u5E8F\u63A7\u5236\u5668

Modified: jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java (original)
+++ jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java Sun Mar 18 16:26:42 2007
@@ -54,6 +54,7 @@
 import org.apache.jmeter.testelement.property.IntegerProperty;
 import org.apache.jmeter.testelement.property.JMeterProperty;
 import org.apache.jmeter.testelement.property.PropertyIterator;
+import org.apache.jmeter.testelement.property.StringProperty;
 import org.apache.jmeter.threads.ThreadGroup;
 import org.apache.jmeter.timers.Timer;
 import org.apache.jmeter.util.JMeterUtils;
@@ -112,6 +113,10 @@
 
 	public static final String HTTPS_SPOOF = "ProxyControlGui.https_spoof";
 
+	public static final String CONTENT_TYPE_EXCLUDE = "ProxyControlGui.content_type_exclude"; // $NON-NLS-1$
+
+	public static final String CONTENT_TYPE_INCLUDE = "ProxyControlGui.content_type_include"; // $NON-NLS-1$
+	
 	public static final int GROUPING_NO_GROUPS = 0;
 
 	public static final int GROUPING_ADD_SEPARATORS = 1;
@@ -231,6 +236,14 @@
 		setProperty(new BooleanProperty(HTTPS_SPOOF, b));
 	}
 	
+	public void setContentTypeExclude(String contentTypeExclude) {
+		setProperty(new StringProperty(CONTENT_TYPE_EXCLUDE, contentTypeExclude));
+	}
+
+	public void setContentTypeInclude(String contentTypeInclude) {
+		setProperty(new StringProperty(CONTENT_TYPE_INCLUDE, contentTypeInclude));
+	}
+
 	public String getClassLabel() {
 		return JMeterUtils.getResString("proxy_title"); // $NON-NLS-1$
 	}
@@ -287,7 +300,14 @@
 		return getPropertyAsBoolean(HTTPS_SPOOF, false);
 	}
 	
-	
+	public String getContentTypeExclude() {
+		return getPropertyAsString(CONTENT_TYPE_EXCLUDE);
+	}
+
+	public String getContentTypeInclude() {
+		return getPropertyAsString(CONTENT_TYPE_INCLUDE);
+	}
+
 
 	public Class getGuiClass() {
 		return org.apache.jmeter.protocol.http.proxy.gui.ProxyControlGui.class;
@@ -347,7 +367,7 @@
 	 * server's response while recording. A future consideration.
 	 */
 	public void deliverSampler(HTTPSamplerBase sampler, TestElement[] subConfigs, SampleResult result) {
-		if (filterUrl(sampler)) {
+		if (filterContentType(result) && filterUrl(sampler)) {
 			JMeterTreeNode myTarget = findTargetControllerNode();
 			Collection defaultConfigurations = findApplicableElements(myTarget, ConfigTestElement.class, false);
 			Collection userDefinedVariables = findApplicableElements(myTarget, Arguments.class, true);
@@ -363,6 +383,11 @@
 
 			notifySampleListeners(new SampleEvent(result, sampler.getName()));
 		}
+		else {
+			if(log.isDebugEnabled()) {
+				log.debug("Sample excluded based on url or content-type: " + result.getUrlAsString() + " - " + result.getContentType());
+			}
+		}
 	}
 
 	public void stopProxy() {
@@ -400,6 +425,74 @@
 		}
 
 		return true;
+	}
+
+    // Package protected to allow test case access
+    /**
+     * Filter the response based on the content type.
+     * If no include nor exclude filter is specified, the result will be included
+     * 
+     * @param result the sample result to check
+     */
+    boolean filterContentType(SampleResult result) {
+    	String includeExp = getContentTypeInclude(); 
+    	String excludeExp = getContentTypeExclude();
+    	// If no expressions are specified, we let the sample pass
+    	if((includeExp == null || includeExp.length() == 0) &&
+    			(excludeExp == null || excludeExp.length() == 0)
+    			)
+    	{
+    		return true;
+    	}
+    	
+    	// Check that we have a content type
+    	String sampleContentType = result.getContentType();    	
+    	if(sampleContentType == null || sampleContentType.length() == 0) {
+        	if(log.isDebugEnabled()) {
+        		log.debug("No Content-type found for : " + result.getUrlAsString());
+        	}
+    		
+    		return true;
+    	}
+
+    	if(log.isDebugEnabled()) {
+    		log.debug("Content-type to filter : " + sampleContentType);
+    	}
+    	// Check if the include pattern is mathed
+    	if(includeExp != null && includeExp.length() > 0) {
+        	if(log.isDebugEnabled()) {
+        		log.debug("Include expression : " + includeExp);
+        	}    		
+    		
+    		Pattern pattern = null;
+    		try {
+    			pattern = JMeterUtils.getPatternCache().getPattern(includeExp, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK);
+    			if(!JMeterUtils.getMatcher().contains(sampleContentType, pattern)) {
+    				return false;
+    			}
+    		} catch (MalformedCachePatternException e) {
+    			log.warn("Skipped invalid content include pattern: " + includeExp, e);
+    		}
+    	}
+
+    	// Check if the exclude pattern is mathed
+    	if(excludeExp != null && excludeExp.length() > 0) {
+        	if(log.isDebugEnabled()) {
+        		log.debug("Exclude expression : " + excludeExp);
+        	}
+
+    		Pattern pattern = null;
+    		try {
+    			pattern = JMeterUtils.getPatternCache().getPattern(excludeExp, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK);
+    			if(JMeterUtils.getMatcher().contains(sampleContentType, pattern)) {
+    				return false;
+    			}
+    		} catch (MalformedCachePatternException e) {
+    			log.warn("Skipped invalid content exclude pattern: " + includeExp, e);
+    		}
+    	}
+
+    	return true;
 	}
 
 	/*

Modified: jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java (original)
+++ jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java Sun Mar 18 16:26:42 2007
@@ -57,6 +57,7 @@
 import org.apache.jmeter.gui.util.HorizontalPanel;
 import org.apache.jmeter.gui.util.MenuFactory;
 import org.apache.jmeter.gui.util.PowerTableModel;
+import org.apache.jmeter.gui.util.VerticalPanel;
 import org.apache.jmeter.protocol.http.proxy.ProxyControl;
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jmeter.testelement.TestPlan;
@@ -66,9 +67,6 @@
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
 
-/**
- * @version $Revision$ updated on $Date$
- */
 public class ProxyControlGui extends LogicControllerGui implements JMeterGUIComponent, ActionListener, ItemListener,
 		KeyListener, FocusListener, UnsharedComponent {
 	private static transient Logger log = LoggingManager.getLoggerForClass();
@@ -112,12 +110,12 @@
 	 * Set/clear the Redirect automatically box on the samplers (default is false)
 	 */
 	private JCheckBox samplerRedirectAutomatically;
+
 	/**
 	 * Set/clear the Follow-redirects box on the samplers (default is true)
 	 */
 	private JCheckBox samplerFollowRedirects;
 
-
 	/**
 	 * Set/clear the Download images box on the samplers (default is false)
 	 */
@@ -128,6 +126,16 @@
 	 * even if it is really https.
 	 */
 	private JCheckBox httpsSpoof;
+
+	/**
+	 * Regular expression to include results based on content type
+	 */
+	private JTextField contentTypeInclude;
+
+	/**
+	 * Regular expression to exclude results based on content type
+	 */
+	private JTextField contentTypeExclude;
 	
 	/**
 	 * List of available target controllers
@@ -146,27 +154,27 @@
 
 	private PowerTableModel includeModel;
 
-	private static final String CHANGE_TARGET = "change_target";
+	private static final String CHANGE_TARGET = "change_target"; // $NON-NLS-1$
 
 	private JButton stop, start, restart;
 
-	private static final String STOP = "stop";
+	private static final String STOP = "stop"; // $NON-NLS-1$
 
-	private static final String START = "start";
+	private static final String START = "start"; // $NON-NLS-1$
 
-	private static final String RESTART = "restart";
+	private static final String RESTART = "restart"; // $NON-NLS-1$
 
-	private static final String ADD_INCLUDE = "add_include";
+	private static final String ADD_INCLUDE = "add_include"; // $NON-NLS-1$
 
-	private static final String ADD_EXCLUDE = "add_exclude";
+	private static final String ADD_EXCLUDE = "add_exclude"; // $NON-NLS-1$
 
-	private static final String DELETE_INCLUDE = "delete_include";
+	private static final String DELETE_INCLUDE = "delete_include"; // $NON-NLS-1$
 
-	private static final String DELETE_EXCLUDE = "delete_exclude";
+	private static final String DELETE_EXCLUDE = "delete_exclude"; // $NON-NLS-1$
 
-	private static final String INCLUDE_COL = JMeterUtils.getResString("patterns_to_include");
+	private static final String INCLUDE_COL = JMeterUtils.getResString("patterns_to_include"); // $NON-NLS-1$
 
-	private static final String EXCLUDE_COL = JMeterUtils.getResString("patterns_to_exclude");
+	private static final String EXCLUDE_COL = JMeterUtils.getResString("patterns_to_exclude"); // $NON-NLS-1$
 
 	public ProxyControlGui() {
 		super();
@@ -207,7 +215,9 @@
 			model.setUseKeepAlive(useKeepAlive.isSelected());
 			model.setSamplerDownloadImages(samplerDownloadImages.isSelected());
 			model.setRegexMatch(regexMatch.isSelected());
-			model.setHttpsSpoof(httpsSpoof.isSelected());			
+			model.setHttpsSpoof(httpsSpoof.isSelected());
+			model.setContentTypeInclude(contentTypeInclude.getText());
+			model.setContentTypeExclude(contentTypeExclude.getText());
 			TreeNodeWrapper nw = (TreeNodeWrapper) targetNodes.getSelectedItem();
 			if (nw == null) {
 				model.setTarget(null);
@@ -237,7 +247,7 @@
 	}
 
 	public String getLabelResource() {
-		return "proxy_title";
+		return "proxy_title"; // $NON-NLS-1$
 	}
 
 	public Collection getMenuCategories() {
@@ -259,6 +269,8 @@
 		samplerDownloadImages.setSelected(model.getSamplerDownloadImages());
 		regexMatch.setSelected(model.getRegexMatch());
 		httpsSpoof.setSelected(model.getHttpsSpoof());
+		contentTypeInclude.setText(model.getContentTypeInclude());
+		contentTypeExclude.setText(model.getContentTypeExclude());
 
 		reinitializeTargetCombo();// Set up list of potential targets and
 									// enable listener
@@ -324,7 +336,9 @@
 				|| command.equals(ProxyControl.USE_KEEPALIVE)
 				|| command.equals(ProxyControl.SAMPLER_DOWNLOAD_IMAGES) 
 				|| command.equals(ProxyControl.REGEX_MATCH)
-				|| command.equals(ProxyControl.HTTPS_SPOOF)) {
+				|| command.equals(ProxyControl.HTTPS_SPOOF)
+				|| command.equals(ProxyControl.CONTENT_TYPE_INCLUDE)
+				|| command.equals(ProxyControl.CONTENT_TYPE_EXCLUDE)) {
 			enableRestart();
 		} else if (command.equals(ADD_EXCLUDE)) {
 			excludeModel.addNewRow();
@@ -361,7 +375,9 @@
 			stop.setEnabled(true);
 			restart.setEnabled(false);
 		} catch (InvalidVariableException e) {
-			JOptionPane.showMessageDialog(this, JMeterUtils.getResString("invalid_variables"), "Error",
+			JOptionPane.showMessageDialog(this, 
+					JMeterUtils.getResString("invalid_variables"), // $NON-NLS-1$
+					"Error",
 					JOptionPane.ERROR_MESSAGE);
 		}
 	}
@@ -415,7 +431,7 @@
 					// the user closes the error dialog, the text would change
 					// from "5t" to "1". A litle confusing. If anything, it
 					// should display just "5". Future enhancement...
-					portField.setText("");
+					portField.setText(""); // $NON-NLS-1$
 				}
 			}
 			enableRestart();
@@ -437,10 +453,8 @@
 		myBox.add(Box.createVerticalStrut(5));
 		myBox.add(createHTTPSamplerPanel());
 		myBox.add(Box.createVerticalStrut(5));
-		myBox.add(createTargetPanel());
-		myBox.add(Box.createVerticalStrut(5));
-		myBox.add(createGroupingPanel());
-		myBox.add(Box.createVerticalStrut(5));
+		myBox.add(createContentTypePanel());
+		myBox.add(Box.createVerticalStrut(5));				
 		mainPanel.add(myBox, BorderLayout.NORTH);
 
 		Box includeExcludePanel = Box.createVerticalBox();
@@ -454,17 +468,17 @@
 	}
 
 	private JPanel createControls() {
-		start = new JButton(JMeterUtils.getResString("start"));
+		start = new JButton(JMeterUtils.getResString("start")); // $NON-NLS-1$
 		start.addActionListener(this);
 		start.setActionCommand(START);
 		start.setEnabled(true);
 
-		stop = new JButton(JMeterUtils.getResString("stop"));
+		stop = new JButton(JMeterUtils.getResString("stop")); // $NON-NLS-1$
 		stop.addActionListener(this);
 		stop.setActionCommand(STOP);
 		stop.setEnabled(false);
 
-		restart = new JButton(JMeterUtils.getResString("restart"));
+		restart = new JButton(JMeterUtils.getResString("restart")); // $NON-NLS-1$
 		restart.addActionListener(this);
 		restart.setActionCommand(RESTART);
 		restart.setEnabled(false);
@@ -481,10 +495,10 @@
 		portField.setName(ProxyControl.PORT);
 		portField.addKeyListener(this);
 
-		JLabel label = new JLabel(JMeterUtils.getResString("port"));
+		JLabel label = new JLabel(JMeterUtils.getResString("port")); // $NON-NLS-1$
 		label.setLabelFor(portField);
 
-		httpsSpoof = new JCheckBox(JMeterUtils.getResString("proxy_httpsspoofing"));
+		httpsSpoof = new JCheckBox(JMeterUtils.getResString("proxy_httpsspoofing")); // $NON-NLS-1$
 		httpsSpoof.setName(ProxyControl.HTTPS_SPOOF);
 		httpsSpoof.setSelected(false);
 		httpsSpoof.addActionListener(this);
@@ -501,77 +515,80 @@
 	}
 
 	private JPanel createTestPlanContentPanel() {
-		JLabel label = new JLabel("Test plan content:");
-
-		httpHeaders = new JCheckBox(JMeterUtils.getResString("proxy_headers"));
+		httpHeaders = new JCheckBox(JMeterUtils.getResString("proxy_headers")); // $NON-NLS-1$
 		httpHeaders.setName(ProxyControl.CAPTURE_HTTP_HEADERS);
 		httpHeaders.setSelected(true); // maintain original default
 		httpHeaders.addActionListener(this);
 		httpHeaders.setActionCommand(ProxyControl.CAPTURE_HTTP_HEADERS);
 
-		addAssertions = new JCheckBox(JMeterUtils.getResString("proxy_assertions"));
+		addAssertions = new JCheckBox(JMeterUtils.getResString("proxy_assertions")); // $NON-NLS-1$
 		addAssertions.setName(ProxyControl.ADD_ASSERTIONS);
 		addAssertions.setSelected(false);
 		addAssertions.addActionListener(this);
 		addAssertions.setActionCommand(ProxyControl.ADD_ASSERTIONS);
 
-		regexMatch = new JCheckBox(JMeterUtils.getResString("proxy_regex"));
+		regexMatch = new JCheckBox(JMeterUtils.getResString("proxy_regex")); // $NON-NLS-1$
 		regexMatch.setName(ProxyControl.REGEX_MATCH);
 		regexMatch.setSelected(false);
 		regexMatch.addActionListener(this);
 		regexMatch.setActionCommand(ProxyControl.REGEX_MATCH);
 
-		HorizontalPanel panel = new HorizontalPanel();
-		panel.add(label);
-
-		panel.add(httpHeaders);
-		panel.add(addAssertions);
-		panel.add(regexMatch);
+		VerticalPanel mainPanel = new VerticalPanel();
+		mainPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
+				JMeterUtils.getResString("proxy_test_plan_content"))); // $NON-NLS-1$
+
+		HorizontalPanel nodeCreationPanel = new HorizontalPanel();
+		nodeCreationPanel.add(httpHeaders);
+		nodeCreationPanel.add(addAssertions);
+		nodeCreationPanel.add(regexMatch);
+		
+		mainPanel.add(createTargetPanel());
+		mainPanel.add(createGroupingPanel());
+		mainPanel.add(nodeCreationPanel);
 
-		return panel;
+		return mainPanel;
 	}
 
 	private JPanel createHTTPSamplerPanel() {
-		JLabel label = new JLabel("HTTP Sampler settings:");
-		
 		DefaultComboBoxModel m = new DefaultComboBoxModel();
 		// Note: position of these elements in the menu *must* match the
 		// corresponding ProxyControl.SAMPLER_TYPE_* values.
-		m.addElement(JMeterUtils.getResString("web_testing_title"));
-		m.addElement(JMeterUtils.getResString("web_testing2_title"));
+		m.addElement(JMeterUtils.getResString("web_testing_title")); // $NON-NLS-1$
+		m.addElement(JMeterUtils.getResString("web_testing2_title")); // $NON-NLS-1$
 		samplerTypeName = new JComboBox(m);
 		samplerTypeName.setName(ProxyControl.SAMPLER_TYPE_NAME);
 		samplerTypeName.setSelectedIndex(0);
 		samplerTypeName.addItemListener(this);
-		JLabel label2 = new JLabel("Type:");
+		JLabel label2 = new JLabel(JMeterUtils.getResString("proxy_sampler_type")); // $NON-NLS-1$
 		label2.setLabelFor(samplerTypeName);
 
-		samplerRedirectAutomatically = new JCheckBox("Redirect automatically");
+		samplerRedirectAutomatically = new JCheckBox(JMeterUtils.getResString("follow_redirects_auto")); // $NON-NLS-1$
 		samplerRedirectAutomatically.setName(ProxyControl.SAMPLER_REDIRECT_AUTOMATICALLY);
 		samplerRedirectAutomatically.setSelected(false);
 		samplerRedirectAutomatically.addActionListener(this);
 		samplerRedirectAutomatically.setActionCommand(ProxyControl.SAMPLER_REDIRECT_AUTOMATICALLY);
 		
-		samplerFollowRedirects = new JCheckBox("Follow redirects");
+		samplerFollowRedirects = new JCheckBox(JMeterUtils.getResString("follow_redirects")); // $NON-NLS-1$
 		samplerFollowRedirects.setName(ProxyControl.SAMPLER_FOLLOW_REDIRECTS);
 		samplerFollowRedirects.setSelected(true);
 		samplerFollowRedirects.addActionListener(this);
 		samplerFollowRedirects.setActionCommand(ProxyControl.SAMPLER_FOLLOW_REDIRECTS);
 		
-		useKeepAlive = new JCheckBox(JMeterUtils.getResString("proxy_usekeepalive"));
+		useKeepAlive = new JCheckBox(JMeterUtils.getResString("use_keepalive")); // $NON-NLS-1$
 		useKeepAlive.setName(ProxyControl.USE_KEEPALIVE);
 		useKeepAlive.setSelected(true);
 		useKeepAlive.addActionListener(this);
 		useKeepAlive.setActionCommand(ProxyControl.USE_KEEPALIVE);
 
-		samplerDownloadImages = new JCheckBox("Download images");
+		samplerDownloadImages = new JCheckBox(JMeterUtils.getResString("web_testing_retrieve_images")); // $NON-NLS-1$
 		samplerDownloadImages.setName(ProxyControl.SAMPLER_DOWNLOAD_IMAGES);
 		samplerDownloadImages.setSelected(false);
 		samplerDownloadImages.addActionListener(this);
 		samplerDownloadImages.setActionCommand(ProxyControl.SAMPLER_DOWNLOAD_IMAGES);
 		
 		HorizontalPanel panel = new HorizontalPanel();
-		panel.add(label);
+		panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
+				JMeterUtils.getResString("proxy_sampler_settings"))); // $NON-NLS-1$
 		panel.add(label2);
 		panel.add(samplerTypeName);
 		panel.add(samplerRedirectAutomatically);
@@ -588,7 +605,7 @@
 		targetNodes.setActionCommand(CHANGE_TARGET);
 		// Action listener will be added later
 
-		JLabel label = new JLabel(JMeterUtils.getResString("proxy_target"));
+		JLabel label = new JLabel(JMeterUtils.getResString("proxy_target")); // $NON-NLS-1$
 		label.setLabelFor(targetNodes);
 
 		HorizontalPanel panel = new HorizontalPanel();
@@ -628,16 +645,16 @@
 		DefaultComboBoxModel m = new DefaultComboBoxModel();
 		// Note: position of these elements in the menu *must* match the
 		// corresponding ProxyControl.GROUPING_* values.
-		m.addElement(JMeterUtils.getResString("grouping_no_groups"));
-		m.addElement(JMeterUtils.getResString("grouping_add_separators"));
-		m.addElement(JMeterUtils.getResString("grouping_in_controllers"));
-		m.addElement(JMeterUtils.getResString("grouping_store_first_only"));
+		m.addElement(JMeterUtils.getResString("grouping_no_groups")); // $NON-NLS-1$
+		m.addElement(JMeterUtils.getResString("grouping_add_separators")); // $NON-NLS-1$
+		m.addElement(JMeterUtils.getResString("grouping_in_controllers")); // $NON-NLS-1$
+		m.addElement(JMeterUtils.getResString("grouping_store_first_only")); // $NON-NLS-1$
 		groupingMode = new JComboBox(m);
 		groupingMode.setName(ProxyControl.GROUPING_MODE);
 		groupingMode.setSelectedIndex(0);
 		groupingMode.addItemListener(this);
 
-		JLabel label2 = new JLabel(JMeterUtils.getResString("grouping_mode"));
+		JLabel label2 = new JLabel(JMeterUtils.getResString("grouping_mode")); // $NON-NLS-1$
 		label2.setLabelFor(groupingMode);
 
 		HorizontalPanel panel = new HorizontalPanel();
@@ -646,6 +663,36 @@
 
 		return panel;
 	}
+	
+	private JPanel createContentTypePanel() {
+		contentTypeInclude = new JTextField(30);
+		contentTypeInclude.setName(ProxyControl.CONTENT_TYPE_INCLUDE);
+		contentTypeInclude.addActionListener(this);
+		contentTypeInclude.setActionCommand(ProxyControl.CONTENT_TYPE_INCLUDE);
+		JLabel labelInclude = new JLabel(JMeterUtils.getResString("proxy_content_type_include")); // $NON-NLS-1$
+		labelInclude.setLabelFor(contentTypeInclude);
+		// Default value
+		contentTypeInclude.setText(JMeterUtils.getProperty("proxy.content_type_include")); // $NON-NLS-1$
+
+		contentTypeExclude = new JTextField(30);
+		contentTypeExclude.setName(ProxyControl.CONTENT_TYPE_EXCLUDE);
+		contentTypeExclude.addActionListener(this);
+		contentTypeExclude.setActionCommand(ProxyControl.CONTENT_TYPE_EXCLUDE);
+		JLabel labelExclude = new JLabel(JMeterUtils.getResString("proxy_content_type_exclude")); // $NON-NLS-1$
+		labelExclude.setLabelFor(contentTypeExclude);
+		// Default value
+		contentTypeExclude.setText(JMeterUtils.getProperty("proxy.content_type_exclude")); // $NON-NLS-1$
+		
+		HorizontalPanel panel = new HorizontalPanel();
+		panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
+				JMeterUtils.getResString("proxy_content_type_filter"))); // $NON-NLS-1$
+		panel.add(labelInclude);
+		panel.add(contentTypeInclude);
+		panel.add(labelExclude);
+		panel.add(contentTypeExclude);
+		
+		return panel;
+	}
 
 	private JPanel createIncludePanel() {
 		includeModel = new PowerTableModel(new String[] { INCLUDE_COL }, new Class[] { String.class });
@@ -655,7 +702,7 @@
 
 		JPanel panel = new JPanel(new BorderLayout());
 		panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), JMeterUtils
-				.getResString("patterns_to_include")));
+				.getResString("patterns_to_include"))); // $NON-NLS-1$
 
 		panel.add(new JScrollPane(includeTable), BorderLayout.CENTER);
 		panel.add(createTableButtonPanel(ADD_INCLUDE, DELETE_INCLUDE), BorderLayout.SOUTH);
@@ -671,7 +718,7 @@
 
 		JPanel panel = new JPanel(new BorderLayout());
 		panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), JMeterUtils
-				.getResString("patterns_to_exclude")));
+				.getResString("patterns_to_exclude"))); // $NON-NLS-1$
 
 		panel.add(new JScrollPane(excludeTable), BorderLayout.CENTER);
 		panel.add(createTableButtonPanel(ADD_EXCLUDE, DELETE_EXCLUDE), BorderLayout.SOUTH);
@@ -682,12 +729,12 @@
 	private JPanel createTableButtonPanel(String addCommand, String deleteCommand) {
 		JPanel buttonPanel = new JPanel();
 
-		JButton addButton = new JButton(JMeterUtils.getResString("add"));
+		JButton addButton = new JButton(JMeterUtils.getResString("add")); // $NON-NLS-1$
 		addButton.setActionCommand(addCommand);
 		addButton.addActionListener(this);
 		buttonPanel.add(addButton);
 
-		JButton deleteButton = new JButton(JMeterUtils.getResString("delete"));
+		JButton deleteButton = new JButton(JMeterUtils.getResString("delete")); // $NON-NLS-1$
 		deleteButton.setActionCommand(deleteCommand);
 		deleteButton.addActionListener(this);
 		buttonPanel.add(deleteButton);
@@ -707,7 +754,7 @@
 		if (gp != null) {
 			root = (JMeterTreeNode) GuiPackage.getInstance().getTreeModel().getRoot();
 			targetNodesModel
-					.addElement(new TreeNodeWrapper(null, JMeterUtils.getResString("use_recording_controller")));
+					.addElement(new TreeNodeWrapper(null, JMeterUtils.getResString("use_recording_controller"))); // $NON-NLS-1$
 			buildNodesModel(root, "", 0);
 		}
 		TreeNodeWrapper choice = null;
@@ -768,7 +815,7 @@
 		int multi = 4;
 		StringBuffer spaces = new StringBuffer(level * multi);
 		for (int i = 0; i < level * multi; i++) {
-			spaces.append(" ");
+			spaces.append(" "); // $NON-NLS-1$
 		}
 		return spaces.toString();
 	}

Modified: jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java (original)
+++ jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java Sun Mar 18 16:26:42 2007
@@ -20,6 +20,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
 import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
 
@@ -55,5 +56,94 @@
 			sampler.setPath("header.gif");
 			sampler.setDomain("jakarta.org");
 			assertFalse("Should not match header.gif", control.filterUrl(sampler));
+		}
+
+		public void testContentTypeNoFilters() throws Exception {
+			SampleResult result = new SampleResult();
+			// No filters
+			control.setContentTypeInclude(null);
+			control.setContentTypeExclude(null);
+
+			result.setContentType(null);
+			assertTrue("Should allow if no content-type present", control.filterContentType(result));			
+			result.setContentType("text/html; charset=utf-8");
+			assertTrue("Should allow text/html", control.filterContentType(result));			
+			result.setContentType("image/png");
+			assertTrue("Should allow image/png", control.filterContentType(result));
+
+			// Empty filters
+			control.setContentTypeInclude("");
+			control.setContentTypeExclude("");
+			
+			result.setContentType(null);
+			assertTrue("Should allow if no content-type present", control.filterContentType(result));			
+			result.setContentType("text/html; charset=utf-8");
+			assertTrue("Should allow text/html", control.filterContentType(result));			
+			result.setContentType("image/png");
+			assertTrue("Should allow image/png", control.filterContentType(result));
+			
+			// Non empty filters
+			control.setContentTypeInclude(" ");
+			control.setContentTypeExclude(" ");
+			
+			result.setContentType(null);
+			assertTrue("Should allow if no content-type present", control.filterContentType(result));			
+			result.setContentType("text/html; charset=utf-8");
+			assertFalse("Should not allow text/html", control.filterContentType(result));			
+			result.setContentType("image/png");
+			assertFalse("Should not allow image/png", control.filterContentType(result));
+		}
+		
+		public void testContentTypeInclude() throws Exception {
+			SampleResult result = new SampleResult();
+			control.setContentTypeInclude("text/html|text/ascii");
+
+			result.setContentType(null);
+			assertTrue("Should allow if no content-type present", control.filterContentType(result));			
+			result.setContentType("text/html; charset=utf-8");
+			assertTrue("Should allow text/html", control.filterContentType(result));			
+			result.setContentType("text/css");
+			assertFalse("Should not allow text/css", control.filterContentType(result));
+		}
+		
+		public void testContentTypeExclude() throws Exception {
+			SampleResult result = new SampleResult();
+			control.setContentTypeExclude("text/css");
+
+			result.setContentType(null);
+			assertTrue("Should allow if no content-type present", control.filterContentType(result));			
+			result.setContentType("text/html; charset=utf-8");
+			assertTrue("Should allow text/html", control.filterContentType(result));			
+			result.setContentType("text/css");
+			assertFalse("Should not allow text/css", control.filterContentType(result));
+		}
+		
+		public void testContentTypeIncludeAndExclude() throws Exception {
+			SampleResult result = new SampleResult();
+			// Simple inclusion and exclusion filter
+			control.setContentTypeInclude("text/html|text/ascii");
+			control.setContentTypeExclude("text/css");
+
+			result.setContentType(null);
+			assertTrue("Should allow if no content-type present", control.filterContentType(result));			
+			result.setContentType("text/html; charset=utf-8");
+			assertTrue("Should allow text/html", control.filterContentType(result));			
+			result.setContentType("text/css");
+			assertFalse("Should not allow text/css", control.filterContentType(result));			
+			result.setContentType("image/png");
+			assertFalse("Should not allow image/png", control.filterContentType(result));
+			
+			// Allow all but images
+			control.setContentTypeInclude(null);
+			control.setContentTypeExclude("image/.*");
+			
+			result.setContentType(null);
+			assertTrue("Should allow if no content-type present", control.filterContentType(result));			
+			result.setContentType("text/html; charset=utf-8");
+			assertTrue("Should allow text/html", control.filterContentType(result));			
+			result.setContentType("text/css");
+			assertTrue("Should allow text/css", control.filterContentType(result));			
+			result.setContentType("image/png");
+			assertFalse("Should not allow image/png", control.filterContentType(result));
 		}
 }

Modified: jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml?view=diff&rev=519733&r1=519732&r2=519733
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml (original)
+++ jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml Sun Mar 18 16:26:42 2007
@@ -123,6 +123,7 @@
 <li>Bug 41873 - Add name to AssertionResult and display AssertionResult in ViewResultsFullVisualizer</li>
 <li>Bug 41876 - Add more options to control what the HTTP Proxy generates</li>
 <li>Bug 39693 - View Result Table use icon instead of check box</li>
+<li>Bug 41880 - Add content-type filtering to HTTP Proxy Server</li>
 </ul>
 
 <h4>Non-functional improvements:</h4>



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