org.apache.commons.httpclient

Class HttpClient

public class HttpClient extends Object

An HTTP "user-agent", containing an {@link HttpState HTTP state} and one or more {@link HttpConnection HTTP connections}, to which {@link HttpMethod HTTP methods} can be applied.

Version: $Revision: 354155 $ $Date: 2005-12-05 15:18:10 -0500 (Mon, 05 Dec 2005) $

Author: 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 {@link HttpClientParams parameter set}.
HttpClient(HttpClientParams params)
Creates an instance of HttpClient using the given {@link HttpClientParams parameter set}.
HttpClient(HttpClientParams params, HttpConnectionManager httpConnectionManager)
Creates an instance of HttpClient with a user specified {@link HttpClientParams parameter set} and {@link HttpConnectionManager HTTP connection manager}.
HttpClient(HttpConnectionManager httpConnectionManager)
Creates an instance of HttpClient with a user specified {@link HttpConnectionManager HTTP connection manager}.
Method Summary
intexecuteMethod(HttpMethod method)
Executes the given {@link HttpMethod HTTP method}.
intexecuteMethod(HostConfiguration hostConfiguration, HttpMethod method)
Executes the given {@link HttpMethod HTTP method} using custom {@link HostConfiguration host configuration}.
intexecuteMethod(HostConfiguration hostconfig, HttpMethod method, HttpState state)
Executes the given {@link HttpMethod HTTP method} using the given custom {@link HostConfiguration host configuration} with the given custom {@link HttpState HTTP state}.
StringgetHost()
Returns the default host.
HostConfigurationgetHostConfiguration()
Returns the {@link HostConfiguration host configuration} associated with the HttpClient.
HttpConnectionManagergetHttpConnectionManager()
Returns the {@link HttpConnectionManager HTTP connection manager} associated with the HttpClient.
HttpClientParamsgetParams()
Returns {@link HttpClientParams HTTP protocol parameters} associated with this HttpClient.
intgetPort()
Returns the default port.
HttpStategetState()
Returns {@link HttpState HTTP state} associated with the HttpClient.
booleanisStrictMode()
Returns the value of the strict mode flag.
voidsetConnectionTimeout(int newTimeoutInMilliseconds)
Sets the timeout until a connection is etablished.
voidsetHostConfiguration(HostConfiguration hostConfiguration)
Assigns the {@link HostConfiguration host configuration} to use with the HttpClient.
voidsetHttpConnectionFactoryTimeout(long timeout)
Sets the timeout in milliseconds used when retrieving an {@link HttpConnection HTTP connection} from the {@link HttpConnectionManager HTTP connection manager}.
voidsetHttpConnectionManager(HttpConnectionManager httpConnectionManager)
Assigns the {@link HttpConnectionManager HTTP connection manager} to use with the HttpClient.
voidsetParams(HttpClientParams params)
Assigns {@link HttpClientParams HTTP protocol parameters} for this HttpClient.
voidsetState(HttpState state)
Assigns {@link HttpState HTTP state} for the HttpClient.
voidsetStrictMode(boolean strictMode)
Defines how strictly the method follows the HTTP protocol specification (see RFC 2616 and other relevant RFCs).
voidsetTimeout(int newTimeoutInMilliseconds)
Sets the socket timeout (SO_TIMEOUT) in milliseconds which is the timeout for waiting for data.

Constructor Detail

HttpClient

public HttpClient()
Creates an instance of HttpClient using default {@link HttpClientParams parameter set}.

See Also: HttpClientParams

HttpClient

public HttpClient(HttpClientParams params)
Creates an instance of HttpClient using the given {@link HttpClientParams parameter set}.

Parameters: params The {@link HttpClientParams parameters} to use.

Since: 3.0

See Also:

HttpClient

public HttpClient(HttpClientParams params, HttpConnectionManager httpConnectionManager)
Creates an instance of HttpClient with a user specified {@link HttpClientParams parameter set} and {@link HttpConnectionManager HTTP connection manager}.

Parameters: params The {@link HttpClientParams parameters} to use. httpConnectionManager The {@link HttpConnectionManager connection manager} to use.

Since: 3.0

HttpClient

public HttpClient(HttpConnectionManager httpConnectionManager)
Creates an instance of HttpClient with a user specified {@link HttpConnectionManager HTTP connection manager}.

Parameters: httpConnectionManager The {@link HttpConnectionManager connection manager} to use.

Since: 2.0

Method Detail

executeMethod

public int executeMethod(HttpMethod method)
Executes the given {@link HttpMethod HTTP method}.

Parameters: method the {@link HttpMethod HTTP method} to execute.

Returns: the method's response code

Throws: IOException If an I/O (transport) error occurs. Some transport exceptions can be recovered from. HttpException If a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

executeMethod

public int executeMethod(HostConfiguration hostConfiguration, HttpMethod method)
Executes the given {@link HttpMethod HTTP method} using custom {@link HostConfiguration host configuration}.

Parameters: hostConfiguration The {@link HostConfiguration host configuration} to use. method the {@link HttpMethod HTTP method} to execute.

Returns: the method's response code

Throws: IOException If an I/O (transport) error occurs. Some transport exceptions can be recovered from. 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)
Executes the given {@link HttpMethod HTTP method} using the given custom {@link HostConfiguration host configuration} with the given custom {@link HttpState HTTP state}.

Parameters: hostconfig The {@link HostConfiguration host configuration} to use. method the {@link HttpMethod HTTP method} to execute. state the {@link HttpState HTTP state} to use when executing the method. If null, the state returned by {@link #getState} will be used instead.

Returns: the method's response code

Throws: IOException If an I/O (transport) error occurs. Some transport exceptions can be recovered from. HttpException If a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

Since: 2.0

getHost

public String getHost()

Deprecated: use #getHostConfiguration()

Returns the default host.

Returns: The default host.

getHostConfiguration

public HostConfiguration getHostConfiguration()
Returns the {@link HostConfiguration host configuration} associated with the HttpClient.

Returns: {@link HostConfiguration host configuration}

Since: 2.0

getHttpConnectionManager

public HttpConnectionManager getHttpConnectionManager()
Returns the {@link HttpConnectionManager HTTP connection manager} associated with the HttpClient.

Returns: {@link HttpConnectionManager HTTP connection manager}

Since: 2.0

getParams

public HttpClientParams getParams()
Returns {@link HttpClientParams HTTP protocol parameters} associated with this HttpClient.

Since: 3.0

See Also: HttpClientParams

getPort

public int getPort()

Deprecated: use #getHostConfiguration()

Returns the default port.

Returns: The default port.

getState

public HttpState getState()
Returns {@link HttpState HTTP state} associated with the HttpClient.

Returns: the shared client state

See Also: setState

isStrictMode

public boolean isStrictMode()

Deprecated: Use {@link org.apache.commons.httpclient.params.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

See Also:

setConnectionTimeout

public void setConnectionTimeout(int newTimeoutInMilliseconds)

Deprecated: Use {@link org.apache.commons.httpclient.params.HttpConnectionManagerParams#setConnectionTimeout(int)}, {@link 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.

See Also: HttpConnection

setHostConfiguration

public void setHostConfiguration(HostConfiguration hostConfiguration)
Assigns the {@link HostConfiguration host configuration} to use with the HttpClient.

Parameters: hostConfiguration The {@link HostConfiguration host configuration} to set

Since: 2.0

setHttpConnectionFactoryTimeout

public void setHttpConnectionFactoryTimeout(long timeout)

Deprecated: Use {@link org.apache.commons.httpclient.params.HttpClientParams#setConnectionManagerTimeout(long)}, {@link HttpClient#getParams()}

Sets the timeout in milliseconds used when retrieving an {@link HttpConnection HTTP connection} from the {@link HttpConnectionManager HTTP connection manager}.

Parameters: timeout the timeout in milliseconds

See Also:

setHttpConnectionManager

public void setHttpConnectionManager(HttpConnectionManager httpConnectionManager)
Assigns the {@link HttpConnectionManager HTTP connection manager} to use with the HttpClient.

Parameters: httpConnectionManager The {@link HttpConnectionManager HTTP connection manager} to set

Since: 2.0

setParams

public void setParams(HttpClientParams params)
Assigns {@link HttpClientParams HTTP protocol parameters} for this HttpClient.

Since: 3.0

See Also: HttpClientParams

setState

public void setState(HttpState state)
Assigns {@link HttpState HTTP state} for the HttpClient.

Parameters: state the new {@link HttpState HTTP state} for the client

See Also: getState

setStrictMode

public void setStrictMode(boolean strictMode)

Deprecated: Use {@link 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

See Also:

setTimeout

public void setTimeout(int newTimeoutInMilliseconds)

Deprecated: Use {@link org.apache.commons.httpclient.params.HttpConnectionManagerParams#setSoTimeout(int)}, {@link 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