You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@jmeter.apache.org by bu...@apache.org on 2014/10/29 15:42:23 UTC

[Bug 56141] Application does not behave correctly when using HTTP Recorder

https://issues.apache.org/bugzilla/show_bug.cgi?id=56141

Dan <ja...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |java.junkee@yahoo.com

--- Comment #4 from Dan <ja...@yahoo.com> ---
I actually have a fix for this, but I'm not sure exactly how to go about
checking in the code -
The problem is that it requires newer httpmime jar, and possibly the httpclient
and http code ones. I'm using 4.3.5 in my fix. 

I modified the HTTPHC4Impl class, and therefore if I were to either check it in
or create a new one, it would require a dependency change and I don't know if
that is acceptable. A lot of code is deprecated. 

The way that I was able to solve the problem was that inside of the method
org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sendPostData(HttpPost),
inside of the  // Check if we should do a multipart/form-data or an
        // application/x-www-form-urlencoded post request
        if(getUseMultipartForPost()) {
I changed the code to the newer MultipartEntityBuilder and most importantly,
had to call the setLaxMode(). 

if(getUseMultipartForPost()) {
            // If a content encoding is specified, we use that as the
            // encoding of any parameter values
            Charset charset = null;
            if(haveContentEncoding) {
                charset = Charset.forName(contentEncoding);
            }

            // Write the request to our own stream
            MultipartEntityBuilder mep = MultipartEntityBuilder.create();

            // Create the parts
            // Add any parameters
            PropertyIterator args = getArguments().iterator();
            while (args.hasNext()) {
               HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
               String parameterName = arg.getName();
               if (arg.isSkippable(parameterName)){
                   continue;
               }

               FormBodyPart formPart;
               mep.addBinaryBody(arg.getName(),
arg.getValue().getBytes("ASCII"));
               mep.setLaxMode();
            }

            // Add any files
            // Cannot retrieve parts once added to the MultiPartEntity, so have
to save them here.
            FileBody[] fileBodies = new FileBody[files.length];
            for (int i=0; i < files.length; i++) {
                HTTPFileArg file = files[i];
                fileBodies[i] = new FileBody(new File(file.getPath()));

                mep.addPart(file.getParamName(), fileBodies[i] );
            }

            HttpEntity pst = mep.build();
            post.setEntity(pst);

            if (pst.isRepeatable()){
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                for(FileBody fileBody : fileBodies){
                   // fileBody.hideFileData = true;
                }
                pst.writeTo(bos);

                bos.flush();
                // We get the posted bytes using the encoding used to create it
                postedBody.append(new String(bos.toByteArray(),
                        contentEncoding == null ? "US-ASCII" // $NON-NLS-1$
this is the default used by HttpClient
                        : contentEncoding));
                bos.close();
            } else {
                postedBody.append("<Multipart was not repeatable, cannot view
what was sent>"); // $NON-NLS-1$
            }


        } else { // not multipart

-- 
You are receiving this mail because:
You are the assignee for the bug.