Technical Articles
How to handle etag if-match in CPI iflow
How to handle etag if-match in CPI iflow? I searched in blogs and found some blogs in this topic . Today I want demo in the most straight way . I will use the post physical inventory document item as the example. To post the document item, I need to get the etag for the document item first . Then I use the etag value as If-Match in header of the posting operation . If we don’t put If-Match in posting operation header, the resposne will end with error 428(Precondition Required) .
The following overview of the iflow:
The following is the screen shot of reading physical document item to get etag in header settings
The following is code of putting tag value as header value of If-Match
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
// //Body
// Reader reader = message.getBody(Reader);
// def A_PhysInventoryDocItem = new XmlSlurper().parse(reader) ;
// def stamp = A_PhysInventoryDocItem.A_PhysInventoryDocItemType.LastChangeDateTime;
// stamp = "W/\"datetimeoffset"+"'"+stamp+"'\"" ;
// stamp = stamp.replaceAll(":","%3A");
def headers = message.getHeaders();
def stamp = headers.get("etag");
message.setHeader("If-Match", stamp );
def body = message.getBody(java.lang.String);
message.setBody();
def messageLog = messageLogFactory.getMessageLog(message);
if (messageLog != null) {
messageLog.addAttachmentAsString('Iventory Document Item', body, 'application/json');
}
return message;
}
The following is screen shot of posting operation with allowing If-Match in header
The end!
Thank you for your time!
Best Regards!
Jacky Liu
Be the first to leave a comment
You must be Logged on to comment or reply to a post.