Package org.htmlunit.util
Class DebuggingWebConnection
java.lang.Object
org.htmlunit.util.WebConnectionWrapper
org.htmlunit.util.DebuggingWebConnection
- All Implemented Interfaces:
AutoCloseable
,WebConnection
Wrapper around a "real" WebConnection that will use the wrapped web connection
to do the real job and save all received responses
in the temp directory with an overview page.
This may be useful at conception time to understand what is "browsed".
Example:
This class is only intended as a help during the conception.
This may be useful at conception time to understand what is "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 help during the conception.
-
Constructor Summary
ConstructorsConstructorDescriptionDebuggingWebConnection
(WebConnection webConnection, String dirName) Wraps a web connection to have a report generated of the received responses. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a mark that will be visible in the HTML result page generated by this class.getResponse
(WebRequest request) Calls the wrapped webconnection and save the received response.boolean
Indicates if it should try to format responses recognized as JavaScript.protected void
saveResponse
(WebResponse response, WebRequest request) Saves the response content in the temp dir and adds it to the summary page.void
setUncompressJavaScript
(boolean decompress) Indicates that responses recognized as JavaScript should be formatted or not.protected WebResponse
uncompressJavaScript
(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 webConnection that do the real workdirName
- the name of the directory to create in the tmp folder to save received responses. If this folder already exists, it will be deleted first.- Throws:
IOException
- in case of problems writing the files
-
-
Method Details
-
getResponse
Calls the wrapped webconnection and save 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:
getResponse
in interfaceWebConnection
- Overrides:
getResponse
in 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 in case of failure
-
addMark
Adds a mark that will be visible in the HTML result page generated by this class.- Parameters:
mark
- the text- Throws:
IOException
- if a problem occurs writing the file
-
saveResponse
Saves the response content in the temp dir and adds it to the summary page.- Parameters:
response
- the response to saverequest
- the request used to get the response- Throws:
IOException
- if a problem occurs writing the file
-
isUncompressJavaScript
public boolean isUncompressJavaScript()Indicates if it should try to format responses recognized as JavaScript.- Returns:
- default is
false
to deliver the original content
-
setUncompressJavaScript
public void setUncompressJavaScript(boolean decompress) Indicates that responses recognized as JavaScript should be formatted or not. Formatting is interesting for debugging when the original script is compressed on a single line. It allows to better follow with a debugger and to obtain more interesting error messages.- Parameters:
decompress
-true
if JavaScript responses should be uncompressed
-