Author: sebb
Date: Thu Oct 6 22:09:21 2011
New Revision: 1179883
URL: http://svn.apache.org/viewvc?rev=1179883&view=rev
Log:
Bug 51981 - Better support for file: protocol in HTTP sampler
Added:
jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.csv
jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.jmx (with props)
jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml (with props)
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java
(with props)
Modified:
jakarta/jmeter/trunk/build.xml
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
jakarta/jmeter/trunk/xdocs/changes.xml
Added: jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.csv
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.csv?rev=1179883&view=auto
==============================================================================
--- jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.csv (added)
+++ jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.csv Thu Oct 6
22:09:21 2011
@@ -0,0 +1,2 @@
+label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,grpThreads,allThreads,URL,Filename,Latency,Encoding,SampleCount,ErrorCount
+Download embedded,200,OK,Thread Group
1-1,text,true,,40174,1,1,file:testfiles/HTMLParserTestFile_2.htm,,0,UTF-8,1,0
Added: jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.jmx
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.jmx?rev=1179883&view=auto
==============================================================================
--- jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.jmx (added)
+++ jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.jmx Thu Oct 6
22:09:21 2011
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jmeterTestPlan version="1.2" properties="2.1">
+ <hashTree>
+ <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan"
enabled="true">
+ <stringProp name="TestPlan.comments"></stringProp>
+ <boolProp name="TestPlan.functional_mode">false</boolProp>
+ <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
+ <elementProp name="TestPlan.user_defined_variables"
elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments"
testname="User Defined Variables" enabled="true">
+ <collectionProp name="Arguments.arguments"/>
+ </elementProp>
+ <stringProp name="TestPlan.user_define_classpath"></stringProp>
+ </TestPlan>
+ <hashTree>
+ <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup"
testname="Thread Group" enabled="true">
+ <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
+ <elementProp name="ThreadGroup.main_controller"
elementType="LoopController" guiclass="LoopControlPanel"
testclass="LoopController" testname="Loop Controller" enabled="true">
+ <boolProp name="LoopController.continue_forever">false</boolProp>
+ <stringProp name="LoopController.loops">1</stringProp>
+ </elementProp>
+ <stringProp name="ThreadGroup.num_threads">1</stringProp>
+ <stringProp name="ThreadGroup.ramp_time">1</stringProp>
+ <longProp name="ThreadGroup.start_time">1317685259000</longProp>
+ <longProp name="ThreadGroup.end_time">1317685259000</longProp>
+ <boolProp name="ThreadGroup.scheduler">false</boolProp>
+ <stringProp name="ThreadGroup.duration"></stringProp>
+ <stringProp name="ThreadGroup.delay"></stringProp>
+ </ThreadGroup>
+ <hashTree>
+ <HTTPSamplerProxy guiclass="HttpTestSampleGui"
testclass="HTTPSamplerProxy" testname="Download embedded" enabled="true">
+ <elementProp name="HTTPsampler.Arguments" elementType="Arguments"
guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined
Variables" enabled="true">
+ <collectionProp name="Arguments.arguments"/>
+ </elementProp>
+ <stringProp name="HTTPSampler.domain"></stringProp>
+ <stringProp name="HTTPSampler.port"></stringProp>
+ <stringProp name="HTTPSampler.connect_timeout"></stringProp>
+ <stringProp name="HTTPSampler.response_timeout"></stringProp>
+ <stringProp name="HTTPSampler.protocol">file</stringProp>
+ <stringProp name="HTTPSampler.contentEncoding"></stringProp>
+ <stringProp
name="HTTPSampler.path">testfiles/HTMLParserTestFile_2.htm</stringProp>
+ <stringProp name="HTTPSampler.method">GET</stringProp>
+ <boolProp name="HTTPSampler.follow_redirects">false</boolProp>
+ <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
+ <boolProp name="HTTPSampler.use_keepalive">false</boolProp>
+ <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
+ <boolProp name="HTTPSampler.image_parser">true</boolProp>
+ <boolProp name="HTTPSampler.monitor">false</boolProp>
+ <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
+ </HTTPSamplerProxy>
+ <hashTree/>
+ </hashTree>
+ <ResultCollector guiclass="ViewResultsFullVisualizer"
testclass="ResultCollector" testname="View Results Tree" enabled="true">
+ <boolProp name="ResultCollector.error_logging">false</boolProp>
+ <objProp>
+ <name>saveConfig</name>
+ <value class="SampleSaveConfiguration">
+ <time>false</time>
+ <latency>false</latency>
+ <timestamp>false</timestamp>
+ <success>true</success>
+ <label>true</label>
+ <code>true</code>
+ <message>true</message>
+ <threadName>true</threadName>
+ <dataType>true</dataType>
+ <encoding>true</encoding>
+ <assertions>true</assertions>
+ <subresults>true</subresults>
+ <responseData>false</responseData>
+ <samplerData>true</samplerData>
+ <xml>true</xml>
+ <fieldNames>false</fieldNames>
+ <responseHeaders>true</responseHeaders>
+ <requestHeaders>true</requestHeaders>
+ <responseDataOnError>false</responseDataOnError>
+
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
+ <assertionsResultsToSave>0</assertionsResultsToSave>
+ <bytes>true</bytes>
+ <url>true</url>
+ <fileName>true</fileName>
+ <threadCounts>true</threadCounts>
+ <sampleCount>true</sampleCount>
+ </value>
+ </objProp>
+ <stringProp name="filename">HTMLParserTestFile_2.xml</stringProp>
+ </ResultCollector>
+ <hashTree/>
+ <ResultCollector guiclass="TableVisualizer" testclass="ResultCollector"
testname="View Results in Table" enabled="true">
+ <boolProp name="ResultCollector.error_logging">false</boolProp>
+ <objProp>
+ <name>saveConfig</name>
+ <value class="SampleSaveConfiguration">
+ <time>false</time>
+ <latency>true</latency>
+ <timestamp>false</timestamp>
+ <success>true</success>
+ <label>true</label>
+ <code>true</code>
+ <message>true</message>
+ <threadName>true</threadName>
+ <dataType>true</dataType>
+ <encoding>true</encoding>
+ <assertions>true</assertions>
+ <subresults>true</subresults>
+ <responseData>false</responseData>
+ <samplerData>false</samplerData>
+ <xml>false</xml>
+ <fieldNames>true</fieldNames>
+ <responseHeaders>false</responseHeaders>
+ <requestHeaders>false</requestHeaders>
+ <responseDataOnError>false</responseDataOnError>
+
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
+ <assertionsResultsToSave>0</assertionsResultsToSave>
+ <bytes>true</bytes>
+ <url>true</url>
+ <fileName>true</fileName>
+ <threadCounts>true</threadCounts>
+ <sampleCount>true</sampleCount>
+ </value>
+ </objProp>
+ <stringProp name="filename">HTMLParserTestFile_2.csv</stringProp>
+ </ResultCollector>
+ <hashTree/>
+ </hashTree>
+ </hashTree>
+</jmeterTestPlan>
Propchange: jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.jmx
------------------------------------------------------------------------------
svn:eol-style = LF
Added: jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml?rev=1179883&view=auto
==============================================================================
--- jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml (added)
+++ jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml Thu Oct 6
22:09:21 2011
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<testResults version="1.2">
+<httpSample s="true" lb="Download embedded" rc="200" rm="OK" tn="Thread Group
1-1" dt="text" de="" by="40174" sc="1" ec="0" ng="1" na="1">
+ <httpSample s="true" lb="file:testfiles/HTMLParserTestFile_2.htm" rc="200"
rm="OK" tn="Thread Group 1-1" dt="text" de="" by="40174" sc="1" ec="0" ng="0"
na="0">
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+ <java.net.URL>file:testfiles/HTMLParserTestFile_2.htm</java.net.URL>
+ </httpSample>
+ <httpSample s="true"
lb="file:testfiles/HTMLParserTestFile_2_files/style.css" rc="200" rm="OK"
tn="Thread Group 1-1" dt="text" de="" by="1321" sc="1" ec="0" ng="0" na="0">
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+
<java.net.URL>file:testfiles/HTMLParserTestFile_2_files/style.css</java.net.URL>
+ </httpSample>
+ <httpSample s="true"
lb="file:testfiles/HTMLParserTestFile_2_files/halfbanner.htm" rc="200" rm="OK"
tn="Thread Group 1-1" dt="text" de="" by="398" sc="1" ec="0" ng="0" na="0">
+ <httpSample s="true"
lb="file:testfiles/HTMLParserTestFile_2_files/halfbanner.htm" rc="200" rm="OK"
tn="Thread Group 1-1" dt="text" de="" by="398" sc="1" ec="0" ng="0" na="0">
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+
<java.net.URL>file:testfiles/HTMLParserTestFile_2_files/halfbanner.htm</java.net.URL>
+ </httpSample>
+ <httpSample s="true"
lb="file:testfiles/HTMLParserTestFile_2_files/halfbanner_data/2011-na-234x60.png"
rc="200" rm="OK" tn="Thread Group 1-1" dt="text" de="" by="7413" sc="1" ec="0"
ng="0" na="0">
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+
<java.net.URL>file:testfiles/HTMLParserTestFile_2_files/halfbanner_data/2011-na-234x60.png</java.net.URL>
+ </httpSample>
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+
<java.net.URL>file:testfiles/HTMLParserTestFile_2_files/halfbanner.htm</java.net.URL>
+ </httpSample>
+ <httpSample s="true"
lb="file:testfiles/HTMLParserTestFile_2_files/jakarta-logo.gif" rc="200"
rm="OK" tn="Thread Group 1-1" dt="text" de="" by="8584" sc="1" ec="0" ng="0"
na="0">
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+
<java.net.URL>file:testfiles/HTMLParserTestFile_2_files/jakarta-logo.gif</java.net.URL>
+ </httpSample>
+ <httpSample s="true" lb="file:testfiles/HTMLParserTestFile_2_files/logo.jpg"
rc="200" rm="OK" tn="Thread Group 1-1" dt="text" de="" by="8886" sc="1" ec="0"
ng="0" na="0">
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+
<java.net.URL>file:testfiles/HTMLParserTestFile_2_files/logo.jpg</java.net.URL>
+ </httpSample>
+ <httpSample s="true"
lb="file:testfiles/HTMLParserTestFile_2_files/http-config-example.png" rc="200"
rm="OK" tn="Thread Group 1-1" dt="text" de="" by="6454" sc="1" ec="0" ng="0"
na="0">
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+
<java.net.URL>file:testfiles/HTMLParserTestFile_2_files/http-config-example.png</java.net.URL>
+ </httpSample>
+ <httpSample s="true"
lb="file:testfiles/HTMLParserTestFile_2_files/scoping1.png" rc="200" rm="OK"
tn="Thread Group 1-1" dt="text" de="" by="3975" sc="1" ec="0" ng="0" na="0">
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+
<java.net.URL>file:testfiles/HTMLParserTestFile_2_files/scoping1.png</java.net.URL>
+ </httpSample>
+ <httpSample s="true"
lb="file:testfiles/HTMLParserTestFile_2_files/scoping2.png" rc="200" rm="OK"
tn="Thread Group 1-1" dt="text" de="" by="5036" sc="1" ec="0" ng="0" na="0">
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+
<java.net.URL>file:testfiles/HTMLParserTestFile_2_files/scoping2.png</java.net.URL>
+ </httpSample>
+ <httpSample s="true"
lb="file:testfiles/HTMLParserTestFile_2_files/scoping3.png" rc="200" rm="OK"
tn="Thread Group 1-1" dt="text" de="" by="7869" sc="1" ec="0" ng="0" na="0">
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+
<java.net.URL>file:testfiles/HTMLParserTestFile_2_files/scoping3.png</java.net.URL>
+ </httpSample>
+ <responseHeader class="java.lang.String"></responseHeader>
+ <requestHeader class="java.lang.String"></requestHeader>
+ <responseFile class="java.lang.String"></responseFile>
+ <cookies class="java.lang.String"></cookies>
+ <method class="java.lang.String">GET</method>
+ <queryString class="java.lang.String"></queryString>
+ <java.net.URL>file:testfiles/HTMLParserTestFile_2.htm</java.net.URL>
+</httpSample>
+
+</testResults>
Propchange: jakarta/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jakarta/jmeter/trunk/build.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/build.xml?rev=1179883&r1=1179882&r2=1179883&view=diff
==============================================================================
--- jakarta/jmeter/trunk/build.xml (original)
+++ jakarta/jmeter/trunk/build.xml Thu Oct 6 22:09:21 2011
@@ -1953,6 +1953,9 @@ run JMeter unless all the JMeter jars ar
<!-- Additional test scripts -->
<target name="batch_scripts">
+ <antcall target="batchtest">
+ <param name="batchtest.name" value="HTMLParserTestFile_2"/>
+ </antcall>
<!-- TODO fix bug so test passes
<antcall target="batchtest">
<param name="batchtest.name" value="Bug50898"/>
Added:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java?rev=1179883&view=auto
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java
(added)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java
Thu Oct 6 22:09:21 2011
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.protocol.http.sampler;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.apache.commons.io.IOUtils;
+
+/**
+ * HTTP Sampler which can read from file: URLs
+ */
+public class HTTPFileImpl extends HTTPAbstractImpl {
+
+ protected HTTPFileImpl(HTTPSamplerBase base) {
+ super(base);
+ }
+
+ public boolean interrupt() {
+ return false;
+ }
+
+ @Override
+ protected HTTPSampleResult sample(URL url, String method,
+ boolean areFollowingRedirect, int frameDepth) {
+
+ HTTPSampleResult res = new HTTPSampleResult();
+ res.setHTTPMethod(GET); // Dummy
+ res.setURL(url);
+ res.setSampleLabel(url.toString());
+ InputStream is = null;
+ res.sampleStart();
+ try {
+ byte[] responseData;
+ URLConnection conn = url.openConnection();
+ is = conn.getInputStream();
+ responseData = IOUtils.toByteArray(is);
+ res.sampleEnd();
+ res.setResponseData(responseData);
+ res.setResponseCodeOK();
+ res.setResponseMessageOK();
+ res.setSuccessful(true);
+ StringBuilder ctb=new StringBuilder("text/html"); // $NON-NLS-1$
+ // TODO can this be obtained from the file somehow?
+ String contentEncoding = getContentEncoding();
+ if (contentEncoding.length() > 0) {
+ ctb.append("; charset="); // $NON-NLS-1$
+ ctb.append(contentEncoding);
+ }
+ String ct = ctb.toString();
+ res.setContentType(ct);
+ res.setEncodingAndType(ct);
+
+ res = resultProcessing(areFollowingRedirect, frameDepth, res);
+
+ return res;
+ } catch (FileNotFoundException e) {
+ return errorResult(e, res);
+ } catch (IOException e) {
+ return errorResult(e, res);
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+
+ }
+}
Propchange:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=1179883&r1=1179882&r2=1179883&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
Thu Oct 6 22:09:21 2011
@@ -17,13 +17,11 @@
package org.apache.jmeter.protocol.http.sampler;
import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
-import java.net.URI;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -42,7 +40,6 @@ import java.util.concurrent.ThreadPoolEx
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import org.apache.commons.io.IOUtils;
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.engine.event.LoopIterationEvent;
@@ -132,7 +129,7 @@ public abstract class HTTPSamplerBase ex
public static final String PROTOCOL = "HTTPSampler.protocol"; //
$NON-NLS-1$
- private static final String PROTOCOL_FILE = "file"; // $NON-NLS-1$
+ static final String PROTOCOL_FILE = "file"; // $NON-NLS-1$
private static final String DEFAULT_PROTOCOL = PROTOCOL_HTTP;
@@ -827,8 +824,15 @@ public abstract class HTTPSamplerBase ex
|| path.startsWith(HTTPS_PREFIX)){
return new URL(path);
}
- if (!path.startsWith("/")){ // $NON-NLS-1$
- pathAndQuery.append("/"); // $NON-NLS-1$
+ String domain = getDomain();
+ String protocol = getProtocol();
+ if (PROTOCOL_FILE.equalsIgnoreCase(protocol)) {
+ domain=null; // allow use of relative file URLs
+ } else {
+ // HTTP URLs must be absolute, allow file to be relative
+ if (!path.startsWith("/")){ // $NON-NLS-1$
+ pathAndQuery.append("/"); // $NON-NLS-1$
+ }
}
pathAndQuery.append(path);
@@ -849,9 +853,9 @@ public abstract class HTTPSamplerBase ex
}
// If default port for protocol is used, we do not include port in URL
if(isProtocolDefaultPort()) {
- return new URL(getProtocol(), getDomain(),
pathAndQuery.toString());
+ return new URL(protocol, domain, pathAndQuery.toString());
}
- return new URL(getProtocol(), getDomain(), getPort(),
pathAndQuery.toString());
+ return new URL(protocol, domain, getPort(), pathAndQuery.toString());
}
/**
@@ -1017,11 +1021,7 @@ public abstract class HTTPSamplerBase ex
public SampleResult sample() {
SampleResult res = null;
try {
- if (PROTOCOL_FILE.equalsIgnoreCase(getProtocol())){
- res = fileSample(new URI(PROTOCOL_FILE,getPath(),null));
- } else {
- res = sample(getUrl(), getMethod(), false, 0);
- }
+ res = sample(getUrl(), getMethod(), false, 0);
res.setSampleLabel(getName());
return res;
} catch (Exception e) {
@@ -1029,45 +1029,6 @@ public abstract class HTTPSamplerBase ex
}
}
- private HTTPSampleResult fileSample(URI uri) throws IOException {
-
- //String urlStr = uri.toString();
-
-
- HTTPSampleResult res = new HTTPSampleResult();
- res.setMonitor(isMonitor());
- res.setHTTPMethod(GET); // Dummy
- res.setURL(uri.toURL());
- res.setSampleLabel(uri.toString());
- FileInputStream fis = null;
- res.sampleStart();
- try {
- byte[] responseData;
- StringBuilder ctb=new StringBuilder("text/html"); // $NON-NLS-1$
- fis = new FileInputStream(getPath());
- String contentEncoding = getContentEncoding();
- if (contentEncoding.length() > 0) {
- ctb.append("; charset="); // $NON-NLS-1$
- ctb.append(contentEncoding);
- }
- responseData = IOUtils.toByteArray(fis);
- res.sampleEnd();
- res.setResponseData(responseData);
- res.setResponseCodeOK();
- res.setResponseMessageOK();
- res.setSuccessful(true);
- String ct = ctb.toString();
- res.setContentType(ct);
- res.setEncodingAndType(ct);
- } finally {
- IOUtils.closeQuietly(fis);
- }
-
- //res.setResponseHeaders("");
-
- return res;
- }
-
/**
* Samples the URL passed in and stores the result in
* <code>HTTPSampleResult</code>, following redirects and downloading
@@ -1127,6 +1088,9 @@ public abstract class HTTPSamplerBase ex
// Iterate through the URLs and download each image:
if (urls != null && urls.hasNext()) {
if (container == null) {
+ // TODO needed here because currently done on sample
completion in JMeterThread,
+ // but that only catches top-level samples.
+ res.setThreadName(Thread.currentThread().getName());
container = new HTTPSampleResult(res);
container.addRawSubResult(res);
}
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java?rev=1179883&r1=1179882&r2=1179883&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
Thu Oct 6 22:09:21 2011
@@ -87,6 +87,9 @@ public class HTTPSamplerFactory {
}
public static HTTPAbstractImpl getImplementation(String impl,
HTTPSamplerBase base){
+ if (HTTPSamplerBase.PROTOCOL_FILE.equals(base.getProtocol())) {
+ return new HTTPFileImpl(base);
+ }
if (impl.trim().length() == 0){
impl = DEFAULT_CLASSNAME;
}
@@ -95,7 +98,7 @@ public class HTTPSamplerFactory {
} else if (IMPL_HTTP_CLIENT3_1.equals(impl) ||
HTTP_SAMPLER_APACHE.equals(impl)) {
return new HTTPHC3Impl(base);
} else if (IMPL_HTTP_CLIENT4.equals(impl)) {
- return new HTTPHC4Impl(base);
+ return new HTTPHC4Impl(base);
} else {
throw new IllegalArgumentException("Unknown implementation type:
'"+impl+"'");
}
Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=1179883&r1=1179882&r2=1179883&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Thu Oct 6 22:09:21 2011
@@ -124,6 +124,7 @@ This has been corrected; can still rever
<h3>HTTP Samplers</h3>
<ul>
+<li>Bug 51981 - Better support for file: protocol in HTTP sampler</li>
</ul>
<h3>Other samplers</h3>
@@ -159,7 +160,7 @@ This has been corrected; can still rever
<li>fixes to build.xml: support scripts; localise re-usable property names</li>
<li>Bug 51923 - Counter function bug or documentation issue ? (fixed docs)</li>
<li>Update velocity.jar to 1.7 (from 1.6.2)</li>
-<li>Bug 51954 - Generated documents include </br> entries which cause extra
blank lines </li>
+<li>Bug 51954 - Generated documents include </br> entries which cause
extra blank lines </li>
</ul>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]