Developing with SAP Integration Suite

Cleaning Up Message Data

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Use the Filter process step and apply Groovy scripting within your iFlow

Clean Up Message Data: Exercise Overview

Scenario

While the OData message has been mapped to SOAP there are still some steps required until it is passed on to the final recipients. For one, the message is filtered to select a particular structure of information and special characters have to be substituted to protect the SOAP message from potential errors. Lastly, the SOAP message is created by framing the body with the necessary SOAP message elements.

Task Flow

In this exercise, you will perform the step 28: Prepare more processing steps.

Prerequisites

Prerequisites are:

Clean Up Message Data

Exercise

Clean Up Message Data

Start Exercise

Task 1: Prepare More Processing Steps

Steps

  1. Set a filter.

    1. In the Transformation menu of the iFlow editor, choose Filter and position it adjacent to the previous process step. Connect both as you have learned.

    2. You can optionally change the name of the filter in the General tab of the configuration view that can be expanded from the bottom right of the screen if closed.

  2. Move to the Processing tab and enter/OrderRequestas XPath Expression.

  3. Depending on whether or not you have chosen to work with the pre-configured mappings or your own, your pre-processed message before the filter process step might look different.

    Example

    In the case of the provided mapping files, a namespace has to be declared within CI. For this, click anywhere outside of the Integration Process pool box to open the Integration Flow configuration view. Navigate to Runtime Configuration and enter the Namespace Mappingxmlns:ns1=http://sap.com/xi/EDI.

    This also means that you have to change the XPath Expression in the filter to include the namespace "/ns1:OrderRequest".
    If you have elected to work with your own file, you can skip this step. If an error in your filter occurs when testing the iFlow because of not declaring the namespace, you will be able to see this in the lesson "5.5 Deploying and Testing iFlows" (Set TRACE log level to view message payload) and go back to edit the iFlow then. Hovering over the Namespace Mapping input field will allow you to see the accepted format.

  4. Choose Save on the top right of the screen to secure your progress.

  5. In the Transformation menu of the iFlow editor, choose ScriptGroovy Script and position it adjacent to the previous Filter process step. Connect both elements via drag and drop.

  6. Click onto the Groovy Script element to access its configuration menu. In the General tab, set the Name to Substitute special characters.

  7. As this script is only needed locally within this particular iFlow, you can provide it directly as a resource. This is now shown for demonstration purposes. In reality, it is common practice to make all functions available via a script collection. This feature will be shown in a later exercise.

    Example

    For the next step, you need to prepare a file on your local file system or take the .groovy file that you downloaded with the .zip file in the exercise Set Up Your Environment. Name it "sub_special_characters.groovy". Enter the following code into this file and save it.

    Code snippet
    import com.sap.gateway.ip.core.customdev.util.Message;
    import java.util.HashMap;
    def Message processData(Message message) {
        //Body 
          def body = message.getBody(java.lang.String);
          
            body = body.replaceAll("<", "<")
            
            body = body.replaceAll(">", ">")
            
            message.setBody(body)
            
          return message;
    }
    Copy code
    Navigate to theProcessing tab in the configuration view and select Upload from File System. Locate the prepared file "sub_special_characters.groovy". Choose OK to proceed.

  8. Select the script resource (path) to familiarize yourself with its workings.

  9. Choose Save to secure your progress.

    Example

    You will now build your final SOAP message that is ready to be passed on to its recipients by providing the SOAP body contents.

  10. Select TransformationContent Modifierand position the element next to the previous process step. Connect both elements.

  11. In the configuration menu of the Content Modifier, change its Name to Create SOAP message.

  12. Move on to the Message Body tab and provide the following input:

    Example

    Code snippet
    <soap:Envelope
    xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
    soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
    <soap:Body xmlns:m="http://www.example.org/PurchaseOrder">
      <m:Contents>${in.body}</m:Contents>
    </soap:Body>
    </soap:Envelope> 
    Copy code
  13. Choose Save to secure your progress.

    Result

    Your message is now ready to be passed on to its final recipients.

Summary of the Lesson: Cleaning Up Message Data and Further Resources

Summary

You have successfully transformed the post-mapping message into its final state. The SOAP message is now ready to be sent to the supplier of eCarHero for order fulfillment.

Further Resources

Here you can find more information about Groovy scripting fundamentals.

Save progress to your learning plan by logging in or creating an account