Class MultithreadedHttpClient
- Object
-
- AbstractHttpClient
-
- MultithreadedHttpClient
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,HTTPBehavior
,HTTPClient
,HTTPConnectionPooling
,HTTPProxy
public class MultithreadedHttpClient extends AbstractHttpClient implements HTTPConnectionPooling, HTTPProxy
An Apache commons HTTP client basedHTTPClient
backed by a multithreaded connection manager that allows to reuse connections to the backing server and to limit themax number of concurrent connections
.Java System properties
http.proxyHost
,http.proxyPort
,http.proxyUser
, andhttp.proxyPassword
are respected.Copied from gt-wms.
- Author:
- groldan, awaterme
- See Also:
AbstractOpenWebService.setHttpClient(HTTPClient)
-
-
Field Summary
-
Fields inherited from class AbstractHttpClient
connectTimeout, extraParams, password, readTimeout, tryGzip, user
-
-
Constructor Summary
Constructors Constructor Description MultithreadedHttpClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
HTTPResponse
get(URL url)
Executes an HTTP GET request against the provided URL and returns the server response.HTTPResponse
get(URL url, Map<String,String> headers)
Executes an HTTP GET request against the provided URL and returns the server response.int
getConnectTimeout()
int
getMaxConnections()
Max connections kept in the poolint
getReadTimeout()
MultithreadedHttpClient.HttpMethodResponse
post(URL url, InputStream postContent, String postContentType)
Executes an HTTP POST request against the provided URL, sending the contents ofpostContent
as the POST method body and setting the Content-Type request header topostContentType
if given, and returns the server response.MultithreadedHttpClient.HttpMethodResponse
post(URL url, InputStream postContent, String postContentType, Map<String,String> headers)
Executes an HTTP POST request against the provided URL, sending the contents ofpostContent
as the POST method body and setting the Content-Type request header topostContentType
if given, and returns the server response.void
setConnectTimeout(int connectTimeout)
void
setMaxConnections(int maxConnections)
Sets max connections kept in the poolvoid
setPassword(String password)
void
setReadTimeout(int readTimeout)
void
setUser(String user)
-
Methods inherited from class AbstractHttpClient
appendURL, createFileResponse, getExtraParams, getPassword, getUser, isFile, isTryGzip, setExtraParams, setTryGzip
-
-
-
-
Method Detail
-
post
public MultithreadedHttpClient.HttpMethodResponse post(URL url, InputStream postContent, String postContentType) throws IOException
Description copied from interface:HTTPClient
Executes an HTTP POST request against the provided URL, sending the contents ofpostContent
as the POST method body and setting the Content-Type request header topostContentType
if given, and returns the server response.If an HTTP authentication
user
andpassword
is set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeout
is set, the http connection will be set to respect that timeout.If a
read timeout
is set, the http connection will be set to respect it.- Specified by:
post
in interfaceHTTPClient
- Specified by:
post
in classAbstractHttpClient
- Parameters:
url
- the URL against which to execute the POST requestpostContent
- an input stream with the contents of the POST bodypostContentType
- the MIME type of the contents sent as the request POST body, can benull
- Returns:
- the
HTTPResponse
encapsulating the response to the HTTP POST request - Throws:
IOException
-
post
public MultithreadedHttpClient.HttpMethodResponse post(URL url, InputStream postContent, String postContentType, Map<String,String> headers) throws IOException
Description copied from interface:HTTPClient
Executes an HTTP POST request against the provided URL, sending the contents ofpostContent
as the POST method body and setting the Content-Type request header topostContentType
if given, and returns the server response.If an HTTP authentication
user
andpassword
is set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeout
is set, the http connection will be set to respect that timeout.If a
read timeout
is set, the http connection will be set to respect it.header parameter contains additional headers to add to the request.
- Specified by:
post
in interfaceHTTPClient
- Parameters:
url
- the URL against which to execute the POST requestpostContent
- an input stream with the contents of the POST bodypostContentType
- the MIME type of the contents sent as the request POST body, can benull
headers
- a list of custom headers to add to the request.- Returns:
- the
HTTPResponse
encapsulating the response to the HTTP POST request - Throws:
IOException
-
get
public HTTPResponse get(URL url) throws IOException
Description copied from interface:HTTPClient
Executes an HTTP GET request against the provided URL and returns the server response.If an HTTP authentication
user
andpassword
is set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeout
is set, the http connection will be set to respect that timeout.If a
read timeout
is set, the http connection will be set to respect it.- Specified by:
get
in interfaceHTTPClient
- Parameters:
url
- the URL to retrieve- Returns:
- an
HTTPResponse
encapsulating the response to the HTTP GET request - Throws:
IOException
-
get
public HTTPResponse get(URL url, Map<String,String> headers) throws IOException
Description copied from interface:HTTPClient
Executes an HTTP GET request against the provided URL and returns the server response.If an HTTP authentication
user
andpassword
is set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeout
is set, the http connection will be set to respect that timeout.If a
read timeout
is set, the http connection will be set to respect it.header parameter contains additional headers to add to the request.
- Specified by:
get
in interfaceHTTPClient
- Parameters:
url
- the URL to retrieveheaders
- a list of custom headers to add to the request.- Returns:
- an
HTTPResponse
encapsulating the response to the HTTP GET request - Throws:
IOException
-
setUser
public void setUser(String user)
- Specified by:
setUser
in interfaceHTTPClient
- Overrides:
setUser
in classAbstractHttpClient
- Parameters:
user
- the HTTP BASIC Authentication user name
-
setPassword
public void setPassword(String password)
- Specified by:
setPassword
in interfaceHTTPClient
- Overrides:
setPassword
in classAbstractHttpClient
- Parameters:
password
- the HTTP BASIC Authentication password
-
getConnectTimeout
public int getConnectTimeout()
- Specified by:
getConnectTimeout
in interfaceHTTPClient
- Overrides:
getConnectTimeout
in classAbstractHttpClient
- Returns:
- the tcp/ip connect timeout in seconds
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
- Specified by:
setConnectTimeout
in interfaceHTTPClient
- Overrides:
setConnectTimeout
in classAbstractHttpClient
- Parameters:
connectTimeout
- tcp/ip connect timeout in seconds
-
getReadTimeout
public int getReadTimeout()
- Specified by:
getReadTimeout
in interfaceHTTPClient
- Overrides:
getReadTimeout
in classAbstractHttpClient
- Returns:
- the socket read timeout in seconds
-
setReadTimeout
public void setReadTimeout(int readTimeout)
- Specified by:
setReadTimeout
in interfaceHTTPClient
- Overrides:
setReadTimeout
in classAbstractHttpClient
- Parameters:
readTimeout
- socket read timeout in seconds
-
getMaxConnections
public int getMaxConnections()
Description copied from interface:HTTPConnectionPooling
Max connections kept in the pool- Specified by:
getMaxConnections
in interfaceHTTPConnectionPooling
- Returns:
-
setMaxConnections
public void setMaxConnections(int maxConnections)
Description copied from interface:HTTPConnectionPooling
Sets max connections kept in the pool- Specified by:
setMaxConnections
in interfaceHTTPConnectionPooling
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-