org.apache.jmeter.protocol.http.sampler

Class HTTPSamplerBase

Implemented Interfaces:
Cloneable, HTTPConstantsInterface, Sampler, Serializable, TestElement, TestListener, ThreadListener
Known Direct Subclasses:
AjpSampler, HTTPSampler, HTTPSampler2, WebServiceSampler

public abstract class HTTPSamplerBase
extends AbstractSampler
implements TestListener, ThreadListener, HTTPConstantsInterface

Common constants and methods for HTTP samplers

Field Summary

static String
ARGUMENTS
static String
AUTH_MANAGER
static String
AUTO_REDIRECTS
static String
CACHE_MANAGER
static String
CLIENT
static String
CONNECT_TIMEOUT
static String
CONTENT_ENCODING
static String
CONTENT_TYPE
static String
COOKIE_MANAGER
static String
DEFAULT_METHOD
static String
DOMAIN
static String
DO_MULTIPART_POST
static String
EMBEDDED_URL_RE
static String
FOLLOW_REDIRECTS
static String
HEADER_MANAGER
static String
IMAGE_PARSER
static String
IMPLEMENTATION
protected static int
MAX_FRAME_DEPTH
protected static int
MAX_REDIRECTS
static String
METHOD
static String
MONITOR
protected static String
NON_HTTP_RESPONSE_CODE
protected static String
NON_HTTP_RESPONSE_MESSAGE
static String
PATH
static String
PORT
static String
PROTOCOL
static String
RESPONSE_TIMEOUT
static int
UNSPECIFIED_PORT
A number to indicate that the port has not been set.
static String
UNSPECIFIED_PORT_AS_STRING
static String
URL
static int
URL_UNSPECIFIED_PORT
If the port is not present in a URL, getPort() returns -1
static String
URL_UNSPECIFIED_PORT_AS_STRING
static String
USE_KEEPALIVE

Fields inherited from interface org.apache.jmeter.protocol.http.util.HTTPConstantsInterface

APPLICATION_X_WWW_FORM_URLENCODED, CONNECTION_CLOSE, DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_PORT_STRING, DEFAULT_HTTP_PORT, DEFAULT_HTTP_PORT_STRING, DELETE, ENCODING_GZIP, ETAG, GET, HEAD, HEADER_AUTHORIZATION, HEADER_CONNECTION, HEADER_CONTENT_DISPOSITION, HEADER_CONTENT_ENCODING, HEADER_CONTENT_LENGTH, HEADER_CONTENT_TYPE, HEADER_COOKIE, HEADER_LOCATION, HEADER_SET_COOKIE, HTTP_1_1, IF_MODIFIED_SINCE, IF_NONE_MATCH, KEEP_ALIVE, LAST_MODIFIED, MULTIPART_FORM_DATA, OPTIONS, POST, PROTOCOL_HTTP, PROTOCOL_HTTPS, PUT, TRACE, TRANSFER_ENCODING

Fields inherited from interface org.apache.jmeter.testelement.TestElement

COMMENTS, ENABLED, GUI_CLASS, NAME, TEST_CLASS

Constructor Summary

HTTPSamplerBase()

