cancel
Showing results for 
Search instead for 
Did you mean: 

User defined exceptions in CPI

ananda_paul
Explorer
0 Kudos
3,805

Hi All,

I am new to SAP and CPI. I have a very good background in Java and J2EE.

I have developed a workflow in CPI where I am parsing the XML and checking a particular value. If that value is less than 5 (for ex), then I am throwing an exception with customised message as "The value is less than 5. Please check". I retrieve the exception message and print them in the messageLog. The workflow is working as expected.

Question is that the exception message is printed along with Groovy errors. It looks like there is no such method. Please see the error below:

No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.Exception() is applicable for argument types: (java.lang.String) values: [The value is less than 5. Please check]

I am expecting just the message. I have also attached Groovy script

def Message processData(Message message) {
if (val<5){
    throw exception("The value is less than 5. Please check")
  }
}

def Message logException(Message message){
  def exceptionMsg = message.getProperty("CamelExceptionCaught")
  def messageLog = messageLogFactory.getMessageLog(message)
  messageLog.addAttachmentAsString("Exception Message",exceptionMsg.getMessage(),"text/plain")     
  return message
}

By the look of the error, it looks like there is no such method with the signature. Please let me know where I am wrong.

View Entire Topic
Sriprasadsbhat
Active Contributor
0 Kudos

Hello Ananda,

I have replicated your scenario and this is what you will get from SAP CPI custom Exception perspective.

Exception Message [${exception.message} ]: javax.script.ScriptException: java.lang.Exception: java.lang.Exception: The value is less than 5. Please check@ line 16 in script2.groovy

Exception stacktrace[ ${exception.stacktrace} ]:javax.script.ScriptException: java.lang.Exception: java.lang.Exception: The value is less than 5. Please check@ line 16 in script2.groovy at com.sap.gateway.ip.core.customdev.processor.IGWScriptProcessor.process(IGWScriptProcessor.java:264) at sun.reflect.GeneratedMethodAccessor1117.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:408) at org.apache.camel.component.bean.MethodInfo$1.doProceed(MethodInfo.java:279) at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:252) at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:177) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:95) at com.sap.it.op.agent.collector.camel.MplInterceptor$MplAsyncProcessor.process(MplInterceptor.java:195) ... 72 more

Regards,

Sriprasad Shivaram Bhat

rupertc
Explorer
0 Kudos

so how to make ONLY the message appear in the log without the "javax.script.ScriptException: java.lang.Exception: java.lang.Exception: " part?

from the example above, if we want in the MPL to show just "The value is less than 5. Please check"

not the stuff around it like you showed: "javax.script.ScriptException: java.lang.Exception: java.lang.Exception: The value is less than 5. Please check@ line 16 in script2.groovy"