public abstract class HTTPSamplerBase extends AbstractSampler implements TestStateListener, TestIterationListener, ThreadListener, HTTPConstantsInterface, Replaceable
Modifier and Type | Class and Description |
---|---|
static class |
HTTPSamplerBase.SourceType |
APPLICATION_X_WWW_FORM_URLENCODED, CACHE_CONTROL, CONNECT, CONNECTION_CLOSE, COPY, DATE, DEFAULT_HTTP_PORT, DEFAULT_HTTP_PORT_STRING, DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_PORT_STRING, DELETE, ENCODING_BROTLI, ENCODING_DEFLATE, ENCODING_GZIP, ETAG, EXPIRES, GET, HEAD, HEADER_AUTHORIZATION, HEADER_CONNECTION, HEADER_CONTENT_DISPOSITION, HEADER_CONTENT_ENCODING, HEADER_CONTENT_LENGTH, HEADER_CONTENT_TYPE, HEADER_COOKIE, HEADER_COOKIE_IN_REQUEST, HEADER_HOST, HEADER_LOCAL_ADDRESS, HEADER_LOCATION, HEADER_SET_COOKIE, HTTP_1_1, IF_MODIFIED_SINCE, IF_NONE_MATCH, KEEP_ALIVE, LAST_MODIFIED, LOCK, MKCALENDAR, MKCOL, MOVE, MULTIPART_FORM_DATA, OPTIONS, PATCH, POST, PROPFIND, PROPPATCH, PROTOCOL_HTTP, PROTOCOL_HTTPS, PUT, REPORT, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_SEE_OTHER, SC_TEMPORARY_REDIRECT, SEARCH, TRACE, TRANSFER_ENCODING, UNLOCK, VARY
COMMENTS, ENABLED, GUI_CLASS, NAME, TEST_CLASS
Constructor and Description |
---|
HTTPSamplerBase() |
Modifier and Type | Method and Description |
---|---|
void |
addArgument(String name,
String value) |
void |
addArgument(String name,
String value,
String metadata) |
void |
addEncodedArgument(String name,
String value)
Add an argument which has already been encoded
|
void |
addEncodedArgument(String name,
String value,
String metaData) |
void |
addEncodedArgument(String name,
String value,
String metaData,
String contentEncoding)
Creates an HTTPArgument and adds it to the current set
getArguments() of arguments. |
void |
addNonEncodedArgument(String name,
String value,
String metadata) |
void |
addNonEncodedArgument(String name,
String value,
String metadata,
String contentType) |
void |
addTestElement(TestElement el) |
boolean |
applies(ConfigTestElement configElement)
Does configElement apply to Sampler
|
void |
clearTestElementChildren()
This method should clear any test element properties that are merged
by
TestElement.addTestElement(TestElement) . |
protected HTTPSampleResult |
downloadPageResources(HTTPSampleResult pRes,
HTTPSampleResult container,
int frameDepth)
Download the resources of an HTML page.
|
protected static String |
encodeBackSlashes(String value) |
protected String |
encodeSpaces(String path) |
protected HTTPSampleResult |
errorResult(Throwable e,
HTTPSampleResult res)
Populates the provided HTTPSampleResult with details from the Exception.
|
protected HTTPSampleResult |
followRedirects(HTTPSampleResult res,
int frameDepth)
Iteratively download the redirect targets of a redirect response.
|
Arguments |
getArguments() |
AuthManager |
getAuthManager() |
boolean |
getAutoRedirects() |
CacheManager |
getCacheManager() |
String |
getConcurrentPool()
Get the pool size for concurrent thread pool to get embedded resources.
|
int |
getConnectTimeout() |
String |
getContentEncoding() |
CookieManager |
getCookieManager() |
static int |
getDefaultPort(String protocol,
int port)
Get the port number for a URL, applying defaults if necessary.
|
DNSCacheManager |
getDNSResolver() |
boolean |
getDoBrowserCompatibleMultipart() |
String |
getDomain() |
boolean |
getDoMultipart() |
boolean |
getDoMultipartPost()
Deprecated.
|
String |
getEmbeddedUrlRE()
Get the regular expression URLs must match.
|
boolean |
getFollowRedirects() |
HeaderManager |
getHeaderManager() |
int |
getHTTPFileCount() |
HTTPFileArg[] |
getHTTPFiles()
Get the collection of files as a list.
|
String |
getImplementation() |
String |
getIpSource()
get IP source to use - does not apply to Java HTTP implementation currently
|
int |
getIpSourceType()
get IP/address source type to use
|
KeystoreConfig |
getKeystoreConfig() |
String |
getMethod() |
String |
getMonitor()
Deprecated.
since 3.2 always returns false
|
String |
getPath() |
int |
getPort()
Get the port; apply the default for the protocol if necessary.
|
int |
getPortIfSpecified()
Get the port number from the port string, allowing for trailing blanks.
|
boolean |
getPostBodyRaw() |
String |
getProtocol()
Gets the protocol, with default.
|
String |
getProxyHost() |
String |
getProxyPass() |
int |
getProxyPortInt() |
String |
getProxyScheme() |
String |
getProxyUser() |
String |
getQueryString()
Gets the QueryString attribute of the UrlConfig object, using
UTF-8 to encode the URL
|
String |
getQueryString(String contentEncoding)
Gets the QueryString attribute of the UrlConfig object, using the
specified encoding to encode the parameter values put into the URL
|
int |
getResponseTimeout() |
boolean |
getSendFileAsPostBody()
Determine if the file should be sent as the entire Content body,
i.e.
|
boolean |
getSendParameterValuesAsPostBody()
Determine if none of the parameters have a name, and if that is the case,
it means that the parameter values should be sent as the entity body
|
static String[] |
getSourceTypeList() |
URL |
getUrl()
Get the URL, built from its component parts.
|
boolean |
getUseKeepAlive() |
boolean |
getUseMultipart()
Determine if we should use multipart/form-data or
application/x-www-form-urlencoded for the post
|
boolean |
getUseMultipartForPost()
Determine if we should use multipart/form-data or
application/x-www-form-urlencoded for the post
|
static String[] |
getValidMethodsAsArray() |
boolean |
hasArguments() |
boolean |
isConcurrentDwn()
Return if used a concurrent thread pool to get embedded resources.
|
boolean |
isImageParser() |
boolean |
isMonitor()
Deprecated.
since 3.2 always returns false
|
boolean |
isProtocolDefaultPort()
Tell whether the default port for the specified protocol is used
|
static boolean |
isSecure(String protocol) |
static boolean |
isSecure(URL url) |
protected boolean |
isSuccessCode(int code)
Determine if the HTTP status code is successful or not
i.e.
|
void |
parseArguments(String queryString) |
void |
parseArguments(String queryString,
String contentEncoding)
This method allows a proxy server to send over the raw text from a
browser's output stream to be parsed and stored correctly into the
UrlConfig object.
|
byte[] |
readResponse(SampleResult sampleResult,
InputStream in,
long length)
Read response from the input stream, converting to MD5 digest if the useMD5 property is set.
|
int |
replace(String regex,
String replaceBy,
boolean caseSensitive)
Replace by replaceBy in path and body (arguments) properties
|
protected HTTPSampleResult |
resultProcessing(boolean pAreFollowingRedirect,
int frameDepth,
HTTPSampleResult pRes)
Follow redirects and download page resources if appropriate.
|
SampleResult |
sample()
Perform a sample, and return the results
|
SampleResult |
sample(Entry e)
Do a sampling and return its results.
|
protected abstract HTTPSampleResult |
sample(URL u,
String method,
boolean areFollowingRedirect,
int depth)
Samples the URL passed in and stores the result in
HTTPSampleResult , following redirects and downloading
page resources as appropriate. |
void |
setArguments(Arguments value) |
void |
setAuthManager(AuthManager value) |
void |
setAutoRedirects(boolean value) |
void |
setCacheManager(CacheManager value) |
void |
setConcurrentDwn(boolean concurrentDwn) |
void |
setConcurrentPool(String poolSize) |
void |
setConnectTimeout(String value) |
void |
setContentEncoding(String charsetName)
Sets the value of the encoding to be used for the content.
|
void |
setCookieManager(CookieManager value) |
void |
setDNSResolver(DNSCacheManager cacheManager) |
void |
setDoBrowserCompatibleMultipart(boolean value) |
void |
setDomain(String value) |
void |
setDoMultipart(boolean value) |
void |
setDoMultipartPost(boolean value)
Deprecated.
|
void |
setEmbeddedUrlRE(String regex) |
void |
setFollowRedirects(boolean value) |
void |
setHeaderManager(HeaderManager value) |
void |
setHTTPFiles(HTTPFileArg[] files)
Saves the list of files.
|
void |
setImageParser(boolean parseImages) |
void |
setImplementation(String value) |
void |
setIpSource(String value)
set IP source to use - does not apply to Java HTTP implementation currently
|
void |
setIpSourceType(int value)
set IP/address source type to use
|
void |
setKeystoreConfig(KeystoreConfig value) |
void |
setMD5(boolean truth) |
void |
setMethod(String value) |
void |
setMonitor(boolean truth) |
void |
setMonitor(String value) |
void |
setPath(String path)
Sets the Path attribute of the UrlConfig object Also calls parseArguments
to extract and store any query arguments
|
void |
setPath(String path,
String contentEncoding)
Sets the PATH property; if the request is a GET or DELETE (and the path
does not start with http[s]://) it also calls
parseArguments(String, String)
to extract and store any query arguments. |
void |
setPort(int value) |
void |
setPostBodyRaw(boolean value) |
void |
setProtocol(String value) |
void |
setProxyHost(String host) |
void |
setProxyPass(String pass) |
void |
setProxyPortInt(String port) |
void |
setProxyScheme(String schema) |
void |
setProxyUser(String user) |
void |
setResponseTimeout(String value) |
void |
setUseKeepAlive(boolean value) |
void |
testEnded()
Called once for all threads after the end of a test.
|
void |
testEnded(String host)
Called once for all threads after the end of a test.
|
void |
testIterationStart(LoopIterationEvent event)
Each time through a Thread Group's test script, an iteration event is
fired for each thread.
|
void |
testStarted()
Called just before the start of the test from the main engine thread.
|
void |
testStarted(String host)
Called just before the start of the test from the main engine thread.
|
void |
threadFinished()
Called for each thread after all samples have been processed.
|
void |
threadStarted()
Called for each thread before starting sampling.
|
String |
toString() |
boolean |
useMD5() |
addPropertiesValues, addProperty, addProperty, canRemove, clear, clearTemporary, clone, emptyTemporary, equals, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getSearchableTokens, getThreadContext, getThreadName, hashCode, isEnabled, isRunningVersion, isTemporary, logProperties, mergeIn, propertyIterator, recoverRunningVersion, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse, traverseCollection, traverseMap, traverseProperty
finalize, getClass, notify, notifyAll, wait, wait, wait
canRemove, clear, clone, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getThreadContext, getThreadName, isEnabled, isRunningVersion, isTemporary, propertyIterator, recoverRunningVersion, removed, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse
public static final String ARGUMENTS
public static final String AUTH_MANAGER
public static final String COOKIE_MANAGER
public static final String KEYSTORE_CONFIG
public static final String SAMPLE_TIMEOUT
public static final String CACHE_MANAGER
public static final String HEADER_MANAGER
public static final String DNS_CACHE_MANAGER
public static final String DOMAIN
public static final String PORT
public static final String PROXYSCHEME
public static final String PROXYHOST
public static final String PROXYPORT
public static final String PROXYUSER
public static final String PROXYPASS
public static final String CONNECT_TIMEOUT
public static final String RESPONSE_TIMEOUT
public static final String METHOD
public static final String CONTENT_ENCODING
public static final String IMPLEMENTATION
public static final String PATH
public static final String FOLLOW_REDIRECTS
public static final String AUTO_REDIRECTS
public static final String PROTOCOL
public static final String URL
public static final String IP_SOURCE
public static final String IP_SOURCE_TYPE
public static final String USE_KEEPALIVE
public static final String DO_MULTIPART_POST
public static final String BROWSER_COMPATIBLE_MULTIPART
public static final String CONCURRENT_DWN
public static final String CONCURRENT_POOL
public static final int CONCURRENT_POOL_SIZE
public static final boolean BROWSER_COMPATIBLE_MULTIPART_MODE_DEFAULT
public static final int SOURCE_TYPE_DEFAULT
public static final String DEFAULT_METHOD
public static final String CONTENT_TYPE
public static final String IMAGE_PARSER
public static final String EMBEDDED_URL_RE
public static final String MONITOR
public static final String MD5
public static final int UNSPECIFIED_PORT
public static final String UNSPECIFIED_PORT_AS_STRING
public static final int URL_UNSPECIFIED_PORT
public static final String URL_UNSPECIFIED_PORT_AS_STRING
protected static final String NON_HTTP_RESPONSE_CODE
protected static final String NON_HTTP_RESPONSE_MESSAGE
public static final String POST_BODY_RAW
public static final boolean POST_BODY_RAW_DEFAULT
protected static final int MAX_REDIRECTS
protected static final int MAX_FRAME_DEPTH
public static String[] getSourceTypeList()
public boolean getSendFileAsPostBody()
public boolean getSendParameterValuesAsPostBody()
true
if there are parameters and none of these have a
name specified, or getPostBodyRaw()
returns
true
public boolean getUseMultipartForPost()
public boolean getUseMultipart()
public void setProtocol(String value)
public String getProtocol()
public void setPath(String path)
path
- The new Path valuepublic void setPath(String path, String contentEncoding)
parseArguments(String, String)
to extract and store any query arguments.path
- The new Path valuecontentEncoding
- The encoding used for the querystring parameter valuespublic String getPath()
public void setFollowRedirects(boolean value)
public boolean getFollowRedirects()
public void setAutoRedirects(boolean value)
public boolean getAutoRedirects()
public void setMethod(String value)
public String getMethod()
public void setContentEncoding(String charsetName)
charsetName
- the name of the encoding to be usedpublic String getContentEncoding()
public void setUseKeepAlive(boolean value)
public boolean getUseKeepAlive()
@Deprecated public void setDoMultipartPost(boolean value)
setDoMultipartPost(boolean)
value
- flag whether multiparts should be used@Deprecated public boolean getDoMultipartPost()
getDoMultipartPost()
public void setDoMultipart(boolean value)
public boolean getDoMultipart()
public void setDoBrowserCompatibleMultipart(boolean value)
public boolean getDoBrowserCompatibleMultipart()
public void setMonitor(String value)
public void setMonitor(boolean truth)
@Deprecated public String getMonitor()
@Deprecated public boolean isMonitor()
public void setImplementation(String value)
public String getImplementation()
public boolean useMD5()
public void setMD5(boolean truth)
public void addEncodedArgument(String name, String value)
name
- name of the argumentvalue
- value of the argumentpublic void addEncodedArgument(String name, String value, String metaData, String contentEncoding)
getArguments()
of arguments.name
- - the parameter namevalue
- - the parameter valuemetaData
- - normally just '='contentEncoding
- - the encoding, may be nullpublic void addNonEncodedArgument(String name, String value, String metadata, String contentType)
public boolean hasArguments()
public void addTestElement(TestElement el)
AbstractTestElement
addTestElement
in interface TestElement
addTestElement
in class AbstractTestElement
public void clearTestElementChildren()
TestElement.addTestElement(TestElement)
.
Default implementation - does nothing
Clears the Header Manager property so subsequent loops don't keep merging more elements
clearTestElementChildren
in interface TestElement
clearTestElementChildren
in class AbstractTestElement
public void setPort(int value)
public static int getDefaultPort(String protocol, int port)
protocol
- from URL.getProtocol()
port
- number from URL.getPort()
public int getPortIfSpecified()
public boolean isProtocolDefaultPort()
public int getPort()
public void setDomain(String value)
public String getDomain()
public void setConnectTimeout(String value)
public int getConnectTimeout()
public void setResponseTimeout(String value)
public int getResponseTimeout()
public String getProxyScheme()
public void setProxyScheme(String schema)
public String getProxyHost()
public void setProxyHost(String host)
public int getProxyPortInt()
public void setProxyPortInt(String port)
public String getProxyUser()
public void setProxyUser(String user)
public String getProxyPass()
public void setProxyPass(String pass)
public final void setArguments(Arguments value)
public Arguments getArguments()
public void setPostBodyRaw(boolean value)
value
- Boolean that indicates body will be sent as ispublic boolean getPostBodyRaw()
public void setAuthManager(AuthManager value)
public AuthManager getAuthManager()
public void setHeaderManager(HeaderManager value)
public HeaderManager getHeaderManager()
public void setCookieManager(CookieManager value)
public CookieManager getCookieManager()
public void setKeystoreConfig(KeystoreConfig value)
public KeystoreConfig getKeystoreConfig()
public void setCacheManager(CacheManager value)
public CacheManager getCacheManager()
public DNSCacheManager getDNSResolver()
public void setDNSResolver(DNSCacheManager cacheManager)
public boolean isImageParser()
public void setImageParser(boolean parseImages)
public String getEmbeddedUrlRE()
public void setEmbeddedUrlRE(String regex)
protected HTTPSampleResult errorResult(Throwable e, HTTPSampleResult res)
e
- Exception representing the error.res
- SampleResult to be modifiedpublic URL getUrl() throws MalformedURLException
As a special case, if the path starts with "http[s]://", then the path is assumed to be the entire URL.
MalformedURLException
- if url is malformedpublic String getQueryString()
public String getQueryString(String contentEncoding)
contentEncoding
- the encoding to use for encoding parameter valuespublic void parseArguments(String queryString, String contentEncoding)
queryString
- -
the query string, might be the post body of a http post request.contentEncoding
- -
the content encoding of the query string;
if non-null then it is used to decode thepublic void parseArguments(String queryString)
public SampleResult sample(Entry e)
public SampleResult sample()
protected abstract HTTPSampleResult sample(URL u, String method, boolean areFollowingRedirect, int depth)
HTTPSampleResult
, following redirects and downloading
page resources as appropriate.
When getting a redirect target, redirects are not followed and resources are not downloaded. The caller will take care of this.
u
- URL to samplemethod
- HTTP method: GET, POST,...areFollowingRedirect
- whether we're getting a redirect targetdepth
- Depth of this target in the frame structure. Used only to
prevent infinite recursion.protected HTTPSampleResult downloadPageResources(HTTPSampleResult pRes, HTTPSampleResult container, int frameDepth)
pRes
- result of the initial request - must contain an HTML responsecontainer
- for storing the results, if anyframeDepth
- Depth of this target in the frame structure. Used only to
prevent infinite recursion.public void testEnded()
Called once for all threads after the end of a test. This will use the same element instances as at the start of the test.
N.B. testStarted() and testEnded() are called from different threads.
testEnded
in interface TestStateListener
StandardJMeterEngine.stopTest()
public void testEnded(String host)
Called once for all threads after the end of a test. This will use the same element instances as at the start of the test.
N.B. testStarted() and testEnded() are called from different threads.
testEnded
in interface TestStateListener
host
- name of hostStandardJMeterEngine.stopTest()
public void testStarted()
Called just before the start of the test from the main engine thread. This is before the test elements are cloned. Note that not all the test variables will have been set up at this point.
N.B. testStarted() and testEnded() are called from different threads.
testStarted
in interface TestStateListener
StandardJMeterEngine.run()
public void testStarted(String host)
Called just before the start of the test from the main engine thread. This is before the test elements are cloned. Note that not all the test variables will have been set up at this point.
N.B. testStarted() and testEnded() are called from different threads.
testStarted
in interface TestStateListener
host
- name of hostStandardJMeterEngine.run()
protected HTTPSampleResult followRedirects(HTTPSampleResult res, int frameDepth)
The returned result will contain one subsample for each request issued, including the original one that was passed in. It will be an HTTPSampleResult that should mostly look as if the final destination of the redirect chain had been obtained in a single shot.
res
- result of the initial request - must be a redirect responseframeDepth
- Depth of this target in the frame structure. Used only to
prevent infinite recursion.protected HTTPSampleResult resultProcessing(boolean pAreFollowingRedirect, int frameDepth, HTTPSampleResult pRes)
pAreFollowingRedirect
- flag whether we are getting a redirect targetframeDepth
- Depth of this target in the frame structure. Used only to prevent infinite recursion.pRes
- sample result to processprotected boolean isSuccessCode(int code)
code
- status code to checkpublic HTTPFileArg[] getHTTPFiles()
public int getHTTPFileCount()
public void setHTTPFiles(HTTPFileArg[] files)
files
- list of files to savepublic static String[] getValidMethodsAsArray()
public static boolean isSecure(String protocol)
public static boolean isSecure(URL url)
public void threadStarted()
ThreadListener
threadStarted
in interface ThreadListener
public void threadFinished()
ThreadListener
threadFinished
in interface ThreadListener
public void testIterationStart(LoopIterationEvent event)
TestIterationListener
testIterationStart
in interface TestIterationListener
event
- the iteration eventpublic byte[] readResponse(SampleResult sampleResult, InputStream in, long length) throws IOException
For the MD5 case, the result byte count is set to the size of the original response.
Closes the inputStream
sampleResult
- sample to store information about the response intoin
- input stream from which to read the responselength
- expected input length or zeroIOException
- if reading the result failspublic void setIpSource(String value)
value
- IP source to usepublic String getIpSource()
public void setIpSourceType(int value)
value
- type of the IP/address sourcepublic int getIpSourceType()
public boolean isConcurrentDwn()
public void setConcurrentDwn(boolean concurrentDwn)
public String getConcurrentPool()
public void setConcurrentPool(String poolSize)
public boolean applies(ConfigTestElement configElement)
AbstractSampler
applies
in interface ConfigMergabilityIndicator
applies
in class AbstractSampler
configElement
- ConfigTestElement
AbstractSampler.applies(org.apache.jmeter.config.ConfigTestElement)
public int replace(String regex, String replaceBy, boolean caseSensitive) throws Exception
replace
in interface Replaceable
regex
- Regular expression to search forreplaceBy
- Text used as replacementcaseSensitive
- flag, whether search should be done case sensitiveException
- when something fails while replacingCopyright © 1998-2019 Apache Software Foundation. All Rights Reserved.