Method Summary

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)
void
addNonEncodedArgument(String name, String value, String metadata)
void
addTestElement(TestElement el)
Object
clone()
protected HTTPSampleResult
downloadPageResources(HTTPSampleResult res, 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)
Obtain a result that will help inform the user that an error has occured during sampling, and how long it took to detect the error.
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
getClient()
int
getConnectTimeout()
String
getContentEncoding()
CookieManager
getCookieManager()
static int
getDefaultPort(String protocol, int port)
Get the port number for a URL, applying defaults if necessary.
boolean
getDoMultipartPost()
String
getDomain()
String
getEmbeddedUrlRE()
Get the regular expression URLs must match.
String
getFileField()
Deprecated. Use getHTTPFiles() array instead
String
getFilename()
Deprecated. Use getHTTPFiles() array instead
boolean
getFollowRedirects()
int
getHTTPFileCount()
HTTPFileArg[]
getHTTPFiles()
Get the collection of files as a list.
HeaderManager
getHeaderManager()
String
getImplementation()
String
getMethod()
String
getMimetype()
Deprecated. Use getHTTPFiles() array instead
String
getMonitor()
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.
String
getProtocol()
Gets the protocol, with default.
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 Post body, i.e. without any additional wrapping
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 post body
URL
getUrl()
Get the URL, built from its component parts.
boolean
getUseKeepAlive()
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
isImageParser()
boolean
isMonitor()
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. in range 200 to 399 inclusive
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, int length)
Read response from the input stream, converting to MD5 digest if the useMD5 property is set.
protected HTTPSampleResult
resultProcessing(boolean areFollowingRedirect, int frameDepth, HTTPSampleResult res)
Follow redirects and download page resources if appropriate. this works, but the container stuff here is what's doing it. followRedirects() is actually doing the work to make sure we have only one container to make this work more naturally, I think this method - sample() - needs to take an HTTPSamplerResult container parameter instead of a boolean:areFollowingRedirect.
SampleResult
sample()
Perform a sample, and return the 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.
SampleResult
sample(Entry e)
Do a sampling and return its results.
void
setArguments(Arguments value)
void
setAuthManager(AuthManager value)
void
setAutoRedirects(boolean value)
void
setCacheManager(CacheManager value)
void
setClient(String client)
void
setConnectTimeout(String value)
void
setContentEncoding(String value)
void
setCookieManager(CookieManager value)
void
setDoMultipartPost(boolean value)
void
setDomain(String value)
void
setEmbeddedUrlRE(String regex)
void
setFileField(String value)
Deprecated. use setHTTPFiles() instead
void
setFilename(String value)
Deprecated. use setHTTPFiles() instead
void
setFollowRedirects(boolean value)
void
setHTTPFiles(HTTPFileArg[] files)
Saves the list of files.
void
setHeaderManager(HeaderManager value)
void
setImageParser(boolean parseImages)
void
setImplementation(String value)
void
setMD5(boolean truth)
void
setMethod(String value)
void
setMimetype(String value)
Deprecated. use setHTTPFiles() instead
void
setMonitor(String value)
void
setMonitor(boolean truth)
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 attribute of the UrlConfig object Also calls parseArguments to extract and store any query arguments
void
setPort(int value)
void
setProtocol(String value)
void
setResponseTimeout(String value)
void
setUseKeepAlive(boolean value)
void
testEnded()
void
testEnded(String host)
void
testIterationStart(LoopIterationEvent event)
void
testStarted()
void
testStarted(String host)
void
threadFinished()
void
threadStarted()
String
toString()
boolean
useMD5()

Methods inherited from class org.apache.jmeter.testelement.AbstractTestElement

addProperty, addTestElement, canRemove, clear, clearTemporary, clone, emptyTemporary, equals, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getThreadContext, getThreadName, hashCode, isEnabled, isRunningVersion, isTemporary, logProperties, mergeIn, propertyIterator, recoverRunningVersion, removeProperty, setComment, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse, traverseCollection, traverseMap, traverseProperty

Field Details

ARGUMENTS

public static final String ARGUMENTS

AUTH_MANAGER

public static final String AUTH_MANAGER

AUTO_REDIRECTS

public static final String AUTO_REDIRECTS

CACHE_MANAGER

public static final String CACHE_MANAGER

CLIENT

public static final String CLIENT

CONNECT_TIMEOUT

public static final String CONNECT_TIMEOUT

CONTENT_ENCODING

public static final String CONTENT_ENCODING

CONTENT_TYPE

public static final String CONTENT_TYPE

COOKIE_MANAGER

public static final String COOKIE_MANAGER

DEFAULT_METHOD

public static final String DEFAULT_METHOD

DOMAIN

public static final String DOMAIN

DO_MULTIPART_POST

public static final String DO_MULTIPART_POST

EMBEDDED_URL_RE

public static final String EMBEDDED_URL_RE

FOLLOW_REDIRECTS

public static final String FOLLOW_REDIRECTS

HEADER_MANAGER

public static final String HEADER_MANAGER

IMAGE_PARSER

public static final String IMAGE_PARSER

IMPLEMENTATION

public static final String IMPLEMENTATION

MAX_FRAME_DEPTH

protected static final int MAX_FRAME_DEPTH

