Package org.geotools.http
Class AbstractHttpClient
- Object
-
- AbstractHttpClient
-
- All Implemented Interfaces:
HTTPClient
- Direct Known Subclasses:
MultithreadedHttpClient
,SimpleHttpClient
public abstract class AbstractHttpClient extends Object implements HTTPClient
A base class for HTTPClient, that implements everything except the get and post methods.- Author:
- Andrea Aime - GeoSolutions
-
-
Field Summary
Fields Modifier and Type Field Description protected int
connectTimeout
protected Map<String,String>
extraParams
protected String
password
protected int
readTimeout
protected boolean
tryGzip
protected String
user
-
Constructor Summary
Constructors Constructor Description AbstractHttpClient()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static URL
appendURL(URL oldUrl, Map<String,String> appendQuery)
Appends query parameters to an existing URL.protected HTTPResponse
createFileResponse(URL url)
int
getConnectTimeout()
Map<String,String>
getExtraParams()
Optional query parameters.String
getPassword()
int
getReadTimeout()
String
getUser()
protected boolean
isFile(URL url)
boolean
isTryGzip()
abstract HTTPResponse
post(URL url, InputStream content, String contentType)
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
setExtraParams(Map<String,String> extraParams)
void
setPassword(String password)
void
setReadTimeout(int readTimeout)
void
setTryGzip(boolean tryGZIP)
void
setUser(String user)
-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface HTTPClient
get, get, post
-
-
-
-
Method Detail
-
getUser
public String getUser()
- Specified by:
getUser
in interfaceHTTPClient
- Returns:
- the HTTP BASIC Authentication user name, or
null
if not set
-
setUser
public void setUser(String user)
- Specified by:
setUser
in interfaceHTTPClient
- Parameters:
user
- the HTTP BASIC Authentication user name
-
getPassword
public String getPassword()
- Specified by:
getPassword
in interfaceHTTPClient
- Returns:
- the HTTP BASIC Authentication password, or
null
if not set
-
setExtraParams
public void setExtraParams(Map<String,String> extraParams)
- Specified by:
setExtraParams
in interfaceHTTPClient
- Parameters:
extraParams
- the optional querystring ExtraParams to be appended to finalURL
-
getExtraParams
public Map<String,String> getExtraParams()
Description copied from interface:HTTPClient
Optional query parameters.- Specified by:
getExtraParams
in interfaceHTTPClient
- Returns:
- querystring ExtraParams, or
emptyMap()
if not set
-
setPassword
public void setPassword(String password)
- Specified by:
setPassword
in interfaceHTTPClient
- Parameters:
password
- the HTTP BASIC Authentication password
-
getConnectTimeout
public int getConnectTimeout()
- Specified by:
getConnectTimeout
in interfaceHTTPClient
- Returns:
- the tcp/ip connect timeout in seconds
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
- Specified by:
setConnectTimeout
in interfaceHTTPClient
- Parameters:
connectTimeout
- tcp/ip connect timeout in seconds
-
getReadTimeout
public int getReadTimeout()
- Specified by:
getReadTimeout
in interfaceHTTPClient
- Returns:
- the socket read timeout in seconds
-
setReadTimeout
public void setReadTimeout(int readTimeout)
- Specified by:
setReadTimeout
in interfaceHTTPClient
- Parameters:
readTimeout
- socket read timeout in seconds
-
setTryGzip
public void setTryGzip(boolean tryGZIP)
- Specified by:
setTryGzip
in interfaceHTTPClient
- See Also:
HTTPClient.setTryGzip(boolean)
-
isTryGzip
public boolean isTryGzip()
- Specified by:
isTryGzip
in interfaceHTTPClient
- Returns:
- whether gzip content encoding will be attempted; defaults to
false
- See Also:
HTTPClient.isTryGzip()
-
appendURL
protected static URL appendURL(URL oldUrl, Map<String,String> appendQuery) throws MalformedURLException
Appends query parameters to an existing URL.- Parameters:
oldUrl
- The original URL to which parameters will be appended.appendQuery
- A map containing key-value pairs to be appended as query parameters.- Returns:
- A new URL with the appended query parameters.
- Throws:
MalformedURLException
- If the resulting URL is malformed.
-
isFile
protected boolean isFile(URL url)
-
createFileResponse
protected HTTPResponse createFileResponse(URL url) throws IOException
- Throws:
IOException
-
post
public abstract HTTPResponse post(URL url, InputStream content, String contentType) 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
- Parameters:
url
- the URL against which to execute the POST requestcontent
- an input stream with the contents of the POST bodycontentType
- 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
-
-