Quantcast
Channel: SCN : Blog List - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 676

Retaining SOAP Adapter Attachment Names

$
0
0

As per thread: SOAP Sender attachment named attachment-1 discussion, SOAP sender Adapter always replaces the incoming attachment names with attachment-1, attachment-2 etc.. And as Stefan Grube mentioned in the thread, this is the default SOAP adapter behavior since it was hardcoded in SOAP adapter for incoming attachments to XI. But most of the times, the business needs the original attachment names at the receiving target application. So, how can we achieve this.

 

In this blog, I am providing UDF code snippet using which we can retain original attachment names in the mapping by reading incoming attachments using mapping API for attachments (applicable from PI7.1 onwards). Also, with this procedure we can overwrite existing attachments with any content as bytes. Note:- the same can be achieved with a java mapping/XSLT with java enhancements as well.

 

String attachmentID = null;
java.util.Map map;
AbstractTrace trace;

//gets the input attachment from the source message
GlobalContainer globalContainer = container.getGlobalContainer();
InputAttachments inputAttachments = globalContainer.getInputAttachments();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
trace = container.getTrace();
//map = globalContainer.getParameters(); 
try
{
          //checks for the availability of attachments in the input message          if(inputAttachments.areAttachmentsAvailable())          {                    trace.addInfo("Attachments Available");                    //gets the attachmentIds and store it in an Object array                    Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);                    Object[] arrayObj = CollectionIDs.toArray();                     //Loops at the input attachments to get the content of the attachment                    for(int i =0;i<arrayObj.length;i++)                    {                              attachmentID =(String)arrayObj[i];                              trace.addInfo((i+1) + ") Attachment Name: " + attachmentID);                              Attachment attachment = inputAttachments.getAttachment(attachmentID);                              String contentType = attachment.getContentType();                              byte[] attachmentBytes = attachment.getContent();                              Attachment renameAttachment = outputAttachments.create(attachmentID, contentType, attachmentBytes);                               outputAttachments.setAttachment(renameAttachment);                              //remove each attachment if required. Uncommonent below                              //trace.addInfo("Removing Attachment no: " + (i+1) + " & Name: " + attachmentID);                              //outputAttachments.removeAttachment(attachmentID);                     }          } 
}
catch (Exception e)
{          e.printStackTrace();
}


return           var1;

 

Attachments sent from SOAP UI as SOAP message to XI.

 

SOAP UI.JPG

 

 

With the above UDF in the graphical mapping, the results will be as shown below for the inbound/mapping pipeline stages in MONI

 

PipelineSteps.JPG

Regards,

Praveen Gujjeti


Viewing all articles
Browse latest Browse all 676

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>