org.apache.commons.httpclient
Class HttpClient

java.lang.Object
  |
  +--org.apache.commons.httpclient.HttpClient

public class HttpClient
extends java.lang.Object

An HTTP "user-agent", containing an HttpState and one or more HttpConnections, to which HttpMethods can be applied.

Version:
$Revision: 1.54 $ $Date: 2002/08/09 04:44:16 $
Author:
Remy Maucherat, Rodney Waldhoff, Sean C. Sullivan, dIon Gillard, Ortwin Glück

Constructor Summary
HttpClient()
          Constructor.
 
Method Summary
 void endSession()
          End the current session, closing my the associated connection if any.
 int executeMethod(HttpMethod method)
          Execute the given HttpMethod using my current connection and HttpState.
 HttpState getState()
          Get my state.
 void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)
          Specifies an alternative factory for SSL sockets.
 void setState(HttpState state)
          Set my state.
 void setTimeout(int newTimeoutInMilliseconds)
          Sets the SO_TIMEOUT which is the timeout for waiting for data.
 void startSession(java.lang.String host, int port)
          Start an HTTP session with the server at the given host and port.
 void startSession(java.lang.String host, int port, boolean https)
          Start an HTTP or HTTPS session with the server at the given host and port.
 void startSession(java.lang.String host, int port, Credentials creds)
          Start an HTTP session with the server at the given host and port using the given default default credentials.
 void startSession(java.lang.String host, int port, Credentials creds, boolean https)
          Start an HTTP or HTTPS session with the server at the given host and port using the given default default credentials.
 void startSession(java.lang.String host, int port, java.lang.String proxyhost, int proxyport)
          Start an HTTP session with the server specified by the given host and port via the given proxyhost and proxyport.
 void startSession(java.lang.String host, int port, java.lang.String proxyhost, int proxyport, boolean secure)
          Start an HTTP session with the server specified by the given host and port via the given proxyhost and proxyport.
 void startSession(java.net.URL url)
          Start an HTTP or HTTPS session with the server specified by the protocol, host and port of the given url.
 void startSession(java.net.URL url, Credentials creds)
          Start an HTTP or HTTPS session with the server specified by the protocol, host and port of the given url, using the given credentials by default.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpClient

public HttpClient()
Constructor.
Method Detail

getState

public HttpState getState()
Get my state.
Returns:
the shared client state
See Also:
setState(HttpState)

setState

public void setState(HttpState state)
Set my state.
Parameters:
state - the new state for the client
See Also:
getState()

setSSLSocketFactory

public void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)
Specifies an alternative factory for SSL sockets.
Parameters:
sslSocketFactory - a living instance of the alternative SSLSocketFactory
See Also:
HttpConnection.setSSLSocketFactory

setTimeout

public void setTimeout(int newTimeoutInMilliseconds)
Sets the SO_TIMEOUT which is the timeout for waiting for data. A timeout value of zero is interpreted as an infinite timeout.
Parameters:
newTimeoutInMilliseconds - Timeout in milliseconds

startSession

public void startSession(java.lang.String host,
                         int port)
Start an HTTP session with the server at the given host and port.
Parameters:
host - the host to connect to
port - the port to connect to
See Also:
endSession()

startSession

public void startSession(java.lang.String host,
                         int port,
                         boolean https)
Start an HTTP or HTTPS session with the server at the given host and port.
Parameters:
host - the host to connect to
port - the port to connect to
https - when true, create an HTTPS session
See Also:
endSession()

startSession

public void startSession(java.lang.String host,
                         int port,
                         Credentials creds)
Start an HTTP session with the server at the given host and port using the given default default credentials.
Parameters:
host - the host to connect to
port - the port to connect to
creds - the default credentials to use
See Also:
endSession()

startSession

public void startSession(java.lang.String host,
                         int port,
                         Credentials creds,
                         boolean https)
Start an HTTP or HTTPS session with the server at the given host and port using the given default default credentials.
Parameters:
host - the host to connect to
port - the port to connect to
creds - the default credentials to use
https - when true, create an HTTPS session
See Also:
endSession()

startSession

public void startSession(java.net.URL url)
Start an HTTP or HTTPS session with the server specified by the protocol, host and port of the given url.

Note that everything but the protocol, host and port of the given url is ignored.

Parameters:
url - the URL from which the protocol, host, and port of the session are determined
See Also:
endSession()

startSession

public void startSession(java.net.URL url,
                         Credentials creds)
Start an HTTP or HTTPS session with the server specified by the protocol, host and port of the given url, using the given credentials by default.

Note that everything but the protocol, host and port of the given url is ignored.

Parameters:
creds - the default credentials to use
url - the URL from which the protocol, host, and port of the session are determined
See Also:
endSession()

startSession

public void startSession(java.lang.String host,
                         int port,
                         java.lang.String proxyhost,
                         int proxyport)
Start an HTTP session with the server specified by the given host and port via the given proxyhost and proxyport.
Parameters:
host - the host to connect to
port - the port to connect to
proxyhost - the proxy host to connect via
proxyport - the proxy port to connect via
See Also:
endSession()

startSession

public void startSession(java.lang.String host,
                         int port,
                         java.lang.String proxyhost,
                         int proxyport,
                         boolean secure)
Start an HTTP session with the server specified by the given host and port via the given proxyhost and proxyport.
Parameters:
host - the host to connect to
port - the port to connect to
proxyhost - the proxy host to connect via
proxyport - the proxy port to connect via
secure - whether or not to connect using HTTPS
See Also:
endSession()

executeMethod

public int executeMethod(HttpMethod method)
                  throws java.io.IOException,
                         HttpException,
                         java.lang.IllegalStateException
Execute the given HttpMethod using my current connection and HttpState.
Parameters:
method - the HttpMethod to execute
Returns:
the method's response code
Throws:
java.io.IOException - if an I/O error occurs
HttpException - if a protocol exception occurs
java.lang.IllegalStateException - if the session has not been started

endSession

public void endSession()
                throws java.io.IOException
End the current session, closing my the associated connection if any.
Throws:
java.io.IOException - when i/o errors occur closing the connection
See Also:
startSession(String, int), startSession(String, int, boolean), startSession(String, int, Credentials), startSession(String, int, Credentials, boolean), startSession(java.net.URL), startSession(java.net.URL, Credentials), startSession(String, int, String, int)


Copyright (c) 2001 - Apache Software Foundation