cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Exception Caught!! payloadName Error!!

Former Member
0 Likes
1,959

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.!!!

View Entire Topic
Former Member
0 Likes

HI Eng/

    Sorry for the late and refrain!! I have added the MessageLoggerBean in the channel after my custom module. Please find the below screenshots of the same.

Communication Channel Setting:



PIMON Screenshot Step 2:


PIMON Screenshot Step 2:



From the above screenshots i have provided the log details from PIMON and also the data inside the attachment. And from the body attachment it will be converted to mail body.Would request you to kindly help on the same and let me know whether i need to change any module code.

Also Please suggest me if i need to try with attachment api's in the module code.


Kindly help on the same.

Many Thanks,

Best Regards,

Prashanth Bharadwaj Ch.

engswee
Active Contributor
0 Likes

Hi Prashanth

Unfortunately, different mail providers act differently on the MIME details, so it is always a trial and error.

For your mail server, it looks like the content type is not enough, so let's try a few more things.

1. Set payload name

Add the following to your code at the appropriate position.


payload.setName(targetFileName);

Then retest your case.

If it still does not work, try below

2. Set content disposition

Add following code in addition to above


payload.setAttribute("content-disposition", "attachment;filename=\"" + targetFileName + "\"");

If it still does not work, provide the same screenshot for the Attachment tab of the logged version.

Rgds

Eng Swee