|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.slamd.http.HTTPClient
This class defines a client that may be used for communicating with Web servers using HTTP or HTTPS. It offers a number of features for behaving like actual Web browsers, including the ability to parse the contents of an HTML document, the ability to include images when retrieving a page, and the ability to operate through a proxy server.
| Field Summary | |
static java.lang.String |
AUTH_HEADER_PREFIX
The prefix that will be used for the HTTP header that sends authentication information to the remote Web server. |
static int |
BUFFER_SIZE
The size of the buffer that we will use for reading data. |
static java.lang.String |
PROXY_AUTH_HEADER_PREFIX
The prefix that will be used for the HTTP header that sends authentication information to the proxy server. |
static java.lang.String |
STAT_TRACKER_REDIRECTS_FOLLOWED
The display name for the stat tracker used to keep track of the number of redirects followed. |
static java.lang.String |
STAT_TRACKER_REQUESTS_PROCESSED
The display name for the stat tracker used to keep track of the total number of requests processed. |
static java.lang.String |
STAT_TRACKER_RESPONSE_BODY_TIME
The display name for the stat tracker used to keep track of the length of time required to retrieve the body of the response. |
static java.lang.String |
STAT_TRACKER_RESPONSE_CODES
The display name for the stat tracker used to keep track of the response codes from all the requests. |
static java.lang.String |
STAT_TRACKER_RESPONSE_HEADER_TIME
The display name for the stat tracker used to keep track of the length of time required to retrieve send the request and retrieve the header. |
static java.lang.String |
STAT_TRACKER_RESPONSE_SIZE
The display name for the stat tracker used to keep track of the size in bytes of the response. |
static java.lang.String |
STAT_TRACKER_TOTAL_REQUEST_TIME
The display name for the stat tracker used to keep track of the total length of time required to handle a request. |
| Constructor Summary | |
HTTPClient()
Creates a new instance of this HTTP client. |
|
| Method Summary | |
void |
addCookie(HTTPCookie cookie)
Adds the specified cookie to the set of cookies associated with this client. |
boolean |
authenticationEnabled()
Indicates whether the client will attempt to provide authentication information to the remote HTTP server. |
void |
clearCommonHeaders()
Removes all common headers that have been defined for this client. |
void |
clearCookies()
Clears all cookie information associated with this client. |
void |
closeAll()
Closes all open connections that are associated with this HTTP client. |
boolean |
cookiesEnabled()
Indicates whether support for cookies is enabled in this client. |
void |
disableAuthentication()
Indicates that no authentication should be performed for the remote Web server. |
void |
disableDebugMode()
Indicates that this HTTP client should not operate in debug mode. |
void |
disableProxy()
Indicates that the client should not use a proxy server but rather try to communicate directly with the remote Web server. |
void |
disableStatisticsCollection()
Indicates that the client should not automatically maintain any statistics. |
void |
enableAuthentication(java.lang.String authID,
java.lang.String authPW)
Indicates that authentication should be performed for the remote Web server using the provided information. |
void |
enableDebugMode()
Indicates that this HTTP client should operate in debug mode. |
void |
enableDebugMode(java.io.PrintStream debugStream)
Indicates that this HTTP client should operate in debug mode. |
void |
enableProxy(java.lang.String proxyHost,
int proxyPort)
Indicates that the client should communicate with the specified proxy server rather than attempting to communicate directly with the remote Web server. |
void |
enableProxy(java.lang.String proxyHost,
int proxyPort,
java.lang.String proxyAuthID,
java.lang.String proxyAuthPW)
Indicates that the client should communicate with the specified proxy server rather than attempting to communicate directly with the remote Web server. |
void |
enableStatisticsCollection(java.lang.String clientID,
java.lang.String threadID,
int collectionInterval)
Indicates that the client should automatically maintain a set of stat trackers that keep track of various statistics around HTTP processing. |
boolean |
followRedirects()
Indicates whether this client will attempt to automatically follow redirects returned by the server. |
java.lang.String |
getAuthID()
Retrieves the username that will be provided to the remote HTTP server if authentication will be performed. |
java.lang.String |
getAuthPassword()
Retrieves the password that will be provided to the remote HTTP server if authentication will be performed. |
java.lang.String |
getCommonHeader(java.lang.String name)
Retrieves the value of the common header with the provided name. |
java.lang.String[] |
getCommonHeaderNames()
Retrieves the names of the common headers that have been defined for this client. |
java.lang.String[][] |
getCommonHeaders()
Retrieves a two-dimensional array containing the names and values of all headers that will always be included in requests sent using this client. |
java.lang.String[] |
getCommonHeaderValues()
Retreives the values of the common headers that have been defined for this client. |
HTTPCookie[] |
getCookies(java.net.URL requestURL)
Retrieves an array of cookies that apply to the given URL. |
java.lang.String |
getProxyAuthID()
Retrieves the username that will be provided to the HTTP proxy server if authentication will be performed. |
java.lang.String |
getProxyAuthPassword()
Retrieves the password that will be provided to the HTTP proxy server if authentication will be performed. |
java.lang.String |
getProxyHost()
Retrieves the address of the proxy server that has been configured. |
int |
getProxyPort()
Retrieves the port number of the proxy server that has been configured. |
javax.net.ssl.SSLSocketFactory |
getSSLSocketFactory()
Retrieves the socket factory that will be used to create SSL-based connections. |
StatTracker[] |
getStatTrackers()
Retrieves the set of stat trackers that have been maintained by this client. |
void |
invalidateSSLSessions()
Invalidates all SSL sessions associated with any connections held by this HTTP client. |
static boolean |
isRedirect(int statusCode)
Indicates whether the provided status code defines a redirect that may be followed to get the actual content. |
boolean |
proxyAuthenticationEnabled()
Indicates whether the client will attempt to authenticate to an HTTP proxy server. |
boolean |
proxyEnabled()
Indicates whether the client will attempt to forward requests through an HTTP proxy server. |
void |
removeCommonHeader(java.lang.String name)
Removes the common header with the specified name. |
boolean |
retrieveAssociatedFiles()
Indicates whether this client should automatically retrieve any additional files associated with the HTML documents that are retrieved. |
HTTPResponse |
sendRequest(HTTPRequest request)
Sends the provided request to the specified server and returns the response. |
void |
setCommonHeader(java.lang.String name,
java.lang.String value)
Adds a common header with the specified name and value. |
void |
setCookiesEnabled(boolean cookiesEnabled)
Specifies whether cookie support should be enabled for this client. |
void |
setFollowRedirects(boolean followRedirects)
Specifies whether this client should attempt to automatically follow redirects returned by the server. |
void |
setRetrieveAssociatedFiles(boolean retrieveAssociatedFiles)
Specifies whether this client should automatically retrieve any additional files (images, external style sheets, frame elements, etc.) associated with any HTML documents that it retrieves. |
void |
setSSLSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)
Specifies the socket factory that should be used to create SSL-based connections. |
void |
setUseKeepAlive(boolean useKeepAlive)
Indicates whether to use HTTP 1.1 keepalive to possibly re-use the same connection for multiple requests. |
boolean |
useKeepAlive()
Indicates whether this connection will attempt to use HTTP 1.1 keepalive to possibly re-use the same connection for multiple requests. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int BUFFER_SIZE
public static final java.lang.String AUTH_HEADER_PREFIX
public static final java.lang.String PROXY_AUTH_HEADER_PREFIX
public static final java.lang.String STAT_TRACKER_REDIRECTS_FOLLOWED
public static final java.lang.String STAT_TRACKER_REQUESTS_PROCESSED
public static final java.lang.String STAT_TRACKER_RESPONSE_BODY_TIME
public static final java.lang.String STAT_TRACKER_RESPONSE_CODES
public static final java.lang.String STAT_TRACKER_RESPONSE_HEADER_TIME
public static final java.lang.String STAT_TRACKER_RESPONSE_SIZE
public static final java.lang.String STAT_TRACKER_TOTAL_REQUEST_TIME
| Constructor Detail |
public HTTPClient()
| Method Detail |
public void enableDebugMode()
public void enableDebugMode(java.io.PrintStream debugStream)
debugStream - The print stream to which debug messages should be
sent.public void disableDebugMode()
public void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)
sslSocketFactory - The socket factory that should be used to create
SSL-based connections.public javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
public void enableProxy(java.lang.String proxyHost,
int proxyPort)
proxyHost - The address of the proxy server.proxyPort - The port of the proxy server.
public void enableProxy(java.lang.String proxyHost,
int proxyPort,
java.lang.String proxyAuthID,
java.lang.String proxyAuthPW)
proxyHost - The address of the proxy server.proxyPort - The port of the proxy server.proxyAuthID - The user ID to use to authenticate to the proxy
server.proxyAuthPW - The password to use to authenticate to the proxy
server.public void disableProxy()
public boolean proxyEnabled()
true if an HTTP proxy server will be used, or
false if not.public boolean proxyAuthenticationEnabled()
true if an HTTP proxy server will be used and
authentication information will be provided to it, or
false if not.public java.lang.String getProxyHost()
null if none has been specified.public int getProxyPort()
public java.lang.String getProxyAuthID()
null if no
authentication will be performed.public java.lang.String getProxyAuthPassword()
null if no
authentication will be performed.
public void enableAuthentication(java.lang.String authID,
java.lang.String authPW)
authID - The user ID to use to authenticate to the remote Web
server.authPW - The password to use to authenticate to the remote Web
server.public void disableAuthentication()
public boolean authenticationEnabled()
true if HTTP authentication will be performed, or
false if not.public java.lang.String getAuthID()
null if no
authentication will be performed.public java.lang.String getAuthPassword()
null if no
authentication will be performed.public boolean followRedirects()
true if this client will attempt to follow redirects,
or false if not.public void setFollowRedirects(boolean followRedirects)
followRedirects - Indicates whether to try to automatically follow
redirects returned by the server.public boolean useKeepAlive()
true if the connection should attempt to use
keepalive, or false if not.public void setUseKeepAlive(boolean useKeepAlive)
useKeepAlive - Indicates whether to use HTTP 1.1 keepalive to
possibly re-use the same connection for multiple
requests.public boolean retrieveAssociatedFiles()
sendRequest() -- only the contents of the primary document
requested.
true if this client should automatically retrieve any
additional files associated with the HTML documents that are
retrieved, or falses if not.public void setRetrieveAssociatedFiles(boolean retrieveAssociatedFiles)
retrieveAssociatedFiles - Indicates whether this client should
automatically retrieve any additional
files associated with the HTML documents
that are retrieved.public java.lang.String[][] getCommonHeaders()
public java.lang.String getCommonHeader(java.lang.String name)
name - The name of the common header whose value should be
retrieved.
null if
no such header has been defined.public java.lang.String[] getCommonHeaderNames()
public java.lang.String[] getCommonHeaderValues()
getCommonHeaderNames() method.
public void setCommonHeader(java.lang.String name,
java.lang.String value)
null, then any
existing header with that name will be removed.
name - The name to use for the common header.value - The value to use for the common header.public void removeCommonHeader(java.lang.String name)
name - The name of the common header to be removed.public void clearCommonHeaders()
public boolean cookiesEnabled()
true if support for cookies is enabled, or
false if not.public void setCookiesEnabled(boolean cookiesEnabled)
cookiesEnabled - Indicates whether cookie support should be enabled
for this client.public HTTPCookie[] getCookies(java.net.URL requestURL)
requestURL - The URL for which to retrieve the applicable cookies.
public void addCookie(HTTPCookie cookie)
cookie - The cookie to be added to this client.public void clearCookies()
public void enableStatisticsCollection(java.lang.String clientID,
java.lang.String threadID,
int collectionInterval)
clientID - The client ID to use for the stat trackers.threadID - The thread ID to use for the stat trackers.collectionInterval - The statistics collection interval to use for
the stat trackers.public void disableStatisticsCollection()
public StatTracker[] getStatTrackers()
public HTTPResponse sendRequest(HTTPRequest request)
throws HTTPException
request - The request to send to the server.
HTTPException - If a problem occurs while sending the request or
reading the response.public static boolean isRedirect(int statusCode)
statusCode - The HTTP status code for which to make the
determination.
true if the provided status code will be used for a
redirect, or false if not.public void closeAll()
public void invalidateSSLSessions()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||