Class HL7V2RestClient

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

public class HL7V2RestClient extends Object implements AutoCloseable
A REST client for sending HL7V2 messages to a Smile CDR server.
  • Method Details

    • open

      @Nonnull public static HL7V2RestClient open(@Nonnull String theBaseUrl, @Nullable String theUsername, @Nullable String thePassword)
      Opens a client 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, so this client shares its session rather than starting another.

      The client is configured the way every other Smile test client is: generous timeouts and redirects disabled, so a 3xx is returned rather than followed.

      Parameters:
      theBaseUrl - The base URL of the HL7V2 endpoint, including port if needed.
      theUsername - The username for authentication (optional)
      thePassword - The password for authentication (optional)
      Returns:
      A new HL7V2RestClient
    • issuingOn

      @Nonnull public static HL7V2RestClient 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 HL7V2 endpoint, including port if needed.
      theUsername - The username for authentication (optional)
      thePassword - The password for authentication (optional)
      Returns:
      A new HL7V2RestClient
      See Also:
    • build

      @Deprecated(since="2026.11.R01", forRemoval=true) @Nonnull public static HL7V2RestClient build(@Nonnull String theBaseUrl, @Nullable String theUsername, @Nullable String thePassword)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use open(String, String, String), whose name says that the client owns the connection pool it returns and that the caller has to close it.
    • sendMessage

      @Nonnull public ca.uhn.hl7v2.model.Message sendMessage(String theMessage) throws ca.uhn.hl7v2.HL7Exception
      Send an HL7V2 message to the server.
      Parameters:
      theMessage - The HL7V2 message to send
      Returns:
      The response message from the server
      Throws:
      ca.uhn.hl7v2.HL7Exception - If there is an error parsing the response
    • sendMessage

      @Nonnull public ca.uhn.hl7v2.model.Message sendMessage(ca.uhn.hl7v2.model.Message theMessage) throws ca.uhn.hl7v2.HL7Exception
      Send a pre-parsed HL7V2 message to the server.
      Parameters:
      theMessage - The pre-parsed HL7V2 message to send
      Returns:
      The response message from the server
      Throws:
      ca.uhn.hl7v2.HL7Exception - If there is an error encoding the message or parsing the response
    • 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