Class CdsHooksClient

java.lang.Object
ca.cdr.test.app.clients.CdsHooksClient
All Implemented Interfaces:
AutoCloseable

public class CdsHooksClient extends Object implements 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 Type
    Method
    Description
    void
    Releases the connection pool this client built for itself.
    com.fasterxml.jackson.databind.JsonNode
    Lists the services this endpoint offers: GET {base}/cds-services.
    com.fasterxml.jackson.databind.JsonNode
    feedback(String theServiceId, com.fasterxml.jackson.databind.JsonNode theFeedback)
    Reports what became of a service's cards: POST {base}/cds-services/{id}/feedback.
    com.fasterxml.jackson.databind.JsonNode
    invoke(String theServiceId, com.fasterxml.jackson.databind.JsonNode theRequest)
    Invokes a service: POST {base}/cds-services/{id}.
    issuingOn(SmileTestHttpClient theHttpClient, String theBaseUrl, String theUsername, String thePassword)
    Builds a client that issues its requests on theHttpClient, sharing that client's connection pool and cookie store with everything else built over it.
    open(String theBaseUrl, String theUsername, String thePassword)
    Opens a client authenticating as the given user, over a connection pool of its own.
    openAnonymous(String theBaseUrl)
    Opens a client sending no credentials, over a connection pool of its own.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 @AfterAll when it is a field. Use issuingOn(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 path
      theUsername - the user to authenticate as
      thePassword - that user's password
      Returns:
      a new client
    • openAnonymous

      @Nonnull public static CdsHooksClient openAnonymous(@Nonnull String theBaseUrl)
      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 on theHttpClient, 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. Use open(String, String, String) to build a pool of your own.

      Parameters:
      theHttpClient - the client to issue on, which the caller keeps ownership of
      theBaseUrl - the base URL of the CDS Hooks endpoint, including port and context path
      theUsername - the user to authenticate as, or null to send no credentials
      thePassword - that user's password
      Returns:
      a new client
    • discovery

      @Nonnull public com.fasterxml.jackson.databind.JsonNode discovery()
      Lists the services this endpoint offers: GET {base}/cds-services.
      Returns:
      the discovery response, whose services array 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's id from discovery()
      theRequest - the CDS Hooks request, carrying hook, hookInstance, context and optionally prefetch
      Returns:
      the CDS Hooks response, whose cards array 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's id from discovery()
      theFeedback - the feedback request, whose feedback array names each card and its outcome
      Returns:
      the response body, which the specification leaves empty; an empty object if there was none
    • close

      public void 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:
      close in interface AutoCloseable