cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for attachment name

itabhishek9
Participant
0 Kudos

Hi SDNites,

I have a SOAP to File interface where webservice is sending an attachment along with it. I wanted to read the attachment name and generate the output file with the same name. I have written an UDF and it is not working. Can you please help me with the below 2 queries,

1. How can I debug the UDF as it is reading an attachment during runtime. Is there any way I can simulate the same scenario in eclipse and debug the UDF.

2. Below is the UDF I am using. Can you please let me know what could be the issue,

String attachmentID = null;
AbstractTrace trace;
GlobalContainer globalContainer = container.getGlobalContainer();
InputAttachments inputAttachments = globalContainer.getInputAttachments();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
trace = container.getTrace();
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
try
{
if(inputAttachments.areAttachmentsAvailable())
{
Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);
Object[] arrayObj = CollectionIDs.toArray();
for(int i =0;i<arrayObj.length;i++)
{
attachmentID =(String)arrayObj[i];
Attachment attachment = inputAttachments.getAttachment(attachmentID);
byte[] attachmentBytes = attachment.getContent();
Attachment renameAttachment = outputAttachments.create(attachmentID, attachmentBytes);
DynamicConfigurationKey key = DynamicConfigurationKey.create(“http://sap.com/xi/XI/System/File“,”FileName”);
attachmentID =”” + renameAttachment;
conf.put(key, attachmentID);
}
}
}
catch (Exception e)
{
trace.addWarning(“caught exception: ” + e + ” – probably no adapter-specific message attribute.”);
e.printStackTrace();
}

return attachmentID;

Accepted Solutions (0)

Answers (4)

Answers (4)

itabhishek9
Participant
0 Kudos

Hi Evgeniy,

Can you please elaborate on the above point.

Following is what I can see in Sender channel,

Below is how I can see it in SXMB_MONI in SOAP Body,

Can you please let me know how can I get the attachment name which in this case in SOAP_Attachment_Test.txt.

Regards,

Abhishek

manoj_khavatkopp
Active Contributor

I am still wondering why u are not able to read , because eif you refer the link which I have provided in the screenshot I am able to read the attachment name from <SAP:Payload xlin:href......>

Can you please provide the screenshot of you sender SOAP channel , UDF , OM screenshot .

Br,

Manoj

former_member190293
Active Contributor

I'm agree with Manoj's suggestion. You should either use MultipartHeaderBean in your sender communication channel to save all message headers to Dynamic Configuration or develop custom adapter module where you can use Payload class to get attachment name.

Regards, Evgeniy.

itabhishek9
Participant
0 Kudos

Hi Manoj / Evgeniy,

I have got partial success in the above,

1. Using Multipart Header Bean, I am able to get the file names in Dynamic Configuration but not sure how do I read them so that when I generate that file / files in the receiver directory it will have corresponding name. (Please advise if multiple files are there).

2. Using UDF also I am able to read the attachment and get the filename from there and use it to generate the file in the receiver using File adapter. But this approach will not work for multiple files. For multiple files, I have used SFTP adapter and am able o generate multiple files into the receiver. But the query again here is how do I get the same attachment file name in receiver directory.

(Please advise if multiple files are there).

Regards,

Abhi

former_member190293
Active Contributor
0 Kudos

Hi, Abhishek!

As far as I remember you should refer to Content-Description of attachment in order to get attachment name.

Regards, Evgeniy.

itabhishek9
Participant
0 Kudos

Yes I have enabled the Read attachment in OM.

My understanding of above UDF is that it gets the attachment name and sets the FileName parameter via dynamic configuration. So in the receiver file adapter, if I use ASMA then it will generate the output file with the file name as value set in FileName dynamic parameter.

Regards,

Abhi

manoj_khavatkopp
Active Contributor
0 Kudos

Abhishek ,

What is the output after this UDF? Have you enabled "Read attachment" in OM?

Refer : https://archive.sap.com/discussions/thread/3956705

Br,

Manoj