Author: sebb
Date: Tue Feb  6 15:08:48 2007
New Revision: 504359

URL: http://svn.apache.org/viewvc?view=rev&rev=504359
Log:
Bug 39827 - set correct content length; and allow override if necessary

Modified:
    
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/SoapSampler.java

Modified: 
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/SoapSampler.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/SoapSampler.java?view=diff&rev=504359&r1=504358&r2=504359
==============================================================================
--- 
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/SoapSampler.java
 (original)
+++ 
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/SoapSampler.java
 Tue Feb  6 15:08:48 2007
@@ -28,6 +28,7 @@
 import org.apache.log.Logger;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -117,16 +118,19 @@
                setProperty(SEND_SOAP_ACTION, String.valueOf(action));
        }
 
-    protected void setPostHeaders(PostMethod post) {
+    protected int setPostHeaders(PostMethod post) {
+       int length=0;// Take length from file
         if (getHeaderManager() != null) {
             // headerManager was set, so let's set the connection
             // to use it.
             HeaderManager mngr = getHeaderManager();
             int headerSize = mngr.size();
-            // we set all the header properties
             for (int idx = 0; idx < headerSize; idx++) {
                 Header hd = mngr.getHeader(idx);
-                post.addParameter(hd.getName(), hd.getValue());
+                if (HEADER_CONTENT_LENGTH.equalsIgnoreCase(hd.getName())) {// 
Use this to override file length
+                       length = Integer.parseInt(hd.getValue());
+                }
+                // All the other headers are set up by 
HTTPSampler2.setupConnection()
             }
         } else {
             // otherwise we use "text/xml" as the default
@@ -135,6 +139,7 @@
         if (getSendSOAPAction()) {
             post.setRequestHeader(SOAPACTION, getSOAPActionQuoted());
         }
+        return length;
     }
 
     /**
@@ -143,7 +148,7 @@
      * @param post
      * @throws IOException if an I/O exception occurs
      */
-    protected void sendPostData(PostMethod post) {
+    protected void sendPostData(PostMethod post, final int length) {
         final String xmlFile = getXmlFile();
         if (xmlFile != null && getXmlFile().length() > 0) {
             post.setRequestEntity(new RequestEntity() {
@@ -167,7 +172,14 @@
                 }
 
                 public long getContentLength() {
-                    return -1;
+                       switch(length){
+                               case -1:
+                                       return -1;
+                               case 0: // No header provided
+                                       return (new File(xmlFile)).length();
+                               default:
+                                       return length;
+                               }
                 }
 
                 public String getContentType() {
@@ -216,11 +228,11 @@
         HttpClient client = null;
         InputStream instream = null;
         try {
-            setPostHeaders(httpMethod);
+            int content_len = setPostHeaders(httpMethod);
             client = setupConnection(url, httpMethod, res);
 
             res.setQueryString(getQueryString());
-            sendPostData(httpMethod);
+            sendPostData(httpMethod,content_len);
 
             int statusCode = client.executeMethod(httpMethod);
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to