During the journey of SAP Cloud Integrations, there was a requirement that we have to trigger emails for every failure of message/transaction respective to Integration flows occurring in the SAP Cloud Integration tenant. This is not just it. The recipient email addresses can be different as per the owner of Integration flows.
To cater to the solution, I have designed the integration flow and thought of sharing it as a blog post.
For an instance, we have an integration flow that is responsible to transmit the file from one SFTP location to another. Whenever there is any failure for this flow during file transmission, the exception sub-process should capture the exception message and send it to the owner of the flow to enable him to take further necessary actions.
Below is the integration flow snapshot of the Integration flow:
Steps performed for Exception Subprocess in Integration flow:
Exception Subprocess has a Content Modifier that captures the message headers and prepares an XML Message body and posts the same using ProcessDirect adapter to Exception Integration Main flow designed for posting the emails to integration flow respective owners.
Exception Subprocess:-
Content Modifier (named as Send Exception Details):
Message Header:
Expression – stacktrace: ${exception.stacktrace}
Constant – InterfaceID: IFLOW_01 (you can set this as anything unique name to use it as I-flow specific Id)
Message Body:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<InterfaceId>${header.InterfaceID}</InterfaceId>
<Exception_Details>
<Date>${date:now:MM-dd-yyyy}</Date>
<Time>${date:now:hh:mm:ss}</Time>
<Message_ID>${property.SAP_MessageProcessingLogID}</Message_ID>
<IFlow_Name>${camelId}</IFlow_Name>
<Exception_Message>${exception.message}</Exception_Message>
</Exception_Details>
</root>
Process Direct Adapter:
Main Exception Handling Flow:
Using the ProcessDirect adapter at the sender end and keeping the same endpoint, the exception message is received in Exception Handling Main Flow.
Sender side Process Direct Snapshot below:
Content Modifier (named as Get Header/Properties):
Message Header:
Exchange Property:
Groovy Script (named as Call Value Map):
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import com.sap.it.api.ITApiFactory;
import com.sap.it.api.mapping.ValueMappingApi;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.*
import java.lang.*;
import java.util.*;
def Message processData(Message message)
{
def body = message.getBody(java.lang.String) as String;
def map = message.getHeaders();
def InterfaceName = map.get("InterfaceId") as String;
def obj = ITApiFactory.getApi(ValueMappingApi.class, null);
def mappedValue = obj.getMappedValue("InterfaceDetails", "InterfaceName", InterfaceName, "InterfaceDetails", "RecipientName");
if (mappedValue == null)
{ throw new IllegalStateException("No valuemapping maintained for Interface: "+InterfaceName);
}
message.setProperty("RecipientName", mappedValue);
return message;
}
Mail Adapter Configuration:
In the Connection tab, the connectivity details are maintained. In the Processing tab of the mail adapter, below is the snapshot of the configuration done:
Mail Body:
Hi Team Members
</br>
</br>
This email is to notify you that an interface has failed in the middleware SAP Cloud Integration.</br>
Here are the details about the interface, and the exception caught which would help you analyze this issue further:</br>
</br>
<table style="width:50%">
<tr>
<td style="background-color:#5B8AB6;color:white">
<b>Date</b>
</td>
<td>${property.Date}</td>
</tr>
<tr>
<td style="background-color:#5B8AB6;color:white">
<b>Time</b>
</td>
<td>${property.Time}</td>
</tr>
<tr>
<td style="background-color:#5B8AB6;color:white">
<b>Message ID</b>
</td>
<td>${property.Message_ID}</td>
</tr>
<tr>
<td style="background-color:#5B8AB6;color:white">
<b>Integration Flow Name</b>
</td>
<td>${property.IFlow_Name}</td>
</tr> <tr>
<td style="background-color:#5B8AB6;color:white">
<b>Exception Message</b>
</td>
<td>${property.Exception_Message}</td>
</tr>
</table>
</br>
</br>
<i>This is an auto-generated email from the middleware (SAP Cloud Integration). Please do not reply to this email.</i>
</br>
The above Groovy is calling the Value Mapping maintained as per the InterfaceID that we had set in the above steps as Constant in Exception Subprocess Content Modifier to maintain a unique Iflow-specific ID which would enable sending the email as per Iflow respective owners.
Value Map Snapshot:
In the value map, we can add more entries and correspond to them, we can assign the desired email IDs (separated with commas) to which email should be sent for that specific iFlow failure.
This is how we can handle the exceptions for the iFlows and send email notifications to desired emails.
Hope this blog post would add value to SAP Cloud Integration Community.