Apache JMeter
2.0.1.20050615

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

java.lang.Object
  extended byorg.apache.jmeter.testelement.AbstractTestElement
      extended byorg.apache.jmeter.samplers.AbstractSampler
          extended byorg.apache.jmeter.protocol.http.sampler.HTTPSamplerBase
              extended byorg.apache.jmeter.protocol.http.sampler.HTTPSampler
All Implemented Interfaces:
Cloneable, Sampler, Serializable, TestElement, TestListener
Direct Known Subclasses:
AccessLogSampler, SoapSampler, WebServiceSampler

public class HTTPSampler
extends HTTPSamplerBase

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

Version:
$Revision: 1.91.2.5 $ Last updated $Date: 2004/10/03 14:23:30 $
See Also:
Serialized Form

Nested Class Summary
static class HTTPSampler.Test
           
 
Field Summary
 
Fields inherited from class org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase
ARGUMENTS, AUTH_MANAGER, AUTO_REDIRECTS, CONTENT_TYPE, COOKIE_MANAGER, DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT, DEFAULT_PROTOCOL, DOMAIN, FILE_DATA, FILE_FIELD, FILE_MIMETYPE, FILE_NAME, FOLLOW_REDIRECTS, GET, HEADER_MANAGER, IMAGE_PARSER, MAX_FRAME_DEPTH, MAX_REDIRECTS, METHOD, MIMETYPE, MONITOR, MULTIPART_FORM, NON_HTTP_RESPONSE_CODE, NON_HTTP_RESPONSE_MESSAGE, NORMAL_FORM, PATH, PORT, POST, PROTOCOL, UNSPECIFIED_PORT, URL, USE_KEEPALIVE
 
Fields inherited from interface org.apache.jmeter.testelement.TestElement
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
protected  void modifyHeaderValues(HttpURLConnection conn, int headerIndex, StringBuffer resultBuf)
           
protected  byte[] readResponse(HttpURLConnection conn)
          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.
 void sendPostData(URLConnection connection)
          Send POST data from Entry to the open connection.
 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, addTestElement, clone, downloadPageResources, encodeSpaces, errorResult, getArguments, getAuthManager, getCookieManager, getDomain, getFileField, getFilename, getFollowRedirects, getHeaderManager, getMethod, getMimetype, getMonitor, getPath, getPort, getProtocol, getQueryString, getUrl, getUseKeepAlive, isImageParser, isMonitor, parseArguments, sample, sample, setArguments, setAuthManager, setCookieManager, setDomain, setFileField, setFilename, setFollowRedirects, setHeaderManager, setImageParser, setMethod, setMimetype, setMonitor, setPath, setPort, setProtocol, setUseKeepAlive, testEnded, testEnded, testIterationStart, testStarted, testStarted, toString
 
Methods inherited from class org.apache.jmeter.testelement.AbstractTestElement
addProperty, canRemove, clear, clearTemporary, emptyTemporary, equals, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsLong, getPropertyAsString, getThreadContext, getThreadName, isRunningVersion, isTemporary, logProperties, mergeIn, nextIsNull, propertyIterator, recoverRunningVersion, removeProperty, setName, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, threadFinished, threadStarted, 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
canRemove, clear, getProperty, getPropertyAsBoolean, getPropertyAsFloat, getPropertyAsInt, getPropertyAsLong, getPropertyAsString, getThreadContext, getThreadName, isRunningVersion, isTemporary, propertyIterator, recoverRunningVersion, removeProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, threadFinished, threadStarted, traverse
 

Constructor Detail

HTTPSampler

public HTTPSampler()
Constructor for the HTTPSampler object.

Method Detail

setPostHeaders

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

Parameters:
conn - URLConnection to set headers on
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 where POST data should be sent
Throws:
IOException - if an I/O exception occurs

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 - http/https
res - sample result to save request infos to
Returns:
HttpURLConnection ready for .connect
Throws:
IOException - if an I/O Exception occurs

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 content
Throws:
IOException - if an I/O exception occurs

getResponseHeaders

protected String getResponseHeaders(HttpURLConnection conn)
                             throws IOException
Gets the ResponseHeaders from the URLConnection

Parameters:
conn - connection from which the headers are read
Returns:
string containing the headers, one per line
Throws:
IOException

modifyHeaderValues

protected void modifyHeaderValues(HttpURLConnection conn,
                                  int headerIndex,
                                  StringBuffer resultBuf)
Parameters:
conn - connection
headerIndex - which header to use
resultBuf - output string buffer

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.

Specified by:
sample in class 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

disconnect

protected void disconnect(HttpURLConnection conn)

Apache JMeter
2.0.1.20050615

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