cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

messageLogFactory Vs MessageLogFactory in CPI Groovy scripting

srini_reddy1
Participant
0 Likes
4,729

I am trying to understand what is the difference between

MessageLogFactory and messageLogFactory

I am tried using below class to get the instance of message log but getting an exception as shown in error details.

com.sap.it.api.msglog.MessageLogFactory
Error Details java.lang.NoSuchMethodException: No signature of method: static com.sap.it.api.msglog.MessageLogFactory.getMessageLog() is applicable for argument types: (com.sap.gateway.ip.core.customdev.processor.MessageImpl) values: [com.sap.gateway.ip.core.customdev.processor.MessageImpl@172e1254]
Interface Java doc says this about the input parameter for MessageLogFactory interface.

The context object can be either a Camel Exchange, a CXF exchange, or a com.sap.it.api.msg.ExchangePropertyProvider.

This piece of code works fine

def logVariable(Message message, String name, String value) {
boolean enableLogging = Boolean.parseBoolean(message.getProperty("enable_logging") as String)
if (enableLogging) {
def messageLog = messageLogFactory.getMessageLog(message)
messageLog.setStringProperty(name, value)
}
}

This code gives me an error

def logVariable1(Message message){
def messageLog = MessageLogFactory.getMessageLog(message)
messageLog.setStringProperty("Test_Log", "Test Log")
}

Accepted Solutions (1)

Accepted Solutions (1)

MortenWittrock
SAP Mentor
SAP Mentor

Hi Srini

MessageLogFactory (upper case M) is the name of an interface in the com.sap.it.api.msglog package. messageLogFactory (lower case M), on the other hand, is the name of a variable made available to your scripts by the runtime. The variable references an instance of a class, which implements the MessageLogFactory (upper case M again) interface.

If you are curious about which class, run the following script:

import com.sap.gateway.ip.core.customdev.util.Message

def Message processData(Message message) {
    message.setBody(messageLogFactory.getClass().getName())
    return message
}

Right now it returns com.sap.it.op.agent.mpl.factory.impl.MessageLogFactoryImpl. The class is not important, though. What's important is that it implements the interface, and therefore lets you create MessageLog instances.

Regards,

Morten

srini_reddy1
Participant

Thanks, Morten.

It helps me understand it better now. I never thought of it as the implementation class for the interface. 🙂


Regards,

Srini

MichaelBuonoGKN
Participant

Answers (0)