Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.meterware.httpunit
Class WebResponse

    java.lang.Object
      |
      +--com.meterware.httpunit.WebResponse

All Implemented Interfaces:
  HTMLSegment

public abstract class WebResponse
extends Object
implements HTMLSegment

A response to a web request from a web server.

Author:
  Russell Gold, Drew Varner, Dave Glowacki, Benoit Xhenseval

Constructor Summary
`protected` | `WebResponse(String frameName, URL url)` Constructs a response object.

Method Summary
`protected void` | `defineRawInputStream(InputStream inputStream)`
`String` | `getCharacterSet()` Returns the character set used in this response.
`int` | `getContentLength()` Returns the content length of this response.
`String` | `getContentType()` Returns the content type of this response.
`Document` | `getDOM()` Returns a copy of the domain object model tree associated with this response.
`String` | `getExternalStyleSheet()` Returns the stylesheet linked in the head of the page.
`WebForm[]` | `getForms()` Returns the forms found in the page in the order in which they appear.
`WebForm` | `getFormWithID(String ID)` Returns the form found in the page with the specified ID.
`WebForm` | `getFormWithName(String name)` Returns the form found in the page with the specified name.
`String[]` | `getFrameNames()` 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[]` | `getHeaderFieldNames()` Returns the names of the header fields found in the response.
`abstract String[]` | `getHeaderFields(String fieldName)` Returns the values for the specified header field.
`InputStream` | `getInputStream()` 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.
`WebLink` | `getLinkWith(String text)` Returns the first link which contains the specified text.
`WebLink` | `getLinkWithID(String ID)` Returns the link found in the page with the specified ID.
`WebLink` | `getLinkWithImageText(String text)` Returns the first link which contains an image with the specified text as its 'alt' attribute.
`WebLink` | `getLinkWithName(String name)` Returns the link found in the page with the specified name.
`String[]` | `getMetaTagContent(String attribute, String attributeValue)` Retrieves the "content" of the meta tags for a key pair attribute-attributeValue.
`String[]` | `getNewCookieNames()` Returns a list of new cookie names defined as part of this response.
`String` | `getNewCookieValue(String name)` Returns the new cookie value defined as part of this response.
`int` | `getRefreshDelay()` Returns the delay before normally following the request to refresh this page, if any.
`WebRequest` | `getRefreshRequest()` Returns a request to refresh this page, if any.
`abstract int` | `getResponseCode()` Returns the response code associated with this response.
`abstract String` | `getResponseMessage()` Returns the response message associated with this response.
`WebResponse` | `getSubframeContents(String subFrameName)` Returns the contents of the specified subframe of this frameset response.
`WebTable[]` | `getTables()` Returns the top-level tables found in this page in the order in which they appear.
`WebTable` | `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.
`WebTable` | `getTableStartingWithPrefix(String text)` 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.
`WebTable` | `getTableWithID(String text)` Returns the first table in the response which has the specified text as its ID attribute.
`WebTable` | `getTableWithSummary(String text)` Returns the first table in the response which has the specified text as its summary attribute.
`String` | `getTarget()` Returns the target of the page.
`String` | `getText()` Returns the text of the response (excluding headers) as a string.
`String` | `getTitle()` Returns the title of the page.
`URL` | `getURL()` Returns the URL which invoked this response.
`boolean` | `isHTML()` Returns true if the response is HTML.
`protected void` | `loadResponseText()`
`static WebResponse` | `newResponse(URLConnection connection)` Returns a web response built from a URL connection.
`protected void` | `readRefreshRequest(String contentTypeHeader)`
`protected void` | `setContentTypeHeader(String value)` Overwrites the current value (if any) of the content type header.
`abstract String` | `toString()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### WebResponse

    protected WebResponse(String frameName,
                          URL url)

  Constructs a response object.
  Parameters:
    `frameName` - the name of the frame to hold the response
    `url` - the url from which the response was received

Method Detail

### newResponse

    public static WebResponse newResponse(URLConnection connection)
                                   throws IOException

  Returns a web response built from a URL connection. Provided to allow access to WebResponse parsing without using a WebClient.

### isHTML

    public boolean isHTML()

  Returns true if the response is HTML.

### getURL

    public URL getURL()

  Returns the URL which invoked this response.

### getTitle

    public String getTitle()
                    throws SAXException

  Returns the title of the page.
  Throws:
    `SAXException` - thrown if there is an error parsing this response

### getExternalStyleSheet

    public String getExternalStyleSheet()
                                 throws SAXException

  Returns the stylesheet linked in the head of the page. `` will return "/mystyle.css".
  Throws:
    `SAXException` - thrown if there is an error parsing this response

### getMetaTagContent

    public String[] getMetaTagContent(String attribute,
                                      String attributeValue)
                               throws SAXException

  Retrieves the "content" of the meta tags for a key pair attribute-attributeValue. `` this can be used like this `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

