|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface HttpClient
The API that makes HTTP requests for Neustar Web Performance Management scripts. This class can be used directly to make HTTP requests. It is also used to proxy HTTP requests made by any real browser opened by test scripts. In both cases, requests to this API are logged in the transaction results, with timings for time-to-first-byte, DNS lookup, time-to-last-byte, etc captured. In addition to the basic GET/POST HTTP actions, this API provides many useful utilities to extend/modify the normal script or browser behavior. For example:
remapHost(java.lang.String, java.lang.String)
- Useful for simulating entries in your /etc/hosts file.autoBasicAuthorization(java.lang.String, java.lang.String, java.lang.String)
- If your site is protected by BASIC authentication, use this.rewriteUrl(java.lang.String, java.lang.String)
- Uses regular expressions to rewrite a URL before the request is made.blacklistRequests(java.lang.String, int)
and whitelistRequests(java.lang.String[], int)
- For when you don't want certain requests to even be made.
Method Summary | |
---|---|
void |
addPointOfFailureRequests(java.lang.String pattern)
Emulate failing requests. |
void |
addHeader(java.lang.String name, java.lang.String value)
Adds a new HTTP header to every request. If the header already exists on the request, it will be replaced with the specified header. |
void |
removeHeader(java.lang.String name)
Removes a header previously added with {@link #addHeader(String name, String value)}. |
void |
autoBasicAuthorization(java.lang.String domain,
java.lang.String username,
java.lang.String password)
Forces all requests to the specific domain ("example.com") or host ("www.example.com") to have the proper header necessary to automatically pass any BASIC authentication challenge (ie: the Authorization header) with the supplied username and password. |
void |
blacklistCommonUrls()
Blacklist well-known sites that are commonly used for site analytics and advertising. |
void |
blacklistRealUserUrls()
Blacklist Real User Measurement requests. |
void |
blacklistRequests(java.lang.String pattern,
int responseCode)
Blacklist any HTTP request that matches the supplied regular expression pattern, automatically registering the supplied response code as the response without actually making the call. |
void |
clearBlacklist()
Clear any existing blacklist rules. |
void |
clearCookies()
Remove all cookies. |
void |
clearDNSCache()
Flushes the DNS cache used by this http client |
void |
clearWhitelist()
Clear any existing whitelist rules. |
void |
configureSSL(java.lang.String sslAlgorithm)
Allows setting of SSL version to use when connecting over HTTPS/SSL. |
void |
configureSSL(java.lang.String sslAlgorithm,
boolean forceSSLCertificateVerification)
Allows fine tuning of the SSL version to use when connecting over HTTPS/SSL. |
void |
createCookie(java.lang.String name,
java.lang.String value,
java.lang.String domain)
Create a new cookie. |
void |
createCookie(java.lang.String name,
java.lang.String value,
java.lang.String domain,
java.lang.String path)
Create a new cookie. |
HttpResponse |
del(java.lang.String url)
Issues an HTTP DELETE without any content verification. |
HttpResponse |
del(java.lang.String url,
NativeObject verifyParams)
Issues an HTTP DELETE with a parameter for text/status code/location verification. |
HttpResponse |
get(java.lang.String url)
Issues an HTTP GET without any content verification. |
HttpResponse |
get(java.lang.String url,
NativeObject verifyParams)
Issues an HTTP GET with a parameter for text/status code/location verification. |
Cookie |
getCookie(java.lang.String name)
Retrieve a cookie by name. |
Cookie |
getCookie(java.lang.String name,
java.lang.String domain)
Retrieve a cookie by name. |
Cookie |
getCookie(java.lang.String name,
java.lang.String domain,
java.lang.String path)
Retrieve a cookie by name. |
boolean |
getEnableSNI()
Returns if SSL SNI (Server Name Indication) is enabled or disabled. |
HttpResponse |
head(java.lang.String url)
Issues an HTTP HEAD without any verification. |
HttpResponse |
head(java.lang.String url,
NativeObject verifyParams)
Issues an HTTP HEAD with a parameter for status code/location verification. |
HttpRequest |
newDelete(java.lang.String url)
Creates a new DELETE request that can be further modified before finally executed. |
HttpRequest |
newGet(java.lang.String url)
Creates a new GET request that can be further modified before finally executed. |
HttpRequest |
newHead(java.lang.String url)
Creates a new HEAD request that can be further modified before finally executed. |
HttpRequest |
newOptions(java.lang.String url)
Creates a new OPTIONS request that can be further modified before finally executed. |
HttpRequest |
newPatch(java.lang.String url)
Creates a new PATCH request that can be further modified before finally executed. |
HttpRequest |
newPost(java.lang.String url)
Creates a new POST request that can be further modified before finally executed. |
HttpRequest |
newPut(java.lang.String url)
Creates a new PUT request that can be further modified before finally executed. |
HttpRequest |
newTrace(java.lang.String url)
Creates a new TRACE request that can be further modified before finally executed. |
HttpResponse |
options(java.lang.String url)
Issues an HTTP OPTIONS without any content verification. |
HttpResponse |
options(java.lang.String url,
NativeObject verifyParams)
Issues an HTTP OPTIONS with a parameter for text/status code/location verification. |
HttpResponse |
post(java.lang.String url)
Issues an HTTP POST with a parameter for text/status code/location verification. |
HttpResponse |
post(java.lang.String url,
NativeObject verifyParams)
Issues an HTTP POST with a parameter for text/status code/location verification. |
HttpResponse |
put(java.lang.String url,
NativeObject verifyParams)
Issues an HTTP PUT with a parameter for text/status code/location verification. |
void |
remapHost(java.lang.String source,
java.lang.String target)
Provides functionality similar to editing your "hosts file" on your local computer. |
void |
rewriteUrl(java.lang.String match,
java.lang.String replace)
Tells the browser to rewrite any URL it encounters using the provided regular expression and replacement string. |
void |
setCheckValidSSL(boolean checkValidSSL)
Turn SSL certificate validation on or off when going through the proxy or making HTTP requests directly. |
void |
setConnectionTimeout(int connectionTimeout)
Sets the timeout for the connection to be established. |
void |
setDNSCacheTimeout(int timeout)
Sets the TTL for objects in the DNS cache in seconds. |
void |
setEnableSNI(boolean enable)
Enabled or disable SSL SNI (Server Name Indication). |
void |
setFollowRedirects(boolean followRedirects)
Tells the HttpClient whether redirects (300 status codes) should automatically be followed. |
void |
setRequestTimeout(int requestTimeout)
Sets the request timeout for all subsequent HTTP requests. |
void |
setRetryCount(int count)
Set the automatic retry count for HTTP requests (both requests made directly and request made by the browser). |
void |
setSocketOperationTimeout(int socketOperationTimeout)
Sets the timeout for a socket operation, such as reading a byte from the HTTP stream (SO_TIMEOUT). |
void |
useClientCertificates(java.lang.String keystoreType,
java.lang.String keystoreFilename,
java.lang.String keystorePassword)
Configures the HttpClient to use client certificates. |
void |
whitelistRequests(java.lang.String[] patterns,
int responseCode)
Whitelist any HTTP request that matches the supplied regular expression patterns, automatically registering the supplied response code as the response for any request not in the set of whitelists. |
Method Detail |
---|
void setRetryCount(int count)
count
- the number of times to retry an HTTP request (0 by default)void remapHost(java.lang.String source, java.lang.String target)
source
- the source host to re-map from (ie: www.example.com)target
- the target host to re-map to (ie: new.example.com)void addHeader(java.lang.String name, java.lang.String value)
name
- name of the header to add
value
- new header's valuevoid removeHeader(java.lang.String name)
name
- previously-added header's namevoid autoBasicAuthorization(java.lang.String domain, java.lang.String username, java.lang.String password)
domain
- the domain or host to auto authenticateusername
- the username to login withpassword
- the password to login withvoid createCookie(java.lang.String name, java.lang.String value, java.lang.String domain)
name
- the cookie namevalue
- the cookie valuedomain
- the domain the cookie will be usedvoid createCookie(java.lang.String name, java.lang.String value, java.lang.String domain, java.lang.String path)
name
- the cookie namevalue
- the cookie valuedomain
- the domain the cookie will be usedpath
- the path the cookie will be usedvoid clearCookies()
Cookie getCookie(java.lang.String name)
name
- the name of the cookie
Cookie getCookie(java.lang.String name, java.lang.String domain)
name
- the name of the cookiedomain
- the domain for which the cookie is valid
Cookie getCookie(java.lang.String name, java.lang.String domain, java.lang.String path)
name
- the name of the cookiedomain
- the domain for which the cookie is validpath
- the subset of URLs on the origin server to which this cookie applies
void rewriteUrl(java.lang.String match, java.lang.String replace)
match
- the regular expression string to match against. You can use regex symbols such as ".", "\d", "\W",
"[...]", etc.replace
- the plain text string to replace any matching subsection of a URL handled by the browser.void blacklistRequests(java.lang.String pattern, int responseCode)
c.blacklistRequests("http://www\\.google-analytics\\.com/.*", 200);
pattern
- the regular expression string to match against. You can use regex symbols such as ".", "\d",
"\W", "[...]", etc.responseCode
- the HTTP response code to immediately "return" instead of making the actual HTTP request.void blacklistCommonUrls()
c.blacklistRequests("http(s)?://[^/]+\\.google-analytics\\.com/.*", 200); c.blacklistRequests("http://[^/]+\\.quantserve\\.com/.*", 200); c.blacklistRequests("http://www\\.quantcast\\.com/.*", 200); c.blacklistRequests("http://c\\.compete\\.com/.*", 200); c.blacklistRequests("http(s)?://s?b\\.scorecardresearch\\.com/.*", 200); c.blacklistRequests("http://s\\.stats\\.wordpress\\.com/.*", 200); c.blacklistRequests("http://partner\\.googleadservices\\.com/.*", 200); c.blacklistRequests("http://ad\\.adtegrity\\.net/.*", 200); c.blacklistRequests("http(s)?://[^/]+\\.doubleclick\\.net/.*", 200); c.blacklistRequests("http(s)?://connect\\.facebook\\.net/.*", 200); c.blacklistRequests("http://platform\\.twitter\\.com/.*", 200); c.blacklistRequests("http://[^/]+\\.addthis\\.com/.*", 200); c.blacklistRequests("http://widgets\\.digg\\.com/.*", 200); c.blacklistRequests("http(s)?://plus\\.google\\.com/.*", 200); c.blacklistRequests("http(s)?://plusone\\.google\\.com/.*", 200);
void blacklistRealUserUrls()
c.blacklistRequests("http(s)?://d2lo2tipcl3aii.cloudfront.net/.*", 200);
void clearBlacklist()
void addPointOfFailureRequests(java.lang.String pattern)
c.addPointOfFailureRequests("http://www\\.google-analytics\\.com/.*");
void whitelistRequests(java.lang.String[] patterns, int responseCode)
c.whitelistRequests(["http://www\\.example\\.com/.*", "http://images\\.example.com\\.com/.*"], 200);
patterns
- the array regular expression string to match against. You can use regex symbols such as ".", "\d",
"\W", "[...]", etc.responseCode
- the HTTP response code to immediately "return" instead of making the actual HTTP request.void clearWhitelist()
HttpResponse get(java.lang.String url)
url
- the URL to make an HTTP GET request to.
HttpResponse get(java.lang.String url, NativeObject verifyParams)
c.get("http://google.com", { text: "Google", statusCode: 301, location: "http://www.google.com/" });
url
- the URL to make an HTTP GET request to.verifyParams
- the verification parameters to check
HttpResponse post(java.lang.String url)
url
- the URL to make an HTTP POST request to.
HttpResponse post(java.lang.String url, NativeObject verifyParams)
c.post("http://your_site", { text: "Search Text", statusCode: 301, location: "http://expectedLocation", params: { user: "foo", password: "bar" } });
url
- the URL to make an HTTP POST request to.verifyParams
- the verification parameters to check
HttpResponse put(java.lang.String url, NativeObject verifyParams)
c.put("http://your_site", { text: "Search Text", statusCode: 301, location: "http://expectedLocation", params: { user: "foo", password: "bar", other_param: ['hello', 'world'] } });
url
- the URL to make an HTTP PUT request to.verifyParams
- the verification parameters to check
HttpResponse del(java.lang.String url)
url
- the URL to make an HTTP DELETE request to.
HttpResponse del(java.lang.String url, NativeObject verifyParams)
c.del("http://your_site", { text: "Search Text", statusCode: 301, location: "http://expectedLocation" });
url
- the URL to make an HTTP DELETE request to.verifyParams
- the verification parameters to check
HttpResponse options(java.lang.String url)
url
- the URL to make an HTTP OPTIONS request to.
HttpResponse options(java.lang.String url, NativeObject verifyParams)
c.options("http://your_site", { text: "Search Text", statusCode: 301, location: "http://expectedLocation" });
url
- the URL to make an HTTP OPTIONS request to.verifyParams
- the verification parameters to check
HttpResponse head(java.lang.String url)
url
- the URL to make an HTTP HEAD request to.
HttpResponse head(java.lang.String url, NativeObject verifyParams)
c.head("http://your_site", { statusCode: 301, location: "http://expectedLocation" });
url
- the URL to make an HTTP HEAD request to.verifyParams
- the verification parameters to check
void setFollowRedirects(boolean followRedirects)
followRedirects
- true for redirects to be followed.void setRequestTimeout(int requestTimeout)
requestTimeout
- the timeout value, in milliseconds, to use.void setSocketOperationTimeout(int socketOperationTimeout)
socketOperationTimeout
- the timeout value, in milliseconds, to use.void setConnectionTimeout(int connectionTimeout)
connectionTimeout
- the timeout value, in milliseconds, to use.HttpRequest newGet(java.lang.String url)
url
- the URL to make an HTTP GET request to.
HttpRequest newPost(java.lang.String url)
url
- the URL to make an HTTP POST request to.
HttpRequest newPut(java.lang.String url)
url
- the URL to make an HTTP PUT request to.
HttpRequest newDelete(java.lang.String url)
url
- the URL to make an HTTP DELETE request to.
HttpRequest newOptions(java.lang.String url)
url
- the URL to make an HTTP OPTIONS request to.
HttpRequest newHead(java.lang.String url)
url
- the URL to make an HTTP HEAD request to.
HttpRequest newPatch(java.lang.String url)
url
- the URL to make an HTTP PATCH request to.
HttpRequest newTrace(java.lang.String url)
url
- the URL to make an HTTP TRACE request to.
void clearDNSCache()
void setDNSCacheTimeout(int timeout)
timeout
- timeout in secondsvoid setCheckValidSSL(boolean checkValidSSL)
var driver = test.openWebDriver(); var c = test.openHttpClient(); c.setCheckValidSSL(true); test.beginTransaction(); test.beginStep("Goto https://www.mysite.com but only if the SSL is valid"); driver.get("https://www.mysite.com"); test.endStep(); test.endTransaction();You can wrap HTTP-generating calls in a try-catch block to capture the exception and let your script continue.
checkValidSSL
- when set to true all SSL certs must be valid or the transaction will fail.void configureSSL(java.lang.String sslAlgorithm)
sslAlgorithm
:
sslAlgorithm
- the SSL algorithm to use when connecting to your HTTPS enabled site.void configureSSL(java.lang.String sslAlgorithm, boolean forceSSLCertificateVerification)
sslAlgorithm
:
forceSSLCertificateVerification
flag controls whether your server's SSL certificate will be
verified like most browsers tend to do. If this is set to false (the default), then SSL certificate warnings and
errors (mismatched common name, expired cert, etc) will be ignored. If this is set to true, then HTTP requests
will fail if the certificate cannot be verified.
sslAlgorithm
- the SSL algorithm to use when connecting to your HTTPS enabled site.forceSSLCertificateVerification
- true to force ssl certificate verification, false to be relaxed and ignore
certificate warningsvoid useClientCertificates(java.lang.String keystoreType, java.lang.String keystoreFilename, java.lang.String keystorePassword)
keystoreType
- either "JKS" or "PKCS12"keystoreFilename
- the name of the keystore datafilekeystorePassword
- the password that was provided to the keytool when the keystore was createdvoid setEnableSNI(boolean enable)
enable
- boolean getEnableSNI()
|
© 2023 Vercara, LLC. All Rights Reserved. | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |