Hi Guys,
In one of my requirement, i need to have an email attachment and body as well.
For this used an artcle http://scn.sap.com/community/pi-and-soa-middleware/blog/2012/04/13/renaming-email-attachment-with-input-file-name
I did the same but not getting the attachment with Renamed value.
My Adapter configurations as below:
The below is my module code: and also you see the logs which got from the channel monitoring.
//-------------------------Sree Code2 Start Here------
public static final String VERSION_ID ="$Id://tc/aii/30_REL/src/_adapters/_sample/java/user/module/Sree_AttachNameBean.java#1 $";
static final long serialVersionUID = 7435850550539048633L;
String fileName = null;
@SuppressWarnings("deprecation")
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData) throws ModuleException
{
String SIGNATURE = "process(ModuleContext moduleContext, ModuleData inputModuleData)";
Location location = null;
AuditAccess audit = null;
Payload attName =null;
int attnum=0;
try {
location = Location.getLocation(this.getClass().getName());
}
catch (Exception t)
{
t.printStackTrace();
ModuleException me = new ModuleException("Unable to create trace location", t);
location.throwing(SIGNATURE, me);
throw me;
}
Object obj = null;
Message msg = null;
MessageKey key = null;
try {
obj = inputModuleData.getPrincipalData();
msg = (Message) obj;
key = new MessageKey(msg.getMessageId(), msg.getMessageDirection());
audit = PublicAPIAccessFactory.getPublicAPIAccess().getAuditAccess();
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "EmailAttach: Module called");
fileName = msg.getMessageProperty("http://sap.com/xi/XI/System/File", "FileName");
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"RequestFileName:" + fileName);
attnum=msg.countAttachments();
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"number of Attachment: " + attnum);
attName = msg.getAttachment("%F");
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"Name of Attachment after msg.getattchment method: " + attName.getName());
msg.removeAttachment("%F");
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"Name of Attachment after msg.removeattchment method: " + attName.getName());
attnum=msg.countAttachments();
if(attName != null)
{
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"Name of Attachment: " + attName.getName());
}
else
{
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"Attachment not found" + attName);
}
try
{
attName.setName(fileName);
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"Attachment name is successfully changed to : " + attName.getName());
}
catch(Exception e)
{
audit.addAuditLogEntry(key, AuditLogStatus.ERROR,attName +": attachmentName is not matching");
ModuleException me = new ModuleException(e);
throw me;
}
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"No of Attachments Before attachment added: " + msg.countAttachments());
msg.addAttachment(attName);
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,"No of Attachments After attachment added: " + msg.countAttachments());
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS," Before Attachment added to InputModueData.");
inputModuleData.setPrincipalData(msg);
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS," After Attachment added to InputModueData.");
}
catch (Exception e) {
ModuleException me = new ModuleException(e);
throw me;
}
return inputModuleData;//sending original payload to call adapter.
}
//-------------------------Sree Code2 End Here---------
My Sender Channel as below:
Channel Monitoring LOG:
Generated Email as below:
Please sugget me what is wrong in the coding OR in any place in the configuration.
Regards,
Sreeni.