Package dev.galasa.http
Interface IHttpClient
public interface IHttpClient
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCommonHeader
(String name, String value) Add a header that will be used on all http requestsvoid
addOkResponseCode
(int responseCode) Add a response code for the execute to ignore and treat as OKbuild()
Build the clientvoid
Remove all headers for this http requestvoid
close()
close the underlying HTTPClientHttpClientResponse<byte[]>
deleteBinary
(String url, byte[] binary) Issue an HTTP DELETE to the provided URL, sending the providedbyte
and receiving abyte
in 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 aString
in the response.HttpClientResponse<byte[]>
Issue an HTTP GET to the provided URL, sending the providedbyte
and receiving abyte
in the response.org.apache.http.client.methods.CloseableHttpResponse
Download a file from a specified location to a specified destination on local host.org.apache.http.client.methods.CloseableHttpResponse
getFile
(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 aString
in the response.Get the username set for this clientgetUsername
(URI scope) Get the username set for this client for a specific scopeExecute anHttpClientRequest
returning 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 providedbyte
and receiving abyte
in 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 providedbyte
and receiving abyte
in the response.void
putFile
(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.JsonObject
and receiving acom.google.gson.JsonObject
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.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 installvoid
Set 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:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with 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.JsonObject
and receiving acom.google.gson.JsonObject
in the response.- Parameters:
url
-json
-- Returns:
- -
HttpClientResponse
with acom.google.gson.JsonObject
content type - Throws:
HttpClientException
-
deleteJson
Issue an HTTP DELETE to the provided URL, receiving a com.google.gson.JsonObject in the response.- Parameters:
url
-- Returns:
- -
HttpClientResponse
with 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:
- -
HttpClientResponse
with a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
getText
Issue an HTTP GET to the provided URL, receiving aString
in the response.- Parameters:
url
-- Returns:
- -
HttpClientResponse
with aString
content type - Throws:
HttpClientException
-
postText
Issue an HTTP POST to the provided URL, sending the providedString
and receiving aString
in the response.- Parameters:
url
-text
-- Returns:
- -
HttpClientResponse
with aString
content type - Throws:
HttpClientException
-
putText
Issue an HTTP PUT to the provided URL, sending the providedString
and receiving aString
in the response.- Parameters:
url
-text
-- Returns:
- -
HttpClientResponse
with aString
content type - Throws:
HttpClientException
-
deleteText
Issue an HTTP DELETE to the provided URL, receiving aString
in the response.- Parameters:
url
-- Returns:
- -
HttpClientResponse
with aString
content type - Throws:
HttpClientException
-
putBinary
Issue an HTTP PUT to the provided URL, sending the providedbyte
and receiving abyte
in the response.- Parameters:
url
-binary
-- Returns:
- -
HttpClientResponse
with a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
getBinary
Issue an HTTP GET to the provided URL, sending the providedbyte
and receiving abyte
in the response.- Parameters:
url
-binary
-- Returns:
- -
HttpClientResponse
with a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
postBinary
Issue an HTTP POST to the provided URL, sending the providedbyte
and receiving abyte
in the response.- Parameters:
url
-binary
-- Returns:
- -
HttpClientResponse
with a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
deleteBinary
Issue an HTTP DELETE to the provided URL, sending the providedbyte
and receiving abyte
in the response.- Parameters:
url
-binary
-- Returns:
- -
HttpClientResponse
with 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 anHttpClientRequest
returning 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
SSLContext
or 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
-
-