Skip to Content
0

UDF for attachment name

Jan 10, 2017 at 02:26 PM

193

avatar image

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;

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Manoj K Jan 10, 2017 at 02:59 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Abhishek Gupta Jan 13, 2017 at 09:58 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Evgeniy Kolmakov Jan 13, 2017 at 11:15 AM
0

Hi, Abhishek!

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

Regards, Evgeniy.

Share
10 |10000 characters needed characters left characters exceeded
Abhishek Gupta Jan 13, 2017 at 11:40 AM
0

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


wuotf.png (10.0 kB)
mb6z6.png (13.6 kB)
Show 3 Share
10 |10000 characters needed characters left characters exceeded

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

1

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.

1

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

0