Blog Archive

Thursday, June 21, 2018

java mapping reference links for SAP PI

Om


Referece1
csv to xml file and binary files dealing
xml format correction
https://blogs.sap.com/2015/02/08/how-to-create-java-mapping-in-sap-pi-po/

Reference2 code java mapping code
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();
    }
  }
}



youtube link



No comments:

Post a Comment