MAX_REDIRECTS

protected static final int MAX_REDIRECTS

METHOD

public static final String METHOD

MONITOR

public static final String MONITOR

NON_HTTP_RESPONSE_CODE

protected static final String NON_HTTP_RESPONSE_CODE

NON_HTTP_RESPONSE_MESSAGE

protected static final String NON_HTTP_RESPONSE_MESSAGE

PATH

public static final String PATH

PORT

public static final String PORT

PROTOCOL

public static final String PROTOCOL

RESPONSE_TIMEOUT

public static final String RESPONSE_TIMEOUT

UNSPECIFIED_PORT

public static final int UNSPECIFIED_PORT
A number to indicate that the port has not been set.
Field Value:
0

UNSPECIFIED_PORT_AS_STRING

public static final String UNSPECIFIED_PORT_AS_STRING

URL

public static final String URL

URL_UNSPECIFIED_PORT

public static final int URL_UNSPECIFIED_PORT
If the port is not present in a URL, getPort() returns -1
Field Value:
-1

URL_UNSPECIFIED_PORT_AS_STRING

public static final String URL_UNSPECIFIED_PORT_AS_STRING

USE_KEEPALIVE

public static final String USE_KEEPALIVE

Constructor Details

HTTPSamplerBase

public HTTPSamplerBase()

Method Details

addArgument

public void addArgument(String name,
                        String value)

addArgument

public void addArgument(String name,
                        String value,
                        String metadata)

addEncodedArgument

public void addEncodedArgument(String name,
                               String value)
Add an argument which has already been encoded

addEncodedArgument

public void addEncodedArgument(String name,
                               String value,
                               String metaData)

addEncodedArgument

public void addEncodedArgument(String name,
                               String value,
                               String metaData,
                               String contentEncoding)

addNonEncodedArgument

public void addNonEncodedArgument(String name,
                                  String value,
                                  String metadata)

addTestElement

public void addTestElement(TestElement el)
Specified by:
addTestElement in interface TestElement
Overrides:
addTestElement in interface AbstractTestElement

clone

public Object clone()
Specified by:
clone in interface TestElement
Overrides:
clone in interface AbstractTestElement

downloadPageResources

protected HTTPSampleResult downloadPageResources(HTTPSampleResult res,
                                                 HTTPSampleResult container,
                                                 int frameDepth)
Download the resources of an HTML page.

If createContainerResult is true, the returned result will contain one subsample for each request issued, including the original one that was passed in. It will otherwise look exactly like that original one.

If createContainerResult is false, one subsample will be added to the provided result for each requests issued.

Parameters:
res - result of the initial request - must contain an HTML response
container - for storing the results
frameDepth - Depth of this target in the frame structure. Used only to prevent infinite recursion.
Returns:
"Container" result with one subsample per request issued

encodeBackSlashes

protected static String encodeBackSlashes(String value)

encodeSpaces

protected String encodeSpaces(String path)

errorResult

protected HTTPSampleResult errorResult(Throwable e,
                                       HTTPSampleResult res)
Obtain a result that will help inform the user that an error has occured during sampling, and how long it took to detect the error.
Parameters:
e - Exception representing the error.
res - SampleResult
Returns:
a sampling result useful to inform the user about the exception.

followRedirects

protected HTTPSampleResult followRedirects(HTTPSampleResult res,
                                           int frameDepth)
Iteratively download the redirect targets of a redirect response.

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.

Parameters:
res - result of the initial request - must be a redirect response
frameDepth - Depth of this target in the frame structure. Used only to prevent infinite recursion.
Returns:
"Container" result with one subsample per request issued

getArguments

public Arguments getArguments()

getAuthManager

public AuthManager getAuthManager()

getAutoRedirects

public boolean getAutoRedirects()

getCacheManager

public CacheManager getCacheManager()

getClient

public String getClient()

getConnectTimeout

public int getConnectTimeout()

getContentEncoding

public String getContentEncoding()

getCookieManager

public CookieManager getCookieManager()

getDefaultPort

public static int getDefaultPort(String protocol,
                                 int port)
Get the port number for a URL, applying defaults if necessary. (Called by CookieManager.)
Parameters:
protocol - from URL.getProtocol()
port - number from URL.getPort()
Returns:
the default port for the protocol

