java.lang.Object
org.htmlunit.util.WebConnectionWrapper
org.htmlunit.util.FalsifyingWebConnection
- All Implemented Interfaces:
AutoCloseable,WebConnection
Extension of
WebConnectionWrapper providing utility methods to deliver content other than
what the wrapped connection would deliver.- Author:
- Marc Guillemot, Ronald Brill
-
Constructor Summary
ConstructorsConstructorDescriptionFalsifyingWebConnection(WebClient webClient) Constructs an instance and installs itself as the connection of the givenWebClient.FalsifyingWebConnection(WebConnection webConnection) Constructs a web connection wrapping the providedWebConnection. -
Method Summary
Modifier and TypeMethodDescriptionprotected WebResponsecreateWebResponse(WebRequest wr, String content, String contentType) Creates a fakedWebResponsefor the given request with the provided content, using HTTP status 200 OK.protected WebResponsecreateWebResponse(WebRequest wr, String content, String contentType, int responseCode, String responseMessage) Creates a fakedWebResponsefor the given request with the provided content and status.protected WebResponsedeliverFromAlternateUrl(WebRequest webRequest, URL url) Delivers the content for an alternate URL as if it comes from the originally requested URL.protected WebResponsereplaceContent(WebResponse wr, String newContent) Builds a newWebResponsewith the given content, preserving all other response attributes.Methods inherited from class org.htmlunit.util.WebConnectionWrapper
close, getResponse, getWrappedWebConnection
-
Constructor Details
-
FalsifyingWebConnection
Constructs a web connection wrapping the providedWebConnection.- Parameters:
webConnection- the web connection that does the real work- Throws:
IllegalArgumentException- if the connection isnull
-
FalsifyingWebConnection
Constructs an instance and installs itself as the connection of the givenWebClient.- Parameters:
webClient- theWebClientwhose connection should be wrapped- Throws:
IllegalArgumentException- if theWebClientisnull
-
-
Method Details
-
deliverFromAlternateUrl
Delivers the content for an alternate URL as if it comes from the originally requested URL.- Parameters:
webRequest- the original web requesturl- the URL from which the content should actually be retrieved- Returns:
- the response
- Throws:
IOException- if a problem occurs
-
replaceContent
Builds a newWebResponsewith the given content, preserving all other response attributes.- Parameters:
wr- the web response to adaptnewContent- 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 fakedWebResponsefor the given request with the provided content, using HTTP status 200 OK.- Parameters:
wr- the web request for which a response should be createdcontent- the content to place in the responsecontentType- 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 fakedWebResponsefor the given request with the provided content and status.- Parameters:
wr- the web request for which a response should be createdcontent- the content to place in the responsecontentType- the content type of the responseresponseCode- the HTTP status code for the responseresponseMessage- the HTTP status message for the response- Returns:
- a web response with the provided content
- Throws:
IOException- if an encoding problem occurs
-