public class HalClient implements IHalClient
HAL client for navigating the HAL links
@NotNull public static java.lang.String ROOT
@NotNull public static java.lang.String LINKS
@NotNull public static java.lang.String PREEMPTIVE_AUTHENTICATION
public static au.com.dius.pact.core.pactbroker.HalClient.Companion Companion
@JvmOverloads
public HalClient(@NotNull
java.lang.String baseUrl,
@NotNull
java.util.Map<java.lang.String,? extends java.lang.Object> options)
HAL client for navigating the HAL links
@JvmOverloads
public HalClient(@NotNull
java.lang.String baseUrl)
HAL client for navigating the HAL links
@Nullable public org.apache.http.impl.client.CloseableHttpClient getHttpClient()
public void setHttpClient(@Nullable
org.apache.http.impl.client.CloseableHttpClient p)
@Nullable public org.apache.http.client.protocol.HttpClientContext getHttpContext()
public void setHttpContext(@Nullable
org.apache.http.client.protocol.HttpClientContext p)
@Nullable public com.google.gson.JsonElement getPathInfo()
public void setPathInfo(@Nullable
com.google.gson.JsonElement p)
@Nullable public java.lang.String getLastUrl()
public void setLastUrl(@Nullable
java.lang.String p)
@NotNull public java.util.Map<java.lang.String,java.lang.String> getDefaultHeaders()
public void setDefaultHeaders(@NotNull
java.util.Map<java.lang.String,java.lang.String> p)
@NotNull public <Method extends HttpMessage> Method initialiseRequest(@NotNull Method method)
@NotNull
public au.com.dius.pact.com.github.michaelbull.result.Result<java.lang.Boolean,java.lang.Exception> postJson(@NotNull
java.lang.String url,
@NotNull
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 body@NotNull
public au.com.dius.pact.com.github.michaelbull.result.Result<java.lang.Boolean,java.lang.Exception> postJson(@NotNull
java.lang.String url,
@NotNull
java.lang.String body,
@Nullable
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 handler@NotNull public org.apache.http.impl.client.CloseableHttpClient setupHttpClient()
@NotNull public IHalClient navigate(@NotNull java.util.Map<java.lang.String,? extends java.lang.Object> options, @NotNull 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 navigate@NotNull public IHalClient navigate(@NotNull java.lang.String link)
Navigates the URL associated with the given link using the current HAL document
link - Link name to navigate@NotNull
public com.google.gson.JsonElement fetch(@NotNull
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 URL@NotNull
public com.google.gson.JsonElement fetch(@NotNull
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 URL@NotNull public IHalClient withDocContext(@NotNull java.util.Map<java.lang.String,? extends java.lang.Object> docAttributes)
Sets the starting context from a previous broker interaction (Pact document)
@NotNull
public java.lang.String parseLinkUrl(@NotNull
java.lang.String href,
@NotNull
java.util.Map<java.lang.String,? extends java.lang.Object> options)
public void initPathInfo()
@Nullable
public java.lang.Object uploadJson(@NotNull
java.lang.String path,
@NotNull
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 body@Nullable
public java.lang.Object uploadJson(@NotNull
java.lang.String path,
@NotNull
java.lang.String bodyJson,
@NotNull
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 bereturned.@Nullable
public java.lang.Object uploadJson(@NotNull
java.lang.String path,
@NotNull
java.lang.String bodyJson,
@NotNull
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 bereturned.encodePath - If the path must be encoded beforehand.@Nullable
public java.lang.Object handleFailure(@NotNull
org.apache.http.HttpResponse resp,
@Nullable
java.lang.String body,
@NotNull
java.util.function.BiFunction<java.lang.String,java.lang.String,java.lang.Object> closure)
@Nullable
public java.lang.String linkUrl(@NotNull
java.lang.String name)
Returns the HREF of the named link from the current HAL document
public void forAll(@NotNull
java.lang.String linkName,
@NotNull
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 attributes@NotNull
public au.com.dius.pact.com.github.michaelbull.result.Result<java.lang.Boolean,java.lang.Exception> putJson(@NotNull
java.lang.String link,
@NotNull
java.util.Map<java.lang.String,? extends java.lang.Object> options,
@NotNull
java.lang.String json)
Upload a JSON document to the current path link, using a PUT request
@NotNull public java.lang.String getBaseUrl()
@NotNull public java.util.Map<java.lang.String,java.lang.Object> getOptions()
public void setOptions(@NotNull
java.util.Map<java.lang.String,? extends java.lang.Object> p)
@JvmStatic
@NotNull
public static java.util.Map<java.lang.String,java.lang.Object> asMap(@NotNull
com.google.gson.JsonObject jsonObject)
@JvmStatic
@Nullable
public static java.lang.Object fromJson(@NotNull
com.google.gson.JsonElement jsonValue)