Package dev.galasa.http
Interface IHttpClient
public interface IHttpClient
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommonHeader(String name, String value) Add a header that will be used on all http requestsvoidaddOkResponseCode(int responseCode) Add a response code for the execute to ignore and treat as OKbuild()Build the clientvoidRemove all headers for this http requestvoidclose()close the underlying HTTPClientHttpClientResponse<byte[]>deleteBinary(String url, byte[] binary) Issue an HTTP DELETE to the provided URL, sending the providedbyteand receiving abytein the response.deleteJaxb(String url, Class<?>... responseTypes) Issue an HTTP DELETE to the provided URL, receiving a JAXB Object in the response.HttpClientResponse<com.google.gson.JsonObject>deleteJson(String url) Issue an HTTP DELETE to the provided URL, receiving a com.google.gson.JsonObject in the response.HttpClientResponse<com.google.gson.JsonObject>deleteJson(String url, com.google.gson.JsonObject json) Issue an HTTP DELETE to the provided URL, receiving a com.google.gson.JsonObject in the response.deleteText(String url) Issue an HTTP DELETE to the provided URL, receiving aStringin the response.HttpClientResponse<byte[]>Issue an HTTP GET to the provided URL, sending the providedbyteand receiving abytein the response.org.apache.http.client.methods.CloseableHttpResponseDownload a file from a specified location to a specified destination on local host.org.apache.http.client.methods.CloseableHttpResponsegetFile(String path, ContentType... acceptTypes) Download a file from a specified location to a specified destination on local host.Issue an HTTP GET to the provided URL, receiving a JAXB Object in the response.HttpClientResponse<com.google.gson.JsonObject>Issue an HTTP GET to the provided URL, receiving a com.google.gson.JsonObject in the response.Get the SSL context used by this clientIssue an HTTP GET to the provided URL, receiving aStringin the response.Get the username set for this clientgetUsername(URI scope) Get the username set for this client for a specific scopeExecute anHttpClientRequestreturning a JAXB object available through the returnedHttpClientResponse.HttpClientResponse<com.google.gson.JsonObject>Issue an HTTP PATCH to the provided URL, sending the provided com.google.gson.JsonObject and receiving a com.google.gson.JsonObject in the response.post(String path, Map<String, String> queryParams, ContentType contentType, Object data, ContentType[] acceptTypes, Class<?>[] jaxbClasses, boolean retry) HttpClientResponse<byte[]>postBinary(String url, byte[] binary) Issue an HTTP POST to the provided URL, sending the providedbyteand receiving abytein the response.postForm(String path, Map<String, String> queryParams, HashMap<String, String> fields, ContentType[] acceptTypes, Class<?>[] jaxbClasses, boolean retry) Issue an HTTP POST to the provided URL, sending the provided jaxbObject and receiving a JAXB Object in the response.HttpClientResponse<com.google.gson.JsonObject>Issue an HTTP POST to the provided URL, sending the provided com.google.gson.JsonObject and receiving a com.google.gson.JsonObject in the response.Issue an HTTP POST to the provided URL, sending the provided XML as a String and receiving a String in the response.Issue an HTTP POST to the provided URL, sending the provided XML as a String and receiving a String in the response.HttpClientResponse<byte[]>Issue an HTTP PUT to the provided URL, sending the providedbyteand receiving abytein the response.voidputFile(String path, InputStream file) Send a compressed (tar) file from a local location to a specified destination on a host.Issue an HTTP PUT to the provided URL, sending the provided jaxbObject and receiving a JAXB Object in the response.HttpClientResponse<com.google.gson.JsonObject>Issue an HTTP PUT to the provided URL, sending the providedcom.google.gson.JsonObjectand receiving acom.google.gson.JsonObjectin the response.Issue an HTTP PUT to the provided URL, sending the provided XML as a String and receiving a String in the response.Issue an HTTP PUT to the provided URL, sending the provided XML as a String and receiving a String in the response.setAuthorisation(String username, String password) Set the username and password for all scopessetAuthorisation(String username, String password, URI scope) Set the username and password for a specific scopesetHostnameVerifier(HostnameVerifier hostnameVerifier) Set the hostname verifierSet the hostname verifier to a no-op verifiersetSSLContext(SSLContext sslContext) Set the SSL ContextSet the SSL Context to a Trust All contextsetupClientAuth(KeyStore clientKeyStore, KeyStore serverKeyStore, String alias, String password) Set up Client Authentication SSL Context and installvoidSet the URI endpoint for this client
-
Method Details
-
getJaxb
HttpClientResponse<Object> getJaxb(String url, Class<?>... responseTypes) throws HttpClientException Issue an HTTP GET to the provided URL, receiving a JAXB Object in the response. In order to unmarshal the response, an array of possible response classes must be provided in responseTypes- Parameters:
url-responseTypes-- Returns:
- -
HttpClientResponsewith a JAXB content type - Throws:
HttpClientException
-
putJaxb
HttpClientResponse<Object> putJaxb(String url, Object jaxbObject, Class<?>... responseTypes) throws HttpClientException Issue an HTTP PUT to the provided URL, sending the provided jaxbObject and receiving a JAXB Object in the response. In order to unmarshal the response, an array of possible response classes must be provided in responseTypes- Parameters:
url-jaxbObject-responseTypes-- Returns:
- -
HttpClientResponsewith a JAXB content type - Throws:
HttpClientException
-
postJaxb
HttpClientResponse<Object> postJaxb(String url, Object jaxbObject, Class<?>... responseTypes) throws HttpClientException Issue an HTTP POST to the provided URL, sending the provided jaxbObject and receiving a JAXB Object in the response. In order to unmarshal the response, an array of possible response classes must be provided in responseTypes- Parameters:
url-jaxbObject-responseTypes-- Returns:
- -
HttpClientResponsewith a JAXB content type - Throws:
HttpClientException
-
deleteJaxb
HttpClientResponse<Object> deleteJaxb(String url, Class<?>... responseTypes) throws HttpClientException Issue an HTTP DELETE to the provided URL, receiving a JAXB Object in the response. In order to unmarshal the response, an array of possible response classes must be provided in responseTypes- Parameters:
url-responseTypes-- Returns:
- -
HttpClientResponsewith a JAXB content type - Throws:
HttpClientException
-
putXML
Issue an HTTP PUT to the provided URL, sending the provided XML as a String and receiving a String in the response.- Parameters:
url-xml-- Returns:
- -
HttpClientResponsewith a String content type - Throws:
HttpClientException
-
postSOAP
Issue an HTTP POST to the provided URL, sending the provided XML as a String and receiving a String in the response. Uses a content type of application/soap+xml- Parameters:
url-xml-- Returns:
- -
HttpClientResponsewith a String content type - Throws:
HttpClientException
-
putSOAP
Issue an HTTP PUT to the provided URL, sending the provided XML as a String and receiving a String in the response. Uses a content type of application/soap+xml- Parameters:
url-xml-- Returns:
- -
HttpClientResponsewith a String content type - Throws:
HttpClientException
-
postXML
Issue an HTTP POST to the provided URL, sending the provided XML as a String and receiving a String in the response.- Parameters:
url-xml-- Returns:
- -
HttpClientResponsewith a String content type - Throws:
HttpClientException
-
getJson
Issue an HTTP GET to the provided URL, receiving a com.google.gson.JsonObject in the response.- Parameters:
url-- Returns:
- -
HttpClientResponsewith a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
postJson
HttpClientResponse<com.google.gson.JsonObject> postJson(String url, com.google.gson.JsonObject json) throws HttpClientException Issue an HTTP POST to the provided URL, sending the provided com.google.gson.JsonObject and receiving a com.google.gson.JsonObject in the response.- Parameters:
url-json-- Returns:
- -
HttpClientResponsewith a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
patchJson
HttpClientResponse<com.google.gson.JsonObject> patchJson(String url, com.google.gson.JsonObject json) throws HttpClientException Issue an HTTP PATCH to the provided URL, sending the provided com.google.gson.JsonObject and receiving a com.google.gson.JsonObject in the response.- Parameters:
url-json-- Returns:
- -
HttpClientResponsewith a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
putJson
HttpClientResponse<com.google.gson.JsonObject> putJson(String url, com.google.gson.JsonObject json) throws HttpClientException Issue an HTTP PUT to the provided URL, sending the providedcom.google.gson.JsonObjectand receiving acom.google.gson.JsonObjectin the response.- Parameters:
url-json-- Returns:
- -
HttpClientResponsewith acom.google.gson.JsonObjectcontent type - Throws:
HttpClientException
-
deleteJson
Issue an HTTP DELETE to the provided URL, receiving a com.google.gson.JsonObject in the response.- Parameters:
url-- Returns:
- -
HttpClientResponsewith a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
deleteJson
HttpClientResponse<com.google.gson.JsonObject> deleteJson(String url, com.google.gson.JsonObject json) throws HttpClientException Issue an HTTP DELETE to the provided URL, receiving a com.google.gson.JsonObject in the response.- Parameters:
url-json-- Returns:
- -
HttpClientResponsewith a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
getText
Issue an HTTP GET to the provided URL, receiving aStringin the response.- Parameters:
url-- Returns:
- -
HttpClientResponsewith aStringcontent type - Throws:
HttpClientException
-
postText
Issue an HTTP POST to the provided URL, sending the providedStringand receiving aStringin the response.- Parameters:
url-text-- Returns:
- -
HttpClientResponsewith aStringcontent type - Throws:
HttpClientException
-
putText
Issue an HTTP PUT to the provided URL, sending the providedStringand receiving aStringin the response.- Parameters:
url-text-- Returns:
- -
HttpClientResponsewith aStringcontent type - Throws:
HttpClientException
-
deleteText
Issue an HTTP DELETE to the provided URL, receiving aStringin the response.- Parameters:
url-- Returns:
- -
HttpClientResponsewith aStringcontent type - Throws:
HttpClientException
-
putBinary
Issue an HTTP PUT to the provided URL, sending the providedbyteand receiving abytein the response.- Parameters:
url-binary-- Returns:
- -
HttpClientResponsewith a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
getBinary
Issue an HTTP GET to the provided URL, sending the providedbyteand receiving abytein the response.- Parameters:
url-binary-- Returns:
- -
HttpClientResponsewith a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
postBinary
Issue an HTTP POST to the provided URL, sending the providedbyteand receiving abytein the response.- Parameters:
url-binary-- Returns:
- -
HttpClientResponsewith a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
deleteBinary
Issue an HTTP DELETE to the provided URL, sending the providedbyteand receiving abytein the response.- Parameters:
url-binary-- Returns:
- -
HttpClientResponsewith a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
getFile
org.apache.http.client.methods.CloseableHttpResponse getFile(String path) throws HttpClientException Download a file from a specified location to a specified destination on local host.- Parameters:
path- = URL path- Throws:
HttpClientException
-
getFile
org.apache.http.client.methods.CloseableHttpResponse getFile(String path, ContentType... acceptTypes) throws HttpClientException Download a file from a specified location to a specified destination on local host.- Parameters:
acceptTypes-path- - URL path- Throws:
HttpClientException
-
putFile
Send a compressed (tar) file from a local location to a specified destination on a host.- Parameters:
path- - URL pathfile- - tar archive file
-
head
Execute anHttpClientRequestreturning a JAXB object available through the returnedHttpClientResponse. In order to unmarshal the response, an array of possible response classes must be provided in responseTypes *- Parameters:
url-- Returns:
- -
HttpClientResponse - Throws:
HttpClientException
-
post
Object post(String path, Map<String, String> queryParams, ContentType contentType, Object data, ContentType[] acceptTypes, Class<?>[] jaxbClasses, boolean retry) throws HttpClientException- Throws:
HttpClientException
-
postForm
Object postForm(String path, Map<String, String> queryParams, HashMap<String, throws HttpClientExceptionString> fields, ContentType[] acceptTypes, Class<?>[] jaxbClasses, boolean retry) - Throws:
HttpClientException
-
getSSLContext
SSLContext getSSLContext()Get the SSL context used by this client- Returns:
- the
SSLContextor null if there is none
-
getUsername
String getUsername()Get the username set for this client- Returns:
- the username
-
getUsername
Get the username set for this client for a specific scope- Parameters:
scope-- Returns:
- the username
-
addCommonHeader
Add a header that will be used on all http requests- Parameters:
name-value-
-
clearCommonHeaders
void clearCommonHeaders()Remove all headers for this http request -
addOkResponseCode
void addOkResponseCode(int responseCode) Add a response code for the execute to ignore and treat as OK- Parameters:
responseCode-
-
build
IHttpClient build()Build the client- Returns:
- the built client
-
close
void close()close the underlying HTTPClient -
setAuthorisation
Set the username and password for all scopes- Parameters:
username-password-- Returns:
- the updated client
-
setAuthorisation
Set the username and password for a specific scope- Parameters:
username-password-scope-- Returns:
- the updated client
-
setHostnameVerifier
Set the hostname verifier- Parameters:
hostnameVerifier-- Returns:
- the updated client
-
setNoopHostnameVerifier
IHttpClient setNoopHostnameVerifier()Set the hostname verifier to a no-op verifier- Returns:
- the updated client
-
setSSLContext
Set the SSL Context- Parameters:
sslContext-- Returns:
- the updated client
-
setTrustingSSLContext
Set the SSL Context to a Trust All context- Returns:
- the updated client
- Throws:
HttpClientException
-
setupClientAuth
IHttpClient setupClientAuth(KeyStore clientKeyStore, KeyStore serverKeyStore, String alias, String password) throws HttpClientException Set up Client Authentication SSL Context and install- Parameters:
clientKeyStore-serverKeyStore-alias-password-- Returns:
- the updated client
- Throws:
HttpClientException
-
setURI
Set the URI endpoint for this client- Parameters:
host-
-