cancel
Showing results for 
Search instead for 
Did you mean: 

Adapter Module to Rename Attachement in MAIL Recever Side Issue

former_member201264
Active Contributor
0 Kudos

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.

Accepted Solutions (0)

Answers (5)

Answers (5)

anandvithal
Active Participant
0 Kudos

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

peter_wallner2
Active Contributor
0 Kudos

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

former_member181985
Active Contributor
0 Kudos

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

peter_wallner2
Active Contributor
0 Kudos

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

anandvithal
Active Participant
0 Kudos

Hi Peter,

I had tested my code(with filename) in java mapping and it works. So i thought that same would work in module as well

Thanks,

Anand

former_member181985
Active Contributor
0 Kudos

Thanks Peter for sharing your previous experiences in this thread.

Regards,

Praveen Gujjeti

former_member201264
Active Contributor
0 Kudos

Hi All,

Thank you very much for inputs.

We actually changed design to another way.

But I am eager to test this.

I will update you once done it in the adapter module.

Regards,

Sreeni.

Former Member
0 Kudos

Hi,

In Mail receiver channel ASMA attributes, check variable transport binding variable and give a try.

Hope this works.

Regards,

Veerendra.

former_member201264
Active Contributor
0 Kudos

Hi Veerendra,

No Luck..

Regards,

Sreeni.

Former Member
0 Kudos

Hi,

Please comment the below line of code in the module, re-deploy the module and test it.

                                  inputModuleData.setPrincipalData(msg);

Regards,

Veerendra.

former_member201264
Active Contributor
0 Kudos

Hi Veer,

Initially I coded wihout inputModuleData.setPrincipalData(msg);  No Luck..

Later, I added this to check my luck with this new line using set Method.

Regards,

Sreeni.

former_member181985
Active Contributor
0 Kudos

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

former_member201264
Active Contributor
0 Kudos

Hi Praveen,

I am getting attachment name as required but it is in xml.

I want the same as surce file name example  AA.txt  ,  this extension .txt all required.

Any other idea plz..

iaki_vila
Active Contributor
0 Kudos

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.

former_member201264
Active Contributor
0 Kudos

I checked Evrything fine.

Any other idea plz..

former_member201264
Active Contributor
0 Kudos

Any Idea....