-
- All Implemented Interfaces:
-
au.com.dius.pact.core.pactbroker.IHalClient
public class HalClient implements IHalClient
HAL client for navigating the HAL links
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classHalClient.Companion
-
Field Summary
Fields Modifier and Type Field Description private CloseableHttpClienthttpClientprivate HttpClientContexthttpContextprivate JsonValue.ObjectpathInfoprivate StringlastUrlprivate Map<String, String>defaultHeadersprivate final StringbaseUrlprivate Map<String, Object>optionsprivate final PactBrokerClientConfigconfig
-
Constructor Summary
Constructors Constructor Description HalClient(String baseUrl, Map<String, Object> options, PactBrokerClientConfig config)HalClient(String baseUrl, PactBrokerClientConfig config)
-
Method Summary
Modifier and Type Method Description final CloseableHttpClientgetHttpClient()final UnitsetHttpClient(CloseableHttpClient httpClient)final HttpClientContextgetHttpContext()final UnitsetHttpContext(HttpClientContext httpContext)final JsonValue.ObjectgetPathInfo()final UnitsetPathInfo(JsonValue.Object pathInfo)final StringgetLastUrl()final UnitsetLastUrl(String lastUrl)final Map<String, String>getDefaultHeaders()final UnitsetDefaultHeaders(Map<String, String> defaultHeaders)final StringgetBaseUrl()final Map<String, Object>getOptions()final UnitsetOptions(@Deprecated(message = Move use of options to PactBrokerClientConfig) Map<String, Object> options)final PactBrokerClientConfiggetConfig()final <Method extends HttpMessage> MethodinitialiseRequest(Method method)Result<Boolean, Exception>postJson(String url, String body)Upload the JSON document to the provided URL, using a POST request Result<Boolean, Exception>postJson(String url, String body, Function2<Integer, CloseableHttpResponse, Boolean> handler)Upload the JSON document to the provided URL, using a POST request Result<JsonValue.Object, Exception>postJson(String link, Map<String, Object> options, String json)Upload a JSON document to the current path link, using a POST request CloseableHttpClientsetupHttpClient()IHalClientnavigate()Navigates to the Root IHalClientnavigate(Map<String, Object> options, String link)Navigates the URL associated with the given link using the current HAL document IHalClientnavigate(String link)Navigates the URL associated with the given link using the current HAL document Result<JsonValue.Object, Exception>fetch(String path)Fetches the HAL document from the provided path Result<JsonValue.Object, Exception>fetch(String path, Boolean encodePath)Fetches the HAL document from the provided path IHalClientwithDocContext(Map<String, Object> docAttributes)Sets the starting context from a previous broker interaction (Pact document) IHalClientwithDocContext(JsonValue.Object docAttributes)Sets the starting context from a previous broker interaction (Pact document) Result<JsonValue, Exception>getJson(String path)Get JSON from the provided path Result<JsonValue, Exception>getJson(String path, Boolean encodePath)Get JSON from the provided path final StringparseLinkUrl(String href, Map<String, Object> options)final UnitinitPathInfo()final ObjecthandleFailure(HttpResponse resp, String body, BiFunction<String, String, Object> closure)StringlinkUrl(String name)Returns the HREF of the named link from the current HAL document UnitforAll(String linkName, Consumer<Map<String, Object>> closure)Calls the closure with a Map of attributes for all links associated with the link name Result<String, Exception>putJson(String link, Map<String, Object> options, String json)Upload a JSON document to the current path link, using a PUT request -
-
Constructor Detail
-
HalClient
HalClient(String baseUrl, Map<String, Object> options, PactBrokerClientConfig config)
-
HalClient
HalClient(String baseUrl, PactBrokerClientConfig config)
-
-
Method Detail
-
getHttpClient
final CloseableHttpClient getHttpClient()
-
setHttpClient
final Unit setHttpClient(CloseableHttpClient httpClient)
-
getHttpContext
final HttpClientContext getHttpContext()
-
setHttpContext
final Unit setHttpContext(HttpClientContext httpContext)
-
getPathInfo
final JsonValue.Object getPathInfo()
-
setPathInfo
final Unit setPathInfo(JsonValue.Object pathInfo)
-
getLastUrl
final String getLastUrl()
-
setLastUrl
final Unit setLastUrl(String lastUrl)
-
getDefaultHeaders
final Map<String, String> getDefaultHeaders()
-
setDefaultHeaders
final Unit setDefaultHeaders(Map<String, String> defaultHeaders)
-
getBaseUrl
final String getBaseUrl()
-
getOptions
final Map<String, Object> getOptions()
-
setOptions
final Unit setOptions(@Deprecated(message = Move use of options to PactBrokerClientConfig) Map<String, Object> options)
-
getConfig
final PactBrokerClientConfig getConfig()
-
initialiseRequest
final <Method extends HttpMessage> Method initialiseRequest(Method method)
-
postJson
Result<Boolean, Exception> postJson(String url, String body)
Upload the JSON document to the provided URL, using a POST request
- Parameters:
url- Url to upload the document tobody- JSON contents for the body
-
postJson
Result<Boolean, Exception> postJson(String url, String body, Function2<Integer, CloseableHttpResponse, Boolean> handler)
Upload the JSON document to the provided URL, using a POST request
- Parameters:
url- Url to upload the document tobody- JSON contents for the bodyhandler- Response handler
-
postJson
Result<JsonValue.Object, Exception> postJson(String link, Map<String, Object> options, String json)
Upload a JSON document to the current path link, using a POST request
-
setupHttpClient
CloseableHttpClient setupHttpClient()
-
navigate
IHalClient navigate()
Navigates to the Root
-
navigate
IHalClient navigate(Map<String, Object> options, String link)
Navigates the URL associated with the given link using the current HAL document
- Parameters:
options- Map of key-value pairs to use for parsing templated linkslink- Link name to navigate
-
navigate
IHalClient navigate(String link)
Navigates the URL associated with the given link using the current HAL document
- Parameters:
link- Link name to navigate
-
fetch
Result<JsonValue.Object, Exception> fetch(String path)
Fetches the HAL document from the provided path
- Parameters:
path- The path to the HAL document.
-
fetch
Result<JsonValue.Object, Exception> fetch(String path, Boolean encodePath)
Fetches the HAL document from the provided path
- Parameters:
path- The path to the HAL document.encodePath- If the path should be encoded to make a valid URL
-
withDocContext
IHalClient withDocContext(Map<String, Object> docAttributes)
Sets the starting context from a previous broker interaction (Pact document)
-
withDocContext
IHalClient withDocContext(JsonValue.Object docAttributes)
Sets the starting context from a previous broker interaction (Pact document)
-
getJson
Result<JsonValue, Exception> getJson(String path, Boolean encodePath)
Get JSON from the provided path
- Parameters:
path- Path to fetch the JSON document fromencodePath- If the path should be encoded
-
initPathInfo
final Unit initPathInfo()
-
handleFailure
final Object handleFailure(HttpResponse resp, String body, BiFunction<String, String, Object> closure)
-
linkUrl
String linkUrl(String name)
Returns the HREF of the named link from the current HAL document
-
forAll
Unit forAll(String linkName, Consumer<Map<String, Object>> closure)
Calls the closure with a Map of attributes for all links associated with the link name
- Parameters:
linkName- Name of the link to loop overclosure- Closure to invoke with the link attributes
-
-
-
-