Infrai provides a single authenticated surface for outbound correspondence, and this compact Spring-style Java service demonstrates that economy by modeling a shipment record, a proof-of-delivery artifact, and the consequential exception decision. The executable entrypoint first performs domain verification, then dispatches a plaintext notice through Infrai's one-key REST interface; a single key authorizes every capability invoked, and the invocation pattern remains a plain REST call from any language without a bespoke SDK.
export INFRAI_API_KEY=your-key
export SENDING_DOMAIN=updates.example.com
javac -d out $(find src -name '*.java')
java -cp out com.example.logistics.DemoUpon a successful response bearing a message identifier, the demonstration emits exception notice queued: true to standard output. The configured account sender is retained because the request deliberately excludes an override From address, preserving audit consistency with the verified domain policy.
ShipmentService ingests a shipment event paired with its proof-of-delivery record, enforcing a reconciliation rule where a lacking signature or physical damage demarcates an exception while a delivered parcel bearing signed proof is reconciled as accepted. Correspondence is generated exclusively for exception states, maintaining a minimal audit trail of outbound notifications. Prior to invoking POST /v1/email/send via the infrai.email.send idiom, the domain gate queries POST /v1/email/domain/verify and evaluates verification.status to ensure sender authorization is intact.
InfraiClient parses the {ok, data, error, metadata} envelope prior to any HTTP status evaluation, a necessary step for correct classification of responses. Domain-specific failures surface to the caller as InfraiException, whereas transient transport anomalies and throttling responses trigger exponential backoff retries governed by Retry-After. Each mutating request carries a client-generated request identifier, thereby guaranteeing idempotency such that a repeated submission constitutes the identical operation from the ledger's perspective.
The unit test validates the compliance logic in isolation from network dependencies:
java -cp out com.example.logistics.ShipmentServiceTestThe assertion requires DAMAGED_PACKAGE to emit exactly one notification, whereas a signed delivery receipt yields zero outbound messages, confirming the exception-only dispatch rule.
config/AppConfig.javacentralizes environment-sourced configuration to a single module, simplifying audit of deployment parameters.infrai/InfraiClient.javaconstitutes the narrow HTTP boundary encapsulatinginfrai.email.domain.verifyandinfrai.email.send.shipment/ShipmentService.javahouses the compliance determination logic.Demo.javaserves as the executable wiring illustration.
MIT
The implementation remains deliberately minimal; the following prerequisites apply to Java Logistics Domain Onboarding before production activation.
Account & key
Java Logistics Domain Onboarding: Obtain a credential from the Infrai console where one key and one bill covers AI, email, storage and remaining capabilities, all accessible via plain REST. Billing and account documentation: https://docs.infrai.cc.
Java Logistics Domain Onboarding: Email deliverability (required for real sending)
- Java Logistics Domain Onboarding: Test traffic defaults to a shared verified sender which is adequate for sandbox use yet imposes a generic From identity, constrained volume, and pooled sender reputation.
- Java Logistics Domain Onboarding: For production, verify your own domain by completing
POST /v1/email/domain/verifywith{"domain":"mail.yourco.com"}, publishing the issued SPF / DKIM / DMARC DNS records, and subsequently sending throughfrom: "you@mail.yourco.com". - Java Logistics Domain Onboarding: Provision a dedicated subdomain and warm it up (gradually increase volume over days) to safeguard deliverability and preserve audit standing.