org.apache.jmeter.protocol.http.sampler

Class HTTPSampler

Implemented Interfaces:
Cloneable, HTTPConstantsInterface, Interruptible, Sampler, Serializable, TestElement, TestListener, ThreadListener
Known Direct Subclasses:
AccessLogSampler

public class HTTPSampler
extends HTTPSamplerBase
implements Interruptible

A sampler which understands all the parts necessary to read statistics about HTTP requests, including cookies and authentication.

Field Summary

Fields inherited from class org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase

ARGUMENTS, AUTH_MANAGER, AUTO_REDIRECTS, CACHE_MANAGER, CLIENT, CONNECT_TIMEOUT, CONTENT_ENCODING, CONTENT_TYPE, COOKIE_MANAGER, DEFAULT_METHOD, DOMAIN, DO_MULTIPART_POST, EMBEDDED_URL_RE, FOLLOW_REDIRECTS, HEADER_MANAGER, IMAGE_PARSER, IMPLEMENTATION, MAX_FRAME_DEPTH, MAX_REDIRECTS, METHOD, MONITOR, NON_HTTP_RESPONSE_CODE, NON_HTTP_RESPONSE_MESSAGE, PATH, PORT, PROTOCOL, RESPONSE_TIMEOUT, UNSPECIFIED_PORT, UNSPECIFIED_PORT_AS_STRING, URL, URL_UNSPECIFIED_PORT, URL_UNSPECIFIED_PORT_AS_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

HTTPSampler()
Constructor for the HTTPSampler object.

Method Summary

protected void
disconnect(HttpURLConnection conn)
protected String
getResponseHeaders(HttpURLConnection conn)
Gets the ResponseHeaders from the URLConnection
boolean
interrupt()
protected byte[]
readResponse(HttpURLConnection conn, SampleResult res)
Reads the response from the URL connection.
protected HTTPSampleResult
sample(URL url, String method, boolean areFollowingRedirect, int frameDepth)
Samples the URL passed in and stores the result in HTTPSampleResult, following redirects and downloading page resources as appropriate.
protected String
sendPostData(URLConnection connection)
Send POST data from Entry to the open connection.
protected void
setPostHeaders(URLConnection conn)
Set request headers in preparation to opening a connection.
protected HttpURLConnection
setupConnection(URL u, String method, HTTPSampleResult res)
Returns an HttpURLConnection fully ready to attempt connection.

Methods inherited from class org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase

addArgument, addArgument, addEncodedArgument, addEncodedArgument, addEncodedArgument, addNonEncodedArgument, addTestElement, clone, downloadPageResources, encodeBackSlashes, encodeSpaces, errorResult, followRedirects, getArguments, getAuthManager, getAutoRedirects, getCacheManager, getClient, getConnectTimeout, getContentEncoding, getCookieManager, getDefaultPort, getDoMultipartPost, getDomain, getEmbeddedUrlRE, getFileField, getFilename, getFollowRedirects, getHTTPFileCount, getHTTPFiles, getHeaderManager, getImplementation, getMethod, getMimetype, getMonitor, getPath, getPort, getPortIfSpecified, getProtocol, getQueryString, getQueryString, getResponseTimeout, getSendFileAsPostBody, getSendParameterValuesAsPostBody, getUrl, getUseKeepAlive, getUseMultipartForPost, getValidMethodsAsArray, hasArguments, isImageParser, isMonitor, isProtocolDefaultPort, isSecure, isSecure, isSuccessCode, parseArguments, parseArguments, readResponse, resultProcessing, sample, sample, sample, setArguments, setAuthManager, setAutoRedirects, setCacheManager, setClient, setConnectTimeout, setContentEncoding, setCookieManager, setDoMultipartPost, setDomain, setEmbeddedUrlRE, setFileField, setFilename, setFollowRedirects, setHTTPFiles, setHeaderManager, setImageParser, setImplementation, setMD5, setMethod, setMimetype, setMonitor, setMonitor, setPath, setPath, setPort, setProtocol, setResponseTimeout, setUseKeepAlive, testEnded, testEnded, testIterationStart, testStarted, testStarted, threadFinished, threadStarted, toString, 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

Constructor Details

HTTPSampler

public HTTPSampler()
Constructor for the HTTPSampler object. Consider using HTTPSamplerFactory.newInstance() instead

Method Details

disconnect

protected void disconnect(HttpURLConnection conn)

getResponseHeaders

protected String getResponseHeaders(HttpURLConnection conn)
Gets the ResponseHeaders from the URLConnection
Parameters:
conn - connection from which the headers are read
Returns:
string containing the headers, one per line

interrupt

public boolean interrupt()
Specified by:
interrupt in interface Interruptible

readResponse

protected byte[] readResponse(HttpURLConnection conn,
                              SampleResult res)
            throws IOException
Reads the response from the URL connection.
Parameters:
conn - URL from which to read response
Returns:
response content

sample

protected HTTPSampleResult sample(URL url,
                                  String method,
                                  boolean areFollowingRedirect,
                                  int frameDepth)
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.

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

sendPostData

protected String sendPostData(URLConnection connection)
            throws IOException
Send POST data from Entry to the open connection. This also handles sending data for PUT requests
Parameters:
connection - URLConnection where POST data should be sent
Returns:
a String show what was posted. Will not contain actual file upload content

setPostHeaders

protected void setPostHeaders(URLConnection conn)
            throws IOException
Set request headers in preparation to opening a connection.
Parameters:
conn - URLConnection to set headers on

setupConnection

protected HttpURLConnection setupConnection(URL u,
                                            String method,
                                            HTTPSampleResult res)
            throws IOException
Returns an HttpURLConnection fully ready to attempt connection. This means it sets the request method (GET or POST), headers, cookies, and authorization for the URL request.

The request infos are saved into the sample result if one is provided.

Parameters:
u - URL of the URL request
method - GET, POST etc
res - sample result to save request infos to
Returns:
HttpURLConnection ready for .connect

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