cancel
Showing results for 
Search instead for 
Did you mean: 

SCPI: How to log in groovy script for message mapping

mwoelm
Participant
0 Kudos
1,261

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

View Entire Topic
kuznetsov_in2
Explorer

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;
}
mwoelm
Participant
0 Kudos

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

mwoelm
Participant
0 Kudos

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.

kuznetsov_in2
Explorer

messageLog.addAttachmentAsString("Log - Message", "xxxxx") is wrong, because the function has 3 args.

messageLog.addAttachmentAsString("Log - Message",   "xxxxx", "text/plain"); //ok
mwoelm
Participant
0 Kudos

oh! 😄

Thank you. Too hot here in germany. Didn't see that 😉