Dear all,
I have been using Groovy scripting to log my Payload as an attachment in SCPI. (SAP Cloud Platform Integration)
Sometimes the script doesn't log my payload as my attachment.But sometimes it does.
Is there any other setting to be enabled in SCPI or SAP Cloud Platform to enable this ?
Some kind of Permissions or Roles is required ?
Below is the script I am using:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def bodyAsString = message.getBody(String.class);
def messageLog = messageLogFactory.getMessageLog(message);
messageLog.setStringProperty("Logging#1", "Printing Payload As Attachment");
messageLog.addAttachmentAsString("Log Payload",bodyAsString,"text/xml");
return message;
}
I am just using the script after the request reply as below:

Even in Logs, I am not getting Logging#1", "Printing Payload As Attachment

Request clarification before answering.
Hi Sravan,
Yes, we need to add.
def bodyAsString =message.getBody(String.class);In the statement you are trying to convert from message type to String type but actually i think it is coming as Bufferd stream so we need to add the code.
BufferedInputStream bis = new BufferedInputStream(message);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int result = bis.read();
while(result != -1) {
buf.write((byte) result);
result = bis.read();
}
// StandardCharsets.UTF_8.name() > JDK 7
return buf.toString("UTF-8");
<br>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Should the script be changes as following ?
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
BufferedInputStream bis = new BufferedInputStream(message);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int result = bis.read();
while(result != -1) {
buf.write((byte) result);
result = bis.read();
}
return buf.toString("UTF-8");
// def bodyAsString = message.getBody(String.class);
def messageLog = messageLogFactory.getMessageLog(message);
messageLog.setStringProperty("Logging#1", "Printing Payload As Attachment");
//messageLog.addAttachmentAsString("Log Payload",bodyAsString,"text/xml");
messageLog.addAttachmentAsString("Log Payload",buf,"text/xml");
return message;
}
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.