on 2022 Jul 20 8:08 AM
Hi community,
I want to log some messages in a groovy script in SCPI.
I know from standard scripts, I could get a message logger with this:
def messageLog = messageLogFactory.getMessageLog(message);
message is of type com.sap.gateway.ip.core.customdev.util.Message.
The problem is, whenever I try to pass the Message object in the groovy script used in a mapping (mmap), the script is not accepted.
def String methodName(String parameter, MappingContext context, Message message) .....
Is it possible to place any log messages in a groovy script that is invoked by a mmap?
Best Regards,
Michael
Hi Michael,
I would put messageLogFactory.getMessageLog(message) into some property "mpl" before mmap and use it inside mmap like that:
def String methodName(String parameter, MappingContext context) {
def messageLog = context.getProperty("mpl");
messageLog.setStringProperty("parameter", parameter);
return parameter;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ilya,
I tried your propasal. I added another groovy script before:
def Message processData(Message message) {
MessageLog messageLog = messageLogFactory.getMessageLog(message)
message.setProperty("messageLog",messageLog);
return message
}
In the other groovy script invoked by the mmap, I added this:
MessageLog messageLog = context.getProperty("messageLog") as MessageLog
if(messageLog != null){
messageLog.addAttachmentAsString("Log - Message", "xxxxx")
}
But sadly I get:
com.sap.xi.mapping.camel.impl.MappingContextImpl@2d2360dd, com.sap.aii.mappingtool.tf7.rt.Context@62a085a7] No signature of method: com.sap.it.op.agent.mpl.factory.impl.MessageLogImpl.addAttachmentAsString() is applicable for argument types: (java.lang.String, java.lang.String) values: [Log - Message, xxxxx]
although I explicitly use strict types. Any ideas? 😄
BR,
Michael
I have seen that you proposed to use
messageLog.setStringProperty(...)
That is accepted by the CPI and I can see message. I don't understand why the other method is not available although the type is actually not changed (or I don't see where/who is changing the implementation in the background)
But your message helped! Thank you.
messageLog.addAttachmentAsString("Log - Message", "xxxxx") is wrong, because the function has 3 args.
messageLog.addAttachmentAsString("Log - Message", "xxxxx", "text/plain"); //ok
User | Count |
---|---|
67 | |
10 | |
10 | |
10 | |
7 | |
7 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.