on 09-23-2013 6:44 AM
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-in...
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.
Hi Sreeni,
Add below line of code in the module. It should work.
...
attName.setName(fileName);
attName.setContentType("text/plain;charset=\"UTF-8\";filename=\""+fileName+".txt"+"\"");
...
Thanks,
Anand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
According to this thread http://scn.sap.com/thread/1946656
it should be:
attName.setContentType("text/plain;charset=\"UTF-8\";name=\""+fileName+".txt"+"\"");
Best regards,
Peter
Hi Peter, Indeed the solution works.
Hi Sreeni,
I adapted the above snippet code provided by Peter in UDF and it works fine with mail adapter now.
contentType = contentType + ";charset = \"UTF-8\";"+ "name=\"" + attachmentID + "\"";
I updated my blog:http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/07/01/retaining-soap-adapter-attachment...
with the same
Regards,
Praveen Gujjeti
Hello Praveen,
Thank you for your confirmation. I remember using this code once too and opened thread http://scn.sap.com/thread/1946656 and Stefan Grube helped me out. Thank you for updating your blog.
Best regards,
Peter
Hi,
In Mail receiver channel ASMA attributes, check variable transport binding variable and give a try.
Hope this works.
Regards,
Veerendra.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sreeni,
Can you try with my blog concept (without using your custom module in MAIL adapter) : http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/07/01/retaining-soap-adapter-attachment...
I believe the above concept should work in case of email adapter as well. Please let me know the result.
Regards,
Praveen Gujjeti
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kancham,
It's a weird issue, all you development seems ok to me. Have you tried to use a MessageTransformBean key without spaces and with only alphabetic characters?
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any Idea....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.