Skip to Content

Accessing file Attachments name in JAVA Mapping

Hello Folks,

I have File sender Channel and it is having additional files concept. So I have total 4 files on Sender side.

Lets say these are :

Attachment Files :

Student_1.txt

Student_2.txt

Student_3.txt

Main payload file : Student_Final.txt

These files are getting picked up without any issue and I am getting Student_Final.txt as main Payload and others are as attachment. I am fine till now.

SOAP Header :

Now I need to access the file attachment name in Java Mapping before reading the content of the file. So here I need to access the filename which is inside the <sap:name> tag i.e. Student_1.txt  or Student_2.txt or Student_3.txt
.

I tried with the below methods and getting the values :

Method : attachment.getContantType() 

Value : application/xml;

Method : attachment.getContentId();

Value is different for the each attachment and looks like :

I had look in message monitor :

So Content Type is not containing the file name here.

Please suggest how to get attachment file name.

Thanks.

Best Regards

Om Heerani

SOAPHeader.JPG (80.2 kB)
Capture.JPG (12.4 kB)
Capture.JPG (21.4 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Sep 14, 2016 at 12:06 PM

    Om,

    Can you try with this UDF.

    String attachmentID = null;
    GlobalContainer globalContainer = container.getGlobalContainer();
    InputAttachments inputAttachments = globalContainer.getInputAttachments();
    
    if(inputAttachments.areAttachmentsAvailable())
    {
    Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);
    Object[] arrayObj = CollectionIDs.toArray();
    attachmentID = (String)arrayObj[0];
    Attachment attachment = inputAttachments.getAttachment(attachmentID);
    int attachmentsize = attachment.getContent().length;
    return "Attachment Name : "+attachmentID +"  Attachment Size : "+attachmentsize+" bytes";
    }
    else {
    return "no attachment found";
    }
    
    

    In OM make sure you mark "Read Attachments".

    Br,

    Manoj

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Manoj,

      Yes. It worked. As per your suggestion I used the MultipartHeaderBean Module in Sender File channel. This module worked fine with the file Sender channel.

      All Header information of Main Payload & Attachments appeared in Dynamic Configuration tab as below.

      Now I checked the file name on the basis of Content-Disposition using Dynamic Configuration and got the corresponding Attachment data using the Content-ID.

      In the below method, I put the Content-ID which was retrieved from Dynamic Configuration instead of putting the Attachment ID because both values are same.

      Attachment attachment = inputAttachments.getAttachment(key_id);

      Thanks for your help.

      Best Regards

      Om Heerani

      Capture1.JPG (111.3 kB)