cancel
Showing results for 
Search instead for 
Did you mean: 

PI 7.0 -- Not getting the attachment after using adapter module SetAttachmentName

Former Member
0 Kudos


In order to dynamically name the attachment in the mail receiver adapter, I deployed the module SetAttachmentName (as shown in wiki Adapter Module PI 7.0 Set Attachment Name - Process Integration - SCN Wiki) into my PI and used it in the my mail receiver comm channel before the mail module. But now when I test it, the whole attachment is coming inside the body of the email and not as an attachment. I have checked in scn blogs but did not find any relevant material for my issue. Did anybody face such an issue while using this custom module?

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Syed

You can try Java map also for setting the attachment name dynamically. Make sure that you need to check the option 'Keep Attachment' in the mail adapter

Java map Code:

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

import java.io.*;

public class JavaMapWithoutMailPackage extends AbstractTransformation

{

 

    public void transform(TransformationInput arg0, TransformationOutput arg1)

        throws StreamTransformationException

    {

        try

        {

            DynamicConfiguration conf = arg0.getDynamicConfiguration();

            DynamicConfigurationKey dynKey = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");

            String filename = conf.get(dynKey);

            String ContentType = "text";

            String CharSet = "UTF-8";

            String CompositeContentType = (new StringBuilder()).append(ContentType).append(";charset=\"").append(CharSet).append("\";filename=\"").append(filename).append("\"").toString();

            arg1.getOutputHeader().setContentType(CompositeContentType);

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(arg0.getInputPayload().getInputStream()));

            StringBuffer sb = new StringBuffer();

            String separator = System.getProperty("line.separator");

            String line;

            while((line = bufferedReader.readLine()) != null)

            {

                sb.append(line);

                sb.append(separator);

            }

            String srcdoc = sb.toString();

            arg1.getOutputPayload().getOutputStream().write(srcdoc.getBytes("UTF-8"));

        }

        catch(Exception e)

        {

            e.printStackTrace();

        }

    }

}

Former Member
0 Kudos

Hi Indrajit,

The java map code you have given will work only from PI 7.1 onwards and not on my PI7.0.

regards,

Syed

Former Member
0 Kudos

Hi Syed

You can change the code as per PI 7.0. Only the method name and argument types are gonna be changed.

The main logic will be same and can be used.

Former Member
0 Kudos

Hi Indrajit,

In PI7.0 there are no similar methods as getOutputHeader, getInputPayload .. etc.

Please see this wiki XI libraries for development - Process Integration - SCN Wiki.

regards,

Syed

Former Member
0 Kudos

Hi Syed

Then try this approach.

Use the mail package and in the message mapping write an UDF and map it to the field 'Content_Type'.

Inside the UDF read the file name and populate the content type in the below format

String ContentType = "text";

            String CharSet = "UTF-8";

            String CompositeContentType = (new StringBuilder()).append(ContentType).append(";charset=\"").append(CharSet).append("\";filename=\"").append(filename).append("\"").toString();

return CompositeContentType;

This will work for sure.

Former Member
0 Kudos

Hi Indrajit,

Thanks for your replies.

But the problem is the payload is in xml format(which should go on as attachment) and I will not be able to map it to the content field of the mail package.

regards,

Syed

Former Member
0 Kudos

Hi Syed

Please use mail package and use a simple java map to populate the output.Below are the sample codes for the same

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

import java.io.*;

public class JavaMapforAttachmentName extends AbstractTransformation

{

   

    public void transform(TransformationInput arg0, TransformationOutput arg1)

        throws StreamTransformationException

    {

        try

        {

            DynamicConfiguration conf = arg0.getDynamicConfiguration();

            DynamicConfigurationKey dynKey = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");

            String filename = conf.get(dynKey);

            String ContentType = "text";

            String CharSet = "UTF-8";

            String CompositeContentType = (new StringBuilder()).append(ContentType).append(";charset=\"").append(CharSet).append("\";filename=\"").append(filename).append("\"").toString();

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(arg0.getInputPayload().getInputStream()));

            StringBuffer sb = new StringBuffer();

            String line;

            while((line = bufferedReader.readLine()) != null)

            {

                sb.append((new StringBuilder()).append(line).append("\n").toString());

            }

            String srcdoc = sb.toString();

            String trgdoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

            trgdoc = (new StringBuilder()).append(trgdoc).append("<ns1:Mail xmlns:ns1=\"http://sap.com/xi/XI/Mail/30\">").toString();

            trgdoc = (new StringBuilder()).append(trgdoc).append("<Subject>Test of Mail adapter</Subject>").toString();

            trgdoc = (new StringBuilder()).append(trgdoc).append("<From>test@gmail.com</From><To>test@test.com</To>").toString();

            trgdoc = (new StringBuilder()).append(trgdoc).append("<Content_Type>").append(CompositeContentType).append("</Content_Type><Content>").append(srcdoc).append("</Content></ns1:Mail>").toString();

            arg1.getOutputPayload().getOutputStream().write(trgdoc.getBytes("UTF-8"));

        }

        catch(Exception e)

        {

            e.printStackTrace();

        }

    }

}

Former Member
0 Kudos

Hello Syed,

I had tried this long back but the scenario failed since my payload was PDF that failed in Adapter, But yours is XML.

I didnt use the Mail Package. But you can try below steps.

Can you try to name Subject Field as same as Dynamic Name(using Java Mapping), You might have to uncheck the Keep attachments tab and also you Need to use PayloadSwapBean to swap payload as attachment.


Regards,

Hiren Asher

Former Member
0 Kudos

Hello,

I believe u have ticked "Keep Attachments" option in ur receiver mail adapter?BTW, u are using mail package?

In addition to that, i think there are other simple ways of setting dynamic attachment name instead of writing AM and one of them is:

http://wiki.scn.sap.com/wiki/pages/viewpage.action?title=Dynamic+Email+Attachment+name+for+Received+...

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

The keep attachments is ticked. I tried all the steps in that wiki but maybe because of my PI 7.0 version it did not work.

regards,

Syed

Former Member
0 Kudos

Hello Syed,

I don't have PI7.0, so not sure abt the steps in PI7.0. But i was looking below wiki and here the author is using mail package to accomplish very similar kind of requirement.

Dynamic Email Attachment name for Received Mails - Process Integration - SCN Wiki

Now coming to passing input XML inside content, may be u can think of using XSLT mapping  and pass entire input XML data as XML string inside content field and then check the output?

Thanks

Amit Sriavstava

gagandeep_batra
Active Contributor
0 Kudos

Hi Syed,

But now when I test it, the whole attachment is coming inside the body of the email and not as an attachment.

means Before this module your Scenario is working without right name?

did you check this blog also?

Regards

GB

Former Member
0 Kudos

Hi Gagandeep,

Yes, before this module my scenario was working without the correct name which should be set dynamically. I cannot use the mail package because of difficulty in populating the "content" with my required xml payload inside the attachment.

Regards,

Syed.