Package org.htmlunit.util
Class FalsifyingWebConnection
- java.lang.Object
-
- org.htmlunit.util.WebConnectionWrapper
-
- org.htmlunit.util.FalsifyingWebConnection
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,WebConnection
public abstract class FalsifyingWebConnection extends WebConnectionWrapper
Extension ofWebConnectionWrapper
providing facility methods to deliver something other than what the wrapped connection would deliver.
-
-
Constructor Summary
Constructors Constructor Description FalsifyingWebConnection(WebClient webClient)
Constructs an instance and places itself as connection of the WebClient.FalsifyingWebConnection(WebConnection webConnection)
Constructs a WebConnection object wrapping provided WebConnection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected WebResponse
createWebResponse(WebRequest wr, java.lang.String content, java.lang.String contentType)
Creates a faked WebResponse for the request with the provided content.protected WebResponse
createWebResponse(WebRequest wr, java.lang.String content, java.lang.String contentType, int responseCode, java.lang.String responseMessage)
Creates a faked WebResponse for the request with the provided content.protected WebResponse
deliverFromAlternateUrl(WebRequest webRequest, java.net.URL url)
Delivers the content for an alternate URL as if it comes from the requested URL.protected WebResponse
replaceContent(WebResponse wr, java.lang.String newContent)
Builds a WebResponse with new content, preserving all other information.-
Methods inherited from class org.htmlunit.util.WebConnectionWrapper
close, getResponse, getWrappedWebConnection
-
-
-
-
Constructor Detail
-
FalsifyingWebConnection
public FalsifyingWebConnection(WebConnection webConnection) throws java.lang.IllegalArgumentException
Constructs a WebConnection object wrapping provided WebConnection.- Parameters:
webConnection
- the webConnection that does the real work- Throws:
java.lang.IllegalArgumentException
- if the connection isnull
-
FalsifyingWebConnection
public FalsifyingWebConnection(WebClient webClient) throws java.lang.IllegalArgumentException
Constructs an instance and places itself as connection of the WebClient.- Parameters:
webClient
- the WebClient which WebConnection should be wrapped- Throws:
java.lang.IllegalArgumentException
- if the WebClient isnull
-
-
Method Detail
-
deliverFromAlternateUrl
protected WebResponse deliverFromAlternateUrl(WebRequest webRequest, java.net.URL url) throws java.io.IOException
Delivers the content for an alternate URL as if it comes from the requested URL.- Parameters:
webRequest
- the original web requesturl
- the URL from which the content should be retrieved- Returns:
- the response
- Throws:
java.io.IOException
- if a problem occurred
-
replaceContent
protected WebResponse replaceContent(WebResponse wr, java.lang.String newContent) throws java.io.IOException
Builds a WebResponse with new content, preserving all other information.- Parameters:
wr
- the web response to adaptnewContent
- the new content to place in the response- Returns:
- a web response with the new content
- Throws:
java.io.IOException
- if an encoding problem occurred
-
createWebResponse
protected WebResponse createWebResponse(WebRequest wr, java.lang.String content, java.lang.String contentType) throws java.io.IOException
Creates a faked WebResponse for the request with the provided content.- 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:
java.io.IOException
- if an encoding problem occurred
-
createWebResponse
protected WebResponse createWebResponse(WebRequest wr, java.lang.String content, java.lang.String contentType, int responseCode, java.lang.String responseMessage) throws java.io.IOException
Creates a faked WebResponse for the request with the provided content.- 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 code for the responseresponseMessage
- the HTTP message for the response- Returns:
- a web response with the provided content
- Throws:
java.io.IOException
- if an encoding problem occurred
-
-