Package ca.cdr.test.app.clients
Class CdsHooksClient
java.lang.Object
ca.cdr.test.app.clients.CdsHooksClient
- All Implemented Interfaces:
AutoCloseable
A client for a Smile CDR CDS Hooks endpoint (
ENDPOINT_CDS_HOOKS), covering the three
endpoints of the CDS Hooks specification: discovery, service invocation and feedback.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases the connection pool this client built for itself.com.fasterxml.jackson.databind.JsonNodeLists the services this endpoint offers:GET {base}/cds-services.com.fasterxml.jackson.databind.JsonNodeReports what became of a service's cards:POST {base}/cds-services/{id}/feedback.com.fasterxml.jackson.databind.JsonNodeInvokes a service:POST {base}/cds-services/{id}.static CdsHooksClientissuingOn(SmileTestHttpClient theHttpClient, String theBaseUrl, String theUsername, String thePassword) Builds a client that issues its requests ontheHttpClient, sharing that client's connection pool and cookie store with everything else built over it.static CdsHooksClientOpens a client authenticating as the given user, over a connection pool of its own.static CdsHooksClientopenAnonymous(String theBaseUrl) Opens a client sending no credentials, over a connection pool of its own.
-
Method Details
-
open
@Nonnull public static CdsHooksClient open(@Nonnull String theBaseUrl, @Nonnull String theUsername, @Nonnull String thePassword) Opens a client authenticating as the given user, over a connection pool of its own.The caller owns the pool: open this in a try-with-resources block, or close it from an
@AfterAllwhen it is a field. UseissuingOn(SmileTestHttpClient, String, String, String)instead where a client to issue on already exists.- Parameters:
theBaseUrl- the base URL of the CDS Hooks endpoint, including port and context paththeUsername- the user to authenticate asthePassword- that user's password- Returns:
- a new client
-
openAnonymous
Opens a client sending no credentials, over a connection pool of its own. CDS Hooks services are often exposed without authentication.The caller owns the pool ? see
open(String, String, String).- Parameters:
theBaseUrl- the base URL of the CDS Hooks endpoint, including port and context path- Returns:
- a new client
-
issuingOn
@Nonnull public static CdsHooksClient issuingOn(@Nonnull SmileTestHttpClient theHttpClient, @Nonnull String theBaseUrl, @Nullable String theUsername, @Nullable String thePassword) Builds a client that issues its requests ontheHttpClient, sharing that client's connection pool and cookie store with everything else built over it.The pool stays the caller's:
close()leaves it open, so there is nothing here for the caller to release. Useopen(String, String, String)to build a pool of your own.- Parameters:
theHttpClient- the client to issue on, which the caller keeps ownership oftheBaseUrl- the base URL of the CDS Hooks endpoint, including port and context paththeUsername- the user to authenticate as, or null to send no credentialsthePassword- that user's password- Returns:
- a new client
-
discovery
Lists the services this endpoint offers:GET {base}/cds-services.- Returns:
- the discovery response, whose
servicesarray describes each service
-
invoke
@Nonnull public com.fasterxml.jackson.databind.JsonNode invoke(@Nonnull String theServiceId, @Nonnull com.fasterxml.jackson.databind.JsonNode theRequest) Invokes a service:POST {base}/cds-services/{id}.- Parameters:
theServiceId- the service'sidfromdiscovery()theRequest- the CDS Hooks request, carryinghook,hookInstance,contextand optionallyprefetch- Returns:
- the CDS Hooks response, whose
cardsarray holds the service's advice
-
feedback
@Nonnull public com.fasterxml.jackson.databind.JsonNode feedback(@Nonnull String theServiceId, @Nonnull com.fasterxml.jackson.databind.JsonNode theFeedback) Reports what became of a service's cards:POST {base}/cds-services/{id}/feedback.- Parameters:
theServiceId- the service'sidfromdiscovery()theFeedback- the feedback request, whosefeedbackarray names each card and its outcome- Returns:
- the response body, which the specification leaves empty; an empty object if there was none
-
close
Releases the connection pool this client built for itself. A no-op when the client was built over one supplied by a caller, which owns its own pool.- Specified by:
closein interfaceAutoCloseable
-