Welcome to my first blog post! This guide is designed especially for beginners who are new to SOAP services in SAP CPI.
When an external SOAP service is called via SOAP UI with proper request payload, we get expected response, but when we use the same request payload to call the same Service via SAP CPI, we may get the below error due to in-proper SOAP Header
java.lang.IllegalArgumentException: The PayLoad elements cannot fit with the message parts of the BindingOperation.
By Following the steps, we can set the SOAP header in CPI to resolve this issue.
First of all, for the basic information, a SOAP message consists of the following parts:
Envelope: The root element of the SOAP message it encloses all the other elements.
Header: It will be the first child element of the Envelop element. it can contain metadata with authentication or other pivotal details.
Body: It's a mandatory part and it contains the actual data.
Consider the below request payload which is success in SOAP UI:
However, when the same request structure is sent via SAP CPI, follow the below steps to Set SOAP Header:
1. Reconstruct the above message by removing the header, envelope parts and by adding proper namespace to each elements. example:
<com:find xmlns:com="http://com.rho.rcf.ged.ws">
<typ:repositoryId xmlns:typ="http://com.rho.rcf.ged.ws/types">Dummy
</typ:repositoryId>
<typ:statement xmlns:typ="http://com.rho.rcf.ged.ws/types">'06BA64C'
</typ:statement>
<typ:allVersions xmlns:typ="http://com.rho.rcf.ged.ws/types">false
</typ:allVersions>
</com:find>This is passed as the body via CPI's content modifier.
2. Set the SOAP Header using the groovy script below:
NB: Modify the script according to the structure.
import com.sap.gateway.ip.core.customdev.util.Message
import javax.xml.namespace.QName
import com.sap.gateway.ip.core.customdev.util.SoapHeader
def Message processData(Message message) {
// Define the namespace details
def namespacePrefix = "typ"
def namespaceURI = "http://com.rho.rcf.ged.ws/types"
// Construct the SOAP Header XML with explicit prefix and namespace
def xml = """<${namespacePrefix}:userName xmlns:${namespacePrefix}="${namespaceURI}">USER</${namespacePrefix}:userName>"""
// Create SOAP header entry with proper QName
def header = new SoapHeader(new QName(namespaceURI, "userName", namespacePrefix), xml, false, "")
def headers = [header]
// Set the headers in the message
message.setSoapHeaders(headers)
return message
}This script will set the SOAP Header part in below structure:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<typ:userName
xmlns:typ="http://com.rho.rcf.ged.ws/types">USER
</typ:userName>
</soap:Header>
<soap:Body></soap:Body>
</soap:Envelope>And CPI will sent below consolidated SOAP request message to Server:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<typ:userName
xmlns:typ="http://com.rho.rcf.ged.ws/types">USER
</typ:userName>
</soap:Header>
<soap:Body>
<com:find
xmlns:com="http://com.rho.rcf.ged.ws">
<typ:repositoryId
xmlns:typ="http://com.rho.rcf.ged.ws/types">Dummy
</typ:repositoryId>
<typ:statement
xmlns:typ="http://com.rho.rcf.ged.ws/types">'06BA64C'
</typ:statement>
<typ:allVersions
xmlns:typ="http://com.rho.rcf.ged.ws/types">false
</typ:allVersions>
</com:find>
</soap:Body>
</soap:Envelope>3, Blank out these marked 4 fields in receiver SOAP adapter in CPI
Refer the below SAP Help document for more on the SOAP header modifying: Help Document
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 35 | |
| 29 | |
| 15 | |
| 10 | |
| 8 | |
| 8 | |
| 7 | |
| 6 | |
| 6 | |
| 5 |