|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.htmlparser.http.ConnectionManager
Handles proxies, password protected URLs and request properties including cookies.
Field Summary | |
protected java.util.Hashtable |
mCookieJar
Cookie storage, a hashtable (by site or host) of vectors of Cookies. |
protected static java.util.Hashtable |
mDefaultRequestProperties
Default Request header fields. |
protected static java.text.SimpleDateFormat |
mFormat
Cookie expiry date format for parsing. |
protected ConnectionMonitor |
mMonitor
The object to be notified prior to and after each connection. |
protected java.lang.String |
mPassword
The user password for accessing the URL. |
protected java.lang.String |
mProxyHost
The proxy server name. |
protected java.lang.String |
mProxyPassword
The proxy user password. |
protected int |
mProxyPort
The proxy port number. |
protected java.lang.String |
mProxyUser
The proxy username name. |
protected java.util.Hashtable |
mRequestProperties
Request header fields. |
protected java.lang.String |
mUser
The username name for accessing the URL. |
Constructor Summary | |
ConnectionManager()
Create a connection manager. |
|
ConnectionManager(java.util.Hashtable properties)
Create a connection manager with the given connection properties. |
Method Summary | |
void |
addCookies(java.net.URLConnection connection)
Generate a HTTP cookie header value string from the cookie jar. |
protected java.util.Vector |
addCookies(java.util.Vector cookies,
java.lang.String path,
java.util.Vector list)
Add qualified cookies from cookies into list. |
static java.lang.String |
encode(byte[] array)
Encodes a byte array into BASE64 in accordance with RFC 2045. |
java.lang.String |
fixSpaces(java.lang.String url)
Turn spaces into %20. |
protected java.lang.String |
generateCookieProperty(java.util.Vector cookies)
Creates the cookie request property value from the list of valid cookies for the domain. |
boolean |
getCookieProcessingEnabled()
Predicate to determine if cookie processing is currently enabled. |
static java.util.Hashtable |
getDefaultRequestProperties()
Get the current default request header properties. |
protected java.lang.String |
getDomain(java.lang.String host)
Get the domain from a host. |
ConnectionMonitor |
getMonitor()
Get the monitoring object, if any. |
java.lang.String |
getPassword()
Get the URL users's password. |
java.lang.String |
getProxyHost()
Get the proxy host name, if any. |
java.lang.String |
getProxyPassword()
Set the proxy user's password. |
int |
getProxyPort()
Get the proxy port number. |
java.lang.String |
getProxyUser()
Get the user name for proxy authorization, if any. |
java.util.Hashtable |
getRequestProperties()
Get the current request header properties. |
java.lang.String |
getUser()
Get the user name to access the URL. |
java.net.URLConnection |
openConnection(java.lang.String string)
Opens a connection based on a given string. |
java.net.URLConnection |
openConnection(java.net.URL url)
Opens a connection using the given url. |
void |
parseCookies(java.net.URLConnection connection)
Check for cookie and parse into cookie jar. |
protected void |
saveCookies(java.util.Vector list,
java.net.URLConnection connection)
Save the cookies received in the response header. |
void |
setCookie(Cookie cookie,
java.lang.String domain)
Adds a cookie to the cookie jar. |
void |
setCookieProcessingEnabled(boolean enable)
Enables and disabled cookie processing. |
static void |
setDefaultRequestProperties(java.util.Hashtable properties)
Set the default request header properties. |
void |
setMonitor(ConnectionMonitor monitor)
Set the monitoring object. |
void |
setPassword(java.lang.String password)
Set the URL users's password. |
void |
setProxyHost(java.lang.String host)
Set the proxy host to use. |
void |
setProxyPassword(java.lang.String password)
Get the proxy user's password. |
void |
setProxyPort(int port)
Set the proxy port number. |
void |
setProxyUser(java.lang.String user)
Set the user name for proxy authorization. |
void |
setRequestProperties(java.util.Hashtable properties)
Set the current request properties. |
void |
setUser(java.lang.String user)
Set the user name to access the URL. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static java.util.Hashtable mDefaultRequestProperties
protected java.util.Hashtable mRequestProperties
protected java.lang.String mProxyHost
protected int mProxyPort
protected java.lang.String mProxyUser
protected java.lang.String mProxyPassword
protected java.lang.String mUser
protected java.lang.String mPassword
protected java.util.Hashtable mCookieJar
protected ConnectionMonitor mMonitor
protected static java.text.SimpleDateFormat mFormat
Constructor Detail |
public ConnectionManager()
public ConnectionManager(java.util.Hashtable properties)
properties
- Name/value pairs to be added to the HTTP request.Method Detail |
public static java.util.Hashtable getDefaultRequestProperties()
mDefaultRequestProperties
,
setRequestProperties(java.util.Hashtable)
public static void setDefaultRequestProperties(java.util.Hashtable properties)
URLConnection
,
i.e. If-Modified-Since is set with setIfModifiedSince(long),
but since the parser transparently opens the connection on behalf
of the developer, these properties are not available before the
connection is fetched. Setting these request header fields affects all
subsequent connections opened by the parser. For more direct control
create a URLConnection
massage it the way you want and
then set it on the parser.From RFC 2616 Hypertext Transfer Protocol -- HTTP/1.1:
5.3 Request Header Fields The request-header fields allow the client to pass additional information about the request, and about the client itself, to the server. These fields act as request modifiers, with semantics equivalent to the parameters on a programming language method invocation. request-header = Accept ; Section 14.1 | Accept-Charset ; Section 14.2 | Accept-Encoding ; Section 14.3 | Accept-Language ; Section 14.4 | Authorization ; Section 14.8 | Expect ; Section 14.20 | From ; Section 14.22 | Host ; Section 14.23 | If-Match ; Section 14.24 | If-Modified-Since ; Section 14.25 | If-None-Match ; Section 14.26 | If-Range ; Section 14.27 | If-Unmodified-Since ; Section 14.28 | Max-Forwards ; Section 14.31 | Proxy-Authorization ; Section 14.34 | Range ; Section 14.35 | Referer ; Section 14.36 | TE ; Section 14.39 | User-Agent ; Section 14.43 Request-header field names can be extended reliably only in combination with a change in the protocol version. However, new or experimental header fields MAY be given the semantics of request- header fields if all parties in the communication recognize them to be request-header fields. Unrecognized header fields are treated as entity-header fields.
properties
- The new set of default request header properties to
use. This affects all subsequently created connections.mDefaultRequestProperties
,
setRequestProperties(java.util.Hashtable)
public java.util.Hashtable getRequestProperties()
public void setRequestProperties(java.util.Hashtable properties)
setProxyUser(java.lang.String)
and setProxyPassword(java.lang.String)
values or the Authorization property
which is constructed from the setUser(java.lang.String)
and setPassword(java.lang.String)
values. Nor does it replace the
Cookie property which is constructed from the current cookie jar.
properties
- The new fixed properties.public java.lang.String getProxyHost()
public void setProxyHost(java.lang.String host)
host
- The host to use for proxy access.
Note: You must also set the proxy port
.public int getProxyPort()
public void setProxyPort(int port)
port
- The proxy port.
Note: You must also set the proxy host
.public java.lang.String getProxyUser()
null
if no proxy authorization is required.public void setProxyUser(java.lang.String user)
user
- The proxy user name.
Note: You must also set the proxy password
.public java.lang.String getProxyPassword()
public void setProxyPassword(java.lang.String password)
password
- The password for the proxy user.
Note: You must also set the proxy user
.public java.lang.String getUser()
null
if no authorization is required.public void setUser(java.lang.String user)
user
- The user name for accessing the URL.
Note: You must also set the password
.public java.lang.String getPassword()
public void setPassword(java.lang.String password)
password
- The password for the URL.public boolean getCookieProcessingEnabled()
true
if cookies are being processed.public void setCookieProcessingEnabled(boolean enable)
enable
- if true
cookie processing will occur,
else cookie processing will be turned off.public void setCookie(Cookie cookie, java.lang.String domain)
cookie
- The cookie to add.domain
- The domain to use in case the cookie has no domain attribute.public ConnectionMonitor getMonitor()
public void setMonitor(ConnectionMonitor monitor)
monitor
- The monitor to set.public java.net.URLConnection openConnection(java.net.URL url) throws ParserException
url
- The url to open.
ParserException
- if an i/o exception occurs accessing the url.public static final java.lang.String encode(byte[] array)
array
- The bytes to convert.
public java.lang.String fixSpaces(java.lang.String url)
url
- The url containing spaces.
public java.net.URLConnection openConnection(java.lang.String string) throws ParserException
file://localhost
is prepended to a canonical path derived from the string, or a url that
begins with one of the known protocol strings, i.e. http://
.
Embedded spaces are silently converted to %20 sequences.
string
- The name of a file or a url.
ParserException
- if the string is not a valid url or file.public void addCookies(java.net.URLConnection connection)
The syntax for the header is: cookie = "Cookie:" cookie-version 1*((";" | ",") cookie-value) cookie-value = NAME "=" VALUE [";" path] [";" domain] cookie-version = "$Version" "=" value NAME = attr VALUE = value path = "$Path" "=" value domain = "$Domain" "=" value
connection
- The connection being accessed.protected java.util.Vector addCookies(java.util.Vector cookies, java.lang.String path, java.util.Vector list)
cookies
- The list of cookies to check (may be null).path
- The path being accessed.list
- The list of qualified cookies.
protected java.lang.String getDomain(java.lang.String host)
host
- The supposed host name.
protected java.lang.String generateCookieProperty(java.util.Vector cookies)
cookies
- The list of valid cookies to be encoded in the request.
public void parseCookies(java.net.URLConnection connection)
connection
- The connection to extract cookie information from.protected void saveCookies(java.util.Vector list, java.net.URLConnection connection)
list
- The list of cookies extracted from the response header.connection
- The connection (used when a cookie has no domain).
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |