Package ca.cdr.test.app.clients
Class HL7V2RestClient
java.lang.Object
ca.cdr.test.app.clients.HL7V2RestClient
- All Implemented Interfaces:
AutoCloseable
A REST client for sending HL7V2 messages to a Smile CDR server.
-
Method Summary
Modifier and TypeMethodDescriptionstatic HL7V2RestClientDeprecated, for removal: This API element is subject to removal in a future version.voidclose()Releases the connection pool this client built for itself.static HL7V2RestClientissuingOn(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 HL7V2RestClientOpens a client over a connection pool of its own.ca.uhn.hl7v2.model.MessagesendMessage(ca.uhn.hl7v2.model.Message theMessage) Send a pre-parsed HL7V2 message to the server.ca.uhn.hl7v2.model.MessagesendMessage(String theMessage) Send an HL7V2 message to the 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
@AfterAllwhen it is a field. UseissuingOn(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 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 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.Useopen(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
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
-
open(String, String, String), whose name says that the client owns the connection pool it returns and that the caller has to close it.