Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
stefan_grube
Active Contributor


In some forum entries, I found a question about debugging Java Mapping. There are a lot of Blogs about Java Mappings like this one of Thorsten Søbirk:
Using JAXP to both parse and emit XML in XI Java mapping programs

Now, how should you debug your code before a upload it to the XI? It is quite simple: Add the method "main" to your Java Mapping class.

Here is a template for a Java Mapping class with the method "main":


 

package sample;

import java.io.*;
import com.sap.aii.mapping.api.*;


public class MyJavaMapping extends AbstractTransformation {

DynamicConfiguration conf; // used for dynamic configuration
// (adapter-specific message attributes)
InputParameters param;     // used for input parameters


// the method "transform" is called by Java Mapping Runtime
public void transform (TransformationInput arg0, TransformationOutput arg1) 
throws StreamTransformationException {

conf = arg0.getDynamicConfiguration(); // provide dynamic configuration
param = arg0.getInputParameters();     // provide input parameters
this.execute(arg0.getInputPayload().getInputStream(),
arg1.getOutputPayload().getOutputStream());

}

// the method "execute" is called by "transform" and "main"
public void execute (InputStream in, OutputStream out) 
throws StreamTransformationException {


// Add your code here

}

// reading dynamic values
String getDynamicValue(String namespace, String name){

if (conf == null) // in test mode, dynamic parameters cannot be used.
return ""; // Use default values instead
DynamicConfigurationKey key =
DynamicConfigurationKey.create(namespace, name);
return conf.get(key);

}
 
// reading input parameters
String getInputParameter(String name){

if (param == null){  // in test mode, input parameters cannot be used.
return ""; // Use default values instead
} else {
return (String) param.getValue(name);
}
}

// the method "main" is using files for input and output
public static void main(String[] args) {

try {
InputStream in = new FileInputStream(new File("in.xml"));
OutputStream out = new FileOutputStream(new File("out.xml"));
MyJavaMapping myMapping = new MyJavaMapping();
myMapping.execute(in, out);
} catch (Exception e) {
e.printStackTrace();
}
}
}

 

All you have to do is placing an xml file "in.xml" in the working directory of your Java program, set a breakpoint and start the program.

API Documentation

https://help.sap.com/doc/javadocs_pi_sp3_xpi/7.1.3/en-US/index.html

Additional Information

See also this Weblog for Debugging Java Mappings using SAP Netweaver Developer Studio

Examples for Java Mapping (scroll down to III-Java Mapping)

7 Comments
Labels in this area