Class Request
- java.lang.Object
-
- com.facilita.fc.web.Request
-
public class Request extends java.lang.Object
Describes an HTTP request.A
Request
object is created by callingWebBrowser.createRequest(HttpMethod, Url)
. The request can then be sent to the web server using thesend()
orsendTopLevel()
methods.e.g.
Request request1 = getWebBrowser().createRequest(HttpMethod.GET, new Url("http://www.testplant.com/"), 1); Response response1 = request1.send();
- See Also:
Response
-
-
Constructor Summary
Constructors Constructor Description Request(long cPtr, boolean cMemoryOwn)
For internal use only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addKeepSubRequestContentType(java.lang.String typeFragment)
Adds a Content-Type fragment, so the content of sub-request responses that match the specified Content-Type fragment will be kept.void
addKeepSubRequestContentUrl(java.lang.String urlFragment)
Adds a URL, so the content of sub-request responses that match the specified URL fragment will be kept.void
addSubRequest(Protocol protocol, IpEndPoint ipEndPoint, java.lang.String path)
Adds a URL to the list of sub-requests that will be fetched from the web server by this request.void
addSubRequest(Url url)
Adds aUrl
to the list of sub-requests that will be fetched from the web server by this request.void
addSubRequest(java.lang.String resource)
Adds a URL to the list of sub-requests that will be fetched from the web server by this request.void
clearHeaders()
Clears the list of HTTP headers for thisRequest
.boolean
containsHeader(java.lang.String header)
Returnstrue
if thisRequest
contains a particular HTTP header.void
delete()
void
end()
Ends this request - this method should be called when eithersendTopLevel()
orsendSubRequests(Response)
has been called.java.lang.String
getCharactersAllowedInPostedForm()
Gets the characters that will NOT be percent-encoded when aForm
is sent to the web server using a POST request.int
getChunkSize()
Gets the size in bytes of the chunk size to use when sending data using Transfer-Encoding: chunkedjava.lang.String
getContentType()
Gets the value of the"Content-Type"
HTTP header.java.util.List<java.lang.String>
getContentTypeFragments()
Gets a list of all the Content-Type fragments for which the content of sub-request responses will be kept.java.util.List<java.lang.String>
getContentUrlFragments()
Gets a list of all the URL fragments for which the content of sub-request responses will be kept.static long
getCPtr(Request obj)
For internal use only.boolean
getFollowRedirects()
Returnstrue
if redirects will automatically be followed for thisRequest
.java.util.List<java.lang.String>
getHeaderKeys()
Gets a list of names of all the HTTP request headers set in thisRequest
.java.lang.String
getHeaderValue(java.lang.String header)
Gets the value of the specified HTTP request header.HttpStatusCategory
getHttpStatusCategory(HttpStatus status)
Returns the registered status category for the given HTTP status.int
getID()
Gets the unique ID that has been assigned to thisRequest
.java.util.List<Url>
getIgnoredSubRequests()
Gets the list of sub-requests that will be ignored when fetching sub-requests from the web server.boolean
getIncludeQueryDataInLabels()
Returnstrue
if URLs with different query data should be considered different from each other for analysis purposes.boolean
getKeepAllSubRequestContent()
Returnstrue
if the content of responses to sub-requests will be kept.boolean
getKeepContent()
Returnstrue
if the content of responses will be kept.java.lang.String
getMessageBody()
Gets the body of the HTTP request that will be sent to the server.HttpMethod
getMethod()
int
getReference()
Gets the reference id that was passed to theWebBrowser.createRequest(HttpMethod, Url, int)
method when thisRequest
object was created.java.lang.String
getReferer()
Gets the value of the"Referer"
HTTP header.boolean
getRetrieveSubRequests()
Returnstrue
if sub-requests will be retrieved for thisRequest
.java.util.List<Url>
getSubRequests()
Gets the list of sub-requests that will be fetched from the web server by this request.int
getSubRequestThreadCount()
Gets the number of threads that will be used to fetch sub-requests from the web server.boolean
getTimeEveryHttpRequest()
Returnstrue
if sub-requests will be timed as well as top-level HTTP requests.Url
getUrl()
Gets theUrl
that thisRequest
is targeting.java.lang.String
getUserAgent()
Gets the value of the"User-Agent"
HTTP header.java.lang.String
getVersion()
Gets the HTTP version as aString
.boolean
hasReferer()
Returnstrue
if the"Referer"
HTTP header has been set for thisRequest
.void
ignoreSubRequest(Protocol protocol, IpEndPoint ipEndPoint, java.lang.String path)
Specifies a URL that will be ignored when fetching sub-requests from the web server.void
ignoreSubRequest(Url url)
Specifies aUrl
that will be ignored when fetching sub-requests from the web server.void
ignoreSubRequest(java.lang.String resource)
Specifies a URL that will be ignored when fetching sub-requests from the web server.boolean
isDynatraceIntegrationEnabled()
Returnstrue
if dynaTrace integration is enabled.void
removeHeader(java.lang.String header)
Removes an HTTP header from thisRequest
.void
removeKeepSubRequestContentType(java.lang.String typeFragment)
Removes a Content-Type fragment, so the content of sub-request responses that match the specified Content-Type fragment will no longer be kept.void
removeKeepSubRequestContentUrl(java.lang.String urlFragment)
Removes a URL, so the content of sub-request responses that match the specified URL fragment will no longer be kept.Response
send()
Sends this request and any sub-requests to the web server, and waits for all the responses to be served.void
sendSubRequests(Response response)
Sends the sub-requests for this request to the web server, and waits for the responses.Response
sendTopLevel()
Sends this request to the web server, and waits for the response to be served, but doesn't send any sub-requests.void
setCharactersAllowedInPostedForm(java.lang.String charactersAllowedInPostedForm)
Sets the characters that will NOT be percent-encoded when aForm
is sent to the web server using a POST request.void
setChunkSize(int chunkSize)
Sets the size in bytes of the chunk size to use when sending data using Transfer-Encoding: chunkedvoid
setContentType(java.lang.String contentType)
Sets the value of the"Content-Type"
HTTP header.void
setDynatraceIntegrationEnabled(boolean value)
Sets whether or not dynaTrace integration is enabled.void
setFollowRedirects()
Sets the behaviour of thisRequest
so redirects will automatically be followed.void
setFollowRedirects(boolean followRedirects)
Sets whether redirects will automatically be followed for thisRequest
.void
setHeader(java.lang.String header)
Sets an HTTP header for thisRequest
.void
setHeader(java.lang.String header, java.lang.String value)
Sets an HTTP header for thisRequest
.void
setHttpStatusCategory(HttpStatusRange statusRange, HttpStatusCategory category)
Registers the provided HTTP status code range against the predefined category.void
setHttpStatusCategory(HttpStatus status, HttpStatusCategory category)
Registers the provided HTTP status code range against the predefined category.void
setIgnoredSubRequests(java.util.List<Url> ignoreList)
Sets the list of sub-requests that will be ignored when fetching sub-requests from the web server.void
setIncludeQueryDataInLabels(boolean includeQueryDataInLabels)
Sets whether URLs with different query data should be considered different from each other for analysis purposes.void
setKeepAlive(boolean f)
Sets the value of the"Connection"
request header.void
setKeepAllSubRequestContent(boolean keep)
Sets whether the content of responses to sub-requests should be kept.void
setKeepContent(boolean keep)
Sets whether to keep the content of responses.void
setMessageBody(byte[] messageBody)
Sets the body of the HTTP request that will be sent to the server.void
setMessageBody(Form form)
Sets the body of the HTTP request that will be sent to the server, as name/value pairs extracted from the specifiedForm
object.void
setMessageBody(java.lang.String messageBody)
Sets the body of the HTTP request that will be sent to the server.void
setMessageBody(java.lang.String messageBody, java.lang.String encoding)
Sets the body of the HTTP request that will be sent to the server, specifying the character encoding to use to encode the post data.void
setMessageBodyFromFile(java.lang.String fileName)
Sets the body of the HTTP request that will be sent to the server, by loading data from a data file.void
setOffsetEdit(OffsetEditSequence edits)
Sets anOffsetEditSequence
object to be applied to the message body of thisRequest
object, immediately before the request is sent to the web server.void
setReferer(Url url)
Sets the value of the"Referer"
HTTP header.void
setReferer(java.lang.String referer)
Sets the value of the"Referer"
HTTP header.void
setRetrieveSubRequests(boolean getEmbeddedUrls)
Sets whether sub-requests will be retrieved for thisRequest
.void
setSubRequests(java.util.List<Url> resourceList)
Sets the list of sub-requests that will be fetched from the web server by this request.void
setSubRequestThreadCount(int subRequestThreadCount)
Sets the number of threads that will be used to fetch sub-requests from the web server.void
setTimeEveryHttpRequest(boolean timings)
Sets whether sub-requests should be timed as well as top-level HTTP requests.void
setUrl(Url url)
Sets theUrl
that thisRequest
is targeting.void
setUserAgent(java.lang.String userAgent)
Sets the value of the"User-Agent"
HTTP header.void
setVersion(java.lang.String version)
Sets the HTTP version.void
unsetReferer()
Removes the"Referer"
HTTP header.
-
-
-
Method Detail
-
getCPtr
public static long getCPtr(Request obj)
For internal use only. Of no interest to the user.- Parameters:
obj
- a reference to an object of this class- Returns:
- a long containing the address of the CPP wrapped object
-
delete
public void delete()
-
getUrl
public Url getUrl()
Gets theUrl
that thisRequest
is targeting.- Returns:
- the target
Url
- See Also:
WebBrowser.createRequest(com.facilita.fc.web.HttpMethod, com.facilita.fc.web.Url, int)
,setUrl(Url)
-
setUrl
public void setUrl(Url url)
Sets theUrl
that thisRequest
is targeting.- Parameters:
url
- the targetUrl
- See Also:
getUrl()
-
getMethod
public HttpMethod getMethod() throws BadValueException
- Returns:
- the HTTP method that this
Request
uses - Throws:
BadValueException
- An internal error occurred- See Also:
WebBrowser.createRequest(com.facilita.fc.web.HttpMethod, com.facilita.fc.web.Url, int)
-
send
public Response send() throws java.lang.Exception
Sends this request and any sub-requests to the web server, and waits for all the responses to be served. The top-level request is sent first. Once the server has responded, a list of sub-requests is compiled. This list is made up of:- Any sub-requests that are identified by parsing the initial
Response
- The sub-requests explicitly defined by calls to
addSubRequest(Url)
,setSubRequests(List)
For example:
In this example, eggPlant Performance will first make an HTTP GET request to the url specified byUrl url1 = new Url(protocol1, localhost, "/"); Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); request1.addSubRequest(protocol1, localhost, "/Themes/TestPlant/Content/images/orange_button_bg.gif"); Response response1 = request1.send();
url1
(http://localhost/
). Once the server responds, eggPlant Performance will parse the HTML in the response, looking for additional resources that need to be downloaded (such as images, stylesheets or javascript files). These resources will be requested from the server. In addition, the sub-request that has been explicitly added usingaddSubRequest(Url)
(http://localhost/Themes/TestPlant/Content/images/orange_button_bg.gif
) will also be requested from the server.- Returns:
- a
Response
object that describes the HTTP response from the server, including any sub-responses - Throws:
java.lang.Exception
- There was an error when sending the request- See Also:
addSubRequest(String)
,ignoreSubRequest(String)
,setSubRequests(List)
,setIgnoredSubRequests(List)
,sendTopLevel()
,sendSubRequests(Response)
,setSubRequestThreadCount(int)
- Any sub-requests that are identified by parsing the initial
-
sendTopLevel
public Response sendTopLevel() throws java.lang.Exception
Sends this request to the web server, and waits for the response to be served, but doesn't send any sub-requests. This is unlikesend()
which also sends sub-requests. You can send the sub-requests later by callingsendSubRequests(Response)
.e.g.
Url url1 = new Url(protocol1, localhost, "/"); Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Send the top-level request only Response response1 = request1.sendTopLevel(); // Now send the sub-requests request1.sendSubRequests(response1); // We must call end() when we have finished with this request request1.end();
- Returns:
- the
Response
to the top-level request. Note that this will not contain any sub-responses - Throws:
java.lang.Exception
- There was an error when sending the request- See Also:
send()
,sendSubRequests(Response)
,end()
-
setMessageBody
public void setMessageBody(java.lang.String messageBody)
Sets the body of the HTTP request that will be sent to the server. This method is normally used with a POST or PUT request.- If the message body is a
Form
, then you should use thesetMessageBody(Form)
overload instead. - If the message body consists of binary data, then you should use the
setMessageBody(byte[])
overload. - If the message body is very large, then it may be easier to store the data in a file and use the
setMessageBodyFromFile(String)
method instead.
e.g.
Url url32 = new Url(protocol1, localhost, "/login"); Request request32 = getWebBrowser().createRequest(HttpMethod.POST, url32, 32); request32.setMessageBody("Email=user@facilita.com&Password=password&RememberMe=false"); Response response32 = request32.send();
- Parameters:
messageBody
- the body of the message (e.g. the POST data)- See Also:
setMessageBody(Form)
,setMessageBody(byte[])
,setMessageBodyFromFile(String)
- If the message body is a
-
setMessageBody
public void setMessageBody(java.lang.String messageBody, java.lang.String encoding) throws java.io.UnsupportedEncodingException
Sets the body of the HTTP request that will be sent to the server, specifying the character encoding to use to encode the post data. This method is normally used with a POST or PUT request.- If the message body is a
Form
, then you should use thesetMessageBody(Form)
overload instead. - If the message body consists of binary data, then you should use the
setMessageBody(byte[])
overload. - If the message body is very large, then it may be easier to store the data in a file and use the
setMessageBodyFromFile(String)
method instead.
e.g.
Url url32 = new Url(protocol1, localhost, "/login"); Request request32 = getWebBrowser().createRequest(HttpMethod.POST, url32, 32); request32.setMessageBody("Email=user@facilita.com&Password=password&RememberMe=false", "UTF-8"); Response response32 = request32.send();
- Parameters:
messageBody
- the body of the message (e.g. the POST data)encoding
- the character encoding to use when encoding the message body- Throws:
java.io.UnsupportedEncodingException
- The specified encoding is not supported.- See Also:
setMessageBody(String)
,setMessageBody(byte[])
,setMessageBodyFromFile(String)
- If the message body is a
-
sendSubRequests
public void sendSubRequests(Response response) throws java.lang.Exception
Sends the sub-requests for this request to the web server, and waits for the responses. The response parameter should be theResponse
object that was returned by a call tosendTopLevel()
.This method will compile a list of sub-requests to send to the web server. This list is made up of:
- Any sub-requests that are identified by parsing the initial
Response
- The sub-requests explicitly defined by calls to
addSubRequest(Url)
,setSubRequests(List)
The sub-responses will be attached to the Response object that is passed in, and can be accessed by calling the
Response.getSubResponses()
method.e.g.
Url url1 = new Url(protocol1, localhost, "/"); Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Send the top-level request only Response response1 = request1.sendTopLevel(); // Now send the sub-requests request1.sendSubRequests(response1); // We must call end() when we have finished with this request request1.end();
- Parameters:
response
- theResponse
object returned by a call tosendTopLevel()
- Throws:
java.lang.Exception
- An error occurred when sending the sub-requests- See Also:
send()
,sendTopLevel()
,end()
,setSubRequestThreadCount(int)
- Any sub-requests that are identified by parsing the initial
-
end
public void end()
Ends this request - this method should be called when eithersendTopLevel()
orsendSubRequests(Response)
has been called. It tells eggPlant Performance that no more HTTP requests will be made as part of thisRequest
object.Note that it is not necessary to call this method if you have called
send()
rather thansendTopLevel()
orsendSubRequests(Response)
.e.g.
Url url1 = new Url(protocol1, localhost, "/"); Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Send the top-level request only Response response1 = request1.sendTopLevel(); // Now send the sub-requests request1.sendSubRequests(response1); // We must call end() when we have finished with this request request1.end();
- See Also:
sendTopLevel()
,sendSubRequests(Response)
-
getSubRequests
public java.util.List<Url> getSubRequests() throws com.facilita.exception.InternalError
Gets the list of sub-requests that will be fetched from the web server by this request. The sub-requests will be fetched whensend()
orsendSubRequests(Response)
are called.- Returns:
- the list of sub-requests that will be fetched from the web server by this request
- Throws:
com.facilita.exception.InternalError
- An internal error occurred
-
setSubRequests
public void setSubRequests(java.util.List<Url> resourceList)
Sets the list of sub-requests that will be fetched from the web server by this request. The sub-requests will be fetched whensend()
orsendSubRequests(Response)
are called.e.g.
Url url1 = new Url(protocol1, localhost, "/"); // Create a GET request Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Create a list of sub-requests List%lt;Url> subRequests = new ArrayList<Url>(); subRequests.add(new Url(protocol1, localhost, "/Themes/TestPlant/Content/images/orange_button_bg.gif")); subRequests.add(new Url(protocol1, localhost, "/Themes/TestPlant/Content/images/bg_maincolumn_3.gif")); subRequests.add(new Url(protocol1, localhost, "/Themes/TestPlant/Content/images/logo-reflection.gif")); // Attach the list of sub-requests to the top-level request request1.setSubRequests(subRequests); // Send the top-level request to the server, followed by all of the sub-requests Response response1 = request1.send();
- Parameters:
resourceList
- the list of sub-requests that should be fetched- See Also:
send()
,sendSubRequests(Response)
,addSubRequest(String)
,ignoreSubRequest(String)
-
getIgnoredSubRequests
public java.util.List<Url> getIgnoredSubRequests() throws com.facilita.exception.InternalError
Gets the list of sub-requests that will be ignored when fetching sub-requests from the web server. Any requests included in this list will not be downloaded, even if references to them are found in the HTML of the top-level request.- Returns:
- the list of sub-requests that will be ignored when fetching sub-requests from the web server.
- Throws:
com.facilita.exception.InternalError
- an internal error occurred
-
setIgnoredSubRequests
public void setIgnoredSubRequests(java.util.List<Url> ignoreList)
Sets the list of sub-requests that will be ignored when fetching sub-requests from the web server. Any requests included in this list will not be downloaded, even if references to them are found in the HTML of the top-level request.e.g.
Url url1 = new Url(protocol1, localhost, "/"); // Create a GET request Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Create a list of sub-requests List<Url> subRequests = new ArrayList<Url>(); subRequests.add(new Url(protocol1, localhost, "/Themes/TestPlant/Content/images/orange_button_bg.gif")); subRequests.add(new Url(protocol1, localhost, "/Themes/TestPlant/Content/images/bg_maincolumn_3.gif")); subRequests.add(new Url(protocol1, localhost, "/Themes/TestPlant/Content/images/logo-reflection.gif")); // Specify that all requests on this list should be ignored when fetching sub-requests request1.setIgnoredSubRequests(subRequests); Response response1 = request1.send();
- Parameters:
ignoreList
- the list of sub-requests to ignore- See Also:
send()
,sendSubRequests(Response)
,ignoreSubRequest(String)
,addSubRequest(String)
-
ignoreSubRequest
public void ignoreSubRequest(Url url)
Specifies aUrl
that will be ignored when fetching sub-requests from the web server. This URL will not be downloaded, even if a reference to it is found in the HTML of the top-level request.e.g.
Url url1 = new Url(protocol1, localhost, "/"); // Create a GET request Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Specify the sub-requests to ignore request1.ignoreSubRequest(new Url(protocol1, localhost, "/Themes/TestPlant/Content/images/orange_button_bg.gif")); request1.ignoreSubRequest(new Url(protocol1, localhost, "/Themes/TestPlant/Content/images/bg_maincolumn_3.gif")); request1.ignoreSubRequest(new Url(protocol1, localhost, "/Themes/TestPlant/Content/images/logo-reflection.gif")); Response response1 = request1.send();
- Parameters:
url
- the sub-request to ignore- See Also:
send()
,sendSubRequests(Response)
,ignoreSubRequest(String)
,setIgnoredSubRequests(List)
,addSubRequest(String)
-
ignoreSubRequest
public void ignoreSubRequest(java.lang.String resource)
Specifies a URL that will be ignored when fetching sub-requests from the web server. This URL will not be downloaded, even if a reference to it is found in the HTML of the top-level request.e.g.
Url url1 = new Url(protocol1, localhost, "/"); // Create a GET request Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Specify the sub-request to ignore request1.ignoreSubRequest("http://localhost/Themes/TestPlant/Content/images/orange_button_bg.gif"); Response response1 = request1.send();
- Parameters:
resource
- the sub-request to ignore- See Also:
send()
,sendSubRequests(Response)
,ignoreSubRequest(Url)
,setIgnoredSubRequests(List)
,addSubRequest(String)
-
ignoreSubRequest
public void ignoreSubRequest(Protocol protocol, IpEndPoint ipEndPoint, java.lang.String path) throws NoSuchValueException
Specifies a URL that will be ignored when fetching sub-requests from the web server. This URL will not be downloaded, even if a reference to it is found in the HTML of the top-level request.e.g.
Url url1 = new Url(protocol1, localhost, "/"); // Create a GET request Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Specify the sub-requests to ignore request1.ignoreSubRequest(protocol1, localhost, "/Themes/TestPlant/Content/images/orange_button_bg.gif"); request1.ignoreSubRequest(protocol1, localhost, "/Themes/TestPlant/Content/images/bg_maincolumn_3.gif"); request1.ignoreSubRequest(protocol1, localhost, "/Themes/TestPlant/Content/images/logo-reflection.gif"); Response response1 = request1.send();
- Parameters:
protocol
- the protocol of the sub-request to ignoreipEndPoint
- the IpEndPoint of the sub-request to ignorepath
- the path of the sub-request to ignore- Throws:
NoSuchValueException
- theProtocol
is not valid- See Also:
send()
,sendSubRequests(Response)
,ignoreSubRequest(Url)
,setIgnoredSubRequests(List)
,addSubRequest(String)
-
addSubRequest
public void addSubRequest(Url url)
Adds aUrl
to the list of sub-requests that will be fetched from the web server by this request. The sub-requests will be fetched whensend()
orsendSubRequests(Response)
are called.e.g.
Url url1 = new Url(protocol1, localhost, "/"); // Create a GET request Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Add a sub-request request1.addSubRequest(new Url(protocol1, localhost, "/Themes/TestPlant/Content/images/orange_button_bg.gif")); // Send the top-level request to the server, followed by all of the sub-requests Response response1 = request1.send();
- Parameters:
url
- the url that should be fetched- See Also:
send()
,sendSubRequests(Response)
,addSubRequest(String)
,ignoreSubRequest(String)
-
addSubRequest
public void addSubRequest(java.lang.String resource)
Adds a URL to the list of sub-requests that will be fetched from the web server by this request. The sub-requests will be fetched whensend()
orsendSubRequests(Response)
are called.e.g.
Url url1 = new Url(protocol1, localhost, "/"); // Create a GET request Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Add a sub-request request1.addSubRequest("http://localhost/Themes/TestPlant/Content/images/orange_button_bg.gif"); // Send the top-level request to the server, followed by all of the sub-requests Response response1 = request1.send();
- Parameters:
resource
- the url that should be fetched- See Also:
send()
,sendSubRequests(Response)
,addSubRequest(Url)
,ignoreSubRequest(String)
-
addSubRequest
public void addSubRequest(Protocol protocol, IpEndPoint ipEndPoint, java.lang.String path) throws NoSuchValueException
Adds a URL to the list of sub-requests that will be fetched from the web server by this request. The sub-requests will be fetched whensend()
orsendSubRequests(Response)
are called.e.g.
Url url1 = new Url(protocol1, localhost, "/"); // Create a GET request Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1); // Add a sub-request request1.addSubRequest(protocol1, localhost, "/Themes/TestPlant/Content/images/orange_button_bg.gif"); // Send the top-level request to the server, followed by all of the sub-requests Response response1 = request1.send();
- Parameters:
protocol
- theProtocol
of the urlipEndPoint
- theIpEndPoint
of the urlpath
- the path of the url- Throws:
NoSuchValueException
- theProtocol
is not valid- See Also:
send()
,sendSubRequests(Response)
,addSubRequest(Url)
,ignoreSubRequest(String)
-
setKeepAlive
public void setKeepAlive(boolean f)
Sets the value of the"Connection"
request header.- If the parameter is set to
true
, then the"Connection"
header will be assigned the value "Keep-Alive". - If the parameter is set to
false
, then the"Connection"
header will be removed.
- Parameters:
f
-true
if the"Connection: Keep-Alive"
request header should be set
- If the parameter is set to
-
setOffsetEdit
public void setOffsetEdit(OffsetEditSequence edits)
Sets anOffsetEditSequence
object to be applied to the message body of thisRequest
object, immediately before the request is sent to the web server.- Parameters:
edits
- anOffsetEditSequence
object, which can contain multiple edits
-
setMessageBody
public void setMessageBody(byte[] messageBody)
Sets the body of the HTTP request that will be sent to the server. This method is normally used with a POST or PUT request.- If the message body is a
Form
, then you should use thesetMessageBody(Form)
overload instead. - If the message body consists of text, then you should use the
setMessageBody(String)
overload. - If the message body is very large, then it may be easier to store the data in a file and use the
setMessageBodyFromFile(String)
method instead.
e.g.
Url url32 = new Url(protocol1, localhost, "/login"); Request request32 = getWebBrowser().createRequest(HttpMethod.POST, url32, 32); request32.setMessageBody(new byte[] { 0x01, 0x02, 0x03}); Response response32 = request32.send();
- Parameters:
messageBody
- the body of the message (e.g. the POST data)- See Also:
setMessageBody(String)
,setMessageBody(Form)
,setMessageBodyFromFile(String)
- If the message body is a
-
setMessageBodyFromFile
public void setMessageBodyFromFile(java.lang.String fileName)
Sets the body of the HTTP request that will be sent to the server, by loading data from a data file. This method is normally used with a POST or PUT request.- If the message body is a
Form
, then you should use thesetMessageBody(Form)
overload instead. - If the message body is a short section of text or a few binary bytes, consider
using the
setMessageBody(String)
orsetMessageBody(byte[])
overloads.
If you are using this method in your script, make sure that the file containing the data is in the
Data/Files
directory within your project.e.g.
Url url32 = new Url(protocol1, localhost, "/uploadFile"); Request request32 = getWebBrowser().createRequest(HttpMethod.POST, url32, 32); request32.setMessageBodyFromFile("myDoc.doc"); Response response32 = request32.send();
- Parameters:
fileName
- the path of the filename, relative to the Virtual User's data directory- See Also:
setMessageBody(String)
,setMessageBody(byte[])
- If the message body is a
-
setMessageBody
public void setMessageBody(Form form)
Sets the body of the HTTP request that will be sent to the server, as name/value pairs extracted from the specifiedForm
object. This method is normally used with a POST or PUT request.- If the message body consists of text, then you should use the
setMessageBody(String)
overload instead. - If the message body consists of binary data, then you should use the
setMessageBody(byte[])
overload. - If the message body is very large, then it may be easier to store the data in a file and use the
setMessageBodyFromFile(String)
method instead.
e.g.
// Create a POST request Url url33 = new Url(protocol1, localhost, "/cart"); Request request33 = getWebBrowser().createRequest(HttpMethod.POST, url33, 33); // Create a new form and populate it with some data Form postData33 = new Form(); postData33.setCharEncoding("utf-8"); postData33.addElement(new InputElement("itemquantity82", "1")); postData33.addElement(new InputElement("startcheckout", "startcheckout")); // attach the form to the POST request and send it request33.setMessageBody(postData33); Response response33 = request33.send();
- Parameters:
form
- the body of the message (e.g. the POST data)- See Also:
setMessageBody(String)
,setMessageBody(byte[])
,setMessageBodyFromFile(String)
- If the message body consists of text, then you should use the
-
getReference
public int getReference()
Gets the reference id that was passed to theWebBrowser.createRequest(HttpMethod, Url, int)
method when thisRequest
object was created.- Returns:
- the reference number of this
Request
-
getID
public int getID()
Gets the unique ID that has been assigned to thisRequest
. This ID number is created by theWebBrowser
. It is the value that is displayed in the web log viewer.- Returns:
- the unique ID assigned to this
Request
-
getMessageBody
public java.lang.String getMessageBody()
Gets the body of the HTTP request that will be sent to the server.- Returns:
- the body of the HTTP request
- See Also:
setMessageBody(String)
-
getHeaderValue
public java.lang.String getHeaderValue(java.lang.String header)
Gets the value of the specified HTTP request header.- Parameters:
header
- the header to get the value of- Returns:
- the value of the header
- See Also:
setHeader(String, String)
,removeHeader(String)
-
setHeader
public void setHeader(java.lang.String header, java.lang.String value)
Sets an HTTP header for thisRequest
. The header will be sent to the web server when thisRequest
is sent.e.g.
request34.setHeader("X-Requested-With", "XMLHttpRequest");
- Parameters:
header
- the header to setvalue
- the value to assign to the header- See Also:
removeHeader(String)
,clearHeaders()
-
setHeader
public void setHeader(java.lang.String header)
Sets an HTTP header for thisRequest
. The header will be sent to the web server when thisRequest
is sent.e.g.
request34.setHeader("X-Requested-With: XMLHttpRequest");
- Parameters:
header
- the header to set, including the value, which should be separated from the name with a colon- See Also:
removeHeader(String)
,clearHeaders()
-
removeHeader
public void removeHeader(java.lang.String header)
Removes an HTTP header from thisRequest
.- Parameters:
header
- the header to remove- See Also:
setHeader(String, String)
,clearHeaders()
-
clearHeaders
public void clearHeaders()
Clears the list of HTTP headers for thisRequest
.- See Also:
setHeader(String, String)
,removeHeader(String)
-
containsHeader
public boolean containsHeader(java.lang.String header)
Returnstrue
if thisRequest
contains a particular HTTP header.e.g.
if (request.containsHeader("Content-Type")) { writeMessage(String.format("Content-Type=%s", request.getHeaderValue("Content-Type"))); }
- Parameters:
header
- the HTTP header to check for- Returns:
true
if thisRequest
contains the specified header
-
getUserAgent
public java.lang.String getUserAgent()
Gets the value of the"User-Agent"
HTTP header.- Returns:
- the value of the
"User-Agent"
HTTP header
-
setUserAgent
public void setUserAgent(java.lang.String userAgent)
Sets the value of the"User-Agent"
HTTP header.- Parameters:
userAgent
- the value to set
-
getReferer
public java.lang.String getReferer()
Gets the value of the"Referer"
HTTP header.- Returns:
- the value of the
"Referer"
HTTP header
-
setReferer
public void setReferer(Url url)
Sets the value of the"Referer"
HTTP header.- Parameters:
url
- the value to set
-
setReferer
public void setReferer(java.lang.String referer)
Sets the value of the"Referer"
HTTP header.- Parameters:
referer
- the value to set
-
unsetReferer
public void unsetReferer()
Removes the"Referer"
HTTP header.
-
hasReferer
public boolean hasReferer()
Returnstrue
if the"Referer"
HTTP header has been set for thisRequest
.- Returns:
true
if the"Referer"
header has been set
-
getContentType
public java.lang.String getContentType()
Gets the value of the"Content-Type"
HTTP header.- Returns:
- the value of the
"Content-Type"
HTTP header
-
setContentType
public void setContentType(java.lang.String contentType)
Sets the value of the"Content-Type"
HTTP header.- Parameters:
contentType
- the value to set
-
getHeaderKeys
public java.util.List<java.lang.String> getHeaderKeys() throws com.facilita.exception.InternalError
Gets a list of names of all the HTTP request headers set in thisRequest
.- Returns:
- a list of names of all the HTTP request headers set in this
Request
- Throws:
com.facilita.exception.InternalError
- an internal error occurred
-
setFollowRedirects
public void setFollowRedirects(boolean followRedirects)
Sets whether redirects will automatically be followed for thisRequest
.If the response to this request is an HTTP redirect code (e.g.
301
,302
), and thisRequest
object is set to follow redirects, then the eggPlant Performance engine will automatically follow the redirect link. In this case, theResponse.wasRedirected()
method will returntrue
for theResponse
object returned bysend()
, andResponse.getRedirectedFrom()
will return theResponse
object containing the HTTP redirect code.Default behaviour for newly-created
Request
objects is to follow redirects, but this can be changed for individualRequest
objects using this method, or changed on allRequest
objects usingWebBrowser.setDefaultFollowRedirects(boolean)
.- Parameters:
followRedirects
-true
if redirects should be followed automatically- See Also:
send()
,Response.wasRedirected()
,Response.getRedirectedFrom()
-
setFollowRedirects
public void setFollowRedirects()
Sets the behaviour of thisRequest
so redirects will automatically be followed.If the response to this request is an HTTP redirect code (e.g.
301
,302
), and thisRequest
object is set to follow redirects, then the eggPlant Performance engine will automatically follow the redirect link. In this case, theResponse.wasRedirected()
method will returntrue
for theResponse
object returned bysend()
, andResponse.getRedirectedFrom()
will return theResponse
object containing the HTTP redirect code.Default behaviour for newly-created
Request
objects is to follow redirects, but this can be changed for individualRequest
objects usingsetFollowRedirects(boolean)
, or changed on allRequest
objects usingWebBrowser.setDefaultFollowRedirects(boolean)
.
-
getFollowRedirects
public boolean getFollowRedirects()
Returnstrue
if redirects will automatically be followed for thisRequest
.If the response to this request is an HTTP redirect code (e.g.
301
,302
), and thisRequest
object is set to follow redirects, then the eggPlant Performance engine will automatically follow the redirect link. In this case, theResponse.wasRedirected()
method will returntrue
for theResponse
object returned bysend()
, andResponse.getRedirectedFrom()
will return theResponse
object containing the HTTP redirect code.Default behaviour for newly-created
Request
objects is to follow redirects, but this can be changed for individualRequest
objects usingsetFollowRedirects(boolean)
, or changed on allRequest
objects usingWebBrowser.setDefaultFollowRedirects(boolean)
.- Returns:
true
if redirects will automatically be followed for thisRequest
-
setRetrieveSubRequests
public void setRetrieveSubRequests(boolean getEmbeddedUrls)
Sets whether sub-requests will be retrieved for thisRequest
. By default, sub-requests are retrieved.- Parameters:
getEmbeddedUrls
-true
if sub-requests should be retrieved- See Also:
getRetrieveSubRequests()
-
getRetrieveSubRequests
public boolean getRetrieveSubRequests()
Returnstrue
if sub-requests will be retrieved for thisRequest
.- Returns:
true
if sub-requests will be retrieved for thisRequest
- See Also:
setRetrieveSubRequests(boolean)
-
getIncludeQueryDataInLabels
public boolean getIncludeQueryDataInLabels()
Returnstrue
if URLs with different query data should be considered different from each other for analysis purposes. If this returnstrue
, then the query data will be included in the HTTP metric labels.e.g.
http://localhost:32144/search?q=camera
http://localhost:32144/search?q=laptop
http://localhost:32144/search
.- Returns:
true
if URL query data will be included in the HTTP metric labels- See Also:
setIncludeQueryDataInLabels(boolean)
-
setIncludeQueryDataInLabels
public void setIncludeQueryDataInLabels(boolean includeQueryDataInLabels)
Sets whether URLs with different query data should be considered different from each other for analysis purposes. If set totrue
, then the query data will be included in the HTTP metric labels.e.g.
http://localhost:32144/search?q=camera
http://localhost:32144/search?q=laptop
http://localhost:32144/search
.- Parameters:
includeQueryDataInLabels
-true
if URL query data should be included in the HTTP metric labels
-
setTimeEveryHttpRequest
public void setTimeEveryHttpRequest(boolean timings)
Sets whether sub-requests should be timed as well as top-level HTTP requests. Top-level requests will always be timed, even if this is set tofalse
.- Parameters:
timings
-true
if sub-requests should be timed as well as top-level HTTP requests
-
getTimeEveryHttpRequest
public boolean getTimeEveryHttpRequest()
Returnstrue
if sub-requests will be timed as well as top-level HTTP requests. Top-level requests will always be timed, even if this method returnsfalse
.- Returns:
true
if sub-requests will be timed as well as top-level HTTP requests
-
getSubRequestThreadCount
public int getSubRequestThreadCount()
Gets the number of threads that will be used to fetch sub-requests from the web server. If this value is increased, then more sub-requests can be fetched in parallel. However, using more threads will increase the load on the injector machine.- Returns:
- the number of threads that will be used to fetch sub-requests from the web server
- See Also:
setSubRequestThreadCount(int)
-
setSubRequestThreadCount
public void setSubRequestThreadCount(int subRequestThreadCount)
Sets the number of threads that will be used to fetch sub-requests from the web server. If this value is increased, then more sub-requests can be fetched in parallel. However, using more threads will increase the load on the injector machine.- Parameters:
subRequestThreadCount
- the number of threads that will be used to fetch sub-requests from the web server
-
getVersion
public java.lang.String getVersion()
Gets the HTTP version as aString
.The version of HTTP in common use is currently
"HTTP/1.1"
, but"HTTP/2"
can be used to enable HTTP/2 support where applicable.- Returns:
- the HTTP version
- See Also:
setVersion(String)
-
setVersion
public void setVersion(java.lang.String version)
Sets the HTTP version.The version of HTTP in common use is currently
"HTTP/1.1"
, but"HTTP/2"
can be used to enable HTTP/2 support where applicable.- Parameters:
version
- the HTTP version to use- See Also:
getVersion()
-
getChunkSize
public int getChunkSize()
Gets the size in bytes of the chunk size to use when sending data using Transfer-Encoding: chunked- Returns:
- the size in bytes of the chunk size to use when sending data using Transfer-Encoding: chunked
- See Also:
setChunkSize(int)
-
setChunkSize
public void setChunkSize(int chunkSize)
Sets the size in bytes of the chunk size to use when sending data using Transfer-Encoding: chunked- Parameters:
chunkSize
- the size in bytes of the chunk size to use when sending data using Transfer-Encoding: chunked- See Also:
getChunkSize()
-
getKeepAllSubRequestContent
public boolean getKeepAllSubRequestContent()
Returnstrue
if the content of responses to sub-requests will be kept.If this returns
false
, then all the responses to sub-requests will be discarded. There is a significant performance penalty to keep the sub-request content, so this value should only be set totrue
if it is necessary to examine the content of sub-responses.- Returns:
true
if the content of responses to sub-requests will be kept- See Also:
setKeepAllSubRequestContent(boolean)
,setKeepContent(boolean)
,addKeepSubRequestContentType(String)
,addKeepSubRequestContentUrl(String)
-
setKeepAllSubRequestContent
public void setKeepAllSubRequestContent(boolean keep)
Sets whether the content of responses to sub-requests should be kept.If this is set to
false
, then all the responses to sub-requests will be discarded. There is a significant performance penalty to keep the sub-request content, so this value should only be set totrue
if it is necessary to examine the content of sub-responses.- Parameters:
keep
-true
if the content of responses to sub-requests should be kept- See Also:
getKeepAllSubRequestContent()
,setKeepContent(boolean)
,addKeepSubRequestContentType(String)
,addKeepSubRequestContentUrl(String)
-
setKeepContent
public void setKeepContent(boolean keep)
Sets whether to keep the content of responses.If this value is set to
false
then the content of every response to thisRequest
will be discarded, and it will not be possible to examine the content using theResponse
class (but other information will still be accessible in theResponse
objects).- Parameters:
keep
-true
if the content of responses should be kept- See Also:
getKeepContent()
,setKeepAllSubRequestContent(boolean)
-
getKeepContent
public boolean getKeepContent()
Returnstrue
if the content of responses will be kept.If this returns
false
then the content of every response to thisRequest
will be discarded, and it will not be possible to examine the content using theResponse
class (but other information will still be accessible in theResponse
objects).- Returns:
true
if the content of responses will be kept- See Also:
setKeepContent(boolean)
,setKeepAllSubRequestContent(boolean)
,addKeepSubRequestContentType(String)
,addKeepSubRequestContentUrl(String)
-
addKeepSubRequestContentType
public void addKeepSubRequestContentType(java.lang.String typeFragment)
Adds a Content-Type fragment, so the content of sub-request responses that match the specified Content-Type fragment will be kept.In general, it is not necessary to retain content for sub-requests, and it will incur a performance penalty to do so. However, a situation may arise where it is necessary to check or extract a value from a sub-response. In this situation, you can specify that the content of certain sub-responses should be retained.
e.g.
// Keep the content of any sub-requests that have a Content-Type starting with "text" (e.g. text/html, text/xml) request.addKeepSubRequestContentType("text");
- Parameters:
typeFragment
- sub-request responses that have a Content-Type header containing thistypeFragment
will be kept- See Also:
getKeepContent()
,getKeepAllSubRequestContent()
,removeKeepSubRequestContentType(String)
,addKeepSubRequestContentUrl(String)
-
addKeepSubRequestContentUrl
public void addKeepSubRequestContentUrl(java.lang.String urlFragment)
Adds a URL, so the content of sub-request responses that match the specified URL fragment will be kept.In general, it is not necessary to retain content for sub-requests, and it will incur a performance penalty to do so. However, a situation may arise where it is necessary to check or extract a value from a sub-response. In this situation, you can specify that the content of certain sub-responses should be retained.
e.g.
// Keep the content of the sub-request with the url http://localhost/images/magnifying-glass.png request.addKeepSubRequestContentUrl("http://localhost/images/magnifying-glass.png");
- Parameters:
urlFragment
- the responses from sub-requests that match thisurlFragment
will be kept- See Also:
getKeepContent()
,getKeepAllSubRequestContent()
,removeKeepSubRequestContentUrl(String)
,addKeepSubRequestContentType(String)
-
removeKeepSubRequestContentType
public void removeKeepSubRequestContentType(java.lang.String typeFragment)
Removes a Content-Type fragment, so the content of sub-request responses that match the specified Content-Type fragment will no longer be kept.In general, it is not necessary to retain content for sub-requests, and it will incur a performance penalty to do so. However, a situation may arise where it is necessary to check or extract a value from a sub-response. In this situation, you can specify that the content of certain sub-responses should be retained.
e.g.
// Don't keep the content of any sub-requests that have a Content-Type starting with "text" (e.g. text/html, text/xml) request.removeKeepSubRequestContentType("text");
- Parameters:
typeFragment
- sub-request responses that have a Content-Type header containing thistypeFragment
will no longer be kept- See Also:
addKeepSubRequestContentType(String)
,setKeepAllSubRequestContent(boolean)
-
removeKeepSubRequestContentUrl
public void removeKeepSubRequestContentUrl(java.lang.String urlFragment)
Removes a URL, so the content of sub-request responses that match the specified URL fragment will no longer be kept.In general, it is not necessary to retain content for sub-requests, and it will incur a performance penalty to do so. However, a situation may arise where it is necessary to check or extract a value from a sub-response. In this situation, you can specify that the content of a particular sub-responses should be retained.
e.g.
// Don't keep the content of the sub-request with the url http://localhost/images/magnifying-glass.png request.removeKeepSubRequestContentUrl("http://localhost/images/magnifying-glass.png");
- Parameters:
urlFragment
- the responses from sub-requests that match thisurlFragment
will no longer be kept- See Also:
getKeepContent()
,getKeepAllSubRequestContent()
,addKeepSubRequestContentUrl(String)
-
getContentUrlFragments
public java.util.List<java.lang.String> getContentUrlFragments() throws com.facilita.exception.InternalError
Gets a list of all the URL fragments for which the content of sub-request responses will be kept.- Returns:
- a list of all the URL fragments for which the content of sub-request responses will be kept
- Throws:
com.facilita.exception.InternalError
- an internal error occurred- See Also:
addKeepSubRequestContentUrl(String)
,removeKeepSubRequestContentUrl(String)
-
getContentTypeFragments
public java.util.List<java.lang.String> getContentTypeFragments() throws com.facilita.exception.InternalError
Gets a list of all the Content-Type fragments for which the content of sub-request responses will be kept.- Returns:
- a list of all the Content-Type fragments for which the content of sub-request responses will be kept
- Throws:
com.facilita.exception.InternalError
- an internal error occurred- See Also:
addKeepSubRequestContentType(String)
,removeKeepSubRequestContentType(String)
-
isDynatraceIntegrationEnabled
public boolean isDynatraceIntegrationEnabled()
Returnstrue
if dynaTrace integration is enabled. When dynaTrace integration is enabled, a special dynaTrace HTTP header is sent with each HTTP request.- Returns:
true
if dynaTrace integration is enabled- See Also:
setDynatraceIntegrationEnabled(boolean)
-
setDynatraceIntegrationEnabled
public void setDynatraceIntegrationEnabled(boolean value)
Sets whether or not dynaTrace integration is enabled. When dynaTrace integration is enabled, a special dynaTrace HTTP header is sent with each HTTP request.- Parameters:
value
-true
to enable dynaTrace integration,false
to disable it- See Also:
isDynatraceIntegrationEnabled()
-
getCharactersAllowedInPostedForm
public java.lang.String getCharactersAllowedInPostedForm()
Gets the characters that will NOT be percent-encoded when aForm
is sent to the web server using a POST request.By default, a character will be percent-encoded within a form if it is:
- Outside the ASCII range OR
- Not an alpha-numeric character AND not in this list of allowed characters
' '
- space'-'
- hyphen'_'
- underscore'.'
- full stop'*'
- asterisk
- Returns:
- the characters that will not be encoded
- See Also:
setCharactersAllowedInPostedForm(String)
,setMessageBody(Form)
,Coder.getDefaultCharactersAllowedInPostedForm()
-
setCharactersAllowedInPostedForm
public void setCharactersAllowedInPostedForm(java.lang.String charactersAllowedInPostedForm)
Sets the characters that will NOT be percent-encoded when aForm
is sent to the web server using a POST request.By default, a character will be percent-encoded within a form if it is:
- Outside the ASCII range OR
- Not an alpha-numeric character AND not in this list of allowed characters
' '
- space'-'
- hyphen'_'
- underscore'.'
- full stop'*'
- asterisk
- Parameters:
charactersAllowedInPostedForm
- the list of characters not to percent-encode- See Also:
getCharactersAllowedInPostedForm()
,setMessageBody(Form)
,Coder.getDefaultCharactersAllowedInPostedForm()
-
getHttpStatusCategory
public HttpStatusCategory getHttpStatusCategory(HttpStatus status) throws BadValueException
Returns the registered status category for the given HTTP status. Since all HTTP codes categories can be overwritten to reflect your server behaviour, it can be useful to establish what is the current registered category.- Parameters:
status
- Object of classHttpStatus
representing an HTTP status code.- Returns:
HttpStatusCategory
- Throws:
BadValueException
- An error occurred
-
setHttpStatusCategory
public void setHttpStatusCategory(HttpStatus status, HttpStatusCategory category)
Registers the provided HTTP status code range against the predefined category. All HTTP codes categories can be overwritten to reflect your server behaviour, it will affect how they get reported during the test run (errors, warnings or no report).- Parameters:
status
- Object of classHttpStatus
representing an HTTP status code.category
- One of the enumerationHttpStatusCategory
-
setHttpStatusCategory
public void setHttpStatusCategory(HttpStatusRange statusRange, HttpStatusCategory category)
Registers the provided HTTP status code range against the predefined category. All HTTP codes categories can be overwritten to reflect your server behaviour, it will affect how they get reported during the test run (errors, warnings or no report).- Parameters:
statusRange
- One of the enumerationHttpStatusRange
representing an HTTP status code ranges.category
- One of the enumerationHttpStatusCategory
-
-