4

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

 1 year ago
source link: https://blogs.sap.com/2022/06/24/use-groovy-script-to-extract-attachment-content-from-soap-message-in-cpi/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
June 24, 2022 2 minute read

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

28-2.png
29-2.png
30.png
/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/148851bf8192412cba1f9d2c17f4bd25.html

If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en-US/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
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 .

31-2.png

Step 2, Test with Soap UI .

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

22-4.png
23-4.png

Test with Soap UI

32-1.png
33-2.png
34-1.png

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

Then End

Best regards!

Jacky Liu


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK