Skip to main content
Package: com.helger.phase4.peppol
Maven artifact: com.helger.phase4:phase4-peppol-client
Phase4PeppolSender is the entry point for sending AS4 messages over the Peppol network. It handles Standard Business Document Header (SBDH) creation, payload compression, SMP endpoint lookup, and certificate validation automatically.

Factory methods

// Builder that creates the SBDH automatically from payload element
Phase4PeppolSender.PeppolUserMessageBuilder builder = Phase4PeppolSender.builder();

// Builder when you already have a serialized Standard Business Document
Phase4PeppolSender.PeppolUserMessageSBDHBuilder sbdhBuilder = Phase4PeppolSender.sbdhBuilder();

createSBDH (static utility)

StandardBusinessDocument sbd = Phase4PeppolSender.createSBDH(
    IParticipantIdentifier aSenderID,
    IParticipantIdentifier aReceiverID,
    IDocumentTypeIdentifier aDocTypeID,
    IProcessIdentifier aProcID,
    String sCountryC1,          // nullable
    String sInstanceIdentifier, // nullable - random UUID if omitted
    String sStandard,           // nullable - derived from payload namespace
    String sTypeVersion,        // nullable - derived from doctype ID
    String sType,               // nullable - derived from payload local name
    Element aPayloadElement     // required
);
Since 3.1.0.

PeppolUserMessageBuilder (builder)

Required fields

body.senderParticipantID
IParticipantIdentifier
required
Peppol participant ID of the C1 (sender). Sets the SBDH sender and originalSender user message property.
body.receiverParticipantID
IParticipantIdentifier
required
Peppol participant ID of the C4 (receiver). Sets the SBDH receiver and finalRecipient user message property.
body.documentTypeID
IDocumentTypeIdentifier
required
Peppol document type identifier. Automatically sets the action field.
body.processID
IProcessIdentifier
required
Peppol process identifier. Automatically sets the service field.
body.senderPartyID
String
required
The CN part of the Peppol AP certificate (e.g. POP000123). Must match the certificate used for signing.
body.payload
AS4OutgoingAttachment
required
The payload to send. Use AS4OutgoingAttachment.Builder to construct.
body.endpointDetailProvider
IAS4EndpointDetailProvider
required
Endpoint discovery provider. Use smpClient() for SMP-based lookup or receiverEndpointDetails() for static configuration.

Identity and routing

builder
    .senderParticipantID(IF.createParticipantIdentifierWithDefaultScheme("0088:5790000436057"))
    .receiverParticipantID(IF.createParticipantIdentifierWithDefaultScheme("0088:5790000435999"))
    .documentTypeID(IF.createDocumentTypeIdentifierWithDefaultScheme(
        "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##..."))
    .processID(IF.createProcessIdentifierWithDefaultScheme(
        "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"))
    .senderPartyID("POP000123");

Endpoint discovery

body.smpClient
SMPClientReadOnly
SMP client instance used to perform Peppol SMP lookups. Internally creates an AS4EndpointDetailProviderPeppol.
body.receiverEndpointDetails(X509Certificate, String)
void
Set endpoint statically without SMP lookup. Use for testing or pre-resolved endpoints.
body.receiverEndpointDetails(EndpointType)
void
Set endpoint from an already-resolved Peppol EndpointType SMP response. Since 2.7.6.

Payload options

body.payloadMimeType
IMimeType
default:"application/xml"
MIME type of the payload. Rarely needs to be changed.
body.compressPayload
boolean
default:"true"
Whether to apply AS4 GZip compression to the payload.
body.payloadContentID
String
Custom Content-ID for the payload MIME part. Random by default. Since 1.3.1.
body.countryC1
String
Country code of C1 per Peppol Business Message Envelope 2.0. Optional. Since 2.1.3.

Certificate validation

body.checkReceiverAPCertificate
boolean
default:"true"
Whether to validate the receiver AP certificate against the Peppol CA. Since 1.3.10.
body.peppolAP_CAChecker
TrustedCAChecker
Override the Peppol CA checker used for receiver certificate validation. Since 3.0.0.
body.certificateConsumer
IPhase4PeppolCertificateCheckResultHandler
Optional callback receiving the AP certificate and the validation result.

Callbacks

body.endpointURLConsumer
Consumer<String>
Optional callback receiving the resolved AP endpoint URL. Since 1.3.3.
body.technicalContactConsumer
Consumer<String>
Optional callback receiving the technical contact from the SMP response. Since 3.2.0.

Sending

EAS4UserMessageSendResult result = builder.sendMessageAndCheckForReceipt();

Complete example

import com.helger.phase4.peppol.Phase4PeppolSender;
import com.helger.phase4.sender.EAS4UserMessageSendResult;
import com.helger.phase4.attachment.AS4OutgoingAttachment;
import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration;
import com.helger.peppolid.factory.PeppolIdentifierFactory;
import com.helger.smpclient.peppol.SMPClientReadOnly;
import com.helger.smpclient.url.PeppolNaptrURLProvider;
import com.helger.mime.CMimeType;

final PeppolIdentifierFactory IF = Phase4PeppolSender.IF;

// SMP client pointing to Peppol SMP
SMPClientReadOnly smpClient = new SMPClientReadOnly(
    Phase4PeppolSender.URL_PROVIDER,
    IF.createParticipantIdentifierWithDefaultScheme("0088:5790000435999"),
    ESML.DIGIT_PRODUCTION
);

// Load crypto factory from application.properties
AS4CryptoFactoryConfiguration cryptoFactory =
    AS4CryptoFactoryConfiguration.getDefaultInstance();

EAS4UserMessageSendResult result = Phase4PeppolSender.builder()
    .cryptoFactorySign(cryptoFactory)
    .cryptoFactoryCrypt(cryptoFactory)
    .senderParticipantID(IF.createParticipantIdentifierWithDefaultScheme("0088:5790000436057"))
    .receiverParticipantID(IF.createParticipantIdentifierWithDefaultScheme("0088:5790000435999"))
    .documentTypeID(IF.createDocumentTypeIdentifierWithDefaultScheme(
        "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1"))
    .processID(IF.createProcessIdentifierWithDefaultScheme(
        "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"))
    .senderPartyID("POP000123")
    .countryC1("AT")
    .smpClient(smpClient)
    .payload(
        AS4OutgoingAttachment.builder()
            .data(invoiceXmlBytes)
            .mimeType(CMimeType.APPLICATION_XML)
            .build()
    )
    .sendMessageAndCheckForReceipt(ex -> LOGGER.error("Peppol send failed", ex));

if (result.isSuccess()) {
    System.out.println("Invoice sent via Peppol");
}

Build docs developers (and LLMs) love