Discuss this help topic in SecureBlackbox Forum

EDI: Receive an AS2/AS3 message

AS2 messages are transferred using HTTP or HTTPS protocol and are usually received by the HTTP(S) server. AS3 messages are transferred using FTP or FTPS protocol and are usually received by the FTP(S) server.

You can build your own HTTP(S) or FTP(S) server using the classes provided by SecureBlackbox, such as TElHTTPSServer and TElSimpleFTPSServer.

It is much more common, however, to add a request handler to the existing HTTPS or FTPS server, which will receive messages and handle them. To let you receive messages (as well as asynchronous receipts) the HTTP server must give you the ability to access all fields of the HTTP Request (either as a raw data or as named collections or in any other way).

Composing a message or receipt

If the server gives you access to headers as a raw byte array (or a stream of bytes), you need to

  1. save the headers to the stream;
  2. if the saved data doesn't end with CRLF CRLF, then the missing bytes must be appended;
  3. save the body of the request to the same stream;
  4. reset stream position to 0
Once you have the complete stream, you can process the incoming message.

If the server gives you access to headers as a named collection, you need to

  1. save the collection to the stream in the form where each header is written as "Name: Value<CR><LF>";
  2. append one more CRLF to the stream;
  3. save the body of the request to the same stream;
  4. reset stream position to 0
Once you have the complete stream, you can process the incoming message.

Checking if it's a message or a receipt

The best is to have separate URIs / handlers for messages and receipts. If you for whatever reason need to distinguish between messages and receipts, you can follow the next heuristic procedure:

  1. Inspect Content-Type header of the received information:
    • "multipart/report" content type indicates the regular unsigned receipt
    • "multipart/signed" content type can indicate either the signed message or the signed receipt
    • "application/pkcs7-mime" content type indicates encrypted and/or compressed message
    • any other content type is presumably about the regular unsigned message
  2. If the content type is "multipart/signed", try loading it into TElAS2Receipt. If the data is not a receipt, the EElASMessageError exception will be thrown with the error code set to SB_AS_ERROR_INVALID_CONTENT_TYPE . If you get an exception, try loading the data to TElAS2Message instance.

How To articles about AS2 and AS3 messages

Discuss this help topic in SecureBlackbox Forum