Author: sebb
Date: Fri Feb 9 08:09:58 2007
New Revision: 505341
URL: http://svn.apache.org/viewvc?view=rev&rev=505341
Log:
Bug 33964 - send file as entire post body if name & type are omitted
Modified:
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml
jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml
Modified:
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java?view=diff&rev=505341&r1=505340&r2=505341
==============================================================================
---
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
(original)
+++
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
Fri Feb 9 08:09:58 2007
@@ -234,18 +234,22 @@
// If filename was specified then send the post using multipart
syntax
String filename = getFilename();
if ((filename != null) && (filename.trim().length() > 0)) {
- int argc = getArguments().getArgumentCount();
- Part[] parts = new Part[argc+1];
- PropertyIterator args = getArguments().iterator();
- int i = 0;
- while (args.hasNext()) {
- Argument arg = (Argument) args.next().getObjectValue();
- parts[i++] = new StringPart(arg.getName(), arg.getValue());
- }
- File input = new File(filename);
- //TODO should allow charset to be defined ...
- parts[i]= new FilePart(getFileField(), input, getMimetype(),
"UTF-8" );//$NON-NLS-1$
- post.setRequestEntity(new MultipartRequestEntity(parts,
post.getParams()));
+ if (getSendFileAsPostBody()) {
+ post.setRequestEntity(new FileRequestEntity(new
File(filename),null));
+ } else {
+ int argc = getArguments().getArgumentCount();
+ Part[] parts = new Part[argc+1];
+ PropertyIterator args = getArguments().iterator();
+ int i = 0;
+ while (args.hasNext()) {
+ Argument arg = (Argument) args.next().getObjectValue();
+ parts[i++] = new StringPart(arg.getName(),
arg.getValue());
+ }
+ File input = new File(filename);
+ //TODO should allow charset to be defined ...
+ parts[i]= new FilePart(getFileField(), input,
getMimetype(), "UTF-8" );//$NON-NLS-1$
+ post.setRequestEntity(new MultipartRequestEntity(parts,
post.getParams()));
+ }
} else {
PropertyIterator args = getArguments().iterator();
while (args.hasNext()) {
@@ -558,7 +562,7 @@
if (method.equals(POST)) {
res.setQueryString(getQueryString());
sendPostData((PostMethod)httpMethod);
- }else if (method.equals(PUT)) {
+ } else if (method.equals(PUT)) {
setPutHeaders((PutMethod) httpMethod);
}
@@ -669,7 +673,7 @@
}
}
- // Implement locally, as current implementation (3.1Beta) does not
close file...
+ // Implement locally, as current httpclient InputStreamRI
implementation does not close file...
private class FileRequestEntity implements RequestEntity {
final File file;
Modified:
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java?view=diff&rev=505341&r1=505340&r2=505341
==============================================================================
---
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
(original)
+++
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
Fri Feb 9 08:09:58 2007
@@ -42,9 +42,12 @@
private final static byte[] CRLF = { 0x0d, 0x0A };
- // protected static int fudge = -20;
protected static final String encoding = "iso-8859-1"; // $NON-NLS-1$
+ // Not instantiable
+ private PostWriter(){
+
+ }
/**
* Send POST data from Entry to the open connection.
*/
@@ -53,8 +56,20 @@
String filename = sampler.getFilename();
if ((filename != null) && (filename.trim().length() > 0)) {
OutputStream out = connection.getOutputStream();
- // new FileOutputStream("c:\\data\\experiment.txt");
- // new ByteArrayOutputStream();
+ // Check if not using multi-part:
+ if (sampler.getSendFileAsPostBody())
+ {
+ InputStream in = getFileStream(filename);
+ byte[] buf = new byte[1024];
+ int read;
+ while ((read = in.read(buf)) > 0)
+ {
+ out.write(buf, 0, read);
+ }
+ out.flush();
+ in.close();
+ return;
+ }
writeln(out, DASH_DASH + BOUNDARY);
PropertyIterator args =
sampler.getArguments().iterator();
while (args.hasNext()) {
@@ -85,8 +100,10 @@
// If filename was specified then send the post using multipart
syntax
String filename = sampler.getFilename();
if ((filename != null) && (filename.trim().length() > 0)) {
-
connection.setRequestProperty(HTTPSamplerBase.HEADER_CONTENT_TYPE,
+ if (!sampler.getSendFileAsPostBody()) { // unless the
file is the body...
+
connection.setRequestProperty(HTTPSamplerBase.HEADER_CONTENT_TYPE,
"multipart/form-data; boundary=" + BOUNDARY); //
$NON-NLS-1$
+ }
connection.setDoOutput(true);
connection.setDoInput(true);
}
@@ -95,7 +112,7 @@
else {
String postData = sampler.getQueryString();
connection.setRequestProperty(HTTPSamplerBase.HEADER_CONTENT_LENGTH,
Integer.toString(postData.length()));
-
connection.setRequestProperty(HTTPSamplerBase.HEADER_CONTENT_TYPE,
"application/x-www-form-urlencoded"); // $NON-NLS-1$
+
connection.setRequestProperty(HTTPSamplerBase.HEADER_CONTENT_TYPE,
HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED);
connection.setDoOutput(true);
}
}
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=505341&r1=505340&r2=505341
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml (original)
+++ jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml Fri Feb 9 08:09:58 2007
@@ -57,6 +57,7 @@
<li>Bug 41522 - Use JUnit sampler name in sample results</li>
<li>HttpClient now behaves the same as the JDK http sampler for invalid
certificates etc</li>
<li>Add Domain and Realm support to HTTP Authorisation Manager</li>
+<li>Bug 33964 - send file as entire post body if name/type are omitted</li>
</ul>
<h4>Bug fixes:</h4>
Modified:
jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml?view=diff&rev=505341&r1=505340&r2=505341
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml
(original)
+++ jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml
Fri Feb 9 08:09:58 2007
@@ -126,7 +126,6 @@
<a href="build-adv-web-test-plan.html#session_url_rewriting">6.1
Handling User Sessions With URL Rewriting</a>
for additional configuration steps.</p>
</description>
-<note>The HTTP methods HEAD, TRACE, OPTIONS, PUT, DELETE are new in 2.1.2, and
may have some teething problems.</note>
<properties>
<property name="Name" required="No">Descriptive name for this
controller that is shown in the tree.</property>
<property name="Server" required="No">Domain name or IP address of the
web server.</property>
@@ -164,9 +163,12 @@
question marks, then encoding is usually required.</p></property>
<property name="Filename" required="No">Name of the file to send. If
left blank, JMeter
does not send a file, if filled in, JMeter automatically sends the
request as
- a multipart form request.</property>
- <property name="Value for 'name' attribute" required="No (Yes if
Filename filled in)">Value of the "name" web request parameter.</property>
- <property name="MIME Type" required="No (Yes if Filename filled
in)">MIME type (for example, text/plain).</property>
+ a multipart form request.
+ <b>In versions of JMeter after 2.2: if both the 'name' atribute and
MIME type (below) are omitted, then the file is sent as the body
+ of the POST request. This allows arbitraty POST bodies to be sent.</b>
+ </property>
+ <property name="Value for 'name' attribute" required="No">Value of the
"name" web request parameter.</property>
+ <property name="MIME Type" required="No">MIME type (for example,
text/plain).</property>
<property name="Retrieve All Embedded Resources from HTML Files"
required="No">Tell JMeter to parse the HTML file
and send HTTP/HTTPS requests for all images, Java applets, JavaScript files,
CSSs, etc. referenced in the file.
See below for more details.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]