Skip to Content

Re-using Java mapping from SAP PI in SAP CPI using Groovy

Hi Experts,

Is it possible to reuse older java mappings from PI in CPI by calling them in groovy?

i want to reuse my old java mappings from within PI/PO in CPI.

I have imported the jar files into CPI and i am trying to call the mapping class from within groovy.

Here is my groovy code;

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

import java.util.HashMap;

import Tester.TestBO; // importing the java class from jar

def Message processData(Message message)

{

//Body as string def body = message.getBody(java.lang.String) as String;

def javaMapping = new TestBO(); // reference jar class

def result = javaMapping.transform(body); // calling the transform method

message.setBody(result); // setting the body

return message; // returning the message that should be mapped

}

With this i am getting the following error;

"No signature of method: Tester.TestBO.transform() is applicable for argument types: (java.lang.String) values; (my XML structure i want to map) "

Any help would be appreciated

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • May 08 at 07:15 PM

    Hi Dale,

    def result = javaMapping.transform(body); // calling the transform method

    "body" is a variable of type String whereas the signature of the method transform has an argument of type TransformationInput and another one of type TransformationOutput.

    Normally I take the code of the method transform (in some cases also in the method execute) which usually is called by the method transform) and adapt it as follows in the groovy script:

    1. convert "body" into a variable of type InputStream
    2. adjust the JM code in accordance with groovy syntax
    3. convert the result of the JM (usually an OutputStream object) back into String to set the new body

    It ends up you develop a code sequence like this:

    String->InputStream->Document->[processing/coding]->Document->OutputStream->String

    Regards.

    JT

    Add comment
    10|10000 characters needed characters exceeded