Log All the HTTP Headers as JSON
This is a simple script that will log all headers as pretty JSON. It can be useful for debugging incoming HTTP requests.
This is a simple script that will log all headers as pretty JSON. It can be useful for debugging incoming HTTP requests.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.JsonBuilder;
import groovy.json.JsonOutput;
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String;
def builder = new JsonBuilder()
builder(message.getHeaders())
def prettyJson = JsonOutput.prettyPrint(builder.toString())
def messageLog = messageLogFactory.getMessageLog(message);
if(messageLog != null){
messageLog.addAttachmentAsString("HTTP Headers:", prettyJson, "application/json");
}
return message;
}
Key | Value |
---|---|
http_header1 | Hello! |
http_header2 | World! |