Package com.meterware.httpunit
Class WebResponse
java.lang.Object
com.meterware.httpunit.WebResponse
- All Implemented Interfaces:
CookieSource
,com.meterware.httpunit.dom.DomWindowProxy
,HTMLSegment
public abstract class WebResponse
extends Object
implements HTMLSegment, CookieSource, com.meterware.httpunit.dom.DomWindowProxy
A response to a web request from a web server.
- Author:
- Russell Gold, Drew Varner, Dave Glowacki, Benoit Xhenseval, Wolfgang Fahl
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
WebResponse
(WebClient client, FrameSelector frame, URL url) Constructs a response object.protected
WebResponse
(WebClient client, FrameSelector frame, URL url, String text) Constructs a response object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
close()
boolean
create a DOMScriptingHandlerprotected final void
defineRawInputStream
(InputStream inputStream) Returns the applets found in the page in the order in which they appear.Returns the character set used in this response.getter for the WebClientint
Returns the content length of this response.Returns the content type of this response.getDOM()
Returns a copy of the domain object model tree associated with this response.String[]
Returns a list of HTML element names contained in this HTML section.getElementsByTagName
(String tagName) return the HTMLElements with the specified tag namegetElementsWithAttribute
(String name, String value) Returns the HTMLElements found with the specified attribute value.getElementsWithName
(String name) Returns the HTMLElements found in this segment with the specified name.Returns the HTMLElement with the specified ID.Returns the stylesheet linked in the head of the page.getFirstMatchingForm
(HTMLElementPredicate predicate, Object criteria) Returns the first form found in the page matching the specified criteria.getFirstMatchingLink
(HTMLElementPredicate predicate, Object criteria) Returns the first link found in the page matching the specified criteria.getFirstMatchingTable
(HTMLElementPredicate predicate, Object criteria) Returns the first table in the response which matches the specified predicate and value.getFirstMatchingTextBlock
(HTMLElementPredicate predicate, Object criteria) Returns the first link found in the page matching the specified criteria.WebForm[]
getForms()
Returns the forms found in the page in the order in which they appear.getFormWithID
(String ID) Returns the form found in the page with the specified ID.getFormWithName
(String name) Returns the form found in the page with the specified name.Returns the name of the frame containing this page.String[]
Returns the names of the frames found in the page in the order in which they appear.abstract String
getHeaderField
(String fieldName) Returns the value for the specified header field.abstract String[]
Returns the names of the header fields found in the response.WebImage[]
Returns the images found in the page in the order in which they appear.getImageWithAltText
(String altText) Returns the first image found in the page with the specified alt attribute.getImageWithName
(String source) Returns the image found in the page with the specified name attribute.getImageWithSource
(String source) Returns the first image found in the page with the specified src attribute.Returns a buffered input stream for reading the contents of this reply.WebLink[]
getLinks()
Returns the links found in the page in the order in which they appear.getLinkWith
(String text) Returns the first link which contains the specified text.getLinkWithID
(String ID) Returns the link found in the page with the specified ID.getLinkWithImageText
(String text) Returns the first link which contains an image with the specified text as its 'alt' attribute.getLinkWithName
(String name) Returns the link found in the page with the specified name.WebForm[]
getMatchingForms
(HTMLElementPredicate predicate, Object criteria) Returns all forms found in the page matching the specified criteria.WebLink[]
getMatchingLinks
(HTMLElementPredicate predicate, Object criteria) Returns all links found in the page matching the specified criteria.WebTable[]
getMatchingTables
(HTMLElementPredicate predicate, Object criteria) Returns all tables found in the page matching the specified criteria.String[]
getMetaTagContent
(String attribute, String attributeValue) Retrieves the "content" of the meta tags for a key pair attribute-attributeValue.String[]
Returns a list of new cookie names defined as part of this response.getNewCookieValue
(String name) Returns the new cookie value defined as part of this response.getNextTextBlock
(TextBlock block) Returns the text block after the specified block, if any.int
Returns the delay before normally following the request to refresh this page, if any.Returns a request to refresh this page, if any.abstract int
Returns the response code associated with this response.abstract String
Returns the response message associated with this response.get the scriptable object for this WebResponsegetSubframeContents
(String subFrameName) Returns the contents of the specified subframe of this frameset response.WebTable[]
Returns the top-level tables found in this page in the order in which they appear.getTableStartingWith
(String text) Returns the first table in the response which has the specified text as the full text of its first non-blank row and non-blank column.Returns the first table in the response which has the specified text as a prefix of the text of its first non-blank row and non-blank column.getTableWithID
(String text) Returns the first table in the response which has the specified text as its ID attribute.getTableWithSummary
(String text) Returns the first table in the response which has the specified text as its summary attribute.getText()
Returns the text of the response (excluding headers) as a string.Returns an array of text blocks found in the page.getTitle()
Returns the title of the page.getURL()
Returns the URL which invoked this response.static String[]
allow access to the valid content Typesboolean
isHTML()
Returns true if the response is HTML.protected void
static ScriptableDelegate
newDelegate
(String delegateClassName) static WebResponse
newResponse
(URLConnection connection) Returns a web response built from a URL connection.com.meterware.httpunit.dom.DomWindowProxy
openNewWindow
(String name, String relativeUrl) open a a new Window with the given name and relative URLboolean
replaceText
(String text, String contentType) Replaces the text in the window with the specified text and content type.protected void
setContentTypeHeader
(String value) Overwrites the current value (if any) of the content type header.void
setScriptingHandler
(ScriptingHandler scriptingHandler) protected static void
setValidContentTypes
(String[] validContentTypes) allow modification of the valid content Types use with carecom.meterware.httpunit.dom.DomWindowProxy
submitRequest
(com.meterware.httpunit.dom.HTMLElementImpl sourceElement, String method, String location, String target, com.meterware.httpunit.protocol.MessageBody requestBody) abstract String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.meterware.httpunit.cookies.CookieSource
getHeaderFields
-
Constructor Details
-
WebResponse
Constructs a response object. see [ 1159858 ] patch for RFE 1159844 (parsing intercepted pages)- Parameters:
frame
- the frame to hold the responseurl
- the url from which the response was received
-
WebResponse
Constructs a response object.- Parameters:
frame
- the frame to hold the responseurl
- the url from which the response was received
-
-
Method Details
-
newResponse
Returns a web response built from a URL connection. Provided to allow access to WebResponse parsing without using a WebClient.- Throws:
IOException
-
isHTML
public boolean isHTML()Returns true if the response is HTML.- Returns:
- true if the contenType fits
-
getURL
Returns the URL which invoked this response.- Specified by:
getURL
in interfaceCookieSource
- Specified by:
getURL
in interfacecom.meterware.httpunit.dom.DomWindowProxy
- Returns:
- the URL associated with the window.
-
getTitle
Returns the title of the page.- Throws:
SAXException
- thrown if there is an error parsing this response
-
getExternalStyleSheet
Returns the stylesheet linked in the head of the page.- Throws:
SAXException
- thrown if there is an error parsing this response
-
getMetaTagContent
Retrieves the "content" of the meta tags for a key pair attribute-attributeValue.getMetaTagContent("name","robots") will return { "index","follow" } getMetaTagContent("http-equiv","Expires") will return { "now" }
- Throws:
SAXException
- thrown if there is an error parsing this response
-
getFrameName
Returns the name of the frame containing this page. -
getRefreshRequest
Returns a request to refresh this page, if any. This request will be defined by a tag in the header. If no tag exists, will return null. -
getRefreshDelay
public int getRefreshDelay()Returns the delay before normally following the request to refresh this page, if any. This request will be defined by a tag in the header. If no tag exists, will return zero. -
getResponseCode
public abstract int getResponseCode()Returns the response code associated with this response. -
getResponseMessage
Returns the response message associated with this response. -
getContentLength
public int getContentLength()Returns the content length of this response.- Returns:
- the content length, if known, or -1.
-
getContentType
Returns the content type of this response. -
getCharacterSet
Returns the character set used in this response. -
getNewCookieNames
Returns a list of new cookie names defined as part of this response. -
getNewCookieValue
Returns the new cookie value defined as part of this response. -
getHeaderFieldNames
Returns the names of the header fields found in the response. -
getHeaderField
Returns the value for the specified header field. If no such field is defined, will return null. If more than one header is defined for the specified name, returns only the first found. -
getText
Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' which may be used to represent internal state of this object.- Throws:
IOException
-
getInputStream
Returns a buffered input stream for reading the contents of this reply.- Throws:
IOException
-
getFrameNames
Returns the names of the frames found in the page in the order in which they appear.- Throws:
SAXException
- thrown if there is an error parsing this response
-
getSubframeContents
Returns the contents of the specified subframe of this frameset response.- Parameters:
subFrameName
- the name of the desired frame as defined in the frameset.
-
getElementWithID
Returns the HTMLElement with the specified ID.- Specified by:
getElementWithID
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getElementsByTagName
return the HTMLElements with the specified tag name- Parameters:
tagName
- e.g. "div" or "table"- Returns:
- a list of all HTMLElements with that tag name
- Throws:
SAXException
- Since:
- 1.7
-
getElementNames
Returns a list of HTML element names contained in this HTML section.- Specified by:
getElementNames
in interfaceHTMLSegment
- Throws:
SAXException
-
getElementsWithName
Returns the HTMLElements found in this segment with the specified name.- Specified by:
getElementsWithName
in interfaceHTMLSegment
- Throws:
SAXException
-
getElementsWithAttribute
Returns the HTMLElements found with the specified attribute value.- Specified by:
getElementsWithAttribute
in interfaceHTMLSegment
- Throws:
SAXException
- Since:
- 1.6
-
getForms
Returns the forms found in the page in the order in which they appear.- Specified by:
getForms
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getFormWithName
Returns the form found in the page with the specified name.- Specified by:
getFormWithName
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getFormWithID
Returns the form found in the page with the specified ID.- Specified by:
getFormWithID
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getFirstMatchingForm
public WebForm getFirstMatchingForm(HTMLElementPredicate predicate, Object criteria) throws SAXException Returns the first form found in the page matching the specified criteria.- Specified by:
getFirstMatchingForm
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getMatchingForms
public WebForm[] getMatchingForms(HTMLElementPredicate predicate, Object criteria) throws SAXException Returns all forms found in the page matching the specified criteria.- Specified by:
getMatchingForms
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getLinks
Returns the links found in the page in the order in which they appear.- Specified by:
getLinks
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getLinkWith
Returns the first link which contains the specified text.- Specified by:
getLinkWith
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getLinkWithImageText
Returns the first link which contains an image with the specified text as its 'alt' attribute.- Specified by:
getLinkWithImageText
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getLinkWithName
Returns the link found in the page with the specified name.- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getLinkWithID
Returns the link found in the page with the specified ID.- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getFirstMatchingLink
public WebLink getFirstMatchingLink(HTMLElementPredicate predicate, Object criteria) throws SAXException Returns the first link found in the page matching the specified criteria.- Specified by:
getFirstMatchingLink
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getMatchingLinks
public WebLink[] getMatchingLinks(HTMLElementPredicate predicate, Object criteria) throws SAXException Returns all links found in the page matching the specified criteria.- Specified by:
getMatchingLinks
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getImages
Returns the images found in the page in the order in which they appear.- Specified by:
getImages
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getImageWithName
Returns the image found in the page with the specified name attribute.- Specified by:
getImageWithName
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getImageWithSource
Returns the first image found in the page with the specified src attribute.- Specified by:
getImageWithSource
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getImageWithAltText
Returns the first image found in the page with the specified alt attribute.- Specified by:
getImageWithAltText
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the segment.
-
getApplets
Description copied from interface:HTMLSegment
Returns the applets found in the page in the order in which they appear.- Specified by:
getApplets
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the segment.
-
getTextBlocks
Returns an array of text blocks found in the page.- Specified by:
getTextBlocks
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the segment.- Since:
- 1.6
-
getNextTextBlock
Returns the text block after the specified block, if any.- Throws:
SAXException
- Since:
- 1.6
-
getFirstMatchingTextBlock
public TextBlock getFirstMatchingTextBlock(HTMLElementPredicate predicate, Object criteria) throws SAXException Returns the first link found in the page matching the specified criteria.- Throws:
SAXException
- thrown if there is an error parsing the response.- Since:
- 1.6
-
getDOM
Returns a copy of the domain object model tree associated with this response. If the response is HTML, it will use a special parser which can transform HTML into an XML DOM.- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getTables
Returns the top-level tables found in this page in the order in which they appear.- Specified by:
getTables
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getFirstMatchingTable
public WebTable getFirstMatchingTable(HTMLElementPredicate predicate, Object criteria) throws SAXException Returns the first table in the response which matches the specified predicate and value. Will recurse into any nested tables, as needed.- Specified by:
getFirstMatchingTable
in interfaceHTMLSegment
- Returns:
- the selected table, or null if none is found
- Throws:
SAXException
-
getMatchingTables
public WebTable[] getMatchingTables(HTMLElementPredicate predicate, Object criteria) throws SAXException Returns all tables found in the page matching the specified criteria.- Specified by:
getMatchingTables
in interfaceHTMLSegment
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getTableStartingWith
Returns the first table in the response which has the specified text as the full text of its first non-blank row and non-blank column. Will recurse into any nested tables, as needed. Case is ignored.- Specified by:
getTableStartingWith
in interfaceHTMLSegment
- Returns:
- the selected table, or null if none is found
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getTableStartingWithPrefix
Returns the first table in the response which has the specified text as a prefix of the text of its first non-blank row and non-blank column. Will recurse into any nested tables, as needed. Case is ignored.- Specified by:
getTableStartingWithPrefix
in interfaceHTMLSegment
- Returns:
- the selected table, or null if none is found
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getTableWithSummary
Returns the first table in the response which has the specified text as its summary attribute. Will recurse into any nested tables, as needed. Case is ignored.- Specified by:
getTableWithSummary
in interfaceHTMLSegment
- Returns:
- the selected table, or null if none is found
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getTableWithID
Returns the first table in the response which has the specified text as its ID attribute. Will recurse into any nested tables, as needed. Case is ignored.- Specified by:
getTableWithID
in interfaceHTMLSegment
- Returns:
- the selected table, or null if none is found
- Throws:
SAXException
- thrown if there is an error parsing the response.
-
getScriptableObject
get the scriptable object for this WebResponse -
setScriptingHandler
-
getScriptingHandler
- Specified by:
getScriptingHandler
in interfacecom.meterware.httpunit.dom.DomWindowProxy
-
createJavascriptScriptingHandler
-
createDomScriptingHandler
create a DOMScriptingHandler- Returns:
- the DOM scripting handler (the window)
-
newDelegate
-
openNewWindow
public com.meterware.httpunit.dom.DomWindowProxy openNewWindow(String name, String relativeUrl) throws IOException, SAXException open a a new Window with the given name and relative URL- Specified by:
openNewWindow
in interfacecom.meterware.httpunit.dom.DomWindowProxy
- Parameters:
name
- - the name of the windowrelativeUrl
- - the relative URL to be used- Returns:
- the WebResponse as a DomWindowProxy
- Throws:
IOException
SAXException
-
submitRequest
public com.meterware.httpunit.dom.DomWindowProxy submitRequest(com.meterware.httpunit.dom.HTMLElementImpl sourceElement, String method, String location, String target, com.meterware.httpunit.protocol.MessageBody requestBody) throws IOException, SAXException - Specified by:
submitRequest
in interfacecom.meterware.httpunit.dom.DomWindowProxy
- Throws:
IOException
SAXException
-
close
public void close()- Specified by:
close
in interfacecom.meterware.httpunit.dom.DomWindowProxy
-
alert
- Specified by:
alert
in interfacecom.meterware.httpunit.dom.DomWindowProxy
-
confirm
- Specified by:
confirm
in interfacecom.meterware.httpunit.dom.DomWindowProxy
-
prompt
- Specified by:
prompt
in interfacecom.meterware.httpunit.dom.DomWindowProxy
-
toString
-
defineRawInputStream
- Throws:
IOException
-
setContentTypeHeader
Overwrites the current value (if any) of the content type header. -
replaceText
Description copied from interface:com.meterware.httpunit.dom.DomWindowProxy
Replaces the text in the window with the specified text and content type. Returns false if unable to do the replacement.- Specified by:
replaceText
in interfacecom.meterware.httpunit.dom.DomWindowProxy
-
getClient
getter for the WebClient- Returns:
- the web client for this WebResponse (if any)
- Since:
- 1.7
-
loadResponseText
- Throws:
IOException
-
getValidContentTypes
allow access to the valid content Types- Returns:
- the validContentTypes
- Since:
- 1.7
-
setValidContentTypes
allow modification of the valid content Types use with care- Parameters:
validContentTypes
- the validContentTypes to set- Since:
- 1.7
-