Blog

    Mirth Connect HTTP API Calls on Java 17: A Working Solution with HTTP Sender

    By GauravAugust 17, 20269 mins read
    On this page

    Mirth Connect HTTP API calls broke for many teams after the move to Java 17, because old HTTP JARs in custom-lib reach into JDK internals that are now sealed. The working solution is the HTTP Sender destination, which NextGen documents with URL, method, headers, authentication and response handling.

    Written for digital health founders and hospital CTOs whose channels call partner APIs, it covers the connector settings, queue and retry choices, certificates, and how to move an old transformer client across.

    How should Mirth Connect make HTTP API calls on Java 17?

    Mirth Connect should make HTTP API calls on Java 17 through the HTTP Sender destination, with the URL, method, headers and authentication set on that connector. Agnotic Technologies does not load a second HTTP client into a transformer. NextGen states that Connect 4.8.1 requires Java 17 or later and is tested against it.

    Calling an HTTP API from Connect?

    We use the HTTP Sender destination on Java 17. We do not drop a second client into the transformer.

    NextGen's Mirth Connect 4.8.1 user guide states that the engine requires Java 17 or later, and that it is tested and validated against Java 17.

    The HTTP Sender destination connector sends HTTP requests to an external web server. You configure the URL, method, headers, parameters, authentication, and how the response is handled.

    • Use: HTTP Sender. URL, method, headers, auth, response handling.
    • Runtime: Java 17, the version NextGen tests. Newer JDKs need a non-production check first.
    • HTTPS: the SSL Manager extension, when the destination needs a client certificate or a pinned trust store.
    • Do not: add HttpClient, OkHttp, or another HTTP JAR to custom-lib for a transformer call.

    HTTP Sender ships with the engine, so it needs no extra JAR and no classloader isolation. A client the engine does not ship, such as a Kafka producer, is a different problem with its own isolation pattern.

    What are the common mistakes with Mirth Connect HTTP calls on Java 17?

    The common mistakes are a hand-built HTTP client in a transformer, an --add-opens flag to silence Java 17 errors, and retry rules that treat every failure the same. Agnotic only reviews a custom client when HTTP Sender cannot represent the call, and then isolates its JAR from the engine's own libraries.

    • Wrong: a transformer that new-s up an HTTP client because the author prefers that API.
    • Still wrong: copying a working local JAR onto production without an isolation box.
    • Hard-coded hosts: a production URL typed into the channel, so test traffic can reach a live partner.
    • Trust-all code: a transformer that switches off certificate checks to get past a handshake error.
    • Allowed later: a client NextGen does not ship, isolated from the engine's libraries.

    What changed in Java 17 that breaks old transformer code?

    Java 17 strongly encapsulates the JDK's internals, so a library that reaches into them by reflection now fails at run time. Old HTTP and JSON JARs copied into custom-lib years ago are frequent offenders.

    OpenJDK JEP 403, delivered in Java 17, strongly encapsulates all internal elements of the JDK except critical APIs such as sun.misc.Unsafe. The --illegal-access option no longer relaxes this, though --add-opens can still open named packages.

    • Symptom: an InaccessibleObjectException or IllegalAccessError in the server log the first time the transformer runs.
    • Tempting fix: an --add-opens line in the engine's launcher options. That opens a JDK package for every channel on the server, not only yours.
    • Better fix: remove the old client and send the request through HTTP Sender, which ships with the engine.

    Before a runtime upgrade, run the jdeps tool that ships with the JDK against each JAR in custom-lib. It lists the classes that depend on JDK internals, which becomes the list of channels to fix first.

    Which HTTP Sender settings does a typical API call need?

    A typical call needs the URL, the method, the content type, a few headers and a timeout. The connector fills each one from the message or from maps through ${} variables, so the transformer only prepares values.

    • URL: a configured host plus a path variable, never a hard-coded production address.
    • Method and content: POST or PUT with an application/json or application/fhir+json body, or GET with query parameters.
    • Headers: Accept, Content-Type and whatever authorization header the API expects.
    • Timeout: a socket timeout agreed with the API owner, so a hung call fails instead of holding the destination.

    Where should the URL and credentials for the call live?

    The host, path prefix and credentials should live in per-environment settings on the engine, read by the connector at send time. The channel definition then stays identical in test and production.

    A bearer token that expires needs a refresh step that runs before the send, not a token pasted into the header field. Check which authentication types your Connect version's HTTP Sender documents before writing anything custom.

    How should the channel read the API's response?

    The channel should read the status and body in the destination's response transformer and decide there whether the call succeeded. A 200 that carries an error inside the body is still a failure the channel must catch.

    • 2xx with the expected body: mark it sent and store the returned id, such as a created resource id, with the message.
    • 4xx: the request was wrong. Error the message for a person, because a retry sends the same bad request.
    • 5xx or no answer: a server or network problem. Queue it and let the retry settings do their work.

    What should happen when the API is slow or down?

    The destination should queue on failure and retry at a fixed interval, so the channel keeps accepting messages while the API recovers. Without a queue, each send runs on the channel's main processing thread and blocks new messages.

    • Retry count: how many quick attempts happen before the message moves to the queue.
    • Retry interval: the pause between attempts, for the first tries and for the queue alike.
    • Rotate queue: lets later messages pass a stuck one. Turn it off when the API needs messages in order.
    • Queue threads: more than one sends in parallel and gives up ordering, unless a thread assignment variable groups related messages.

    How do you handle HTTPS certificates on Java 17?

    Handle them in the engine's trust configuration, not inside the transformer. The API's certificate chain must be trusted by the Java 17 runtime that runs Connect, and a client certificate, when the API asks for one, belongs in a managed keystore.

    • Public CA: usually trusted by the JDK's default trust store already. Test it rather than assume.
    • Private CA: import the issuing certificate into the trust store the engine uses, with a note of who added it and when it expires.
    • Mutual TLS: keep the client key out of the channel XML and out of git.
    • Never: a transformer that installs a trust-all manager to get past a handshake error.

    A worked example: posting a result notice to a partner API

    A worked example: a lab channel must notify a partner portal each time a final result is filed. The portal exposes a JSON endpoint that takes an order number and a status, and returns a receipt id.

    • Step 1, the transformer builds a small JSON body with the order number and status. No result values go to the portal.
    • Step 2, HTTP Sender posts it to the configured portal host, with the API key header also read from configuration.
    • Step 3, the response transformer reads the receipt id on a 2xx and stores it with the message.
    • Step 4, a 503 during the portal's maintenance queues the notices, and they drain once the portal is back.

    Built the old way, with an HTTP JAR inside the transformer, the same channel would have no queue and no retry record when the portal went down, and it would break again at the next JDK change.

    What should you log for each outbound call?

    Log enough to trace a call without copying patient data into a second place: the message id, the destination, the status code, the attempt number and how long the call took.

    • Keep: message id, destination name, HTTP status, attempt count, duration and any receipt id.
    • Drop: request and response bodies, unless the channel's storage setting already keeps them under access control.
    • Never: the authorization header, API keys or tokens.

    Send these fields to the same place the rest of the interface monitoring reads, so a rising 5xx count on one destination shows up beside the queue depth for that channel.

    How do you move an existing transformer client onto HTTP Sender?

    Move one channel at a time: capture the request the old code sends, rebuild it in HTTP Sender, prove both produce the same request against a stub, then delete the JAR.

    • Step 1, capture the URL, method, headers and body the old client sends, using a stub server in test.
    • Step 2, add an HTTP Sender destination that sends the same request, with values taken from maps.
    • Step 3, run both against the stub and compare the captured requests field by field.
    • Step 4, remove the transformer code, then remove the JAR from custom-lib once no channel loads it.

    How do you test the call before go-live?

    Test against a stub that can give every answer the real API might give, on the same Java 17 runtime production uses. A pass on a developer laptop running a newer JDK proves little about the server.

    • Answers: 200 with a good body, 200 with an error body, 401, 404, 500 and 503.
    • Network: a timeout, a refused connection, and an expired or untrusted certificate.
    • Load: a burst of messages, to watch the queue fill and drain in order.

    How does Agnotic wire the call?

    Agnotic moves each outbound call onto HTTP Sender on the Java 17 runtime production uses, with settings per environment, a queue and retry policy agreed with the API owner, and a stub test set kept in git with the channel.

    HTTP Sender, not a second client

    Java 17 as tested. Destination connector for the call. No extra JAR in the transformer.

    Related reading on Agnotic

    Kafka classloader isolation, and deploying the channel through the admin API.

    Sources

    Frequently Asked Questions

    Not as the default. Use HTTP Sender. A transformer HTTP client brings back the classloader problems that the connector avoids.

    Talk to an engineer about your project

    Name the HTTP API the channel must call. We will use HTTP Sender on Java 17 and keep extra clients off the transformer classpath.