cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

Hello Experts,

     My Scenario is IDoc to Mail. I need to send the file as an attachment with dynamic filename and body. I am able to send the the file with attachment and body but not with the dynamic filename. Also  I am not supposed to use Mail Package.So for the reason I have implemented Module code for changing the dynamic filename.Here is the code and error exception occurred in the Message Log.

Module Code:

package com.sap.mailmodule;

import javax.ejb.Stateless;

import com.sap.aii.af.lib.mp.module.ModuleContext;

import com.sap.aii.af.lib.mp.module.ModuleData;

import com.sap.aii.af.lib.mp.module.ModuleException;

import com.sap.engine.interfaces.messaging.api.Message;

import com.sap.engine.interfaces.messaging.api.MessageKey;

import com.sap.engine.interfaces.messaging.api.MessagePropertyKey;

import com.sap.engine.interfaces.messaging.api.Payload;

import com.sap.engine.interfaces.messaging.api.PublicAPIAccessFactory;

import com.sap.engine.interfaces.messaging.api.auditlog.AuditAccess;

import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;

/**

* Session Bean implementation class MailAdapterModule

*/

@Stateless

public class MailAdapterModule implements MailAdapterModuleRemote, MailAdapterModuleLocal

{

    public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)throws ModuleException

    {      

        Message msg = (Message) inputModuleData.getPrincipalData();

        MessageKey key = null;

        AuditAccess audit = null;

        String attName = null;

        String targetFileName = null;

       

        try

             {          

             //Custom Adapter module  : Module called

            //Reading file name from message header

            attName = moduleContext.getContextData("AttachmentName");

            Payload payload = msg.getAttachment(attName);                  

            MessagePropertyKey fileKey = new MessagePropertyKey("FileName","http://sap.com/xi/XI/System/Mail");

            targetFileName = fileKey.getPropertyName();

             audit = PublicAPIAccessFactory.getPublicAPIAccess().getAuditAccess();

            audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "Input file read successfully");

            //Reading the Directory Names from the Module Context           

            if(targetFileName == null)

            {

                targetFileName = "Reservation.txt";

            }

            audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, " Name of Attachment after msg.getattchment method: " + targetFileName);

            audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, " Name of Attachment after msg.getattchment method: " + targetFileName);

            payload.setName(targetFileName);

            audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"Attachment renamed successfully : " +targetFileName);

            audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, " Entering Mail Adapter");

             inputModuleData.setPrincipalData(msg);

    

            }

       

        catch (Exception e)

        {

            throw new ModuleException(e);

        }

     return inputModuleData;

    } 

}

Channel Module Configuration:

Message Exception Error ScreenShot:

Kindly help on the same.!!!

0 Likes
View Entire Topic
Former Member
0 Likes

Hi Everyone/ Hi Praveen,

     Initially i have provided the setting same as your post. But I am facing the msgkey error. So as a trial and error i just have given the above setting. Here are the below details of my communication channel setting, UDF used in mapping, and module code and error screen shot.

Communication Channel Setting:



Module Code:

try

             {          

             //Custom Adapter module  : Module called

            //Reading file name from message header

            attName = moduleContext.getContextData("AttachmentName");

            Payload payload = msg.getAttachment(attName);                  

            MessagePropertyKey fileKey = new MessagePropertyKey("FileName","http://sap.com/xi/XI/System/Mail");

            targetFileName = fileKey.getPropertyName();

           payload.setName(targetFileName);

}


UDF used in the mapping:

MappingTrace objTrace = container.getTrace();

DynamicConfiguration objDynConfig;

DynamicConfigurationKey objDCKey;

String Fname = FileName;

objTrace.addInfo(Fname);

final String NAMESPACE = "http://sap.com/xi/XI/System/Mail";

final String ATTRIBUTE1 = "THeaderTO";  //Recipients TO List

final String ATTRIBUTE2 = "THeaderSUBJECT"; // Subject of The Email

//final String ATTRIBUTE3 = "XHeaderName3"; //ContentDisposition

//final String ATTRIBUTE4 = "XHeaderName1";  //ContentType

//final String ATTRIBUTE5 = "XHeaderName2"; //ContentDescription

final String ATTRIBUTE6 = "THeaderCC";  //Recipients BCC List

try

{

objDynConfig = (DynamicConfiguration) container.getTransformationParameters().

get(StreamTransformationConstants.DYNAMIC_CONFIGURATION );

container.setParameter(StreamTransformationConstants.DYNAMIC_CONFIGURATION, objDynConfig);

objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE1);

objDynConfig.put(objDCKey, ZEmail);

objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE2);

objDynConfig.put(objDCKey, Subject);

objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE6);

objDynConfig.put(objDCKey, ZEmailCC);

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

conf.put(key,FileName);

}

catch (Exception objException)

{

objTrace.addWarning(objException.getMessage());

}

return "";

Error In the Message Log:


Also as per your previous reply please confirm whether i need to change the module code to

targetFileName = msg.getMessageProperty(fileKey)  instead of  targetFileName = fileKey.getPropertyName(); or include both.

Kindly help on the same!!!

engswee
Active Contributor
0 Likes

Your error log still does not match your code. There's no msgKey variable in your logic. And there is no call to method getMessageId() in your logic.

Are you sure the correct module is being called?