Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

In this blog, I would like to share the steps to save SOAP attachment in a folder, with the same name. The SOAP adapter will change attachment name to 'attachment-1' in default, so we can't get the original name directly. I was referring a blog, Creating File Name from Mail Attachment using Standard Beans, which must be working fine for Mail to File scenario. When I tried the same for a SOAP adapter, using MultipartHeaderBean module, the attachment name came with some special characters, which is shown in Fig 2.


Fig.1, Attachment sent through SOAP UI

Fig.2, Details of the attached file in PI after using MultipartHeaderBean Module

I used DynamicConfigurationBean and PayloadSwapBean in receiver adapter(File). The attachment name has "<" and ">", which are not permitted in the creation of file name, so they are replaced with underscores "_", which is shown in Fig 3.


Fig.3, Target file name with underscores

The underscores are making the attachment as an unknown file. I tried all the possible ways in Integration Builder, but unable to fix this. I then referred the blog Retaining SOAP Adapter Attachment Names, by making some minor changes in the UDF, I was able to get the correct name.

Configuration Steps

1. Sender Communication Channel

Create the necessary Data types, message types, service interfaces and mappings. In the sender SOAP communication channel, the parameter "keep attachments" should be checked. I didn't use ASMA and MultipartHeaderBean module. Please refer Fig 4 and 5 for sender channel configuration.


Fig.4, Sender Communication channel configuration


Fig.5, Sender Communication channel - advanced options

2. Message Mapping


UDF to get the attachment name:

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","TempFileName");
attachmentID ="" + renameAttachment;
conf.put(key, attachmentID);
}
}
}
catch (Exception e)
{
trace.addWarning("caught exception: " + e + " - probably no adapter-specific message attribute.");
e.printStackTrace();
}
return attachmentID;

I used the Dynamic configuration syntax to show the attachment name generated by the above UDF, which is given in the below figure.

Fig. 6, Attachment Name with it's attributes

I used replace string and trim function to get the file name alone. After that use the below UDF to create the correct attachment name in Dynamic Configuration.

UDF to create the attachment name in Dynamic Configuration:

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String MyFileName = var1;
conf.put(key,MyFileName);
return var1;

Message Mapping Definition:

Fig.7, Message Mapping definition for getting the file name

Note: Please make sure that "Read Attachment" option is enabled in Operation Mapping.

3. Receiver Communication Channel

I used Dynamic Configuration and Payload swap modules in the receiver file communication channel. Please refer Fig. 8,9 and 10.

Fig.8, Receiver Communication channel 1


Fig.9, Receiver Communication channel 2

Fig.10, Receiver Communication channel 3

Testing


I sent the same Test_File.txt, using SOAP UI tool. Please refer the below screen shots of Dynamic Configuration, audit logs and target file.

Fig.11, Dynamic Configuration

Fig.12, Audit log

The audit log show that the DynamicConfigurationBean module is used to get the attachment and PayloadSwapBean module swaps the attachment.

Fig.13, Target file

As shown in the above figure the attachment is saved in the file location with the same name. I'm able to do the same with .jpg, .pdf, .doc, .xlsx, .csv and .xml files.

6 Comments
Labels in this area