cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

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

0 Likes
View Entire Topic
MortenWittrock
SAP Mentor
SAP Mentor

Hi there

You are calling SetBody with an uppercase "S"; the correct method name is setBody with a lowercase "s".

Regards,

Morten

former_member187312
Participant

Thanks Morten, little embarrassed 😅 myself about that silly mistake.

However, Is there any way to check the syntax to avoid such mistakes in future.

BR,

Senz.

MortenWittrock
SAP Mentor
SAP Mentor

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

former_member187312
Participant
MortenWittrock
SAP Mentor
SAP Mentor

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

former_member187312
Participant

Thanks a lot Morten, I'm fired up 🙂