|
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.gargoylesoftware.htmlunit.WebClient
public class WebClient
An object that represents a web browser
Field Summary | |
---|---|
static java.net.URL |
URL_ABOUT_BLANK
URL for "about:blank" |
Constructor Summary | |
---|---|
WebClient()
Creates a web client instance using the browser version returned by BrowserVersion.getDefault() . |
|
WebClient(BrowserVersion browserVersion)
Creates a web client instance using the specified BrowserVersion . |
|
WebClient(BrowserVersion browserVersion,
java.lang.String proxyHost,
int proxyPort)
Create an instance that will use the specified BrowserVersion and proxy server |
Method Summary | |
---|---|
void |
addHostsToProxyBypass(java.lang.String pattern)
Any hosts matched by the specified regular expression pattern will bypass the configured proxy. |
void |
addRequestHeader(java.lang.String name,
java.lang.String value)
Set a header which will be sent up on EVERY request from this client. |
void |
addWebWindowListener(WebWindowListener listener)
Add a listener for WebWindowEvent's. |
void |
assertionFailed(java.lang.String message)
Throw an exception with the specified message. |
void |
deregisterWebWindow(WebWindow webWindow)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
static java.net.URL |
expandUrl(java.net.URL baseUrl,
java.lang.String relativeUrl)
Expands a relative url relative to the specified base. |
java.util.Map |
getActiveXObjectMap()
Return the active X object map for this webclient. |
AjaxController |
getAjaxController()
Gets the current Ajax controller |
AlertHandler |
getAlertHandler()
Return the alert handler for this webclient. |
BrowserVersion |
getBrowserVersion()
Return the current browser version |
ConfirmHandler |
getConfirmHandler()
Return the confirm handler. |
org.apache.commons.httpclient.auth.CredentialsProvider |
getCredentialsProvider()
Returns the credentials provider for this client instance. |
WebWindow |
getCurrentWindow()
Return the "current" window for this client. |
java.lang.String |
getHomePage()
Returns the client's current homepage. |
HTMLParserListener |
getHTMLParserListener()
Gets the configured listener for messages generated by the html parser. |
static boolean |
getIgnoreOutsideContent()
Get the state of the flag to ignore content outside the BODY and HTML tags |
IncorrectnessListener |
getIncorrectnessListener()
Gets the current listener for encountered incorrectness (except HTML parsing messages that are handled by the HTML parser listener). |
Page |
getPage(java.lang.String url)
Convenient method to build an URL and load it into the current WebWindow |
Page |
getPage(java.net.URL url)
Convenient method to load a URL into the current WebWindow |
Page |
getPage(WebRequestSettings request)
Convenient method to load a web request into the current WebWindow |
Page |
getPage(WebWindow opener,
java.lang.String target,
WebRequestSettings params)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
Page |
getPage(WebWindow webWindow,
WebRequestSettings parameters)
Send a request to a server and return a Page that represents the response from the server. |
PageCreator |
getPageCreator()
Return the current page creator. |
boolean |
getPrintContentOnFailingStatusCode()
Return true if the content of the resulting document will be printed to the console in the event of a failing response code. |
PromptHandler |
getPromptHandler()
Return the prompt handler. |
RefreshHandler |
getRefreshHandler()
Return the current refresh handler or null if one has not been set. |
ScriptEngine |
getScriptEngine()
This method is intended for testing only - use at your own risk. |
ScriptPreProcessor |
getScriptPreProcessor()
Return the script pre processor for this webclient. |
StatusHandler |
getStatusHandler()
Return the status handler for this webclient. |
int |
getTimeout()
Gets the timeout value for the WebConnection |
WebConnection |
getWebConnection()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
WebWindow |
getWebWindowByName(java.lang.String name)
Return the first WebWindow that matches the specified name. |
java.util.List |
getWebWindows()
Return an immutable list of open web windows (top windows or not). |
java.lang.String |
guessContentType(java.io.File file)
Tries to guess the content type of the file. |
void |
initialize(Page newPage)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
void |
initialize(WebWindow webWindow)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
void |
initializeEmptyWindow(WebWindow webWindow)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
boolean |
isCookiesEnabled()
Return true if cookies are enabled. |
boolean |
isJavaScriptEnabled()
Return true if javascript is enabled and the script engine was loaded successfully. |
boolean |
isRedirectEnabled()
Return whether or not redirections will be followed automatically on receipt of a redirect status code from the server. |
boolean |
isThrowExceptionOnFailingStatusCode()
Return true if an exception will be thrown in the event of a failing response code. |
boolean |
isThrowExceptionOnScriptError()
Indicates if an exception should be thrown when a script execution fails (the default) or if it should be caught and just logged to allow page execution to continue. |
WebResponse |
loadWebResponse(WebRequestSettings webRequestSettings)
Loads a WebResponse from the server |
Page |
loadWebResponseInto(WebResponse webResponse,
WebWindow webWindow)
Use the specified WebResponse to create a Page object which will then get inserted into the WebWindow. |
WebWindow |
openWindow(java.net.URL url,
java.lang.String windowName)
Open a new window with the specified name. |
WebWindow |
openWindow(java.net.URL url,
java.lang.String windowName,
WebWindow opener)
Open a new window with the specified name. |
WebWindow |
popFirstWindow()
Return the "first" window for this client. |
void |
pushClearFirstWindow()
Clear the first window for this client. |
void |
registerWebWindow(WebWindow webWindow)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
void |
removeHostsFromProxyBypass(java.lang.String pattern)
Any hosts matched by the specified regular expression pattern will no longer bypass the configured proxy. |
void |
removeRequestHeader(java.lang.String name)
Remove a header |
void |
removeWebWindowListener(WebWindowListener listener)
Remove a listener for WebWindowEvent's. |
void |
setActiveXObjectMap(java.util.Map activeXObjectMap)
Set the active X object map for this webclient. |
void |
setAjaxController(AjaxController newValue)
Sets the current Ajax controller EXPERIMENTAL - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
void |
setAlertHandler(AlertHandler alertHandler)
Set the alert handler for this webclient. |
void |
setConfirmHandler(ConfirmHandler handler)
Set the handler that will be executed when the javascript method Window.confirm() is called. |
void |
setCookiesEnabled(boolean isEnabled)
Enable/disable cookies support. |
void |
setCredentialsProvider(org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider)
Sets the credentials provider that will provide authentication information when trying to access protected information on a web server. |
void |
setCurrentWindow(WebWindow window)
Set the current window for this client. |
void |
setHomePage(java.lang.String homePage)
Sets the client's homepage. |
void |
setHTMLParserListener(HTMLParserListener listener)
Defines a listener for messages generated by the html parser. |
static void |
setIgnoreOutsideContent(boolean ignoreOutsideContent)
Set the flag on the HtmlParse to ignore the content that is outside of the BODY and HTML tags. |
void |
setIncorrectnessListener(IncorrectnessListener listener)
Returns the current HTML incorrectness listener. |
void |
setJavaScriptEnabled(boolean isEnabled)
Enable/disable javascript support. |
void |
setPageCreator(PageCreator pageCreator)
Set the object that will be used to create pages. |
void |
setPrintContentOnFailingStatusCode(boolean enabled)
Specify whether or not the content of the resulting document will be printed to the console in the event of a failing response code. |
void |
setPromptHandler(PromptHandler handler)
Set the handler that will be executed when the javascript method Window.prompt() is called. |
void |
setRedirectEnabled(boolean enabled)
Set whether or not redirections will be followed automatically on receipt of a redirect status code from the server. |
void |
setRefreshHandler(RefreshHandler handler)
Set the handler to be used whenever a refresh is triggered. |
void |
setScriptEngine(ScriptEngine engine)
This method is intended for testing only - use at your own risk. |
void |
setScriptPreProcessor(ScriptPreProcessor scriptPreProcessor)
Set the script pre processor for this webclient. |
void |
setStatusHandler(StatusHandler statusHandler)
Set the status handler for this webclient. |
void |
setThrowExceptionOnFailingStatusCode(boolean enabled)
Specify whether or not an exception will be thrown in the event of a failing status code. |
void |
setThrowExceptionOnScriptError(boolean newValue)
Changes the behavior of this webclient when a script error occurs. |
void |
setTimeout(int timeout)
Sets the timeout of the WebConnection. |
void |
setWebConnection(WebConnection webConnection)
Set the object that will resolve all url requests This method is intended for unit testing HtmlUnit itself. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.net.URL URL_ABOUT_BLANK
Constructor Detail |
---|
public WebClient()
BrowserVersion.getDefault()
.
public WebClient(BrowserVersion browserVersion)
BrowserVersion
.
browserVersion
- The browser version to simulate.public WebClient(BrowserVersion browserVersion, java.lang.String proxyHost, int proxyPort)
BrowserVersion
and proxy server
browserVersion
- The browser version to simulateproxyHost
- The server that will act as proxyproxyPort
- The port to use on the proxy serverMethod Detail |
---|
public void addHostsToProxyBypass(java.lang.String pattern)
pattern
- A regular expression pattern that matches the hostnames of the hosts which should
bypass the configured proxy.Pattern
public void addRequestHeader(java.lang.String name, java.lang.String value)
name
- The name of the headervalue
- The value of the headerpublic void addWebWindowListener(WebWindowListener listener)
listener
- A listener.public void assertionFailed(java.lang.String message)
Override this to provide custom behaviour.
message
- The failure messagepublic void deregisterWebWindow(WebWindow webWindow)
webWindow
- The WebWindow to removepublic static java.net.URL expandUrl(java.net.URL baseUrl, java.lang.String relativeUrl) throws java.net.MalformedURLException
new URL(baseUrl, relativeUrl)
but
there are some cases that URL doesn't handle correctly. See
RFC1808
regarding Relative Uniform Resource Locators for more information.
baseUrl
- The base urlrelativeUrl
- The relative url
java.net.MalformedURLException
- If an error occurred when creating a URL objectpublic java.util.Map getActiveXObjectMap()
public AjaxController getAjaxController()
public AlertHandler getAlertHandler()
public BrowserVersion getBrowserVersion()
public ConfirmHandler getConfirmHandler()
public org.apache.commons.httpclient.auth.CredentialsProvider getCredentialsProvider()
DefaultCredentialsProvider
.
public WebWindow getCurrentWindow()
public java.lang.String getHomePage()
public HTMLParserListener getHTMLParserListener()
null
if no listener is defined (default value).public static boolean getIgnoreOutsideContent()
public IncorrectnessListener getIncorrectnessListener()
IncorrectnessListenerImpl
.
null
).public Page getPage(java.lang.String url) throws java.io.IOException, FailingHttpStatusCodeException, java.net.MalformedURLException
url
- The url of the new content.
FailingHttpStatusCodeException
- If the server returns a
failing status code AND the property
setThrowExceptionOnFailingStatusCode(boolean)
is set to true.
java.io.IOException
- If an IO problem occurs.
java.net.MalformedURLException
- if no url can be created from the provided stringpublic Page getPage(java.net.URL url) throws java.io.IOException, FailingHttpStatusCodeException
url
- The url of the new content.
FailingHttpStatusCodeException
- If the server returns a
failing status code AND the property
setThrowExceptionOnFailingStatusCode(boolean)
is set to true.
java.io.IOException
- If an IO problem occurs.public Page getPage(WebRequestSettings request) throws java.io.IOException, FailingHttpStatusCodeException
request
- The request parameters
FailingHttpStatusCodeException
- If the server returns a
failing status code AND the property
setThrowExceptionOnFailingStatusCode(boolean)
is set to true.
java.io.IOException
- If an IO problem occurs.getPage(WebWindow,WebRequestSettings)
public Page getPage(WebWindow opener, java.lang.String target, WebRequestSettings params) throws FailingHttpStatusCodeException, java.io.IOException
Open a new web window and populate it with a page loaded by
getPage(WebWindow,WebRequestSettings)
opener
- The web window that initiated the request.target
- The name of the window to be opened. This is the name that would
be passed into the javascript open() method.params
- Any parameters
FailingHttpStatusCodeException
- If the server returns a
failing status code AND the property
setThrowExceptionOnFailingStatusCode(boolean)
is set to true.
java.io.IOException
- If an IO problem occurs.public Page getPage(WebWindow webWindow, WebRequestSettings parameters) throws java.io.IOException, FailingHttpStatusCodeException
The type of Page will depend on the content type of the http response.
Content type | Type of page |
---|---|
"text/html" | HtmlPage |
"text/xhtml" | HtmlPage |
"application/xhtml+xml" | HtmlPage for now, in the
future it will be XML validated as well
|
"text/*" | TextPage |
Anything else | UnexpectedPage |
webWindow
- The WebWindow to load this request intoparameters
- Parameter object for the web request
java.io.IOException
- If an IO error occurs
FailingHttpStatusCodeException
- If the server returns a
failing status code AND the property
setThrowExceptionOnFailingStatusCode(boolean)
is set to trueWebRequestSettings
public PageCreator getPageCreator()
public boolean getPrintContentOnFailingStatusCode()
setPrintContentOnFailingStatusCode(boolean)
public PromptHandler getPromptHandler()
public RefreshHandler getRefreshHandler()
public ScriptEngine getScriptEngine()
public ScriptPreProcessor getScriptPreProcessor()
public StatusHandler getStatusHandler()
public int getTimeout()
setTimeout(int)
public WebConnection getWebConnection()
Return the object that will resolve all url requests
public WebWindow getWebWindowByName(java.lang.String name) throws WebWindowNotFoundException
WebWindow
that matches the specified name.
name
- The name to search for.
WebWindow
with the specified name
WebWindowNotFoundException
- If the WebWindow
can't be found.public java.util.List getWebWindows()
public java.lang.String guessContentType(java.io.File file)
file
- the file
public void initialize(Page newPage)
newPage
- The new page.public void initialize(WebWindow webWindow)
webWindow
- The new WebWindowpublic void initializeEmptyWindow(WebWindow webWindow)
webWindow
- The new WebWindowpublic boolean isCookiesEnabled()
public boolean isJavaScriptEnabled()
public boolean isRedirectEnabled()
public boolean isThrowExceptionOnFailingStatusCode()
setThrowExceptionOnFailingStatusCode(boolean)
public boolean isThrowExceptionOnScriptError()
true
if an exception is thrown on script error (the default)public final WebResponse loadWebResponse(WebRequestSettings webRequestSettings) throws java.io.IOException
WebResponse
from the server
webRequestSettings
- settings to use when making the request
java.io.IOException
- if an IO problem occurspublic Page loadWebResponseInto(WebResponse webResponse, WebWindow webWindow) throws java.io.IOException, FailingHttpStatusCodeException
webResponse
- The response that will be used to create the new page.webWindow
- The window that the new page will be placed within.
java.io.IOException
- If an IO error occurs.
FailingHttpStatusCodeException
- If the server returns a
failing status code AND the property
setThrowExceptionOnFailingStatusCode(boolean)
is set to truepublic WebWindow openWindow(java.net.URL url, java.lang.String windowName)
url
- The url to load content from or null if no content is to be loaded.windowName
- The name of the new window
public WebWindow openWindow(java.net.URL url, java.lang.String windowName, WebWindow opener)
url
- The url to load content from or null if no content is to be loaded.windowName
- The name of the new windowopener
- The web window that is calling openWindow
public WebWindow popFirstWindow()
public void pushClearFirstWindow()
public void registerWebWindow(WebWindow webWindow)
webWindow
- The new WebWindowpublic void removeHostsFromProxyBypass(java.lang.String pattern)
pattern
- The previously added regular expression pattern.Pattern
public void removeRequestHeader(java.lang.String name)
name
- Name of the headeraddRequestHeader(java.lang.String, java.lang.String)
public void removeWebWindowListener(WebWindowListener listener)
listener
- A listener.public void setActiveXObjectMap(java.util.Map activeXObjectMap)
Map
is used to map the
string passed into the ActiveXObject
constructor to a java class name. Therefore
you can emulate ActiveXObject
s in a web page's javascript by mapping the object
name to a java class to emulate the active X object.
activeXObjectMap
- The new preprocessor or null if none is specifiedpublic void setAjaxController(AjaxController newValue)
newValue
- the controllerpublic void setAlertHandler(AlertHandler alertHandler)
alertHandler
- The new alerthandler or null if none is specified.public void setConfirmHandler(ConfirmHandler handler)
handler
- The new handler or null if no handler is to be used.public void setCookiesEnabled(boolean isEnabled)
isEnabled
- true to enable cookies support.public void setCredentialsProvider(org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider)
credentialsProvider
- The new credentials provider to use to authenticate.public void setCurrentWindow(WebWindow window)
window
- The new window.public void setHomePage(java.lang.String homePage)
homePage
- the new homepage URLpublic void setHTMLParserListener(HTMLParserListener listener)
getIgnoreOutsideContent()
returns false
, the parser
will ignore closing <body> and <html> tags to be able to handle html content
incorrectly located after the end of the html file. As a consequence it will finally
notify as errors that <body> and <html> are not closed properly even if
they were correctly present.
listener
- the new listener, null
if messages should be totally ignored.public static void setIgnoreOutsideContent(boolean ignoreOutsideContent)
ignoreOutsideContent
- The boolean flag to enable or disable the support of
content outside of the HTML and BODY tagspublic void setIncorrectnessListener(IncorrectnessListener listener)
listener
- the new value (not null
)public void setJavaScriptEnabled(boolean isEnabled)
isEnabled
- true to enable javascript support.public void setPageCreator(PageCreator pageCreator)
pageCreator
- The new page creatorpublic void setPrintContentOnFailingStatusCode(boolean enabled)
enabled
- True to enable this featurepublic void setPromptHandler(PromptHandler handler)
handler
- The new handler or null if no handler is to be used.public void setRedirectEnabled(boolean enabled)
enabled
- true to enable automatic redirection.public void setRefreshHandler(RefreshHandler handler)
RefreshHandler
for more details.
handler
- The new handlerpublic void setScriptEngine(ScriptEngine engine)
engine
- The new script engine to use.public void setScriptPreProcessor(ScriptPreProcessor scriptPreProcessor)
scriptPreProcessor
- The new preprocessor or null if none is specifiedpublic void setStatusHandler(StatusHandler statusHandler)
statusHandler
- The new alerthandler or null if none is specified.public void setThrowExceptionOnFailingStatusCode(boolean enabled)
enabled
- True to enable this featurepublic void setThrowExceptionOnScriptError(boolean newValue)
newValue
- indicates if exception should be thrown or notpublic void setTimeout(int timeout)
timeout
- The value of the timeout in millisecondspublic void setWebConnection(WebConnection webConnection)
webConnection
- The new web connection
|
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |