AS4Sender is the low-level entry point for sending AS4 messages when no built-in profile applies. It does not set any profile-specific defaults — every field must be configured explicitly.
If you are sending to a Peppol, CEF eDelivery, BDEW, ENTSOG, or EUDAMED network, prefer the profile-specific senders instead. They pre-configure the correct crypto algorithms, PModes, and mandatory message properties for you.
Dependency
The generic sender is part of the corephase4-lib module.
Sending a user message
Required fields
The following fields must be set before callingsendMessage() or sendMessageAndCheckForReceipt():
| Field | Setter | Description |
|---|---|---|
| AS4 profile ID | as4ProfileID(String) | Identifies the PMode configuration |
| Crypto factory | cryptoFactory(IAS4CryptoFactory) | Used for both signing and encryption |
| HTTP client factory | httpClientFactory(HttpClientFactory) | HTTP transport settings |
| Endpoint URL | endpointURL(String) | Destination AS4 endpoint |
| From party ID | fromPartyID(String) | Sender party identifier |
| From role | fromRole(String) | Sender role URI |
| To party ID | toPartyID(String) | Receiver party identifier |
| To role | toRole(String) | Receiver role URI |
Complete example
Optional fields
Adding attachments
The payload passed to.payload() becomes the first MIME attachment. Additional attachments can be appended with .addAttachment():
AS4OutgoingAttachment.Builder supports:
.data(byte[])/.data(File)/.data(IHasInputStream, String).mimeTypeXML()/.mimeType(IMimeType).charset(Charset).compressionGZIP()/.compression(EAS4CompressionMode).contentID(String)— custom Content-ID header
Message properties
EB-MS 3.0 message properties (the<MessageProperties> element) can be added with the addMessageProperty or messageProperties methods:
Handling the response
Via sendMessageAndCheckForReceipt
This is the simplest approach — it internally sets a signal message consumer that captures the receipt and returns a structured result:Via signalMsgConsumer
For more control, register aIAS4SignalMessageConsumer and call sendMessage():
Raw HTTP response
To inspect the raw HTTP response bytes, provide aIAS4RawResponseConsumer:
Sending a pull request
UseAS4Sender.builderPullRequest() to initiate a pull (retrieve messages from a queue):
Pull request fields
| Field | Setter | Required | Description |
|---|---|---|---|
| Endpoint URL | endpointURL(String) | Yes | AS4 endpoint to pull from |
| MPC | mpc(String) | Yes | Message partition channel |
| PMode | pmode(IPMode) | Recommended | PMode governing the exchange |
| PMode leg | useLeg1(boolean) | No | Default: leg 1 |
| User msg consumer | userMsgConsumer(IAS4UserMessageConsumer) | No | Callback for the pulled message |
| Signal msg consumer | signalMsgConsumer(IAS4SignalMessageConsumer) | No | Callback for signal messages |
Interrupting the send
ImplementIAS4SenderInterrupt to implement a circuit-breaker that prevents sending after all validation checks have passed but before the HTTP call is made: