Monday, 6 April 2020

Remove certain string from the query/url passing to target using groovy script in SAP CPI

Read the query parameters from the source system and remove the $filter= from it as shown below:


CamelHttpQuery from source :$filter=ContactID%3d%271925053%27%2cContactOrigin%3d%27SAP_C4C_BUPA%27

URL should be as send to target system: https://myXXX-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_CONTACT_SRV;v=0003/ContactOriginData(ContactOrigin='SAP_XXX',ContactID='190000')

Query in the channel:

https://myXXX-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_CONTACT_SRV;v=0003/ContactOriginData(${header.Query})

Script:

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

import java.util.HashMap;

def Message processData(Message message) {

def map = message.getHeaders();

def value = map.get("CamelHttpQuery");

value = value.drop(8);

message.setHeader("Query", value);

return message;

}



No comments:

Post a Comment