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: 

Introduction:

This blog explains a method to transform the SAP Cloud Integration(Integration Suite) iFlow HTTP URL into a clickable hyperlink through SAP APIM.

P.S: This marks my debut in the world of blogging!

Requirement:

Imagine a scenario where a client procurement platform generates a link containing input data as a query parameter, but it lacks proper authorization. Our objective is to create a hyperlink that exposes the SAP CI iFlow URL. This hyperlink would send a response after forwarding the request to the target system. However, we are facing below challenges in this process.

  • The URL query parameter is not encoded, potentially causing errors when directly used in the SAP CI iFlow URL.
  • Lack of authentication poses a significant challenge, as SAP CI requires at least basic authentication. 

Solution:

SAP APIM acts as an intermediary layer between the client procurement buying platform and SAP CI iFlow addressing the challenges mentioned above. Here's how it works:

  • Encoding: SAP APIM ensures that query parameters are properly encoded before transmission to the SAP CI iFlow.
  • Authorization Handling: By leveraging SAP APIM, authorization mechanisms can be implemented in APIM. The APIM also ensures that only authorized requests are passed on to SAP CI iFlow using IP whitelisting hence enhancing security and compliance.

iflow.png

 

Setup in SAP API Management:

  1. For initial setup including creating the API Provider, API Proxy, and configuring the iFlow URL along with authentication we can refer the instructions outlined in this blog.
  2. Based on this blog we can implement the IP whitelisting to exclusively permit client IPs to pass through the APIM thereby reinforcing security measures.

Integration Flow Design in SAP CI:

Let's begin by examining the sample URL generated by the client procurement platform.

https://SAP_APIM_URL?purchasingUnit=123&AccountAssignment=Test23&FieldValues={2=546,3=6290459,7=X02,}

In the URL above we will notice that the input data is contained within query parameters. Below we will explore how SAP CI iFlow transforms these query parameters into the desired XML format.

Sample CI iFlow:

sampleiflow.png

1. Configure HTTP Sender:

JSakth_0-1714474984776.png

Set up the HTTPS sender adapter with the Address field starting with '/'. Once the iFlow is deployed we will obtain the iFlow endpoint URL which will then be configured in SAP APIM.

2. Groovy to Get Query Params :

With the below Groovy script (based on this solution ) each query parameter is being stored in a header.

 

import com.sap.gateway.ip.core.customdev.util.Message
import java.util.HashMap
import java.net.URLDecoder

def Message processData(Message message) {
    def params = [:]
    (message.getHeaders().CamelHttpQuery =~ /(\w+)=?([^&]+)?/)[0..-1].each {
        params[it[1]] = URLDecoder.decode(it[2], "UTF-8")
    }
     
    message.setHeader("purchasingUnit", params.purchasingUnit)
    message.setHeader("AccountAssignment", params.AccountAssignment)
    message.setHeader("FieldValues", params.FieldValues)
    return message
}

 

 
3. Groovy to Get Key values:

The below Groovy script is utilized to extract and store each value corresponding to specific keys from the 'FieldValues' query parameter, which contains a key-value map. For example, keys like '2' correspond to 'CostCenter', '3' corresponds to 'Account' and so forth.

 

import com.sap.gateway.ip.core.customdev.util.Message;

def Message processData(Message message) {
    def headerString = message.getHeaders().get("FieldValues");
    
    if (headerString != null && headerString instanceof String) {
        def keyValuePairs = headerString.findAll(/\d+=\w+/);
        
        keyValuePairs.each { pair ->
            def keyValue = pair.tokenize("=");
            if (keyValue.size() == 2) {
                def key = keyValue[0].trim();
                def value = keyValue[1].trim();
                message.setProperty("key_" + key, value);
            }
        }
    }
    return message;
}

 

This script will store the values in a property, as illustrated in the screenshot below.

JSakth_1-1714476486805.png

 

4. Mapping to target XML:

Creating the output XML is straightforward we will match the headers and properties from our previous Groovy scripts with their respective target fields.

Here are examples of how we have mapped the headers and properties to their corresponding target fields.

JSakth_0-1714546521262.pngScreenshot 2024-05-01 122547.png

5. Groovy Script to send response:

After sending the XML to the target system we will receive a response indicating either success or failure along with an error message if applicable. The following script will generate a basic HTML response based on the received response.

 

import com.sap.gateway.ip.core.customdev.util.Message
import groovy.xml.*

def Message processData(Message message) {
    def body = message.getBody(java.lang.String) as String
    def xmlNode = new XmlSlurper().parseText(body)
    def headers = message.getHeaders()

    def returnCode = xmlNode.ReturnCode.text()

    if (returnCode == "success") {
        // Set success response in HTML format
        def successMessage = headers['FieldValues']
        def successBody = "<html><body><h1>Account Validation:</h1><h2>Account validation successful for combination $successMessage</h2></body></html>"
        message.setBody(successBody.getBytes("UTF-8"))
        // Set content type to text/html
        message.setHeader("Content-Type", "text/html")
    } else {
        // Set error response with ErrorMessage in HTML format
        def errorMessage = xmlNode.ErrorMessage.text()
        def errorBody = "<html><body><h1>Account Validation:</h1><h2>Error: $errorMessage</h2></body></html>"
        message.setBody(errorBody.getBytes("UTF-8"))
        // Set content type to text/html
        message.setHeader("Content-Type", "text/html")
    }

    return message
}

 

 

Testing:

Now, let's test some sample scenarios.

Case 1: Success Scenario

In this scenario, when the call is made to the URL from the client's IP address and the target response is successful the user will receive a similar response as shown in the screenshot below.

 

JSakth_0-1714547895505.png
Case 2: Error Scenario:

In this scenario, when the call is made to the URL from the client's IP address and the target response is failure/error the user will receive a similar response with error massage as shown in the screenshot below.

JSakth_1-1714548373029.pngCase 3: Invalid IP: 

In this scenario, if the request is made to the URL from a non-client IP address the error displayed below will appear. The error is thrown at the SAP APIM layer itself thereby the request is not sent to SAP CI iFlow.

JSakth_2-1714549177887.png
 
Conclusion: This blog explains the process of transforming a SAP CI iFlow URL into a clickable hyperlink(the legacy sender system lacks to provide any authentication) while extracting input data from query parameters and constructing the target XML. By leveraging the concepts outlined in this blog we can extend our capabilities to execute more complex integrations using similar methodologies.

 

 

 

 

 

Labels in this area