Use groovy script to extract attachment content from soap message in CPI

Today one customer called a soap api from a third party system. Some important information is in attachment of the soap message . Customer needs to extract message in soap message attachment . I had some test and successfully extract the data from soap message . Let me share the steps, which may help others .

I support the readers has installed Soap UI.

Let me share the steps :

Step 1 , Develope and deploy iflow in CPI .

Develope iflow

/* Refer the link below to learn more about the use cases of script. If you want to know more about the SCRIPT APIs, refer the link below */
import java.util.HashMap;
def Message processData(Message message) { //Attach def attach = message.getAttachments(); def datahandler = attach.values()[0]; def content = datahandler.getContent(); def messageLog = messageLogFactory.getMessageLog(message); if(messageLog != null){ messageLog.setStringProperty("Logging", "Printing Payload As Attachment"); messageLog.addAttachmentAsString("Message#2", content.toString(), "text/plain"); } message.setBody(content); return message;

After depoyment , we can find the iflow runtime URL and download the wsdl file with following screen shot .

Step 2, Test with Soap UI .

Get  CPI runtime  Client ID and Client Secret from CPI runtime instance service key

Test with Soap UI

We can find that the attachment content has been successfully extracted into response body .

Then End

Best regards!

Jacky Liu