cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing file Attachments name in JAVA Mapping

om_prakash7
Explorer
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

manoj_khavatkopp
Active Contributor
0 Kudos

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

om_prakash7
Explorer
0 Kudos

Hello Manoj,

I tried the above Java code and getting below output.

Still Not able to get the Attachment file name.

Thanks.

Best Regards

Om Heerani

manoj_khavatkopp
Active Contributor
0 Kudos

Hi Om,

May i know what is the sender channel you are using ?, because i just tested the above UDF with SOAP UI and i am able to see the attachment name.

Br,

Manoj

om_prakash7
Explorer
0 Kudos

Hello Manoj,

I am using File sender with option "Additional File" to pick the attachments.

Even I have tried with the SOAP Sender channel and the above code is working fine and file name is accessible.

However With the file sender channel, Attachment file name is not accessible. Could you please try with the File sender channel.

Below is sender channel configuration. In my case

manoj_khavatkopp
Active Contributor
0 Kudos

Om,

Yes i already tried with SFTP , and this didn't work

May i know how may files you are picking as an additional attachments ? is this NFS or FTP ?

br,

Manoj

om_prakash7
Explorer
0 Kudos

Hello Manoj,

I am picking three attachment files with the main payload.

Student_Final.txt is main document/payload.

Student_1.txt, Student_2.txt & Student_3.txt are attachment.

Thanks.

Best Regards

Om Heerani

om_prakash7
Explorer
0 Kudos

I am using Transport protocol "NFS".

manoj_khavatkopp
Active Contributor
0 Kudos

Unfortunately ,

I wont be able to test with NFS now , however can you try to add the Module in your sender channel as below . once you have added  Please provide the screenshot of Dynamic Configuration from your MONI/RWB to assist you further. I want to check is this module works with File Adapter or not.

Module:

Dynamic:

Br,

Manoj

om_prakash7
Explorer
0 Kudos

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

Answers (0)