Apache JMeter
1.9

org.apache.jmeter.protocol.http.sampler
Class HTTPSampler

java.lang.Object
  |
  +--org.apache.jmeter.testelement.AbstractTestElement
        |
        +--org.apache.jmeter.samplers.AbstractSampler
              |
              +--org.apache.jmeter.protocol.http.sampler.HTTPSampler
All Implemented Interfaces:
Cloneable, Sampler, Serializable, TestElement
Direct Known Subclasses:
SoapSampler, WebServiceSampler

public class HTTPSampler
extends AbstractSampler

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

Version:
$Revision: 1.47 $
Author:
Michael Stover
See Also:
Serialized Form

Nested Class Summary
static class HTTPSampler.Test
           
 
Field Summary
static String ARGUMENTS
           
static String AUTH_MANAGER
           
protected  HttpURLConnection conn
           
static String CONTENT_TYPE
           
static String COOKIE_MANAGER
           
static String DEFAULT_PROTOCOL
           
static String DOMAIN
           
static String ENCODED_PATH
           
protected static String encoding
           
static String FILE_DATA
           
static String FILE_FIELD
           
static String FILE_MIMETYPE
           
static String FILE_NAME
           
static String FOLLOW_REDIRECTS
           
static String GET
           
static String HEADER
           
static String HEADER_MANAGER
           
static String HEADERS
           
static String IMAGE_PARSER
           
static String METHOD
           
static String MIMETYPE
           
static String MULTIPART_FORM
           
protected static String NON_HTTP_RESPONSE_CODE
          !
protected static String NON_HTTP_RESPONSE_MESSAGE
          !
static String NORMAL_FORM
           
static String PATH
           
static String PORT
           
static String POST
           
static String PROTOCOL
           
static int UNSPECIFIED_PORT
          A number to indicate that the port has not been set.
static String URL
           
static String USE_KEEPALIVE
           
 
Fields inherited from class org.apache.jmeter.testelement.AbstractTestElement
log
 
Fields inherited from interface org.apache.jmeter.testelement.TestElement
ENABLED, GUI_CLASS, NAME, TEST_CLASS
 
Constructor Summary
HTTPSampler()
          Constructor for the HTTPSampler object
HTTPSampler(URL u)
           
 
Method Summary
 void addArgument(String name, String value)
           
 void addArgument(String name, String value, String metadata)
           
 void addEncodedArgument(String name, String value, String metaData)
           
 void addProperty(JMeterProperty prop)
           
 void addTestElement(TestElement el)
           
protected  long connect()
           
protected  void disconnect(HttpURLConnection conn)
           
 Arguments getArguments()
           
 AuthManager getAuthManager()
           
 CookieManager getCookieManager()
           
 String getDomain()
           
 String getEncodedPath()
           
 String getFileField()
           
 String getFilename()
           
 boolean getFollowRedirects()
           
 HeaderManager getHeaderManager()
           
 String getMethod()
           
 String getMimetype()
           
 String getPath()
           
 int getPort()
           
 String getProtocol()
           
 String getQueryString()
          Gets the QueryString attribute of the UrlConfig object
protected  byte[] getResponseHeaders(HttpURLConnection conn, SampleResult res)
          Gets the ResponseHeaders from the URLConnection, save them to the SampleResults object.
 URL getUrl()
          !
 boolean getUseKeepAlive()
           
 boolean isImageParser()
           
 void parseArguments(String queryString)
          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.
protected  byte[] readResponse(HttpURLConnection conn)
          Reads the response from the URL connection
 void removeArguments()
           
 SampleResult sample()
           
 SampleResult sample(Entry e)
          Do a sampling and return its results.
 void sendPostData(URLConnection connection)
          Send POST data from Entry to the open connection.
 void setArguments(Arguments value)
           
 void setAuthManager(AuthManager value)
           
 void setCookieManager(CookieManager value)
           
 void setDomain(String value)
           
 void setEncodedPath(String path)
           
 void setFileField(String value)
           
 void setFilename(String value)
           
 void setFollowRedirects(boolean value)
           
 void setHeaderManager(HeaderManager value)
           
 void setImageParser(boolean parseImages)
           
 void setMethod(String value)
           
 void setMimetype(String value)
           
 void setPath(String path)
          Sets the Path attribute of the UrlConfig object
 void setPort(int value)
           
 void setPostHeaders(URLConnection conn)
          Set request headers in preparation to opening a connection
 void setProperty(JMeterProperty prop)
          Sets and overwrites a property in the TestElement.
 void setProtocol(String value)
           
