You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2015/02/11 08:36:23 UTC

svn commit: r1658893 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/proxy/ xdocs/

Author: pmouawad
Date: Wed Feb 11 07:36:23 2015
New Revision: 1658893

URL: http://svn.apache.org/r1658893
Log:
Bug 57565 - SamplerCreator : Add method to allow implementations to add children to created sampler
Bugzilla Id: 57565

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/AbstractSamplerCreator.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/SamplerCreator.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/AbstractSamplerCreator.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/AbstractSamplerCreator.java?rev=1658893&r1=1658892&r2=1658893&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/AbstractSamplerCreator.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/AbstractSamplerCreator.java Wed Feb 11 07:36:23 2015
@@ -18,13 +18,16 @@
 
 package org.apache.jmeter.protocol.http.proxy;
 
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
 
 import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
 import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testelement.TestElement;
 import org.apache.jmeter.util.JMeterUtils;
 
 /**
@@ -142,4 +145,13 @@ public abstract class AbstractSamplerCre
         populateSampler(sampler, request, pageEncodings, formEncodings);
         return sampler;
     }
+
+    /**
+     * Default implementation returns an empty list
+     * @see SamplerCreator#createChildren(HTTPSamplerBase, SampleResult)
+     */
+    @Override
+    public List<TestElement> createChildren(HTTPSamplerBase sampler, SampleResult result) {
+        return Collections.emptyList();
+    }
 }

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java?rev=1658893&r1=1658892&r2=1658893&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java Wed Feb 11 07:36:23 2015
@@ -32,7 +32,9 @@ import java.nio.charset.IllegalCharsetNa
 import java.security.GeneralSecurityException;
 import java.security.KeyStore;
 import java.security.KeyStoreException;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.net.ssl.KeyManager;
@@ -167,6 +169,7 @@ public class Proxy extends Thread {
         if (isDebug) {
             log.debug(port + "====================================================================");
         }
+        SamplerCreator samplerCreator = null;
         try {
             // Now, parse initial request (in case it is a CONNECT request)
             byte[] ba = request.parse(new BufferedInputStream(clientSocket.getInputStream()));
@@ -219,7 +222,7 @@ public class Proxy extends Thread {
                 }
             }
 
-            SamplerCreator samplerCreator = SAMPLERFACTORY.getSamplerCreator(request, pageEncodings, formEncodings);
+            samplerCreator = SAMPLERFACTORY.getSamplerCreator(request, pageEncodings, formEncodings);
             sampler = samplerCreator.createAndPopulateSampler(request, pageEncodings, formEncodings);
 
             /*
@@ -277,7 +280,17 @@ public class Proxy extends Thread {
             }
             if(result != null) // deliverSampler allows sampler to be null, but result must not be null
             {
-                target.deliverSampler(sampler, new TestElement[] { captureHttpHeaders ? headers : null }, result);
+                List<TestElement> children = new ArrayList<TestElement>();
+                if(captureHttpHeaders) {
+                    children.add(headers);
+                }
+                if(samplerCreator != null) {
+                    children.addAll(samplerCreator.createChildren(sampler, result));
+                } 
+                target.deliverSampler(sampler,
+                        children.isEmpty() ? null : (TestElement[]) children
+                                .toArray(new TestElement[children.size()]),
+                        result);
             }
             try {
                 clientSocket.close();

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/SamplerCreator.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/SamplerCreator.java?rev=1658893&r1=1658892&r2=1658893&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/SamplerCreator.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/SamplerCreator.java Wed Feb 11 07:36:23 2015
@@ -18,10 +18,12 @@
 
 package org.apache.jmeter.protocol.http.proxy;
 
+import java.util.List;
 import java.util.Map;
 
 import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
 import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testelement.TestElement;
 
 /**
  * Factory of sampler
@@ -81,4 +83,15 @@ public interface SamplerCreator {
     HTTPSamplerBase createAndPopulateSampler(HttpRequestHdr request,
             Map<String, String> pageEncodings, Map<String, String> formEncodings)
                     throws Exception;
+
+    /**
+     * Create sampler children.
+     * This method can be used to add PostProcessor or ResponseAssertions by 
+     * implementations of {@link SamplerCreator}.
+     * Return empty list if nothing to create
+     * @param sampler {@link HTTPSamplerBase}
+     * @param result {@link SampleResult}
+     * @return List
+     */
+    List<TestElement> createChildren(HTTPSamplerBase sampler, SampleResult result);
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1658893&r1=1658892&r2=1658893&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Wed Feb 11 07:36:23 2015
@@ -191,6 +191,7 @@ See  <bugzilla>56357</bugzilla> for deta
 <li><bug>25430</bug>HTTP(S) Test Script Recorder : Make it populate HTTP Authorisation Manager. Partly based on a patch from Dzmitry Kashlach (dzmitrykashlach at gmail.com)</li>
 <li><bug>57381</bug>HTTP(S) Test Script Recorder should display an error if Target Controller references a Recording Controller and no Recording Controller exists. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
 <li><bug>57488</bug>Performance : Improve SSLContext reset for Two-way SSL Authentication</li>
+<li><bug>57565</bug>SamplerCreator : Add method to allow implementations to add children to created sampler</li>
 </ul>
 
 <h3>Other samplers</h3>