### getTarget

    public String getTarget()

  Returns the target of the page.

### getRefreshRequest

    public WebRequest 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

    public abstract String 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

    public String getContentType()

  Returns the content type of this response.

### getCharacterSet

    public String getCharacterSet()

  Returns the character set used in this response.

### getNewCookieNames

    public String[] getNewCookieNames()

  Returns a list of new cookie names defined as part of this response.

### getNewCookieValue

    public String getNewCookieValue(String name)

  Returns the new cookie value defined as part of this response.

### getHeaderFieldNames

    public abstract String[] getHeaderFieldNames()

  Returns the names of the header fields found in the response.

### getHeaderField

    public abstract String getHeaderField(String fieldName)

  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.

### getHeaderFields

    public abstract String[] getHeaderFields(String fieldName)

  Returns the values for the specified header field. If no such field is defined, will return an empty array.

### getText

    public String getText()
                   throws IOException

  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.

### getInputStream

    public InputStream getInputStream()
                               throws IOException

  Returns a buffered input stream for reading the contents of this reply.

### getFrameNames

    public String[] getFrameNames()
                           throws SAXException

  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

    public WebResponse getSubframeContents(String subFrameName)

  Returns the contents of the specified subframe of this frameset response.
  Parameters:
    `subFrameName` - the name of the desired frame as defined in the frameset.

### getForms

    public WebForm[] getForms()
                       throws SAXException

  Returns the forms found in the page in the order in which they appear.
  Specified by:
    `getForms` in interface `HTMLSegment`
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getFormWithName

    public WebForm getFormWithName(String name)
                            throws SAXException

  Returns the form found in the page with the specified name.
  Specified by:
    `getFormWithName` in interface `HTMLSegment`
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getFormWithID

    public WebForm getFormWithID(String ID)
                          throws SAXException

  Returns the form found in the page with the specified ID.
  Specified by:
    `getFormWithID` in interface `HTMLSegment`
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getLinks

    public WebLink[] getLinks()
                       throws SAXException

  Returns the links found in the page in the order in which they appear.
  Specified by:
    `getLinks` in interface `HTMLSegment`
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getLinkWith

    public WebLink getLinkWith(String text)
                        throws SAXException

  Returns the first link which contains the specified text.
  Specified by:
    `getLinkWith` in interface `HTMLSegment`
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getLinkWithImageText

    public WebLink getLinkWithImageText(String text)
                                 throws SAXException

  Returns the first link which contains an image with the specified text as its 'alt' attribute.
  Specified by:
    `getLinkWithImageText` in interface `HTMLSegment`
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getLinkWithName

    public WebLink getLinkWithName(String name)
                            throws SAXException

  Returns the link found in the page with the specified name.
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getLinkWithID

    public WebLink getLinkWithID(String ID)
                          throws SAXException

  Returns the link found in the page with the specified ID.
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getTables

    public WebTable[] getTables()
                         throws SAXException

  Returns the top-level tables found in this page in the order in which they appear.
  Specified by:
    `getTables` in interface `HTMLSegment`
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getDOM

    public Document getDOM()
                    throws SAXException

  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.

### getTableStartingWith

    public WebTable getTableStartingWith(String text)
                                  throws SAXException

  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 interface `HTMLSegment`
  Returns:
    the selected table, or null if none is found
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getTableStartingWithPrefix

    public WebTable getTableStartingWithPrefix(String text)
                                        throws SAXException

  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 interface `HTMLSegment`
  Returns:
    the selected table, or null if none is found
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getTableWithSummary

    public WebTable getTableWithSummary(String text)
                                 throws SAXException

  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 interface `HTMLSegment`
  Returns:
    the selected table, or null if none is found
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### getTableWithID

    public WebTable getTableWithID(String text)
                            throws SAXException

  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 interface `HTMLSegment`
  Returns:
    the selected table, or null if none is found
  Throws:
    `SAXException` - thrown if there is an error parsing the response.

### toString

    public abstract String toString()

  Overrides:
    `toString` in class `Object`

### defineRawInputStream

    protected final void defineRawInputStream(InputStream inputStream)
                                       throws IOException

### readRefreshRequest

    protected final void readRefreshRequest(String contentTypeHeader)

### setContentTypeHeader

    protected void setContentTypeHeader(String value)

  Overwrites the current value (if any) of the content type header.

### loadResponseText

    protected void loadResponseText()
                             throws IOException

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD