Author: pmouawad
Date: Wed Feb 15 22:12:19 2012
New Revision: 1244757
URL: http://svn.apache.org/viewvc?rev=1244757&view=rev
Log:
Bug 52675 - Refactor Proxy and HttpRequestHdr to allow Sampler Creation by Proxy
Modified:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java?rev=1244757&r1=1244756&r2=1244757&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
Wed Feb 15 22:12:19 2012
@@ -110,7 +110,7 @@ public class HttpRequestHdr {
private final Map<String, Header> headers = new HashMap<String, Header>();
- private final HTTPSamplerBase sampler;
+ private final String httpSamplerName;
private HeaderManager headerManager;
@@ -123,14 +123,14 @@ public class HttpRequestHdr {
private static volatile int requestNumber = 0;// running number
public HttpRequestHdr() {
- this.sampler = HTTPSamplerFactory.newInstance();
+ this.httpSamplerName = ""; // $NON-NLS-1$
}
/**
- * @param sampler the http sampler
+ * @param httpSamplerName the http sampler name
*/
- public HttpRequestHdr(HTTPSamplerBase sampler) {
- this.sampler = sampler;
+ public HttpRequestHdr(String httpSamplerName) {
+ this.httpSamplerName = httpSamplerName;
}
/**
@@ -253,6 +253,8 @@ public class HttpRequestHdr {
public HTTPSamplerBase getSampler(Map<String, String> pageEncodings, Map<String,
String> formEncodings)
throws MalformedURLException, IOException {
+ // Instantiate the sampler
+ HTTPSamplerBase sampler = HTTPSamplerFactory.newInstance(httpSamplerName);
// Damn! A whole new GUI just to instantiate a test element?
// Isn't there a beter way?
HttpTestSampleGui tempGui = new HttpTestSampleGui();
@@ -260,7 +262,7 @@ public class HttpRequestHdr {
sampler.setProperty(TestElement.GUI_CLASS, tempGui.getClass().getName());
// Populate the sampler
- populateSampler(pageEncodings, formEncodings);
+ populateSampler(sampler, pageEncodings, formEncodings);
tempGui.configure(sampler);
tempGui.modifyTestElement(sampler);
@@ -298,7 +300,9 @@ public class HttpRequestHdr {
return null;
}
- private void populateSampler(Map<String, String> pageEncodings, Map<String,
String> formEncodings)
+ private void populateSampler(
+ HTTPSamplerBase sampler,
+ Map<String, String> pageEncodings, Map<String, String> formEncodings)
throws MalformedURLException, UnsupportedEncodingException {
sampler.setDomain(serverName());
if (log.isDebugEnabled()) {
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=1244757&r1=1244756&r2=1244757&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
15 22:12:19 2012
@@ -176,13 +176,11 @@ public class Proxy extends Thread {
public void run() {
// Check which HTTPSampler class we should use
String httpSamplerName = target.getSamplerTypeName();
- // Instantiate the sampler
- HTTPSamplerBase sampler = HTTPSamplerFactory.newInstance(httpSamplerName);
- HttpRequestHdr request = new HttpRequestHdr(sampler);
+ HttpRequestHdr request = new HttpRequestHdr(httpSamplerName);
SampleResult result = null;
HeaderManager headers = null;
-
+ HTTPSamplerBase sampler = null;
try {
// Now, parse only first line
request.parse(new BufferedInputStream(clientSocket.getInputStream()));
@@ -207,7 +205,7 @@ public class Proxy extends Thread {
// Populate the sampler. It is the same sampler as we sent into
// the constructor of the HttpRequestHdr instance above
- request.getSampler(pageEncodings, formEncodings);
+ sampler = request.getSampler(pageEncodings, formEncodings);
/*
* Create a Header Manager to ensure that the browsers headers are
@@ -279,8 +277,11 @@ public class Proxy extends Thread {
writeErrorToClient(HttpReplyHdr.formInternalError());
result = generateErrorResult(result, e); // Generate result (if nec.) and populate
it
} finally {
+ boolean samplerAvailable = sampler != null;
if (log.isDebugEnabled()) {
- log.debug("Will deliver sample " + sampler.getName());
+ if(samplerAvailable) {
+ log.debug("Will deliver sample " + sampler.getName());
+ }
}
/*
* We don't want to store any cookies in the generated test plan
@@ -293,13 +294,17 @@ public class Proxy extends Thread {
headers.removeHeaderNamed(hdr);
}
}
- target.deliverSampler(sampler, new TestElement[] { captureHttpHeaders ? headers
: null }, result);
+ if(samplerAvailable) {
+ target.deliverSampler(sampler, new TestElement[] { captureHttpHeaders ? headers
: null }, result);
+ }
try {
clientSocket.close();
} catch (Exception e) {
log.error("", e);
}
- sampler.threadFinished(); // Needed for HTTPSampler2
+ if(samplerAvailable) {
+ sampler.threadFinished(); // Needed for HTTPSampler2
+ }
}
}
Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java?rev=1244757&r1=1244756&r2=1244757&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
Wed Feb 15 22:12:19 2012
@@ -67,7 +67,7 @@ public class HTTPSamplerFactory {
* @throws UnsupportedOperationException if alias is not recognised
*/
public static HTTPSamplerBase newInstance(String alias) {
- if (alias.length() == 0) {
+ if (alias ==null || alias.length() == 0) {
alias = DEFAULT_CLASSNAME;
}
if (alias.equals(HTTP_SAMPLER_JAVA) || alias.equals(IMPL_JAVA)) {
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1244757&r1=1244756&r2=1244757&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Wed Feb 15 22:12:19 2012
@@ -149,6 +149,7 @@ Note: the Maven coordinates for the jar
This does not affect JMeter directly, but might cause problems if using JMeter in a Maven
project
with other code that depends on an earlier version of the Rhino Javascript jar.
</li>
+<li>Bug 52675 - Refactor Proxy and HttpRequestHdr to allow Sampler Creation by Proxy</li>
</ul>
</section>
|