| java.lang.Object net.matuschek.http.HttpTool
HttpTool | public class HttpTool (Code) | | Class for retrieving documents from HTTP servers.
The main purpose of this class is to retrieve a document
from an HTTP server.
For many purposes the Java URLInputStream is good for this,
but if you want to have full control over the HTTP headers
(both request and response headers), HttpTool is the answer.
Also it defines a callback interface to inform a client about
the state of the current download operation.
It is possible to abort a download after getting the
HTTP response headers from the server (e.g. if a document of
this Content-Type is useless for your application or the document
is to big or whatever you like)
HttpTool is reusuable. You should initializes it once and use
it for every download operation.
author: Daniel Matuschek version: $Id: HttpTool.java,v 1.28 2004/03/26 20:28:44 matuschd Exp $ |
Inner Class :protected class DocAndConnection | |
Constructor Summary | |
public | HttpTool() Initializes HttpTool with a new CookieManager (that will not contain
any cookie). |
CR | final static byte CR(Code) | | Carriage return
|
HTTP_VERSION | final static String HTTP_VERSION(Code) | | used HTTP version
|
LF | final static byte LF(Code) | | Line feed
|
STATUS_CONNECTED | final public static int STATUS_CONNECTED(Code) | | HTTP connection was established, but no data where retrieved
|
STATUS_CONNECTING | final public static int STATUS_CONNECTING(Code) | | HTTP connection will be established
|
STATUS_DENIEDBYRULE | final public static int STATUS_DENIEDBYRULE(Code) | | download could not be finished because a DownloadRule denied it
|
STATUS_DONE | final public static int STATUS_DONE(Code) | | download finished
|
STATUS_RETRIEVING | final public static int STATUS_RETRIEVING(Code) | | data will be retrieved now
|
HttpTool | public HttpTool()(Code) | | Initializes HttpTool with a new CookieManager (that will not contain
any cookie).
Enables logging
|
clearCookies | public void clearCookies()(Code) | | Delete all cookies
|
finish | public void finish()(Code) | | Insiders BugFix
This method finishes the MemoryCleanupManager.
|
getAgentName | public String getAgentName()(Code) | | Gets the current setting of the User-Agent HTTP header
the User-Agent name |
getBandwidth | public int getBandwidth()(Code) | | Get the value of bandwidth.
value of bandwidth. |
getCallback | public HttpToolCallback getCallback()(Code) | | Gets the current callback object
the defined HttpToolCallback object |
getCookieManager | public CookieManager getCookieManager()(Code) | | Gets the CookieManager used by this HttpTool
the CookieManager that will be used by this HttpTool |
getDownloadRuleSet | public DownloadRuleSet getDownloadRuleSet()(Code) | | Gets the DownloadRules for this object
a DownloadRuleSet |
getEnableCookies | public boolean getEnableCookies()(Code) | | Get the status of the cookie engine
true, if HTTP cookies are enabled, false otherwise |
getIfModifiedSince | public Date getIfModifiedSince()(Code) | | Returns the date used for the "If-Modified-Since" header
a Date object if the "If-Modified-Since" header is set,null otherwise |
getProxy | public String getProxy()(Code) | | Gets a textual representation of the current proxy settings
return the proxy settings in the format host:port |
lineString | protected String lineString(byte[] b)(Code) | | convert an array of bytes to a String. if the last byte is an CR
it will be ignored
|
retrieveDocument | public HttpDoc retrieveDocument(URL u, int method, String parameters) throws HttpException(Code) | | Retrieves a document from the given URL.
If Cookies are enabled it will use the CookieManager to set Cookies
it got from former retrieveDocument operations.
Parameters: u - the URL to retrieve (only http:// supported yet) Parameters: method - HttpConstants.GET for a GET request, HttpConstants.POSTfor a POST request Parameters: parameters - additional parameters. Will be added to the URL ifthis is a GET request, posted if it is a POST request a HttpDoc if a document was retrieved, null otherwise See Also: HttpConstants |
retrieveDocumentInternal | protected DocAndConnection retrieveDocumentInternal(URL u, int method, String parameters, HttpConnection httpConn, String ntlmAuthorizationInfo) throws HttpException(Code) | | Same like method without parameter httpConnection, but this
method uses the passed connection.
Parameters: u - Parameters: method - Parameters: parameters - Parameters: httpConnection - (Use this connection) DocAndConnection throws: HttpException - |
setAgentName | public void setAgentName(String name)(Code) | | Sets the User-Agent: HTTP header
Parameters: name - name of the user agent (may contain spaces) |
setBandwidth | public void setBandwidth(int bandwidth)(Code) | | Set the value of bandwidth.
Parameters: bandwith - Value to assign to bandwidth. |
setCallback | public void setCallback(HttpToolCallback callback)(Code) | | Sets a callback object
If set this object will be used to inform about the current
status of the download. HttpTool will call methods of this
object while retrieving a document.
Parameters: callback - a callback object See Also: HttpToolCallback |
setCookieManager | public void setCookieManager(CookieManager cm)(Code) | | Sets the CookieManager for this HttpTool
By default a MemoryCookieManager will be used, but you can
use this method to use your own CookieManager implementation
Parameters: cm - an object that implements the CookieManager interface |
setDownloadRuleSet | public void setDownloadRuleSet(DownloadRuleSet rules)(Code) | | Sets the DownloadRules for this object
A download rule uses the HTTP return headers to decide if the
download should be finished.
Parameters: rule - a DownloadRule |
setEnableCookies | public void setEnableCookies(boolean enable)(Code) | | Enable/disable cookies
Parameters: enable - if true, HTTP cookies will be enabled, if falseHttpTool will not use cookies |
setFromAddress | public void setFromAddress(String fromAddress)(Code) | | Sets the content From: HTTP header
Parameters: fromAdress - an email adress (e.g. some@where.com) |
setIfModifiedSince | public void setIfModifiedSince(Date modifyDate)(Code) | | Set the value of the "If-Modified-Since" header
Usually, this is null and HttpTool will retrieve every
document. Setting this to a date will retrieve only
documents that were modified since this time
|
setProxy | public void setProxy(String proxyDescr) throws HttpException(Code) | | sets a proxy to use
Parameters: proxyDescr - the Proxy definition in the format host:port |
setReferer | public void setReferer(String referer)(Code) | | Sets the Referer: HTTP header
Parameters: referer - value for the Referer header |
setTimeout | public void setTimeout(int timeout)(Code) | | Sets the timeout for getting data. If HttpTool can't read
data from a remote web server after this number of seconds
it will stop the download of the current file
Parameters: timeout - Timeout in seconds |
setUpdateInterval | public void setUpdateInterval(int updateInterval)(Code) | | Sets the callback update interval
This setting is used if a callback object is defined. Then after
reading this number of bytes, the method
setHttpToolDocCurrentSize will be called.
You should not set this to a value smaller then 1000 unless your
bandwidth is very small, because it will slow down downloads.
Parameters: updateInterval - update interval in bytes See Also: HttpToolCallbackInterface.setHttpToolDocCurrentSize(int) |
useProxy | protected boolean useProxy()(Code) | | should I use a proxy ?
true if a proxy was configured, false otherwise |
|
|