org.apache.commons.httpclient

Class HttpClient


public class HttpClient
extends java.lang.Object

An HTTP "user-agent", containing an HTTP state and one or more HTTP connections, to which HTTP methods can be applied.
Version:
$Revision: 354155 $ $Date: 2005-12-05 15:18:10 -0500 (Mon, 05 Dec 2005) $
Authors:
Remy Maucherat
Rodney Waldhoff
Sean C. Sullivan
dIon Gillard
Ortwin Gl?ck
Michael Becke
Mike Bowler
Sam Maloney
Laura Werner
Oleg Kalnichevski

Constructor Summary

HttpClient()
Creates an instance of HttpClient using default parameter set.
HttpClient(HttpConnectionManager httpConnectionManager)
Creates an instance of HttpClient with a user specified HTTP connection manager.
HttpClient(HttpClientParams params)
Creates an instance of HttpClient using the given parameter set.
HttpClient(HttpClientParams params, HttpConnectionManager httpConnectionManager)
Creates an instance of HttpClient with a user specified parameter set and HTTP connection manager.

Method Summary

int
executeMethod(HostConfiguration hostConfiguration, HttpMethod method)
Executes the given HTTP method using custom host configuration.
int
executeMethod(HostConfiguration hostconfig, HttpMethod method, HttpState state)
Executes the given HTTP method using the given custom host configuration with the given custom HTTP state.
int
executeMethod(HttpMethod method)
Executes the given HTTP method.
String
getHost()
Deprecated. use #getHostConfiguration()
HostConfiguration
getHostConfiguration()
Returns the host configuration associated with the HttpClient.
HttpConnectionManager
getHttpConnectionManager()
Returns the HTTP connection manager associated with the HttpClient.
HttpClientParams
getParams()
Returns HTTP protocol parameters associated with this HttpClient.
int
getPort()
Deprecated. use #getHostConfiguration()
HttpState
getState()
Returns HTTP state associated with the HttpClient.
boolean
isStrictMode()
Deprecated. Use HttpClientParams.getParameter(String) to exercise a more granular control over HTTP protocol strictness.
void
setConnectionTimeout(int newTimeoutInMilliseconds)
Deprecated. Use HttpConnectionManagerParams.setConnectionTimeout(int), HttpConnectionManager.getParams().
void
setHostConfiguration(HostConfiguration hostConfiguration)
Assigns the host configuration to use with the HttpClient.
void
setHttpConnectionFactoryTimeout(long timeout)
Deprecated. Use HttpClientParams.setConnectionManagerTimeout(long), getParams()
void
setHttpConnectionManager(HttpConnectionManager httpConnectionManager)
Assigns the HTTP connection manager to use with the HttpClient.
void
setParams(HttpClientParams params)
Assigns HTTP protocol parameters for this HttpClient.
void
setState(HttpState state)
Assigns HTTP state for the HttpClient.
void
setStrictMode(boolean strictMode)
Deprecated. Use HttpClientParams.setParameter(String,Object) to exercise a more granular control over HTTP protocol strictness.
void
setTimeout(int newTimeoutInMilliseconds)
Deprecated. Use HttpConnectionManagerParams.setSoTimeout(int), HttpConnectionManager.getParams().

Constructor Details

HttpClient

public HttpClient()

HttpClient

public HttpClient(HttpConnectionManager httpConnectionManager)
Creates an instance of HttpClient with a user specified HTTP connection manager.
Parameters:
httpConnectionManager - The connection manager to use.
Since:
2.0

HttpClient

public HttpClient(HttpClientParams params)
Creates an instance of HttpClient using the given parameter set.
Parameters:
params - The parameters to use.
Since:
3.0

HttpClient

public HttpClient(HttpClientParams params,
                  HttpConnectionManager httpConnectionManager)
Creates an instance of HttpClient with a user specified parameter set and HTTP connection manager.
Parameters:
params - The parameters to use.
httpConnectionManager - The connection manager to use.
Since:
3.0

Method Details

executeMethod

public int executeMethod(HostConfiguration hostConfiguration,
                         HttpMethod method)
            throws IOException,
                   HttpException
Executes the given HTTP method using custom host configuration.
Parameters:
hostConfiguration - The host configuration to use.
method - the HTTP method to execute.
Returns:
the method's response code
Throws:
HttpException - If a protocol exception occurs. Usually protocol exceptions cannot be recovered from.
Since:
2.0

executeMethod

public int executeMethod(HostConfiguration hostconfig,
                         HttpMethod method,
                         HttpState state)
            throws IOException,
                   HttpException
Executes the given HTTP method using the given custom host configuration with the given custom HTTP state.
Parameters:
hostconfig - The host configuration to use.
method - the HTTP method to execute.
state - the HTTP state to use when executing the method. If null, the state returned by getState() will be used instead.
Returns:
the method's response code
Throws:
HttpException - If a protocol exception occurs. Usually protocol exceptions cannot be recovered from.
Since:
2.0

executeMethod

public int executeMethod(HttpMethod method)
            throws IOException,
                   HttpException
Executes the given HTTP method.
Parameters:
method - the HTTP method to execute.
Returns:
the method's response code
Throws:
HttpException - If a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

getHost

public String getHost()

Deprecated. use #getHostConfiguration()

Returns the default host.
Returns:
The default host.

getHostConfiguration

public HostConfiguration getHostConfiguration()
Returns the host configuration associated with the HttpClient.
Since:
2.0

getHttpConnectionManager

public HttpConnectionManager getHttpConnectionManager()
Returns the HTTP connection manager associated with the HttpClient.
Since:
2.0

getParams

public HttpClientParams getParams()
Returns HTTP protocol parameters associated with this HttpClient.
Since:
3.0

getPort

public int getPort()

Deprecated. use #getHostConfiguration()

Returns the default port.
Returns:
The default port.

getState

public HttpState getState()
Returns HTTP state associated with the HttpClient.
Returns:
the shared client state

isStrictMode

public boolean isStrictMode()

Deprecated. Use HttpClientParams.getParameter(String) to exercise a more granular control over HTTP protocol strictness.

Returns the value of the strict mode flag.
Returns:
true if strict mode is enabled, false otherwise

setConnectionTimeout

public void setConnectionTimeout(int newTimeoutInMilliseconds)

Deprecated. Use HttpConnectionManagerParams.setConnectionTimeout(int), HttpConnectionManager.getParams().

Sets the timeout until a connection is etablished. A value of zero means the timeout is not used. The default value is zero.
Parameters:
newTimeoutInMilliseconds - Timeout in milliseconds.

setHostConfiguration

public void setHostConfiguration(HostConfiguration hostConfiguration)
Assigns the host configuration to use with the HttpClient.
Parameters:
hostConfiguration - The host configuration to set
Since:
2.0

setHttpConnectionFactoryTimeout

public void setHttpConnectionFactoryTimeout(long timeout)

Deprecated. Use HttpClientParams.setConnectionManagerTimeout(long), getParams()

Sets the timeout in milliseconds used when retrieving an HTTP connection from the HTTP connection manager.
Parameters:
timeout - the timeout in milliseconds

setHttpConnectionManager

public void setHttpConnectionManager(HttpConnectionManager httpConnectionManager)
Assigns the HTTP connection manager to use with the HttpClient.
Parameters:
httpConnectionManager - The HTTP connection manager to set
Since:
2.0

setParams

public void setParams(HttpClientParams params)
Assigns HTTP protocol parameters for this HttpClient.
Since:
3.0

setState

public void setState(HttpState state)
Assigns HTTP state for the HttpClient.
Parameters:
state - the new HTTP state for the client
See Also:
getState()

setStrictMode

public void setStrictMode(boolean strictMode)

Deprecated. Use HttpClientParams.setParameter(String,Object) to exercise a more granular control over HTTP protocol strictness.

Defines how strictly the method follows the HTTP protocol specification (see RFC 2616 and other relevant RFCs). In the strict mode the method precisely implements the requirements of the specification, whereas in non-strict mode it attempts to mimic the exact behaviour of commonly used HTTP agents, which many HTTP servers expect.
Parameters:
strictMode - true for strict mode, false otherwise

setTimeout

public void setTimeout(int newTimeoutInMilliseconds)

Deprecated. Use HttpConnectionManagerParams.setSoTimeout(int), HttpConnectionManager.getParams().

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

Copyright (c) 1999-2005 - Apache Software Foundation