Getting started with AS2 for MuleSoft

Requirements: /n software Connectors for MuleSoft

Introduction

The /n software Connectors for MuleSoft are pure java Connectors which integrate directly into AnyPoint Studio (and your Mule application). The /n software Connectors for MuleSoft extend the functionality of MuleSoft and provide robust enterprise-ready Internet connectivity, secure messaging, and file transfer.

Our AS2 Send module lets you transmit outgoing AS2 messages and our AS2 Receive module lets you process incoming AS2 messages. There are many different connectors currently supported: AS2 for EDI, FTPS, FTP, SFTP, SSH, Email adapters, etc. For details on installation and other connectors please see the Online Documentation.

This guide will walk through first-time configuration of AS2 Send and AS2 Receive. In most cases configuration is as simple as setting a few properties.

Contents

  1. AS2 Receive
  2. AS2 Send
  3. What is a Mule Event?

AS2 Receive Module

The AS2 Receive module supports processing incoming AS2 messages and incoming asynchronous MDN's. Together, the below properties make up the baseline settings necessary for processing AS2 messages.

Core Properties

PropertyDescription
Trading partnerThe identity of the AS2 sending entity.
Receiving partnerThe identity of the AS2 receiving entity. This will always be your identity.
Receive modeControls whether the connector is configured to process AS2 messages (and generate receipts if requested) or verify MDN receipts.
Encryption CertSets the private key to use when decrypting an incoming AS2 message.
Signer CertSets the public key to use when verifying the signature on the incoming message.
SSL Accept Server CertSets a server certificate to unconditionally accept during TLS negotiation. The easiest approach to trusting server certificates is to set the Accept Any field to True. This will implicitly trust the remote host and no further fields should be specified.

To set the fields of Cert properties, the dropbox should be set to Edit inline. The Store Type, Store, Store Password, and Subject fields together identify the certificate within a certificate store.

An example AS2 Receive certificate configuration

AS2 Receive Usage

The AS2 Receive module must use the Mule HTTP Listener as a relay because it does not contain a webserver of its own. In a typical scenario, a HTTP Listener will receive the request and send the response. The AS2 Receive module acts as the processing engine for incoming AS2 messages or asynchronous MDN's in a mule event.

There are three main steps to get up and running with AS2 Receive. First, drag an instance of the module from the Mule Palette into your project's Flow designer. This will automatically establish an AS2 Receive module in a flow.

An example AS2 Receive flow and configuration

Second, apply a configuration to the connector including the core and certificate properties mentioned in the previous section.

Third, specify HTTP Listener settings to relay the receipt back to the client. After AS4Web is finished processing, the body of the receipt can be found in the #[attributes.ResponseBody] field.

The HTTP Listener must be configured to relay the ResponseBody back to the client. In the Responses tab of the Mule properties page for the HTTP Listener, set the Body to #[attributes.ResponseBody]. Add a new header with the value 'Content-Type' and value attributes.ResponseHeaders.'Content-Type'. That is all that is required to relay a synchronous receipt back to the sender from AS2 Receive.

The default behavior of the connector is to return a receipt to the sender synchronously via the HTTP Listener. If the incoming AS2 message requests an asynchronous receipt, this is supported too. Please see Asynchronous Responses with AS2 Receive for more details.

Here is an example of HTTP Listener configuration to support sending a receipt:

An example HTTP Listener and configuration

Configuration XML:

Note: It is not necessary to specify a File Write connector behind AS2 Receive because the connector was designed to save the incoming files to the Incoming Directory automatically.

AS2 Send

The AS2 Send module supports transmitting outgoing AS2 messages. Together, the below properties make up the baseline settings necessary for sending an AS2 message.

Core Properties

PropertyDescription
AS2 FromThe sending party's AS2 Identifier. This will always be your identifier.
AS2 ToThe receiving party's AS2 Identifier.
URLYour trading partner's URL.
Recipient CertSets the public key to use when encrypting the outgoing AS2 message.
Signing CertSets the private key to use when signing the outgoing message..
SSL Accept Server CertSets a server certificate to unconditionally accept during TLS negotiation. The easiest approach to trusting server certificates is to set the Accept Any field to True. This will implicitly trust the remote host and no further fields should be specified.

To set the fields of Cert properties, the dropdown should be set to Edit inline. The Store Type, Store, Store Password, and Subject fields together identify the certificate within a certificate store.

An example AS2 Send certificate configuration

AS2 Send Usage

Begin by dragging an instance of the AS2 Send module into a Mule project. This will automatically establish an AS2 Send module in a flow. First, apply a configuration to the connector, including the core and certificate properties mentioned in the previous section.

An example AS2 Send and configuration

When the application starts, a source event will produce a Mule message. Later in the flow the message will be passed to the connector. The connector will take in the EDI Data from the payload of the incoming message and send it to the specified URL. In this case, a File Read connector was used to set the payload of the mule message to EDI Data. It is entirely up to you where the EDI Data comes from (it does not need to be stored on disk).

The EDI data in the payload is sent to the remote machine and the AS2 Send module waits for the receipt. Once the receipt is received, the output of the connector is a Mule message with additional fields in the #[attributes] collection. These fields can be used to examine the receipt and determine the verification status.

As a note, requesting an asynchronous MDN is supported. Learn more about setting the MDNTo property in our Online Documentation.

What is a Mule Event?

It might be helpful to have a bit of context for all this. Events contain the core information which passes from module to module. A mule event (or mule message) is produced by a source module and travels through the components in your app following the configured application logic.

An example AS2 Send flow

Each flow has a source component on the left which is responsible for generating the events, and the event flows to the right (to each operation in the chain). Certain source modules and operation modules can alter the flow of the event or the data inside it.

A mule event contains a Mule Message and a vars collection:

Mule Event ├── Mule Message | ├── attributes [] | ├── payload ├── vars []

At many times in this guide you will see notation like #[attributes.ResponseBody]. This syntax is the DataWeave language and the can be thought of a reference to data stored in the Mule Event. The syntax is particularly useful for logging or dynamically setting module settings.

We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team at kb@nsoftware.com.