Class MultithreadedHttpClient
- All Implemented Interfaces:
Closeable,AutoCloseable,HTTPBehavior,HTTPClient,HTTPConnectionPooling,HTTPProxy
HTTPClient backed by a multithreaded connection manager that allows to
reuse connections to the backing server and to limit the max number of concurrent
connections.
Java System properties http.proxyHost, http.proxyPort, http.proxyUser, and
http.proxyPassword are respected.
Copied from gt-wms.
- Author:
- groldan, awaterme
- See Also:
-
Field Summary
Fields inherited from class AbstractHttpClient
connectTimeout, extraParams, password, readTimeout, tryGzip, user -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Executes an HTTP GET request against the provided URL and returns the server response.Executes an HTTP GET request against the provided URL and returns the server response.intintMax connections kept in the poolintMultithreadedHttpClient.HttpMethodResponsepost(URL url, InputStream postContent, String postContentType) Executes an HTTP POST request against the provided URL, sending the contents ofpostContentas the POST method body and setting the Content-Type request header topostContentTypeif given, and returns the server response.MultithreadedHttpClient.HttpMethodResponseExecutes an HTTP POST request against the provided URL, sending the contents ofpostContentas the POST method body and setting the Content-Type request header topostContentTypeif given, and returns the server response.voidsetConnectTimeout(int connectTimeout) voidsetMaxConnections(int maxConnections) Sets max connections kept in the poolvoidsetPassword(String password) voidsetReadTimeout(int readTimeout) voidMethods inherited from class AbstractHttpClient
appendURL, createFileResponse, getExtraParams, getPassword, getUser, isFile, isTryGzip, setExtraParams, setTryGzip
-
Constructor Details
-
MultithreadedHttpClient
public MultithreadedHttpClient()
-
-
Method Details
-
post
public MultithreadedHttpClient.HttpMethodResponse post(URL url, InputStream postContent, String postContentType) throws IOException Description copied from interface:HTTPClientExecutes an HTTP POST request against the provided URL, sending the contents ofpostContentas the POST method body and setting the Content-Type request header topostContentTypeif given, and returns the server response.If an HTTP authentication
userandpasswordis set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeoutis set, the http connection will be set to respect that timeout.If a
read timeoutis set, the http connection will be set to respect it.- Specified by:
postin interfaceHTTPClient- Specified by:
postin 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
HTTPResponseencapsulating 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 IOExceptionDescription copied from interface:HTTPClientExecutes an HTTP POST request against the provided URL, sending the contents ofpostContentas the POST method body and setting the Content-Type request header topostContentTypeif given, and returns the server response.If an HTTP authentication
userandpasswordis set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeoutis set, the http connection will be set to respect that timeout.If a
read timeoutis set, the http connection will be set to respect it.header parameter contains additional headers to add to the request.
- Specified by:
postin 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 benullheaders- a list of custom headers to add to the request.- Returns:
- the
HTTPResponseencapsulating the response to the HTTP POST request - Throws:
IOException
-
get
Description copied from interface:HTTPClientExecutes an HTTP GET request against the provided URL and returns the server response.If an HTTP authentication
userandpasswordis set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeoutis set, the http connection will be set to respect that timeout.If a
read timeoutis set, the http connection will be set to respect it.- Specified by:
getin interfaceHTTPClient- Parameters:
url- the URL to retrieve- Returns:
- an
HTTPResponseencapsulating the response to the HTTP GET request - Throws:
IOException
-
get
Description copied from interface:HTTPClientExecutes an HTTP GET request against the provided URL and returns the server response.If an HTTP authentication
userandpasswordis set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeoutis set, the http connection will be set to respect that timeout.If a
read timeoutis set, the http connection will be set to respect it.header parameter contains additional headers to add to the request.
- Specified by:
getin interfaceHTTPClient- Parameters:
url- the URL to retrieveheaders- a list of custom headers to add to the request.- Returns:
- an
HTTPResponseencapsulating the response to the HTTP GET request - Throws:
IOException
-
setUser
- Specified by:
setUserin interfaceHTTPClient- Overrides:
setUserin classAbstractHttpClient- Parameters:
user- the HTTP BASIC Authentication user name
-
setPassword
- Specified by:
setPasswordin interfaceHTTPClient- Overrides:
setPasswordin classAbstractHttpClient- Parameters:
password- the HTTP BASIC Authentication password
-
getConnectTimeout
public int getConnectTimeout()- Specified by:
getConnectTimeoutin interfaceHTTPClient- Overrides:
getConnectTimeoutin classAbstractHttpClient- Returns:
- the tcp/ip connect timeout in seconds
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout) - Specified by:
setConnectTimeoutin interfaceHTTPClient- Overrides:
setConnectTimeoutin classAbstractHttpClient- Parameters:
connectTimeout- tcp/ip connect timeout in seconds
-
getReadTimeout
public int getReadTimeout()- Specified by:
getReadTimeoutin interfaceHTTPClient- Overrides:
getReadTimeoutin classAbstractHttpClient- Returns:
- the socket read timeout in seconds
-
setReadTimeout
public void setReadTimeout(int readTimeout) - Specified by:
setReadTimeoutin interfaceHTTPClient- Overrides:
setReadTimeoutin classAbstractHttpClient- Parameters:
readTimeout- socket read timeout in seconds
-
getMaxConnections
public int getMaxConnections()Description copied from interface:HTTPConnectionPoolingMax connections kept in the pool- Specified by:
getMaxConnectionsin interfaceHTTPConnectionPooling- Returns:
-
setMaxConnections
public void setMaxConnections(int maxConnections) Description copied from interface:HTTPConnectionPoolingSets max connections kept in the pool- Specified by:
setMaxConnectionsin interfaceHTTPConnectionPooling
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-