Skip to Content
Author's profile photo Praveen Tirumareddy

SAP CPI- Clearing the Headers (Reset Header)

Introduction:

To clear the headers from the outgoing message request.

On many occasions we have a business scenario where, we need to do multiple lookup calls to an external system with some message transformation and then make some external HTTP call to post the transformed message.

One of business requirement was wherein we had to look up from S/4 HANA system and subsequently post the transformed message to an external third party system using HTTP Post(method).

While we were making individual calls to the third party system, it was working perfectly fine but once we joined all the pieces and completed the i-flow, we were unable to post the message resulting  in  error 406.

Hence we decided to log all the headers and see if there  were any additional headers which would have been carried from the previous SOAP call to S/4 HANA.

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

def Message processData(Message message) {
	def headers = message.getHeaders()
	def messageLog = messageLogFactory.getMessageLog(message)
	for (header in headers) {
	   messageLog.setStringProperty("header." + header.getKey().toString(), header.getValue().toString())
	}
    return message;
}

Above code helped us to get the list of header values from the current message.

On further analysis we could understand that, there could be various reasons why the message header could get appended with different values which might not be relevant in preceding calls. After reading the below paragraph from standard documentation we had a clue of possible error.

Note that data written to the message header during a processing step (for example, in a Content Modifier or Script step) will also be part of the outbound message addressed to a receiver system (whereas properties will remain within the integration flow and will not be handed over to receivers). Because of this, it is important to consider the following header size restriction if you are using an HTTP-based receiver adapter: If the message header exceeds a certain value, the receiver may not be able to accept the inbound call (this applies to all HTTP-based receiver adapters). The limiting value depends on the characteristics of the receiver system, but typically ranges between 4 and 16 KB. To overcome this issue, you can use a subsequent Content Modifier step to delete all headers that are not supposed to be part of the outbound message.

Now this clearly states that there could be certain irrelevant headers which could be causing a problem.

If we retain some relevant headers and delete the rest we could have three different use cases:

  1. Delete specific header values
  2. Delete all the header values
  3. Delete all the headers except masking a few.

So the next target was to achieve these use cases. Please follow the steps below

  • Select Content Modifier step before the HTTP call.
  • Select Message Header section
  • Click Add button
  • Select Delete from the Drop down.

  • Press on Select Button under Column Name which will give you a pop up

Now we have three options to handle the deletion of the headers:

  1. Delete specific header values: In this case we can select the first option Header and mention all the header needs to be deleted. We could add ‘n’ number of header variables with the  Action as delete and mention the Header to be deleted.
  2. Delete all the header values: In case we had to delete all the headers we could select the Expression instead of Header. This would clear all the headers before the subsequent calls.
  3. Delete all the headers except masking few: And finally if we want to mask few we could mention them under Exclude with wildcard character.

Reference :https://help.sap.com/viewer/732e76b32cab4dd0ab9e862b15b01fa6/Cloud/en-US/8f04a707843a40bf9f6e07ed55b93034.html

Hope this helps !!

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Gagandeep Batra
      Gagandeep Batra

      Great!!

      Regards

      GB

      Author's profile photo Karthik Bangera
      Karthik Bangera

      Thanks for sharing Praveen 🙂

       

      Regards,

      Karthik

      Author's profile photo Sriprasad S Bhat
      Sriprasad S Bhat

      Thanks for sharing nice blog!

      Author's profile photo Christian Simon
      Christian Simon

      Hi colleagues,
      can I enter a list (e.g. separated by comma) in the property/header field?

       

      Best,

      Christian

      Author's profile photo J. Evertse
      J. Evertse

      Christian any news on this? Same applies to Exclude ? Any thoughts on deleting headers like sap_messageprocessinglogid?

      Author's profile photo Tiago Miranda Silva
      Tiago Miranda Silva

      On Expression: Include/Exclude use the "|" separator like in runtime configuration.

      Ex:

      Exclude:

      header1|header2

      Author's profile photo Praveen Tirumareddy
      Praveen Tirumareddy
      Blog Post Author

      Hi Christian Simon,

      Not sure about that but you can create multiple properties and each delete one property/header.

      eg:

      alternatively we can use script as well to delete.

      thanks and regards,

      Praveen T

       

      Author's profile photo Anand Gopinath
      Anand Gopinath

      Thanks Praveen. The material in the blog helped in resolving a seemingly strange issue - the 'Content-Type' header was refusing to appear in the outbound message header even after it was set explicitly, and this was resulting in the request being rejected at the server. It was able to be set only only after the existing headers were deleted.

      Author's profile photo Praveen Tirumareddy
      Praveen Tirumareddy
      Blog Post Author

      Hi Anand,

      Glad that it helped :).

      thanks and regards,

      Praveen T

      Author's profile photo Ravindra Vishwanath
      Ravindra Vishwanath

      Hi Praveen,

      That was helpful.

      Also, if you were using HTTP receiver adapter to connect to other system, make sure avoid using * in the response headers (propagating response headers) unless you need them. If you need them, you can use it selective ones instead of all

      http%20receiver%20adapter%20properties

      http receiver adapter properties