Integration Blog Posts
cancel
Showing results for 
Search instead for 
Did you mean: 
Deljo_Davis
Explorer
2,044

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:

Deljo1_1-1742727845831.png

 

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

Deljo1_0-1742836020719.png

 

Refer the below SAP Help document for more on the SOAP header modifying: Help Document