AS4
Purpose¶
AS4 Messaging Support
This DSL is based on the open source library Phase4: https://github.com/phax/phase4
Warning
p6core 6.9.0 and above uses Java 17 internally. This has a know security constraint/issue: https://github.com/phax/phase4/wiki/Known-Limitations To work around this constraint requires the creation of the file $P6_DATA/conf/security/java.security (see examples)
Warning
For p6core 6.10.X and above, this dsl requires a sidecar, ran using docker. Please speak to R&D/devops to have this enabled on your instance. Initially, old methods will be deprecated and then deleted.
Methods¶
Binding name: p6.as4
Security recommandations
Since 6.9.0
Recommended java.security file for p6core
jdk.xml.dsig.secureValidationPolicy=\
disallowAlg http://www.w3.org/TR/1999/REC-xslt-19991116,\
disallowAlg http://www.w3.org/2001/04/xmldsig-more#rsa-md5,\
disallowAlg http://www.w3.org/2001/04/xmldsig-more#hmac-md5,\
disallowAlg http://www.w3.org/2001/04/xmldsig-more#md5,\
disallowAlg http://www.w3.org/2000/09/xmldsig#dsa-sha1,\
disallowAlg http://www.w3.org/2007/05/xmldsig-more#sha1-rsa-MGF1,\
disallowAlg http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1,\
maxTransforms 5,\
maxReferences 30,\
disallowReferenceUriSchemes file http https,\
minKeySize RSA 1024,\
minKeySize DSA 1024,\
minKeySize EC 224,\
noDuplicateIds,\
noRetrievalMethodLoops
Logging, Debug & Testing
The configuration properties global.production
and global.debug
are used to switch between Test and Production certificate usage and control the generation of DEBUG logs
In Addition, the following line should be added to the log4j.properties file to enable DEBUG logging from the Phase4 library:
logger.phase4.name=com.helger.phase4
logger.phase4.level=debug
receive¶
Receive an AS4 Message.
Proxies to the below method, with the default profile of Peppol.
Syntax
Tuple4<Integer, byte[], Map<String, String>, Path> receive(
final Map<String, String> headers,
final byte[] ba,
final Closure<Void> messageReceipt) throws P6Exception;
receive¶
Receive an AS4 Message.
Parameters:
- The Phase4Profile enum is used to configure which profile is used.
- A map of MIME headers to be used in the request.
- The message to send, as a byte array.
- An optional callback method to use after processing.
Syntax
Tuple4<Integer, byte[], Map<String, String>, Path> receive(
final Phase4Profiles profile,
final Map<String, String> headers,
final byte[] ba,
final Closure<Void> messageReceipt) throws P6Exception;
Currently only the PEPPOL profile is supported, please contact the R&D team if you require new profiles.
This method takes an optional callback method, as the last parameter messageReceipt
, to use during the receipt processing:
- 2 parameters are passed to this:
filePath
Path of received message.messageId
: Unique id of the received message.
Returns a Tuple4 containing: - The HTTP response code. - The response body. - A map of headers returned in the response. - The path of the file.
Example
Receive HTTP POSTed AS4 Message and Generate Receipt
final Tuple4<Integer, byte[], Map<String, String>, Path> res = as4.receive(
AS4.Phase4Profiles.PEPPOL,
p6.pipeline.toStringMap(),
p6.pipeline.getBytes('body'),
{sbdPath, messageId -> p6.log.debug "Recieved AS4 message. Path: ${sbdPath}, ID: ${messageId}"}
)
// --- Build the Http POST response into the pipeline ---
// Response code
p6.pipeline.put('CamelHttpResponseCode', res.getFirst())
// The response or error-message body
p6.pipeline.put('body', res.getSecond())
// Additional headers - prefixed with 'p6rest.' to ensure they are part of the final HTTP response
res.getThird().forEach { (key, val) ->
p6.pipeline.put( 'p6rest.' + key, val )
}
// The SBD file path
p6.pipeline.put('FilePath', res.getFourth())
send¶
Since 6.10.7
Send an AS4 Message.
Syntax
boolean send(final SendMessageDTO sendMessageDTO)
This method returns a boolean: true = successfully sent, false = error sending message.
A builder for the SendMessageDTO object is provided:
- environment: The environment where the request is sent. Values: PROD|STAGING|DEV
- profile: The trading network. Currently only PEPPOL profile is implemented. Values: PEPPOL
- secureContext: The context which the request is sent using.
- message: objects that contains all necessaries elements, here an example for PEPPOL profile
- documentTypeId: Document Type ID from Peppol Code Lists
- processId: Process ID from Peppol Code Lists
- senderParticipantId: Sender ID registered in Peppol Directory
- receiverParticipantId: Receiver ID registered in Peppol Directory
- senderPartyId: Sidetrade Peppol ID
- payloadURI: URI of the
- countryCode: Country Code ISO2
Example
def message = p6.as4.getSendMessageDTOMessage().with {
countryCode 'GB'
processId '1'
senderParticipantId '2'
}
def secureContext = p6.secureSocket.contextBuilder().with {
identityKeyPassword 'password123'
strict true
}
def sendMessage = p6.as4.getSendMessageDTO().with {
environment 'PROD'
message message
secureContext secureContext
}