protected  HttpURLConnection setupConnection(URL u, String method, SampleResult res)
          Returns a HttpURLConnection with request method(GET or POST), headers, cookies, authorization properly set for the URL request
 void setUseKeepAlive(boolean value)
           
 String toString()
           
 
Methods inherited from class org.apache.jmeter.testelement.AbstractTestElement
clear, clone, equals, getName, getProperty, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsLong, getPropertyAsString, isRunningVersion, logProperties, mergeIn, nextIsNull, propertyIterator, recoverRunningVersion, removeProperty, setName, setProperty, setRunningVersion, traverse, traverseCollection, traverseMap, traverseProperty
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.jmeter.testelement.TestElement
clear, clone, getProperty, getPropertyAsBoolean, getPropertyAsFloat, getPropertyAsInt, getPropertyAsLong, getPropertyAsString, isRunningVersion, propertyIterator, recoverRunningVersion, removeProperty, setProperty, setRunningVersion, traverse
 

Field Detail

HEADERS

public static final String HEADERS
See Also:
Constant Field Values

HEADER

public static final String HEADER
See Also:
Constant Field Values

ARGUMENTS

public static final String ARGUMENTS
See Also:
Constant Field Values

AUTH_MANAGER

public static final String AUTH_MANAGER
See Also:
Constant Field Values

COOKIE_MANAGER

public static final String COOKIE_MANAGER
See Also:
Constant Field Values

HEADER_MANAGER

public static final String HEADER_MANAGER
See Also:
Constant Field Values

MIMETYPE

public static final String MIMETYPE
See Also:
Constant Field Values

DOMAIN

public static final String DOMAIN
See Also:
Constant Field Values

PORT

public static final String PORT
See Also:
Constant Field Values

METHOD

public static final String METHOD
See Also:
Constant Field Values

PATH

public static final String PATH
See Also:
Constant Field Values

FOLLOW_REDIRECTS

public static final String FOLLOW_REDIRECTS
See Also:
Constant Field Values

PROTOCOL

public static final String PROTOCOL
See Also:
Constant Field Values

DEFAULT_PROTOCOL

public static final String DEFAULT_PROTOCOL
See Also:
Constant Field Values

URL

public static final String URL
See Also:
Constant Field Values

POST

public static final String POST
See Also:
Constant Field Values

GET

public static final String GET
See Also:
Constant Field Values

USE_KEEPALIVE

public static final String USE_KEEPALIVE
See Also:
Constant Field Values

FILE_NAME

public static final String FILE_NAME
See Also:
Constant Field Values

FILE_FIELD

public static final String FILE_FIELD
See Also:
Constant Field Values

FILE_DATA

public static final String FILE_DATA
See Also:
Constant Field Values

FILE_MIMETYPE

public static final String FILE_MIMETYPE
See Also:
Constant Field Values

CONTENT_TYPE

public static final String CONTENT_TYPE
See Also:
Constant Field Values

NORMAL_FORM

public static final String NORMAL_FORM
See Also:
Constant Field Values

MULTIPART_FORM

public static final String MULTIPART_FORM
See Also:
Constant Field Values

ENCODED_PATH

public static final String ENCODED_PATH
See Also:
Constant Field Values

IMAGE_PARSER

public static final String IMAGE_PARSER
See Also:
Constant Field Values

UNSPECIFIED_PORT

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

See Also:
Constant Field Values

encoding

protected static String encoding

conn

protected transient HttpURLConnection conn

NON_HTTP_RESPONSE_CODE

protected static final String NON_HTTP_RESPONSE_CODE
!ToDo (Field description)

See Also:
Constant Field Values

NON_HTTP_RESPONSE_MESSAGE

protected static final String NON_HTTP_RESPONSE_MESSAGE
!ToDo (Field description)

See Also:
Constant Field Values
Constructor Detail

HTTPSampler

public HTTPSampler()
Constructor for the HTTPSampler object


HTTPSampler

public HTTPSampler(URL u)
Method Detail

setFileField

public void setFileField(String value)

getFileField

public String getFileField()

setFilename

public void setFilename(String value)

getFilename

public String getFilename()

setProtocol

public void setProtocol(String value)

getProtocol

public String getProtocol()

setPath

public void setPath(String path)
Sets the Path attribute of the UrlConfig object

Parameters:
path - The new Path value

setEncodedPath

public void setEncodedPath(String path)

getEncodedPath

public String getEncodedPath()

setProperty

public void setProperty(JMeterProperty prop)
Description copied from interface: TestElement
Sets and overwrites a property in the TestElement. This call will be ignored if the TestElement is currently a "running version".

Specified by:
setProperty in interface TestElement
Overrides:
setProperty in class AbstractTestElement

addProperty

public void addProperty(JMeterProperty prop)
Overrides:
addProperty in class AbstractTestElement

getPath

public String getPath()

setFollowRedirects

public void setFollowRedirects(boolean value)

getFollowRedirects

public boolean getFollowRedirects()

setMethod

public void setMethod(String value)

getMethod

public String getMethod()

setUseKeepAlive

public void setUseKeepAlive(boolean value)

getUseKeepAlive

public boolean getUseKeepAlive()

addEncodedArgument

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

addArgument

public void addArgument(String name,
                        String value)

addTestElement

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

addArgument

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

setPort

public void setPort(int value)

getPort

public int getPort()

setDomain

public void setDomain(String value)

getDomain

public String getDomain()

setArguments

public void setArguments(Arguments value)

getArguments

public Arguments getArguments()

setAuthManager

public void setAuthManager(AuthManager value)

getAuthManager

public AuthManager getAuthManager()

setHeaderManager

public void setHeaderManager(HeaderManager value)

getHeaderManager

public HeaderManager getHeaderManager()

setCookieManager

public void setCookieManager(CookieManager value)

getCookieManager

public CookieManager getCookieManager()

setMimetype

public void setMimetype(String value)

getMimetype

public String getMimetype()

isImageParser

public boolean isImageParser()

setImageParser

public void setImageParser(boolean parseImages)

sample

public SampleResult sample(Entry e)
Do a sampling and return its results.

Parameters:
e - Entry to be sampled
Returns:
results of the sampling

sample

public SampleResult sample()

getUrl

public URL getUrl()
           throws MalformedURLException
!ToDoo (Method description)

Returns:
!ToDo (Return description)
Throws:
MalformedURLException - !ToDo (Exception description)

getQueryString

public String getQueryString()
Gets the QueryString attribute of the UrlConfig object

Returns:
The QueryString value

setPostHeaders

public void setPostHeaders(URLConnection conn)
                    throws IOException
Set request headers in preparation to opening a connection

Throws:
IOException - if an I/O exception occurs

sendPostData

public void sendPostData(URLConnection connection)
                  throws IOException
Send POST data from Entry to the open connection.

Parameters:
connection - URLConnection of where POST data should be sent
Throws:
IOException - if an I/O exception occurs

setupConnection

protected HttpURLConnection setupConnection(URL u,
                                            String method,
                                            SampleResult res)
                                     throws IOException
Returns a HttpURLConnection with request method(GET or POST), headers, cookies, authorization properly set for the URL request

Parameters:
u - URL of the URL request
Returns:
HttpURLConnection of the URL request
Throws:
IOException - if an I/O Exception occurs

parseArguments

public void parseArguments(String queryString)
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.


readResponse

protected byte[] readResponse(HttpURLConnection conn)
                       throws IOException
Reads the response from the URL connection

Parameters:
conn - URL from which to read response
Returns:
response in String
Throws:
IOException - if an I/O exception occurs

getResponseHeaders

protected byte[] getResponseHeaders(HttpURLConnection conn,
                                    SampleResult res)
                             throws IOException
Gets the ResponseHeaders from the URLConnection, save them to the SampleResults object.

Parameters:
conn - connection from which the headers are read
res - where the headers read are stored
IOException

removeArguments

public void removeArguments()

connect

protected long connect()
                throws IOException
IOException

disconnect

protected void disconnect(HttpURLConnection conn)

toString

public String toString()
Overrides:
toString in class Object

Apache JMeter
1.9

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