biz.neustar.wpm.api
Interface HttpResponse


public interface HttpResponse

The result of an HTTP request make by HttpClient. This object contains the actual data that will be stored in the transaction (see getInfo()) as well as the result for any content verification (if one was provided when the request was made).


Method Summary
 void errorString(java.lang.String text)
          Verify that the given text is not present in the response body.
 void errorStringRegex(java.lang.String regex)
          Verify that the given regex does not match the response body.
 HttpHeader[] getAllHeaders()
          Returns an array of all headers included in the response.
 java.lang.String getBody()
          Returns the response body, as a String.
 java.lang.String getCharSet()
          Returns the response character set if and only if the corresponding request asked for text validation to occur.
 java.lang.String getContentType()
          Returns the response content type if and only if the corresponding request asked for text validation to occur.
 java.lang.String getErrorMessage()
          Returns descriptive text of any error that occurred while making the HTTP request.
 java.lang.String getHeader(java.lang.String name)
          Returns the value of the specific response header, or null if no header exists in the response.
 java.lang.String[] getHeaders(java.lang.String name)
          Returns the values for the specific response header, or null if no headers exist in the response.
 TransactionStepObject getInfo()
          Returns the actual information that will be stored in to the core data collected as part of the overall transaction.
 int getStatusCode()
          Returns the HTTP status code
 java.lang.String getStatusText()
          Returns the HTTP status text
 java.lang.String getUrl()
          Returns the URL that the response was generated from.
 boolean isContentMatched()
          Returns true if the content was verified to be in the resulting HTTP response.
 void searchString(java.lang.String text)
          Verify that the given string is present in the response body.
 void searchStringRegex(java.lang.String regex)
          Verify that the given regex matches the response body.
 

Method Detail

isContentMatched

boolean isContentMatched()
Returns true if the content was verified to be in the resulting HTTP response. If no content verification was requested, this function returns true regardless.

Returns:
true if the content was verified in the HTTP request.

getInfo

TransactionStepObject getInfo()
Returns the actual information that will be stored in to the core data collected as part of the overall transaction.

Returns:
the information associated with the HTTP request, such as bytes transferred and HTTP response code.

getBody

java.lang.String getBody()
Returns the response body, as a String. If the corresponding request asked for text validation to occur, and this failed, it returns "null" instead.

Returns:
the body of the HTTP response, as String.

getCharSet

java.lang.String getCharSet()
Returns the response character set if and only if the corresponding request asked for text validation to occur. Otherwise, null is returned.

Returns:
true the character set encoding of the HTTP response.

getContentType

java.lang.String getContentType()
Returns the response content type if and only if the corresponding request asked for text validation to occur. Otherwise, null is returned.

Returns:
true the content type of the HTTP response.

getErrorMessage

java.lang.String getErrorMessage()
Returns descriptive text of any error that occurred while making the HTTP request. This message is usually coupled with an HTTP status code of 9xx or -9xx, which is a Neustar-specific indicator that the request could not complete, usually due to some I/O exception. This error message can usually shed light on what the I/O issue was and is suitable to be thrown as an exception within the underlying script that made the HTTP request.

Returns:
the string error message or null if no error occurred or no message can be found.

getHeader

java.lang.String getHeader(java.lang.String name)
Returns the value of the specific response header, or null if no header exists in the response.

Parameters:
name - the header name
Returns:
the value of the response header, or null if the header did not exist.

getHeaders

java.lang.String[] getHeaders(java.lang.String name)
Returns the values for the specific response header, or null if no headers exist in the response.

This is useful if the same header is included multiple times. For example:

 var r = c.get("http://www.google.com");
 var cookies = r.getHeaders('Set-Cookie');
 test.log("Cookies:");
 for (var i = 0; i < cookies.length; i++) {
   test.log("   " + cookies[i]);
 }
 

Parameters:
name - the header name
Returns:
an array of strings for values in the response header, or null no headers matched.

getAllHeaders

HttpHeader[] getAllHeaders()
Returns an array of all headers included in the response.
 test.log("All Headers:");
 var headers = r.getAllHeaders();
 for (var i = 0; i < headers.length; i++) {
   var header = headers[i];
   test.log("   " + header.name + " : " + header.value);
 }
 

Returns:
array of headers on the response.

getUrl

java.lang.String getUrl()
Returns the URL that the response was generated from.

Note that with redirects this can be different that the url given in the request.

Returns:
the url of the response.

getStatusCode

int getStatusCode()
Returns the HTTP status code

Returns:
the HTTP status code given in the first line of the response.

getStatusText

java.lang.String getStatusText()
Returns the HTTP status text

Returns:
the HTTP status text given in the first line of the response.

searchString

void searchString(java.lang.String text)
Verify that the given string is present in the response body.

Parameters:
text - the text to verify is present

errorString

void errorString(java.lang.String text)
Verify that the given text is not present in the response body.

Parameters:
text - the text to verify is not present

searchStringRegex

void searchStringRegex(java.lang.String regex)
Verify that the given regex matches the response body.

Only a partial match is required. E.g. the following will succeed if the response has the text 'search' anywhere in the body:

     r.searchStringRegex("search");
 

Parameters:
regex - the regex to check for

errorStringRegex

void errorStringRegex(java.lang.String regex)
Verify that the given regex does not match the response body.

Only a partial match is required. E.g. the following will succeed if the response does not have the text 'error' in the body:

     r.errorStringRegex("error");
 

Parameters:
regex - the regex to check for

Copyright © 2014 Neustar, Inc. All Rights Reserved.