
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!
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.
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:
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.
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.
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
}
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.
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.
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
}
Now, let's test some sample scenarios.
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.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
10 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |