public class HalClient implements IHalClient
HAL client for navigating the HAL links
| Modifier and Type | Class and Description |
|---|---|
static class |
HalClient.Companion |
| Modifier and Type | Field and Description |
|---|---|
static HalClient.Companion |
Companion |
static java.lang.String |
LINKS |
static java.lang.String |
ROOT |
| Constructor and Description |
|---|
HalClient(java.lang.String baseUrl,
java.util.Map<java.lang.String,? extends java.lang.Object> options)
HAL client for navigating the HAL links
|
HalClient(java.lang.String baseUrl)
HAL client for navigating the HAL links
|
| Modifier and Type | Method and Description |
|---|---|
static java.util.Map<java.lang.String,java.lang.Object> |
asMap(com.google.gson.JsonObject jsonObject) |
com.google.gson.JsonElement |
fetch(java.lang.String path)
Fetches the HAL document from the provided path
|
com.google.gson.JsonElement |
fetch(java.lang.String path,
boolean encodePath)
Fetches the HAL document from the provided path
|
void |
forAll(java.lang.String linkName,
java.util.function.Consumer<java.util.Map> closure)
Calls the closure with a Map of attributes for all links associated with the link name
|
static java.lang.Object |
fromJson(com.google.gson.JsonElement jsonValue) |
java.lang.String |
getBaseUrl() |
java.util.Map<java.lang.String,java.lang.String> |
getDefaultHeaders() |
org.apache.http.impl.client.CloseableHttpClient |
getHttpClient() |
java.lang.String |
getLastUrl() |
java.util.Map<java.lang.String,java.lang.Object> |
getOptions() |
com.google.gson.JsonElement |
getPathInfo() |
java.lang.Object |
handleFailure(org.apache.http.HttpResponse resp,
java.lang.String body,
java.util.function.BiFunction<java.lang.String,java.lang.String,java.lang.Object> closure) |
void |
initPathInfo() |
<Method extends HttpMessage> |
initialiseRequest(Method method) |
java.lang.String |
linkUrl(java.lang.String name)
Returns the HREF of the named link from the current HAL document
|
IHalClient |
navigate(java.util.Map<java.lang.String,? extends java.lang.Object> options,
java.lang.String link)
Navigates the URL associated with the given link using the current HAL document
|
IHalClient |
navigate(java.lang.String link)
Navigates the URL associated with the given link using the current HAL document
|
java.lang.String |
parseLinkUrl(java.lang.String href,
java.util.Map<java.lang.String,? extends java.lang.Object> options) |
au.com.dius.pact.com.github.michaelbull.result.Result<java.lang.Boolean,java.lang.Exception> |
postJson(java.lang.String url,
java.lang.String body)
Upload the JSON document to the provided URL, using a POST request
|
au.com.dius.pact.com.github.michaelbull.result.Result<java.lang.Boolean,java.lang.Exception> |
postJson(java.lang.String url,
java.lang.String body,
kotlin.jvm.functions.Function2<? super java.lang.Integer,? super org.apache.http.client.methods.CloseableHttpResponse,java.lang.Boolean> handler)
Upload the JSON document to the provided URL, using a POST request
|
void |
setDefaultHeaders(java.util.Map<java.lang.String,java.lang.String> p) |
void |
setHttpClient(org.apache.http.impl.client.CloseableHttpClient p) |
void |
setLastUrl(java.lang.String p) |
void |
setOptions(java.util.Map<java.lang.String,? extends java.lang.Object> p) |
void |
setPathInfo(com.google.gson.JsonElement p) |
org.apache.http.impl.client.CloseableHttpClient |
setupHttpClient() |
java.lang.Object |
uploadJson(java.lang.String path,
java.lang.String bodyJson)
Upload the JSON document to the provided path, using a PUT request
|
java.lang.Object |
uploadJson(java.lang.String path,
java.lang.String bodyJson,
java.util.function.BiFunction<java.lang.String,java.lang.String,java.lang.Object> closure)
Upload the JSON document to the provided path, using a PUT request
|
java.lang.Object |
uploadJson(java.lang.String path,
java.lang.String bodyJson,
java.util.function.BiFunction<java.lang.String,java.lang.String,java.lang.Object> closure,
boolean encodePath)
Upload the JSON document to the provided path, using a PUT request
|
fetch, fetch, forAll, linkUrl, navigate, navigate, postJson, postJson, uploadJson, uploadJson, uploadJsonpublic static java.lang.String ROOT
public static java.lang.String LINKS
public static HalClient.Companion Companion
public HalClient(java.lang.String baseUrl,
java.util.Map<java.lang.String,? extends java.lang.Object> options)
HAL client for navigating the HAL links
public HalClient(java.lang.String baseUrl)
HAL client for navigating the HAL links
public org.apache.http.impl.client.CloseableHttpClient getHttpClient()
public void setHttpClient(org.apache.http.impl.client.CloseableHttpClient p)
public com.google.gson.JsonElement getPathInfo()
public void setPathInfo(com.google.gson.JsonElement p)
public java.lang.String getLastUrl()
public void setLastUrl(java.lang.String p)
public java.util.Map<java.lang.String,java.lang.String> getDefaultHeaders()
public void setDefaultHeaders(java.util.Map<java.lang.String,java.lang.String> p)
public <Method extends HttpMessage> Method initialiseRequest(Method method)
public au.com.dius.pact.com.github.michaelbull.result.Result<java.lang.Boolean,java.lang.Exception> postJson(java.lang.String url,
java.lang.String body)
Upload the JSON document to the provided URL, using a POST request
url - Url to upload the document tobody - JSON contents for the bodypublic au.com.dius.pact.com.github.michaelbull.result.Result<java.lang.Boolean,java.lang.Exception> postJson(java.lang.String url,
java.lang.String body,
kotlin.jvm.functions.Function2<? super java.lang.Integer,? super org.apache.http.client.methods.CloseableHttpResponse,java.lang.Boolean> handler)
Upload the JSON document to the provided URL, using a POST request
url - Url to upload the document tobody - JSON contents for the bodyhandler - Response handlerpublic org.apache.http.impl.client.CloseableHttpClient setupHttpClient()
public IHalClient navigate(java.util.Map<java.lang.String,? extends java.lang.Object> options, java.lang.String link)
Navigates the URL associated with the given link using the current HAL document
options - Map of key-value pairs to use for parsing templated linkslink - Link name to navigatepublic IHalClient navigate(java.lang.String link)
Navigates the URL associated with the given link using the current HAL document
link - Link name to navigatepublic com.google.gson.JsonElement fetch(java.lang.String path)
Fetches the HAL document from the provided path
path - The path to the HAL document. If it is a relative path, it is relative to the base URLpublic com.google.gson.JsonElement fetch(java.lang.String path,
boolean encodePath)
Fetches the HAL document from the provided path
path - The path to the HAL document. If it is a relative path, it is relative to the base URLencodePath - If the path should be encoded to make a valid URLpublic java.lang.String parseLinkUrl(java.lang.String href,
java.util.Map<java.lang.String,? extends java.lang.Object> options)
public void initPathInfo()
public java.lang.Object uploadJson(java.lang.String path,
java.lang.String bodyJson)
Upload the JSON document to the provided path, using a PUT request
path - Path to upload the documentbodyJson - JSON contents for the bodypublic java.lang.Object uploadJson(java.lang.String path,
java.lang.String bodyJson,
java.util.function.BiFunction<java.lang.String,java.lang.String,java.lang.Object> closure)
Upload the JSON document to the provided path, using a PUT request
path - Path to upload the documentbodyJson - JSON contents for the bodyclosure - Closure that will be invoked with details about the response. The result from the closure will be
returned.public java.lang.Object uploadJson(java.lang.String path,
java.lang.String bodyJson,
java.util.function.BiFunction<java.lang.String,java.lang.String,java.lang.Object> closure,
boolean encodePath)
Upload the JSON document to the provided path, using a PUT request
path - Path to upload the documentbodyJson - JSON contents for the bodyclosure - Closure that will be invoked with details about the response. The result from the closure will be
returned.encodePath - If the path must be encoded beforehand.public java.lang.Object handleFailure(org.apache.http.HttpResponse resp,
java.lang.String body,
java.util.function.BiFunction<java.lang.String,java.lang.String,java.lang.Object> closure)
public java.lang.String linkUrl(java.lang.String name)
Returns the HREF of the named link from the current HAL document
public void forAll(java.lang.String linkName,
java.util.function.Consumer<java.util.Map> closure)
Calls the closure with a Map of attributes for all links associated with the link name
linkName - Name of the link to loop overclosure - Closure to invoke with the link attributespublic java.lang.String getBaseUrl()
public java.util.Map<java.lang.String,java.lang.Object> getOptions()
public void setOptions(java.util.Map<java.lang.String,? extends java.lang.Object> p)
public static java.util.Map<java.lang.String,java.lang.Object> asMap(com.google.gson.JsonObject jsonObject)
public static java.lang.Object fromJson(com.google.gson.JsonElement jsonValue)