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 2008/05/29 01:08:45 UTC

svn commit: r661141 - in /jakarta/jmeter/trunk: bin/jmeter.properties src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java xdocs/changes.xml xdocs/usermanual/component_reference.xml

Author: sebb
Date: Wed May 28 16:08:45 2008
New Revision: 661141

URL: http://svn.apache.org/viewvc?rev=661141&view=rev
Log:
Bugs 44808 & 39641 - Proxy support for binary requests

Modified:
    jakarta/jmeter/trunk/bin/jmeter.properties
    jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jakarta/jmeter/trunk/bin/jmeter.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/bin/jmeter.properties?rev=661141&r1=661140&r2=661141&view=diff
==============================================================================
--- jakarta/jmeter/trunk/bin/jmeter.properties (original)
+++ jakarta/jmeter/trunk/bin/jmeter.properties Wed May 28 16:08:45 2008
@@ -370,6 +370,14 @@
 # (Cookie and Authorization are always removed)
 #proxy.headers.remove=If-Modified-Since,If-None-Match
 
+# Binary content-type handling
+# These content-types will be handled by saving the request in a file:
+#proxy.binary.types=application/x-amf,application/x-java-serialized-object
+# The files will be saved in this directory:
+#proxy.binary.directory=user.dir
+# The files will be created with this file filesuffix:
+#proxy.binary.filesuffix=.binary
+
 #---------------------------------------------------------------------------
 # JMeter Proxy configuration
 #---------------------------------------------------------------------------

Modified: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java?rev=661141&r1=661140&r2=661141&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java (original)
+++ jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java Wed May 28 16:08:45 2008
@@ -19,6 +19,7 @@
 package org.apache.jmeter.protocol.http.proxy;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
@@ -26,10 +27,13 @@
 import java.net.ProtocolException;
 import java.net.URL;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.CharUtils;
 import org.apache.jmeter.protocol.http.config.MultipartUrlConfig;
 import org.apache.jmeter.protocol.http.control.Header;
@@ -42,6 +46,8 @@
 import org.apache.jmeter.protocol.http.sampler.HTTPSamplerFactory;
 import org.apache.jmeter.protocol.http.util.ConversionUtils;
 import org.apache.jmeter.protocol.http.util.HTTPConstants;
+import org.apache.jmeter.protocol.http.util.HTTPFileArg;
+import org.apache.jmeter.services.FileServer;
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.logging.LoggingManager;
@@ -62,6 +68,30 @@
     private static final String CONTENT_TYPE = "content-type"; // $NON-NLS-1$
     private static final String CONTENT_LENGTH = "content-length"; // $NON-NLS-1$
 
+    /** Filetype to be used for the temporary binary files*/
+    private static final String binaryFileSuffix = 
+        JMeterUtils.getPropDefault("proxy.binary.filesuffix",// $NON-NLS-1$ 
+                                   ".binary"); // $NON-NLS-1$
+    
+    /** Which content-types will be treated as binary (exact match) */
+    private static final Set binaryContentTypes = new HashSet();
+    
+    /** Where to store the temporary binary files */
+    private static final String binaryDirectory = 
+        JMeterUtils.getPropDefault("proxy.binary.directory",// $NON-NLS-1$ 
+                JMeterUtils.getProperty("user.dir")); // $NON-NLS-1$ proxy.binary.filetype=binary
+    
+    static {
+        String binaries = JMeterUtils.getPropDefault("proxy.binary.types", // $NON-NLS-1$
+                "application/x-amf,application/x-java-serialized-object"); // $NON-NLS-1$ 
+        if (binaries.length() > 0){
+            StringTokenizer s = new StringTokenizer(binaries,"|, ");// $NON-NLS-1$
+            while (s.hasMoreTokens()){
+               binaryContentTypes.add(s.nextToken());
+            }
+        }
+    }
+
 	/**
 	 * Http Request method. Such as get or post.
 	 */
@@ -434,8 +464,20 @@
                 // but maybe we should only parse arguments if the content type is as expected
                 sampler.parseArguments(postData.trim(), contentEncoding); //standard name=value postData
             } else if (postData.length() > 0) {
-                // Just put the whole postbody as the value of a parameter
-                sampler.addNonEncodedArgument("", postData, ""); //used when postData is pure xml (ex. an xml-rpc call)
+                if (isBinaryContent(contentType)) {
+                    try {
+                        File tempDir = new File(binaryDirectory);
+                        File out = File.createTempFile(method, binaryFileSuffix, tempDir);
+                        FileUtils.writeByteArrayToFile(out,rawPostData);
+                        HTTPFileArg [] files = {new HTTPFileArg(out.getPath(),"",contentType)};
+                        sampler.setHTTPFiles(files);
+                    } catch (IOException e) {
+                        log.warn("Could not create binary file: "+e);
+                    }
+                } else {
+                    // Just put the whole postbody as the value of a parameter
+                    sampler.addNonEncodedArgument("", postData, ""); //used when postData is pure xml (ex. an xml-rpc call)
+                }
             }
         }
         if (log.isDebugEnabled()) {
@@ -443,7 +485,12 @@
         }
 	}
 
-	//
+	private boolean isBinaryContent(String contentType) {
+        if (contentType == null) return false;
+        return binaryContentTypes.contains(contentType);
+    }
+
+    //
 	// Parsing Methods
 	//
 

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=661141&r1=661140&r2=661141&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Wed May 28 16:08:45 2008
@@ -30,6 +30,14 @@
 </note>
 <!--  ===================  -->
 
+<h2>Version 2.3.2A</h2>
+<h3>Improvements</h3>
+<ul>
+<li>Bugs 44808 & 39641 - Proxy support for binary requests</li>
+</ul>
+
+<!--  ===================  -->
+
 <h2>Version 2.3.2</h2>
 
 <h3>Summary of main changes</h3>

Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=661141&r1=661140&r2=661141&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Wed May 28 16:08:45 2008
@@ -3861,6 +3861,20 @@
 N.B. the string that is matched by the regular expression must be the same as the <b>whole</b> host+path string.<br></br>Thus <b>&quot;\.html&quot;</b> will <b>not</b> match <b>j.a.o/index.html</b>
 </p>
 
+<p>
+Versions of JMeter after 2.3.2 are able to capture binary POST data.
+To configure which content-types are treated as binary, update the JMeter property proxy.binary.types.
+The default settings are as follows:
+<pre>
+# These content-types will be handled by saving the request in a file:
+proxy.binary.types=application/x-amf,application/x-java-serialized-object
+# The files will be saved in this directory:
+proxy.binary.directory=user.dir
+# The files will be created with this file filesuffix:
+proxy.binary.filesuffix=.binary
+</pre>
+</p>
+
 <p>It is also possible to have the proxy add timers to the recorded script. To
 do this, create a timer directly within the HTTP Proxy Server component.
 The proxy will place a copy of this timer into each sample it records, or into



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