Module org.htmlunit

Class FalsifyingWebConnection

java.lang.Object
org.htmlunit.util.WebConnectionWrapper
org.htmlunit.util.FalsifyingWebConnection
All Implemented Interfaces:
AutoCloseable, WebConnection

public abstract class FalsifyingWebConnection extends WebConnectionWrapper
Extension of WebConnectionWrapper providing utility methods to deliver content other than what the wrapped connection would deliver.
Author:
Marc Guillemot, Ronald Brill
  • Constructor Details

  • Method Details

    • deliverFromAlternateUrl

      protected WebResponse deliverFromAlternateUrl(WebRequest webRequest, URL url) throws IOException
      Delivers the content for an alternate URL as if it comes from the originally requested URL.
      Parameters:
      webRequest - the original web request
      url - the URL from which the content should actually be retrieved
      Returns:
      the response
      Throws:
      IOException - if a problem occurs
    • replaceContent

      protected WebResponse replaceContent(WebResponse wr, String newContent) throws IOException
      Builds a new WebResponse with the given content, preserving all other response attributes.
      Parameters:
      wr - the web response to adapt
      newContent - the new content to place in the response
      Returns:
      a web response with the new content
      Throws:
      IOException - if an encoding problem occurs
    • createWebResponse

      protected WebResponse createWebResponse(WebRequest wr, String content, String contentType) throws IOException
      Creates a faked WebResponse for the given request with the provided content, using HTTP status 200 OK.
      Parameters:
      wr - the web request for which a response should be created
      content - the content to place in the response
      contentType - the content type of the response
      Returns:
      a web response with the provided content
      Throws:
      IOException - if an encoding problem occurs
    • createWebResponse

      protected WebResponse createWebResponse(WebRequest wr, String content, String contentType, int responseCode, String responseMessage) throws IOException
      Creates a faked WebResponse for the given request with the provided content and status.
      Parameters:
      wr - the web request for which a response should be created
      content - the content to place in the response
      contentType - the content type of the response
      responseCode - the HTTP status code for the response
      responseMessage - the HTTP status message for the response
      Returns:
      a web response with the provided content
      Throws:
      IOException - if an encoding problem occurs