java.lang.Object
org.htmlunit.util.WebConnectionWrapper
org.htmlunit.util.DebuggingWebConnection
- All Implemented Interfaces:
AutoCloseable,WebConnection
Wrapper around a "real"
This may be useful during development to understand what is being browsed.
Example:
This class is only intended as a debugging aid during development.
WebConnection that uses the wrapped connection
to perform the actual work and saves all received responses
in the temp directory with an overview page.This may be useful during development to understand what is being browsed.
Example:
final WebClient client = new WebClient(); final WebConnection connection = new DebuggingWebConnection(client.getWebConnection(), "myTest"); client.setWebConnection(connection);In this example an overview page will be generated under the name
myTest/index.html in the temp directory
and all received responses will be saved into the myTest folder.This class is only intended as a debugging aid during development.
- Author:
- Marc Guillemot, Ahmed Ashour, Ronald Brill
-
Constructor Summary
ConstructorsConstructorDescriptionDebuggingWebConnection(WebConnection webConnection, String dirName) Wraps a web connection to have a report generated of the received responses. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a mark that will be visible in the HTML result page generated by this class.getResponse(WebRequest request) Calls the wrapped web connection and saves the received response.booleanReturns whether JavaScript responses should be uncompressed before saving.protected voidsaveResponse(WebResponse response, WebRequest request) Saves the response content in the temp directory and adds it to the summary page.voidsetUncompressJavaScript(boolean decompress) Sets whether responses recognized as JavaScript should be uncompressed.protected WebResponseuncompressJavaScript(WebResponse response) Tries to uncompress the JavaScript code in the provided response.Methods inherited from class org.htmlunit.util.WebConnectionWrapper
close, getWrappedWebConnection
-
Constructor Details
-
DebuggingWebConnection
Wraps a web connection to have a report generated of the received responses.- Parameters:
webConnection- the web connection that does the real workdirName- the name of the directory to create in the temp folder to save received responses; if this folder already exists, it will be deleted first- Throws:
IOException- if there is a problem writing the files
-
-
Method Details
-
getResponse
Calls the wrapped web connection and saves the received response. Submits a request and retrieves a response. The default behavior of this method is to returnWebConnection.getResponse(WebRequest)on the wrapped connection object.- Specified by:
getResponsein interfaceWebConnection- Overrides:
getResponsein classWebConnectionWrapper- Parameters:
request- the request- Returns:
- the response to the request defined by the specified request
- Throws:
IOException- if an IO error occurs
-
uncompressJavaScript
Tries to uncompress the JavaScript code in the provided response.- Parameters:
response- the response to uncompress- Returns:
- a new response with uncompressed JavaScript code, or the original response if uncompression fails
-
addMark
Adds a mark that will be visible in the HTML result page generated by this class.- Parameters:
mark- the text of the mark- Throws:
IOException- if a problem occurs writing the file
-
saveResponse
Saves the response content in the temp directory and adds it to the summary page.- Parameters:
response- the response to saverequest- the request used to obtain the response- Throws:
IOException- if a problem occurs writing the file
-
isUncompressJavaScript
public boolean isUncompressJavaScript()Returns whether JavaScript responses should be uncompressed before saving.- Returns:
trueif JavaScript responses should be uncompressed; default istrue
-
setUncompressJavaScript
public void setUncompressJavaScript(boolean decompress) Sets whether responses recognized as JavaScript should be uncompressed. Uncompressing is useful for debugging when the original script is minified to a single line, as it produces more readable output and more useful error messages.- Parameters:
decompress-trueif JavaScript responses should be uncompressed
-