cancel
Showing results for 
Search instead for 
Did you mean: 

Empty file: Send email alert

Former Member
0 Kudos

Hi,

I want to send out an email in case if an empty file is received from the source system.

I have already explored the following options:

1. Check filesize in Receiver determination and route it to a Mail receiver : This would not work as in case of empty file ...no PI message would  be created.

2. UDF would not work too for the reason cited above

Could you please share your experience of handling such a requirement ? I think EJB module is the only solution....please share the code if you have handled this.

Thanks..

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks everyone for your response.

I solved the issue by creating a receiver for Mail business component in case of empty file (Receiever Determination --> Filesize = 0)......used dummy mapping and interface in IM......and did not use Mail package in Receiver mail adapter....

This helped.

Former Member
0 Kudos

Hi Arijit,

Empty file: Send email alert

I have same requirement please guide me how to achieve this email alert.

mateen_popatia
Participant
0 Kudos

Hi Arijit,

Just a hint. Maybe create 2 mappings as follows:

:

1) From your source to target structure (File to File)

2) From your source to mail structure ( File To Mail)

And then use BPM - SWITCH step for conditional routing.

I have not tried it, but I guess you can try and see.

Regards,

Mateen

Former Member
0 Kudos

Hi Mateen,

This approach would not work as there is no payload in case of empty file so the message would fail in message mapping step with the error :

Runtime exception occurred during application mapping com/sap/xi/tf/_MM_SF_EmployeeData_To_HMS_ReceiveM~; com.sap.aii.utilxi.misc.api.BaseRuntimeException:Premature end of file.</SAP:Stack>

  <SAP:Retry>M</SAP:Retry>

mateen_popatia
Participant
0 Kudos

Hi Arijit,

Put a condition in the SWITCH step (maybe based on a key field) such that the mapping "MM_SF_EmployeeData_To_HMS_Receive" would execute if the payload is not empty and the other mapping (create a mapping to the Mail package structure and use default values in the mapping) would execute if the payload is empty.

Regards,

Mateen

vkaushik82
Active Participant
0 Kudos

Adapter module can be a good option but one more option if u r comfortable with scripts/command line

Run a Batch script before message pick in channel.

In Script check file size if empty put a string "Empty". Now you can use Graphical mapping and route it to mail adapter.

Former Member
0 Kudos

Batch script would be a very discrete design and add another overhead in the overall design.

Your second option would not work as

there is no payload in case of empty file so the message would fail in message mapping step with the error :

Runtime exception occurred during application mapping com/sap/xi/tf/_MM_SF_EmployeeData_To_HMS_ReceiveM~; com.sap.aii.utilxi.misc.api.BaseRuntimeException:Premature end of file.</SAP:Stack>

  <SAP:Retry>M</SAP:Retry>

iaki_vila
Active Contributor
0 Kudos

Hi Arjit,

You can check file size + send email at mapping level.

For example:

1. To check the file this wiki can be helpful File Lookup in UDF - Process Integration - SCN Wiki. Of course, you will need some changes

2. To send an email without mail adapter: Mail without email adapter? Part - I - Process Integration - SCN Wiki

Regards.

Former Member
0 Kudos

Inaki,

As i have said, if the input is empty file then there would not be any input payload and the message would fail with the following error message in message mapping step:

Runtime exception occurred during application mapping com/sap/xi/tf/_MM_SF_EmployeeData_To_HMS_ReceiveM~; com.sap.aii.utilxi.misc.api.BaseRuntimeException:Premature end of file.</SAP:Stack>

  <SAP:Retry>M</SAP:Retry>

Ryan-Crosby
Active Contributor
0 Kudos

Hi Arijit,

You could use a java mapping to read the stream and generate a trigger message type in the event that the payload is empty and simply pass the stream otherwise.  In that way you could use the newly inserted information to determine if the message should pass on success or be sent to another process so that the email is triggered.

Regards,

Ryan Crosby

Former Member
0 Kudos

Hi Ryan,

Do you have a code, which I can reuse perhaps ?

Also, are you sure this would work despite of the fact that there is no payload ?

Ryan-Crosby
Active Contributor
0 Kudos

Hi Arijit,

Here is a sample of some code that you could use to insert a message using the java mapping:


// IO libraries

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.OutputStream;

// Stream transformation libraries

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

public class Test extends AbstractTransformation

{

    public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException

    {

      try   

      {

        // Read InputStream of input payload

        BufferedReader br = new BufferedReader(new InputStreamReader(in.getInputPayload().getInputStream()));

        OutputStream os = out.getOutputPayload().getOutputStream();

        StringBuilder sb = new StringBuilder();

        char[] chars = new char[4096];

        while(br.read(chars) != -1)

        {

          // append characters bytes to stringbuilder

          sb.append(chars);

        }

       

        // Check if any characters have been written

        if(sb.length() == 0)

        {

          sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");

          sb.append("<ns:MT_EMPTY xmlns:ns=\"http://namespace.com\">\r\n");

          sb.append("<isEmpty>true</isEmpty>");

          sb.append("</ns:MT_EMPTY>\r\n");

        }

       

        // Write to output stream

        os.write(sb.toString().getBytes());

        os.flush();

        os.close();

      }   

      catch (IOException e)   

      {   

        throw new StreamTransformationException("Unable to read payload", e); 

      }   

    }

}

You would just need to figure out how to handle and route the two message types but theoretically you should be able to achieve it with something like this...

Regards,

Ryan Crosby