Hello Experts,
I'm trying to build an xml body using groovy script from different sender. I could build xml file and convert to string, same way I could test in IntelliJ without an issue. when I deploy the same code in CPI, I'm getting the below Error.
com.sap.it.rt.adapter.http.api.exception.HttpResponseException: An internal server error occured: No signature of method: com.sap.gateway.ip.core.customdev.processor.MessageImpl.SetBody() is applicable for argument types (java.lang.String) values: [<ProdCatalog>....

Groovy Script
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.MarkupBuilder
import groovy.xml.XmlSlurper
def Message processData(Message message) {
//Body
def body = message.getBody();
def root = new XmlSlurper().parseText(body)
def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
builder.ProdCatalog {
'ArrayOfPCatInfo' {
root.Root.each { item ->
'PCatInfo' {
'PFC'(item.PFCCode)
'PF'(item.ProductFamily)
'S'(item.Security)
'PC'(item.TFSProductID)
'P'(item.ProductDescription)
}
}
}
'ArrayOfPCatVersion' {
root.Root.Version.Version.Package.Package.Module.Module.each { item ->
'PCatVersion' {
'PC'(item.parent().parent().parent().parent().parent().parent().TFSProductID)
'VC'(item.parent().parent().parent().parent().VersionCode)
'VC'(item.parent().parent().parent().parent().VersionDescription)
'PKC'(item.parent().parent().PackageCode)
'PK'(item.parent().parent().PackageDescription)
'MC'(item.ModuleCode)
'M'(item.ModuleDescription)
}
//println item.parent().parent().PackageDescription
}
root.Root.Version.Version.Package.Package.each { item ->
if (item.Module.Module.size() <= 0) {
'PCatVersion' {
'PC'(item.parent().parent().parent().parent().TFSProductID)
'VC'(item.parent().parent().VersionCode)
'VC'(item.parent().parent().VersionDescription)
'PKC'(item.PackageCode)
'PK'(item.PackageDescription)
'MC'("NULL")
'M'("NULL")
}
}
}
root.Root.Version.Version.each { item ->
if (item.Package.Package.size() <= 0) {
'PCatVersion' {
'PC'(item.parent().parent().TFSProductID)
'VC'(item.VersionCode)
'VC'(item.VersionDescription)
'PKC'("NULL")
'PK'("NULL")
'MC'("NULL")
'M'("NULL")
}
}
}
}
}
// println("-----------------" + dc)
def op = writer.toString()
message.SetBody(op)
return message;
}
As I'm still in learning phase of CPI, any explanation/guidance/recommended approach along with solution would be much helpful
Thanks,
Senz
Request clarification before answering.
Hi senz.evo,
Hope you are doing well!
Could you please try message.setBody(op) ?
Regards,
Pavan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there
You are calling SetBody with an uppercase "S"; the correct method name is setBody with a lowercase "s".
Regards,
Morten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi senz.evo
No worries - we all make mistakes. This one is hard to catch before the script actually runs, though. As you already learned, the editor doesn't check or compile the code. But look on the bright side: Now you know how to spot this error, should it happen again 😄
Have fun with CPI!
Regards,
Morten
Hi Morten,
Just found out a blog that I'm looking for.
https://blogs.sap.com/2020/04/06/faster-groovy-development-for-sap-cpi-without-installing-an-ide/
Cool,
Senz
Hello again senz.evo
Ah yes, that's true. Nice find.
Another shortcut is to use the simulation mode to run the script step. That will execute the code, without you having to deploy the entire iflow and call it from somewhere like PostMan.
If you haven't played with the simulation mode yet, take this opportunity to try it out. It's a really useful way to test your work while you are building the iflow.
Regards,
Morten
Thanks a lot Morten, I'm fired up 🙂
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.