cancel
Showing results for 
Search instead for 
Did you mean: 

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

dalebyrne123ire
Explorer
0 Kudos

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

Woodside_Int
Discoverer
0 Kudos

Hi Dale ,

have you got solution on this because I am also looking for the same.

Accepted Solutions (0)

Answers (2)

Answers (2)

fatihpense
Active Contributor
0 Kudos
former_member244738
Participant
0 Kudos

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