on 2016 Jan 21 7:41 AM
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.!!!
Request clarification before answering.
Hi all/Eng,
I have added the same payload.setContentType("text/plain;charset=\"UTF-8\";name=\"" + targetFileName + "\""); in the module code. Still the same issue persists.The attachment name is not getting changed. Here are the below details.
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
key = new MessageKey(msg.getMessageId(), msg.getMessageDirection());
audit = PublicAPIAccessFactory.getPublicAPIAccess().getAuditAccess();
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, this.getClass().getName() + ": Module Initialized");
attName = moduleContext.getContextData("AttachmentName");
Payload payload = msg.getAttachment(attName);
MessagePropertyKey fileKey = new MessagePropertyKey("FileName","http://sap.com/xi/XI/System/Mail");
targetFileName = msg.getMessageProperty(fileKey);
if(targetFileName == null)
{
targetFileName = "Reservation.txt";
}
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, " Entering Mail Adapter");
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, " Name of Attachment after msg.getattchment method: " + targetFileName);
payload.setContentType("text/plain;charset=\"UTF-8\";name=\"" + targetFileName + "\"");
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"Attachment renamed successfully : " +targetFileName);
inputModuleData.setPrincipalData(msg);
}
catch (Exception e)
{
throw new ModuleException(e);
}
return inputModuleData;
}
}
Message Log in Runtime Workbench:
E-mail Generated with MainDocument name as attachment Name:
Please confirm still i need modify anything in the module code or mapping!!
Kindly help on the same!!
Thanks in advance!!
Many Thanks,
Best Regards,
Prashanth Bharadwaj Ch.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Prashanth
Can you add the module MessageLoggerBean after your custom module so that a version of the payload is available in the logs? Refer to the following on how to do that.
Once you have it logged, can you Open the message in PIMON and provide a screenshot of the Attachments tab for the version that was logged above?
It should look something like below. I would like to see the name and content type for the attachment.
Rgds
Eng Swee
| User | Count |
|---|---|
| 13 | |
| 8 | |
| 7 | |
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.