Package org.geotools.http
Class AbstractHttpClient
Object
AbstractHttpClient
- All Implemented Interfaces:
HTTPClient
- Direct Known Subclasses:
MultithreadedHttpClient,SimpleHttpClient
A base class for HTTPClient, that implements everything except the get and post methods.
- Author:
- Andrea Aime - GeoSolutions
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static URLAppends query parameters to an existing URL.protected HTTPResponsecreateFileResponse(URL url) protected static URLPercent-encodes the illegal characters (non ASCII and disallowed ASCII) in the path, query and fragment of the given URL, leaving legal characters and existing%XXescapes untouched (a stray%becomes%25).intOptional query parameters.intgetUser()protected booleanbooleanabstract HTTPResponsepost(URL url, InputStream content, String contentType) 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.voidsetConnectTimeout(int connectTimeout) voidsetExtraParams(Map<String, String> extraParams) voidsetPassword(String password) voidsetReadTimeout(int readTimeout) voidsetTryGzip(boolean tryGZIP) voidMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HTTPClient
get, get, post
-
Field Details
-
user
-
password
-
extraParams
-
connectTimeout
protected int connectTimeout -
readTimeout
protected int readTimeout -
tryGzip
protected boolean tryGzip
-
-
Constructor Details
-
AbstractHttpClient
public AbstractHttpClient()
-
-
Method Details
-
getUser
- Specified by:
getUserin interfaceHTTPClient- Returns:
- the HTTP BASIC Authentication user name, or
nullif not set
-
setUser
- Specified by:
setUserin interfaceHTTPClient- Parameters:
user- the HTTP BASIC Authentication user name
-
getPassword
- Specified by:
getPasswordin interfaceHTTPClient- Returns:
- the HTTP BASIC Authentication password, or
nullif not set
-
setExtraParams
- Specified by:
setExtraParamsin interfaceHTTPClient- Parameters:
extraParams- the optional querystring ExtraParams to be appended to finalURL
-
getExtraParams
Description copied from interface:HTTPClientOptional query parameters.- Specified by:
getExtraParamsin interfaceHTTPClient- Returns:
- querystring ExtraParams, or
emptyMap()if not set
-
setPassword
- Specified by:
setPasswordin interfaceHTTPClient- Parameters:
password- the HTTP BASIC Authentication password
-
getConnectTimeout
public int getConnectTimeout()- Specified by:
getConnectTimeoutin interfaceHTTPClient- Returns:
- the tcp/ip connect timeout in seconds
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout) - Specified by:
setConnectTimeoutin interfaceHTTPClient- Parameters:
connectTimeout- tcp/ip connect timeout in seconds
-
getReadTimeout
public int getReadTimeout()- Specified by:
getReadTimeoutin interfaceHTTPClient- Returns:
- the socket read timeout in seconds
-
setReadTimeout
public void setReadTimeout(int readTimeout) - Specified by:
setReadTimeoutin interfaceHTTPClient- Parameters:
readTimeout- socket read timeout in seconds
-
setTryGzip
public void setTryGzip(boolean tryGZIP) - Specified by:
setTryGzipin interfaceHTTPClient- See Also:
-
isTryGzip
public boolean isTryGzip()- Specified by:
isTryGzipin interfaceHTTPClient- Returns:
- whether gzip content encoding will be attempted; defaults to
false - See Also:
-
appendURL
protected static URL appendURL(URL oldUrl, Map<String, String> appendQuery) throws MalformedURLExceptionAppends 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.
-
encodeURL
Percent-encodes the illegal characters (non ASCII and disallowed ASCII) in the path, query and fragment of the given URL, leaving legal characters and existing%XXescapes untouched (a stray%becomes%25). This restores the automatic request line encoding Apache HttpClient 4 did and that HttpClient 5 andURLConnectiondo not: without it a capabilities document exposing an online resource with raw UTF characters breaks cascading. The scheme and authority are kept verbatim: only the path, query and fragment are encoded. A raw non-ASCII host is left untouched: percent-encoding it would be wrong, a host needs IDNA/punycode (see RFC 5890) rather than percent escapes, but in practice capabilities hosts are already ASCII.- Throws:
MalformedURLException
-
isFile
-
createFileResponse
- Throws:
IOException
-
post
public abstract HTTPResponse post(URL url, InputStream content, String contentType) 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- 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
HTTPResponseencapsulating the response to the HTTP POST request - Throws:
IOException
-