Author: sebb
Date: Wed Apr 16 17:52:32 2008
New Revision: 648910
URL: http://svn.apache.org/viewvc?rev=648910&view=rev
Log:
Replace duplicated code with call to utility routine
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java?rev=648910&r1=648909&r2=648910&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
Wed Apr 16 17:52:32 2008
@@ -40,11 +40,11 @@
import org.apache.jmeter.protocol.http.sampler.HTTPSampler2;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerFactory;
+import org.apache.jmeter.protocol.http.util.ConversionUtils;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
-import org.apache.jorphan.util.JOrphanUtils;
import org.apache.log.Logger;
//For unit tests, @see TestHttpRequestHdr
@@ -225,7 +225,7 @@
}
public HTTPSamplerBase getSampler(Map pageEncodings, Map formEncodings)
- throws MalformedURLException, IOException, ProtocolException {
+ throws MalformedURLException, IOException {
// Damn! A whole new GUI just to instantiate a test element?
// Isn't there a beter way?
HttpTestSampleGui tempGui = null;
@@ -274,24 +274,6 @@
return null;
}
- private String getContentEncoding() {
- String contentType = getContentType();
- if(contentType != null) {
- int charSetStartPos =
contentType.toLowerCase().indexOf("charset=");
- if(charSetStartPos >= 0) {
- String charSet = contentType.substring(charSetStartPos +
"charset=".length());
- if(charSet != null && charSet.length() > 0) {
- // Remove quotes if present
- charSet = JOrphanUtils.replaceAllChars(charSet, '"', "");
- if(charSet.length() > 0) {
- return charSet;
- }
- }
- }
- }
- return null;
- }
-
private boolean isMultipart(String contentType) {
if (contentType != null &&
contentType.startsWith(HTTPConstants.MULTIPART_FORM_DATA)) {
return true;
@@ -350,7 +332,7 @@
// Check if the request itself tells us what the encoding is
String contentEncoding = null;
- String requestContentEncoding = getContentEncoding();
+ String requestContentEncoding =
ConversionUtils.getEncodingFromContentType(getContentType());
if(requestContentEncoding != null) {
contentEncoding = requestContentEncoding;
}
@@ -439,7 +421,7 @@
sampler.setFileField(urlConfig.getFileFieldName());
sampler.setFilename(urlConfig.getFilename());
sampler.setMimetype(urlConfig.getMimeType());
- } else if (postData != null && postData.trim().startsWith("<?")) {
+ } else if (postData.trim().startsWith("<?")) {
// Not sure if this is needed anymore. I assume these requests
// do not have HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED
as content type,
// and they would therefore be catched by the last else if of
these if else if tests
@@ -449,7 +431,7 @@
// We also assume this if no content type is present, to be
most backwards compatible,
// but maybe we should only parse arguments if the content
type is as expected
sampler.parseArguments(postData.trim(), contentEncoding);
//standard name=value postData
- } else if (postData != null && postData.length() > 0) {
+ } else if (postData.length() > 0) {
// Just put the whole postbody as the value of a parameter
sampler.addNonEncodedArgument("", postData, ""); //used when
postData is pure xml (ex. an xml-rpc call)
}
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java?rev=648910&r1=648909&r2=648910&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java
Wed Apr 16 17:52:32 2008
@@ -32,6 +32,7 @@
import org.apache.jmeter.protocol.http.parser.HTMLParseException;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerFactory;
+import org.apache.jmeter.protocol.http.util.ConversionUtils;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testelement.TestElement;
@@ -362,7 +363,7 @@
* @return the page encoding found for the sample result, or null
*/
private String addPageEncoding(SampleResult result) {
- String pageEncoding = getContentEncoding(result);
+ String pageEncoding =
ConversionUtils.getEncodingFromContentType(result.getContentType());
if(pageEncoding != null) {
String urlWithoutQuery = getUrlWithoutQuery(result.getURL());
synchronized(pageEncodings) {
@@ -389,31 +390,6 @@
catch (HTMLParseException parseException) {
log.debug("Unable to parse response, could not find any form
character set encodings");
}
- }
-
- /**
- * Get the value of the charset of the content-type header of the sample
result
- *
- * @param res the sample result to find the charset for
- * @return the charset found, or null
- */
- private String getContentEncoding(SampleResult res) {
- String contentTypeHeader = res.getContentType();
- String charSet = null;
- if (contentTypeHeader != null) {
- int charSetStartPos =
contentTypeHeader.toLowerCase().indexOf("charset=");
- if (charSetStartPos > 0) {
- charSet = contentTypeHeader.substring(charSetStartPos +
"charset=".length());
- if (charSet != null) {
- if (charSet.trim().length() > 0) {
- charSet = charSet.trim();
- } else {
- charSet = null;
- }
- }
- }
- }
- return charSet;
}
private String getUrlWithoutQuery(URL url) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]