|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.slamd.http.HTTPClient
public class 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 |
debug(java.lang.String message)
Writes the provided message to the debug writer. |
boolean |
deleteLogoutCookies()
Indicates whether this client will automatically delete any cookie whose value is set to "LOGOUT". |
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. |
boolean |
enableGZIP()
Indicates whether this client should support GZIP-compressed data. |
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. |
void |
enableStatisticsCollection(java.lang.String clientID,
java.lang.String threadID,
int collectionInterval,
java.lang.String jobID,
RealTimeStatReporter statReporter)
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.net.InetAddress |
getClientAddress()
Retrieves the client address that will be used for the connections created by this HTTP client. |
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()
Retrieves 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. |
int |
getSocketTimeout()
Retrieves the maximum length of time in milliseconds that the client should block while waiting for data from the server. |
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. |
StatTracker[] |
getStatTrackerStubs(java.lang.String clientID,
java.lang.String threadID,
int collectionInterval)
Retrieves the stat tracker stubs that will be used to indicate the types of statistics that will be collected by this HTTP 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 |
removeCookie(java.lang.String name)
Removes the cookie with the specified name from the set of cookies for this client. |
boolean |
removeCookie(java.lang.String name,
java.lang.String value)
Removes the cookie with the specified name and value from the set of cookies for this client. |
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 |
setClientAddress(java.net.InetAddress clientAddress)
Specifies the client address that should be used when this HTTP client creates outbound connections. |
void |
setClientAddress(java.lang.String clientAddress)
Specifies the client address that should be used when this HTTP client creates outbound connections. |
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 |
setDeleteLogoutCookies(boolean deleteLogoutCookies)
Specifies whether this client will automatically delete any cookie whose value is set to "LOGOUT". |
void |
setEnableGZIP(boolean enableGZIP)
Specifies whether this client should support accepting GZIP-compressed data. |
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 |
setSocketTimeout(int socketTimeout)
Specifies the maximum length of time in milliseconds that the client should block while waiting for data from the server. |
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 |
statisticsCollectionEnabled()
Indicates whether this HTTP client is currently configured to collect statistics about the operations it performs. |
void |
stopTrackers()
Stops all the stat trackers associated with this client but still indicating stat statistics collection has been used so that the statistics will be returned by the getStatTrackers method. |
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 debug(java.lang.String message)
message - The message to be written.public java.net.InetAddress getClientAddress()
null if the default client
address should be used.public void setClientAddress(java.net.InetAddress clientAddress)
clientAddress - The client address that should be used when this
HTTP client creates outbound connections.
public void setClientAddress(java.lang.String clientAddress)
throws java.net.UnknownHostException
clientAddress - The client address that should be used when this
HTTP client creates outbound connections.
java.net.UnknownHostException - If the provided address string cannot be
resolved to an actual address.public boolean enableGZIP()
true if this client should support GZIP compression,
or false if it should not.public void setEnableGZIP(boolean enableGZIP)
enableGZIP - Specifies whether this clietn should support accepting
GZIP-compressed data.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 deleteLogoutCookies()
true if this client will automatically delete any
cookie whose value is set to "LOGOUT", or false if
not.public void setDeleteLogoutCookies(boolean deleteLogoutCookies)
deleteLogoutCookies - Specifies whether this client will
automatically delete any cookie whose value is
set to "LOGOUT".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 int getSocketTimeout()
public void setSocketTimeout(int socketTimeout)
socketTimeout - The maximum length of time in milliseconds that the
client should block while waiting for data from the
server.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 false 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 boolean removeCookie(java.lang.String name)
name - The name of the cookie to remove.
true if the requested cookie was found and removed,
or false if it was not.
public boolean removeCookie(java.lang.String name,
java.lang.String value)
name - The name of the cookie to remove.value - The value for the cookie to remove.
true if the requested cookie was found and removed,
or false if it was not.public void clearCookies()
public boolean statisticsCollectionEnabled()
true if this HTTP client is configured to collect
statistics, or false if it is not.
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 enableStatisticsCollection(java.lang.String clientID,
java.lang.String threadID,
int collectionInterval,
java.lang.String jobID,
RealTimeStatReporter statReporter)
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.jobID - The job ID of the job with which this client is
associated.statReporter - The real-time stat reporter that should be used
for the statistics collected.public void stopTrackers()
getStatTrackers method.
public void disableStatisticsCollection()
public StatTracker[] getStatTrackerStubs(java.lang.String clientID,
java.lang.String threadID,
int collectionInterval)
clientID - The client ID to use for the stubs.threadID - The thread ID to use for the stubs.collectionInterval - The collection interval to use for the stubs.
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 | ||||||||