org.apache.commons.httpclient
Class HttpClient

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

public class HttpClient
extends Object

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

Version:
$Revision: 1.76 $ $Date: 2003/05/12 02:42:42 $
Author:
Remy Maucherat, Rodney Waldhoff, Sean C. Sullivan, dIon Gillard, Ortwin Gl?ck, Michael Becke, Mike Bowler, Sam Maloney, Laura Werner

Constructor Summary
HttpClient()
          Creates an HttpClient using SimpleHttpConnectionManager.
HttpClient(HttpConnectionManager httpConnectionManager)
          Creates an HttpClient with a user specified connection manager.
 
Method Summary
 void endSession()
          Deprecated. this method has no effect. HttpMethod.releaseConnection() should be used to release resources after a HttpMethod has been executed.
 int executeMethod(HostConfiguration hostConfiguration, HttpMethod method)
          Executes the given method.
 int executeMethod(HostConfiguration hostConfiguration, HttpMethod method, HttpState state)
          Executes the given method.
 int executeMethod(HttpMethod method)
          Executes the given method.
 String getHost()
          Return the host that the client is accessing.
 HostConfiguration getHostConfiguration()
          Returns the hostConfiguration.
 HttpConnectionManager getHttpConnectionManager()
          Returns the httpConnectionManager.
 int getPort()
          Return the port that the client is accessing.
 HttpState getState()
          Get my state.
 boolean isStrictMode()
           
 void setConnectionTimeout(int newTimeoutInMilliseconds)
          Sets the timeout until a connection is etablished.
 void setHostConfiguration(HostConfiguration hostConfiguration)
          Sets the hostConfiguration.
 void setHttpConnectionFactoryTimeout(long timeout)
          Sets the timeout used when retrieving an HttpConnection from the HttpConnectionManager.
 void setHttpConnectionManager(HttpConnectionManager httpConnectionManager)
          Sets the httpConnectionManager.
 void setState(HttpState state)
          Set my state.
 void setStrictMode(boolean strictMode)
           
 void setTimeout(int newTimeoutInMilliseconds)
          Sets the SO_TIMEOUT which is the timeout for waiting for data.
 void startSession(String host, int port)
          Deprecated. use hostConfiguration Sets the host, port and protocol(http) to be used when executing a method.
 void startSession(String host, int port, boolean https)
          Deprecated. use hostConfiguration Sets the host, port and protocol to be used when executing a method.
 void startSession(String host, int port, Credentials creds)
          Deprecated. use hostConfiguration and httpState Sets the host, port, protocol(http) and credentials to be used when executing a method.
 void startSession(String host, int port, Credentials creds, boolean https)
          Deprecated. use hostConfiguration and httpState Sets the host, port, protocol and credentials to be used when executing a method.
 void startSession(String host, int port, String proxyhost, int proxyport)
          Deprecated. use hostConfiguration Sets the host, port, protocol(http) and proxy to be used when executing a method.
 void startSession(String host, int port, String proxyhost, int proxyport, boolean secure)
          Deprecated. use hostConfiguration Sets the host, port, protocol and proxy to be used when executing a method.
 void startSession(URI uri)
          Deprecated. use hostConfiguration and httpState Sets the host, port, protocol and credentials to be used when executing a method using the server specified by the scheme, userinfo, host and port of the given uri.

Note that the path component is not utilized.

 void startSession(URL url)
          Deprecated. use hostConfiguration Sets the host, port and protocol to be used when executing a method.

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

 void startSession(URL url, Credentials creds)
          Deprecated. use hostConfiguration and httpState Sets the host, port, protocol and credentials to be used when executing a method.

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

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpClient

public HttpClient()
Creates an HttpClient using SimpleHttpConnectionManager.
See Also:
SimpleHttpConnectionManager

HttpClient

public HttpClient(HttpConnectionManager httpConnectionManager)
Creates an HttpClient with a user specified connection manager.
Parameters:
httpConnectionManager - The connection manager to use.
Since:
2.0
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()

setStrictMode

public void setStrictMode(boolean strictMode)
Parameters:
strictMode - true if strict mode should be used
See Also:
isStrictMode()

isStrictMode

public boolean isStrictMode()
Returns:
true if strict mode being used
See Also:
setStrictMode(boolean)

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

setHttpConnectionFactoryTimeout

public void setHttpConnectionFactoryTimeout(long timeout)
Sets the timeout used when retrieving an HttpConnection from the HttpConnectionManager.
Parameters:
timeout - the timeout in milliseconds
See Also:
HttpConnectionManager.getConnection(HostConfiguration, long)

setConnectionTimeout

public void setConnectionTimeout(int newTimeoutInMilliseconds)
Sets the timeout until a connection is etablished. A value of 0 means the timeout is not used. The default value is 0.
Parameters:
newTimeoutInMilliseconds - Timeout in milliseconds.
See Also:
HttpConnection.setConnectionTimeout(int)

startSession

public void startSession(String host,
                         int port)
Deprecated. use hostConfiguration Sets the host, port and protocol(http) to be used when executing a method.

Parameters:
host - the host to connect to
port - the port to connect to
See Also:
getHostConfiguration()

startSession

public void startSession(String host,
                         int port,
                         boolean https)
Deprecated. use hostConfiguration Sets the host, port and protocol to be used when executing a method.

Parameters:
host - the host to connect to
port - the port to connect to
https - when true, create an HTTPS session
See Also:
getHostConfiguration()

startSession

public void startSession(String host,
                         int port,
                         Credentials creds)
Deprecated. use hostConfiguration and httpState Sets the host, port, protocol(http) and credentials to be used when executing a method.

Parameters:
host - the host to connect to
port - the port to connect to
creds - the default credentials to use
See Also:
getHostConfiguration(), getState(), startSession(String, int, Credentials, boolean)

startSession

public void startSession(String host,
                         int port,
                         Credentials creds,
                         boolean https)
Deprecated. use hostConfiguration and httpState Sets the host, port, protocol and credentials to be used when executing a method.

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:
getHostConfiguration(), getState()

startSession

public void startSession(URI uri)
                  throws URIException,
                         IllegalStateException
Deprecated. use hostConfiguration and httpState Sets the host, port, protocol and credentials to be used when executing a method using the server specified by the scheme, userinfo, host and port of the given uri.

Note that the path component is not utilized.

Parameters:
uri - an HttpURL or HttpsURL instance; the URI from which the scheme, userinfo, host and port of the session are determined
Throws:
IllegalStateException - not enough information to process
URIException - If the URI is bad.
See Also:
getHostConfiguration(), getState()

startSession

public void startSession(URL url)
                  throws IllegalArgumentException
Deprecated. use hostConfiguration Sets the host, port and protocol to be used when executing a method.

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
Throws:
IllegalArgumentException - if the protocol is not http or https
See Also:
getHostConfiguration()

startSession

public void startSession(URL url,
                         Credentials creds)
                  throws IllegalArgumentException
Deprecated. use hostConfiguration and httpState Sets the host, port, protocol and credentials to be used when executing a method.

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
creds - the default credentials to use
Throws:
IllegalArgumentException - if the protocol is not http or https
See Also:
getHostConfiguration(), getState()

startSession

public void startSession(String host,
                         int port,
                         String proxyhost,
                         int proxyport)
Deprecated. use hostConfiguration Sets the host, port, protocol(http) and proxy to be used when executing a method.

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:
getHostConfiguration()

startSession

public void startSession(String host,
                         int port,
                         String proxyhost,
                         int proxyport,
                         boolean secure)
Deprecated. use hostConfiguration Sets the host, port, protocol and proxy to be used when executing a method.

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:
getHostConfiguration()

executeMethod

public int executeMethod(HttpMethod method)
                  throws IOException,
                         HttpException
Executes the given method.
Parameters:
method - the HttpMethod to execute.
Returns:
the method's response code
Throws:
IOException - if an I/O error occurs
HttpException - if a protocol exception occurs

executeMethod

public int executeMethod(HostConfiguration hostConfiguration,
                         HttpMethod method)
                  throws IOException,
                         HttpException
Executes the given method.
Parameters:
hostConfiguration - The configuration to use.
method - the HttpMethod to execute.
Returns:
the method's response code
Throws:
IOException - if an I/O error occurs
HttpException - if a protocol exception occurs
Since:
2.0

executeMethod

public int executeMethod(HostConfiguration hostConfiguration,
                         HttpMethod method,
                         HttpState state)
                  throws IOException,
                         HttpException
Executes the given method.
Parameters:
hostConfiguration - The configuration to use.
method - the HttpMethod to execute.
state - the HttpState to use when executing the method. If null, the state returned by getState() will be used instead.
Returns:
the method's response code
Throws:
IOException - if an I/O error occurs
HttpException - if a protocol exception occurs
Since:
2.0

endSession

public void endSession()
                throws IOException
Deprecated. this method has no effect. HttpMethod.releaseConnection() should be used to release resources after a HttpMethod has been executed.

See Also:
HttpMethod.releaseConnection()

getHost

public String getHost()
Return the host that the client is accessing.
Returns:
The host that the client is accessing, or null if the session has not been started via startSession.

getPort

public int getPort()
Return the port that the client is accessing.
Returns:
The port that the client is accessing, or -1 if the session has not been started via startSession().

getHostConfiguration

public HostConfiguration getHostConfiguration()
Returns the hostConfiguration.
Returns:
HostConfiguration
Since:
2.0

setHostConfiguration

public void setHostConfiguration(HostConfiguration hostConfiguration)
Sets the hostConfiguration.
Parameters:
hostConfiguration - The hostConfiguration to set
Since:
2.0

getHttpConnectionManager

public HttpConnectionManager getHttpConnectionManager()
Returns the httpConnectionManager.
Returns:
HttpConnectionManager
Since:
2.0

setHttpConnectionManager

public void setHttpConnectionManager(HttpConnectionManager httpConnectionManager)
Sets the httpConnectionManager.
Parameters:
httpConnectionManager - The httpConnectionManager to set
Since:
2.0


Copyright © 2001-2003 Apache Software Foundation. All Rights Reserved.