---
schema_version: "1"
id: a7036067ae5cee34edd6bbd98e0bc3fd6f6a7521f59a340aba39e2d8fc98ab2e
title: Receiving AS2 Messages and Sending Back MDNs
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/as2-connector/6.9/as2-connector-example-receive-send.md
canonical_url: https://docs.mulesoft.com/as2-connector/6.9/as2-connector-example-receive-send
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 94e0e420a77c165e9472da7321c04df8cdcd29986f84fe44321e9ac45d7ccdbe
description: MuleSoft Documentation Site
release: "6.9"
latest: false
---
---
product: AS2 Connector
version: 6.9
---

# Receiving AS2 Messages and Sending Back MDNs

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

These examples show how to use Anypoint Connector for AS2 (AS2 Connector) to receive AS2 messages
from a trading partner and send MDNs (Message Disposition Notifications) to that partner in
response:

- [Receiving AS2 Messages](#receiving-messages)

  Receive AS2 messages from your partner and, for every received message, log a message that
  contains the message payload to the Studio console.

- [Sending Synchronous AS2 MDNs](#synchronous-mdns)

  Send a synchronous AS2 MDN in response to each received AS2 message.

- [Sending Asynchronous AS2 MDNs](#asynchronous-mdns)

  Send an asynchronous AS2 MDN in response to each received AS2 message.

## Receiving AS2 Messages

Creating this example involves creating a new Mule project and configuring the **As 2 Listener**
source and **Logger** component.

The following screenshot shows the Anypoint Studio app flow for this example:

![Receive AS2 Messages App Flow](/mulesoft/current/en-us/as2-connector/6.9/_images/as2-connector-example-listener-flow.png)

### Create a Flow to Receive the Message

Configure the **AS 2 Listener** source to initiate a Mule flow when a call is made to the
`/as2-receive` path on local host port `8081`:

1.  In Anypoint Studio, create a new Mule project.

2.  In the **Mule Palette** view, select the **As 2 listener** source and drag it to the canvas.

3.  On the **As 2 listener** properties screen, optionally change the value of the **Display Name**
    field.

4.  Set the **Path** field to `/as2-receive`.

5.  Click the plus sign (**+**) next to the **Connector configuration** field to configure a global
    element that can be used by all instances of the **As 2 listener** source in the app.

6.  On the **General** tab, click the plus sign (**+**) next to the **HTTP Listener** field.

7.  Accept the defaults and click **OK**.

8.  On the **General** tab, configure the keystore that contains the certificates and keys:

    <table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p>Keystore Password</p></td><td><p><code>test</code></p></td></tr><tr><td><p>Keystore Path</p></td><td><p><code>as2/partnera.p12</code></p></td></tr><tr><td><p>Private Key Password</p></td><td><p><code>test</code></p></td></tr></tbody></table>

9.  On the **Partners** tab, specify the self and partner credentials.

    For the self credentials, configure these fields:

    <table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p>AS2 Partner Name</p></td><td><p><code>partnera</code></p></td></tr><tr><td><p>x509 Alias</p></td><td><p><code>partnera</code></p></td></tr><tr><td><p>email</p></td><td><p><code>support@partnera.com</code></p></td></tr></tbody></table>

    For the partner credentials, configure these fields:

    <table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p>AS2 Partner Name</p></td><td><p><code>partnerb</code></p></td></tr><tr><td><p>x509 Alias</p></td><td><p><code>partnerb</code></p></td></tr><tr><td><p>email</p></td><td><p><code>support@partnerb.com</code></p></td></tr></tbody></table>

### Add the Logger Component

Add the **Logger** component to the flow and configure it to log a message that includes the payload
of the received message:

1.  From the **Mule Palette** view, select **Core** and drag the **Logger** component next to **As 2
    listener**.

2.  In the Logger properties screen, set the **Message** field to `Message Received: #[payload]`.

### Save and Test the Mule App

1.  Save the project.

2.  Run the app by clicking the project name in **Package Explorer** and then clicking **Run** >
    **Run As** > **Mule Application**.

    If the application starts correctly, the console displays this message:

    `Mule is up and kicking`

3.  Test the app by opening `http://localhost:8081/as2-receive` from a browser or an app like
    Postman and adding the required credentials.

    For each new request, the Studio console displays the received message. For example:

```console
INFO  2022-09-09 17:15:46,409 [[MuleRuntime].uber.06: [as2-basic-example].AS2Listener.CPU_LITE @1369de96] [processor:
AS2Listener/processors/0; event: 30609f70-307c-11ed-8f5a-38f9d3713331] org.mule.runtime.core.internal.processor.
LoggerMessageProcessor: Message Received: Test Message
```

### XML for the Receiving AS2 Messages Example

Paste this code into your Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:as2-mule4="http://www.mulesoft.org/schema/mule/as2-mule4" xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/as2-mule4 http://www.mulesoft.org/schema/mule/as2-mule4/current/mule-as2-mule4.xsd">
	<http:listener-config name="HTTP_Server_Config" doc:name="HTTP Listener config" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<as2-mule4:listener-config name="AS2_Server_Listener" doc:name="AS2 Connector Listener config" httpListenerConfig="HTTP_Server_Config" securityLevel="SIGNED_ENCRYPTED">
		<as2-mule4:self-config as2Name="partnera" x509Alias="partnera" email="support@partnera.com"/>
		<as2-mule4:partner-config as2Name="partnerb" x509Alias="partnerb" email="support@partnerb.com" />
		<as2-mule4:key-store-config keystorePassword="test" keystorePath="as2/partnera.p12" privateKeyPassword="test" />
	</as2-mule4:listener-config>
	<flow name="AS2Listener" >
		<as2-mule4:as2-listener doc:name="As 2 listener" config-ref="AS2_Server_Listener" path="/as2-receive"/>
		<logger level="INFO" doc:name="Message Received!" message="Message Received: #[payload]"/>
	</flow>
</mule>
```

## Sending Synchronous AS2 MDNs

When your trading partner uses an AS2 listener, like in the
[Receiving AS2 Messages](#receiving-messages-example) example, the listener’s MDN mode controls when
a synchronous MDN is returned. The AS2 listener supports these configurations for managing
synchronous MDN delivery timing:

- **Immediate**

  The listener returns the MDN as soon as the incoming message is parsed and validated. The
  receiver’s business flow continues as a separate process after the MDN is sent. This is the
  default MDN Mode.

- **Auto**

  The listener returns the MDN only after its internal business flow completes. This ensures that if
  the flow fails, a negative MDN is returned to the sender to signal a processing error.

  For this configuration, set the MDN mode to `AUTO` on the AS2 listener.

<as2-mule4:as2-listener doc:name="As 2 listener" config-ref="AS2\_Server\_Listener"
path="/as2-receive" mdnMode="AUTO"/>

## Sending Asynchronous AS2 MDNs

The AS2 listener validates the presence of the `Disposition-Notification-To` and
`Receipt-Delivery-Option` headers when receiving an asynchronous MDN request. The listener
immediately returns an `HTTP 200 OK` to acknowledge the inbound message. The listener uses the URL
in the `Receipt-Delivery-Option` header to return the MDN via a new HTTP connection.

The AS2 listener supports these configurations for managing asynchronous MDN delivery timing:

- **Immediate**

  The listener posts the MDN to the `Receipt-Delivery-Option` URL as soon as the inbound message is
  parsed and validated. This is the default MDN Mode.

- **Auto**

  The listener posts the MDN to the `Receipt-Delivery-Option` URL only after its business flow
  completes, allowing a negative MDN to be sent if the flow fails.

  For this configuration, set the MDN mode to `AUTO` on the AS2 listener.

<as2-mule4:as2-listener doc:name="As 2 listener" config-ref="AS2\_Server\_Listener"
path="/as2-receive" mdnMode="AUTO"/>

## See Also

- [AS2 Connector Examples](https://docs.mulesoft.com/as2-connector/6.9/as2-connector-examples)

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [Salesforce Help](https://help.salesforce.com)