getDoMultipartPost

public boolean getDoMultipartPost()

getDomain

public String getDomain()

getEmbeddedUrlRE

public String getEmbeddedUrlRE()
Get the regular expression URLs must match.
Returns:
regular expression (or empty) string

getFileField

public String getFileField()

Deprecated. Use getHTTPFiles() array instead

The name parameter to be applied to the file

getFilename

public String getFilename()

Deprecated. Use getHTTPFiles() array instead

The actual name of the file to POST

getFollowRedirects

public boolean getFollowRedirects()

getHTTPFileCount

public int getHTTPFileCount()

getHTTPFiles

public HTTPFileArg[] getHTTPFiles()
Get the collection of files as a list. The list is built up from the filename/filefield/mimetype properties, plus any additional entries saved in the FILE_ARGS property. If there are no valid file entries, then an empty list is returned.
Returns:
an array of file arguments (never null)

getHeaderManager

public HeaderManager getHeaderManager()

getImplementation

public String getImplementation()

getMethod

public String getMethod()

getMimetype

public String getMimetype()

Deprecated. Use getHTTPFiles() array instead


getMonitor

public String getMonitor()

getPath

public String getPath()

getPort

public int getPort()
Get the port; apply the default for the protocol if necessary.
Returns:
the port number, with default applied if required.

getPortIfSpecified

public int getPortIfSpecified()
Get the port number from the port string, allowing for trailing blanks.
Returns:
port number or UNSPECIFIED_PORT (== 0)

getProtocol

public String getProtocol()
Gets the protocol, with default.
Returns:
the protocol

getQueryString

public String getQueryString()
Gets the QueryString attribute of the UrlConfig object, using UTF-8 to encode the URL
Returns:
the QueryString value

getQueryString

public 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
Parameters:
contentEncoding - the encoding to use for encoding parameter values
Returns:
the QueryString value

getResponseTimeout

public int getResponseTimeout()

getSendFileAsPostBody

public boolean getSendFileAsPostBody()
Determine if the file should be sent as the entire Post body, i.e. without any additional wrapping
Returns:
true if specified file is to be sent as the body, i.e. FileField is blank

getSendParameterValuesAsPostBody

public 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 post body
Returns:
true if none of the parameters have a name specified

getUrl

public URL getUrl()
            throws MalformedURLException
Get the URL, built from its component parts.

As a special case, if the path starts with "http[s]://", then the path is assumed to be the entire URL.

Returns:
The URL to be requested by this sampler.

getUseKeepAlive

public boolean getUseKeepAlive()

getUseMultipartForPost

public boolean getUseMultipartForPost()
Determine if we should use multipart/form-data or application/x-www-form-urlencoded for the post
Returns:
true if multipart/form-data should be used and method is POST

getValidMethodsAsArray

public static String[] getValidMethodsAsArray()

hasArguments

public boolean hasArguments()

isImageParser

public boolean isImageParser()

isMonitor

public boolean isMonitor()

isProtocolDefaultPort

public boolean isProtocolDefaultPort()
Tell whether the default port for the specified protocol is used
Returns:
true if the default port number for the protocol is used, false otherwise

isSecure

public static boolean isSecure(String protocol)

isSecure

public static boolean isSecure(URL url)

isSuccessCode

protected boolean isSuccessCode(int code)
Determine if the HTTP status code is successful or not i.e. in range 200 to 399 inclusive
Returns:
whether in range 200-399 or not

parseArguments

public void parseArguments(String queryString)

parseArguments

public 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. For each name found, addArgument() is called
Parameters:
queryString - - the query string
contentEncoding - - the content encoding of the query string. The query string might actually be the post body of a http post request.

readResponse

public byte[] readResponse(SampleResult sampleResult,
                           InputStream in,
                           int length)
            throws IOException
Read response from the input stream, converting to MD5 digest if the useMD5 property is set. For the MD5 case, the result byte count is set to the size of the original response.
Parameters:
sampleResult -
in - input stream
length - expected input length or zero
Returns:
the response or the MD5 of the response

resultProcessing

protected HTTPSampleResult resultProcessing(boolean areFollowingRedirect,
                                            int frameDepth,
                                            HTTPSampleResult res)
Follow redirects and download page resources if appropriate. this works, but the container stuff here is what's doing it. followRedirects() is actually doing the work to make sure we have only one container to make this work more naturally, I think this method - sample() - needs to take an HTTPSamplerResult container parameter instead of a boolean:areFollowingRedirect.
Parameters:
areFollowingRedirect -
frameDepth -
res -
Returns:
the sample result

sample

public SampleResult sample()
Perform a sample, and return the results
Returns:
results of the sampling

sample

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.

When getting a redirect target, redirects are not followed and resources are not downloaded. The caller will take care of this.

Parameters:
u - URL to sample
method - HTTP method: GET, POST,...
areFollowingRedirect - whether we're getting a redirect target
depth - Depth of this target in the frame structure. Used only to prevent infinite recursion.
Returns:
results of the sampling

sample

public SampleResult sample(Entry e)
Do a sampling and return its results.
Specified by:
sample in interface Sampler
Parameters:
e - Entry to be sampled
Returns:
results of the sampling

setArguments

public void setArguments(Arguments value)

setAuthManager

public void setAuthManager(AuthManager value)

setAutoRedirects

public void setAutoRedirects(boolean value)

setCacheManager

public void setCacheManager(CacheManager value)

setClient

public void setClient(String client)

setConnectTimeout

public void setConnectTimeout(String value)

setContentEncoding

public void setContentEncoding(String value)

setCookieManager

public void setCookieManager(CookieManager value)

setDoMultipartPost

public void setDoMultipartPost(boolean value)

setDomain

public void setDomain(String value)

setEmbeddedUrlRE

public void setEmbeddedUrlRE(String regex)

setFileField

public void setFileField(String value)

Deprecated. use setHTTPFiles() instead

The name parameter to be applied to the file

setFilename

public void setFilename(String value)

Deprecated. use setHTTPFiles() instead

The actual name of the file to POST

setFollowRedirects

public void setFollowRedirects(boolean value)

setHTTPFiles

public void setHTTPFiles(HTTPFileArg[] files)
Saves the list of files. The first file is saved in the Filename/field/mimetype properties. Any additional files are saved in the FILE_ARGS array.
Parameters:
files - list of files to save

setHeaderManager

public void setHeaderManager(HeaderManager value)

setImageParser

public void setImageParser(boolean parseImages)

setImplementation

public void setImplementation(String value)

setMD5

public void setMD5(boolean truth)

setMethod

public void setMethod(String value)

setMimetype

public void setMimetype(String value)

Deprecated. use setHTTPFiles() instead

Set the files mime type
Parameters:
value -

setMonitor

public void setMonitor(String value)

setMonitor

public void setMonitor(boolean truth)

setPath

public void setPath(String path)
Sets the Path attribute of the UrlConfig object Also calls parseArguments to extract and store any query arguments
Parameters:
path - The new Path value

setPath

public void setPath(String path,
                    String contentEncoding)
Sets the Path attribute of the UrlConfig object Also calls parseArguments to extract and store any query arguments
Parameters:
path - The new Path value
contentEncoding - The encoding used for the querystring parameter values

setPort

public void setPort(int value)

setProtocol

public void setProtocol(String value)

setResponseTimeout

public void setResponseTimeout(String value)

setUseKeepAlive

public void setUseKeepAlive(boolean value)

testEnded

public void testEnded()
Specified by:
testEnded in interface TestListener

testEnded

public void testEnded(String host)
Specified by:
testEnded in interface TestListener

testIterationStart

public void testIterationStart(LoopIterationEvent event)
Specified by:
testIterationStart in interface TestListener

testStarted

public void testStarted()
Specified by:
testStarted in interface TestListener

testStarted

public void testStarted(String host)
Specified by:
testStarted in interface TestListener

threadFinished

public void threadFinished()
Specified by:
threadFinished in interface ThreadListener

threadStarted

public void threadStarted()
Specified by:
threadStarted in interface ThreadListener

toString

public String toString()

useMD5

public boolean useMD5()

Copyright © 1998-2010 Apache Software Foundation. All Rights Reserved.