Error in Java Mapping for Single XML conversion

We are working on ABAP Proxy --> SAP PI 7.1 --> SOAP (Synchronous Scenario).
(ECC -> PI -> Legacy CRM)
Client has provided a WSDL with Single Node of XML and asking us to pass the whole structure as an single string along with all the nodes of data structure. To perform mapping we are using Java Mapping.
Message which we are getting after Java Mapping:
Input
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SOReject_Sender xmlns:ns0="http://MTSINDIA/TC/SalesOrderReject">
   <ITEM>
      <sSlsOrderCode>1001</sSlsOrderCode>
      <sDlrCode>A250</sDlrCode>
      <sRejectReason>Z2</sRejectReason>
      <nCircleCode>2</nCircleCode>
   </ITEM>
</ns0:MT_SOReject_Sender>
Output
<?xml version="1.0" encoding="UTF-8"?><MT_Trg xmlns:ns="urn:Test_File_to_File"><stringinp>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;ns0:MT_SOReject_Sender xmlns:ns0="http://MTSINDIA/TC/SalesOrderReject"&gt;&lt;ITEM&gt;&lt;sSlsOrderCode&gt;1001&lt;/sSlsOrderCode&gt;&lt;sDlrCode&gt;A250&lt;/sDlrCode&gt;&lt;sRejectReason&gt;Insufficient Stock Balance&lt;/sRejectReason&gt;&lt;nCircleCode&gt;2&lt;/nCircleCode&gt;&lt;/ITEM&gt;&lt;/ns0:MT_SOReject_Sender&gt;</stringinp></MT_Trg>
Is ther any way from which we can convert &gt; as u201C>u201D and &lt; as u201C<u201D.  Required result is as follows
Required Output
<?xml version="1.0" encoding="UTF-8"?><MT_Trg xmlns:ns="urn:Test_File_to_File"><stringinp><?xml version="1.0" encoding="UTF-8"?><ns0:MT_SOReject_Sender xmlns:ns0="http://MTSINDIA/TC/SalesOrderReject"><ITEM><sSlsOrderCode>1001</sSlsOrderCode><sDlrCode>A250</sDlrCode><sRejectReason>Insufficient Stock Balance</sRejectReason><nCircleCode>2</nCircleCode></ITEM></ns0:MT_SOReject_Sender></stringinp></MT_Trg>
We are using following Java Code for the same.
import java.io.BufferedReader;
          import java.io.FileInputStream;
          import java.io.FileOutputStream;
          import java.io.InputStream;
          import java.io.InputStreamReader;
          import java.io.OutputStream;
          import java.util.Map;
          import javax.xml.parsers.DocumentBuilder;
          import javax.xml.parsers.DocumentBuilderFactory;
          import javax.xml.transform.Transformer;
          import javax.xml.transform.TransformerFactory;
          import javax.xml.transform.dom.DOMSource;
          import javax.xml.transform.stream.StreamResult;
          import org.w3c.dom.Element;
          import org.w3c.dom.Document;
          import org.w3c.dom.Text;
          import com.sap.aii.mapping.api.*;
          import com.sap.aii.mapping.api.StreamTransformation;
public class SingleStr implements StreamTransformation{
      * @author user
      * To change the template for this generated type comment go to
      * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
                public static void main(String args[]) throws Exception {
            FileInputStream inFile =
             new FileInputStream("C:/Documents and Settings/user.HR0102WILT00033/Desktop/Input.XML");
            FileOutputStream outFile =
             new FileOutputStream("C:/Documents and Settings/user.HR0102WILT00033/Desktop/Output.XML");
             SingleStr xml = new SingleStr();
            xml.execute(inFile, outFile);
            System.out.println("Success");
           public void setParameter(Map param) {
            Map map = param;
           public void execute(InputStream in, OutputStream out)
            throws com.sap.aii.mapping.api.StreamTransformationException {
            try {
             //************************Code To Generate The XML Parsing Objects*****************************//    
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
             DocumentBuilder db = dbf.newDocumentBuilder();
             TransformerFactory tf = TransformerFactory.newInstance();
             Transformer transform = tf.newTransformer();
             //Document doc = db.parse(in);
             Document docout = db.newDocument();
             Element root = docout.createElement("MT_Trg");
             root.setAttribute("xmlns:ns","urn:Test_File_to_File");
             docout.appendChild(root);
             Element stringinp = docout.createElement("stringinp");
             root.appendChild(stringinp);
             BufferedReader inpxml = new BufferedReader(new InputStreamReader(in));
             StringBuffer buffer = new StringBuffer();
             String line="";
             while ((line = inpxml.readLine()) != null)
             buffer.append(line);
             String inptxml=buffer.toString();
             Text srcxml = docout.createTextNode(inptxml);
             stringinp.appendChild(srcxml);
             DOMSource domS = new DOMSource(docout);
             transform.transform((domS), new StreamResult(out));
             } catch (Exception e) {
               System.out.print("Problem parsing the file: " + e.getMessage());
               e.printStackTrace();
Please help!!

We are using following Java Code for the same.
import java.io.BufferedReader;
          import java.io.FileInputStream;
          import java.io.FileOutputStream;
          import java.io.InputStream;
          import java.io.InputStreamReader;
          import java.io.OutputStream;
          import java.util.Map;
          import javax.xml.parsers.DocumentBuilder;
          import javax.xml.parsers.DocumentBuilderFactory;
          import javax.xml.transform.Transformer;
          import javax.xml.transform.TransformerFactory;
          import javax.xml.transform.dom.DOMSource;
          import javax.xml.transform.stream.StreamResult;
          import org.w3c.dom.Element;
          import org.w3c.dom.Document;
          import org.w3c.dom.Text;
          import com.sap.aii.mapping.api.*;
          import com.sap.aii.mapping.api.StreamTransformation;
public class SingleStr implements StreamTransformation{
           public static void main(String args[]) throws Exception {
            FileInputStream inFile =
             new FileInputStream("C:/Documents and Settings/user.HR0102WILT00033/Desktop/Input.XML");
            FileOutputStream outFile =
             new FileOutputStream("C:/Documents and Settings/user.HR0102WILT00033/Desktop/Output.XML");
             SingleStr xml = new SingleStr();
            xml.execute(inFile, outFile);
            System.out.println("Success");
           public void setParameter(Map param) {
            Map map = param;
           public void execute(InputStream in, OutputStream out)
            throws com.sap.aii.mapping.api.StreamTransformationException {
            try {
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
             DocumentBuilder db = dbf.newDocumentBuilder();
             TransformerFactory tf = TransformerFactory.newInstance();
             Transformer transform = tf.newTransformer();
             //Document doc = db.parse(in);
             Document docout = db.newDocument();
             Element root = docout.createElement("MT_Trg");
             root.setAttribute("xmlns:ns","urn:Test_File_to_File");
             docout.appendChild(root);
             Element stringinp = docout.createElement("stringinp");
             root.appendChild(stringinp);
             BufferedReader inpxml = new BufferedReader(new InputStreamReader(in));
             StringBuffer buffer = new StringBuffer();
             String line="";
             while ((line = inpxml.readLine()) != null)
             buffer.append(line);
             String inptxml=buffer.toString();
             Text srcxml = docout.createTextNode(inptxml);
             stringinp.appendChild(srcxml);
             DOMSource domS = new DOMSource(docout);
             transform.transform((domS), new StreamResult(out));
             } catch (Exception e) {
               System.out.print("Problem parsing the file: " + e.getMessage());
               e.printStackTrace();
Please help!!

Similar Messages

  • Error in Java Mapping program

    Hi friends,
    I am tryin java mapping for first time.. and created one java program using link https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/wholePayloadtoaXML+field
    But when I am compiling it using JAVAC, I am getting following error message that
    package com.sap.aii.mapping.api does not exist . How can I solve this error.
    Complete error is as follows:
    C:j2sdk1.4.2_16-x64 in>javac PayloadToXMLField.java
    PayloadToXMLField.java:1: package com.sap.aii.mapping.api does not exist
    import com.sap.aii.mapping.api.StreamTransformation;
                                   ^
    PayloadToXMLField.java:2: package com.sap.aii.mapping.api does not exist
    import com.sap.aii.mapping.api.AbstractTrace;
                                   ^
    PayloadToXMLField.java:3: package com.sap.aii.mapping.api does not exist
    import com.sap.aii.mapping.api.StreamTransformationConstants;
                                   ^
    PayloadToXMLField.java:8: cannot resolve symbol
    symbol  : class StreamTransformation
    location: class PayloadToXMLField
    public class PayloadToXMLField implements StreamTransformation {
                                              ^
    PayloadToXMLField.java:16: cannot resolve symbol
    symbol  : class AbstractTrace
    location: class PayloadToXMLField
        AbstractTrace trace;
        ^
    PayloadToXMLField.java:27: cannot resolve symbol
    symbol  : class AbstractTrace
    location: class PayloadToXMLField
                (AbstractTrace) param.get(
                 ^
    PayloadToXMLField.java:28: cannot resolve symbol
    symbol  : variable StreamTransformationConstants
    location: class PayloadToXMLField
                    StreamTransformationConstants.MAPPING_TRACE);
                    ^
    PayloadToXMLField.java:43: cannot resolve symbol
    symbol  : variable outputPayload
    location: class PayloadToXMLField
            outputPayload =
            ^
    PayloadToXMLField.java:50: cannot resolve symbol
    symbol  : variable outputPayload
    location: class PayloadToXMLField
                out.write(outputPayload.getBytes());
                          ^
    9 errors
    Thanks,
    Brijesh Soni

    thanks , it is done now..
    the program is compiled properly and class file is generated.
    but m gettin error in mapping.
    in IR i created two message type  with data type as string.
    and i had imported the class file and java program using Imported archives.
    now in interface mapping mapping program i had selected type as Java Class.and name of java program.
    but when i tested it, it is giving error as Linkage error occurred when loading class zip/PayloadToXMLField
    Please suggest, M i doing some thing wrong?is any thing missing?
    Program tht i had used in java
    from link (https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/wholePayloadtoaXML+field):
    import com.sap.aii.mapping.api.StreamTransformation;
    import com.sap.aii.mapping.api.AbstractTrace;
    import com.sap.aii.mapping.api.StreamTransformationConstants;
    import java.util.Map;
    import java.io.*;
    public class PayloadToXMLField implements StreamTransformation {
        String strXML = new String();
        String outputPayload = new String();
         //Declare the XML tag for your XML message
         String StartXMLTag = "<Payload>";
         String EndXMLTag = "</Payload>";
        AbstractTrace trace;
        private Map param = null;
        public void setParameter(Map param) {
            this.param = param;
        public void execute(InputStream in, OutputStream out) {
            trace =
                (AbstractTrace) param.get(
                    StreamTransformationConstants.MAPPING_TRACE);
            trace.addInfo("Process Started");
            try {
                StringBuffer strbuffer = new StringBuffer();
                byte[] b = new byte[4096];
                for (int n;(n = in.read(b)) != -1;) {
                    strbuffer.append(new String(b, 0, n));
                strXML = strbuffer.toString();
            } catch (Exception e) {
                System.out.println("Exception Occurred");
            outputPayload =
                "<?xml version="1.0" encoding="UTF-8"?>"
                   + StartXMLTag
                   + strXML
                   + EndXMLTag;
            try {
                out.write(outputPayload.getBytes());
                   trace.addInfo("Process Completed");;
            } catch (Exception e) {
                trace.addInfo("Process Terminated: Error in writing out payload");;
    and detailed trace of error is:
    11:34:21 Start of test
    LinkageError at JavaMapping.load(): Could not load class: zip/PayloadToXMLField
    java.lang.NoClassDefFoundError: zip/PayloadToXMLField (wrong name: PayloadToXMLField) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:539) at java.lang.ClassLoader.defineClass(ClassLoader.java:448) at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingLoader.findClass(RepMappingLoader.java:175) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at com.sap.aii.ibrep.server.mapping.ibrun.RepJavaMapping.load(RepJavaMapping.java:136) at com.sap.aii.ibrep.server.mapping.ibrun.RepJavaMapping.execute(RepJavaMapping.java:50) at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingHandler.run(RepMappingHandler.java:80) at com.sap.aii.ibrep.server.mapping.rt.MappingHandlerAdapter.run(MappingHandlerAdapter.java:107) at com.sap.aii.ibrep.server.mapping.ServerMapService.transformInterfaceMapping(ServerMapService.java:127) at com.sap.aii.ibrep.server.mapping.ServerMapService.transform(ServerMapService.java:104) at com.sap.aii.ibrep.sbeans.mapping.MapServiceBean.transform(MapServiceBean.java:40) at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0_0.transform(MapServiceRemoteObjectImpl0_0.java:167) at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0_0p4_Skel.dispatch(MapServiceRemoteObjectImpl0_0p4_Skel.java:104) at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:319) at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:200) at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:136) at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33) at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41) at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37) at java.security.AccessController.doPrivileged(Native Method) at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:102) at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:172)
    11:34:21 End of test

  • Java Mapping for JDBC Interface

    Hi,
    please help on java mapping for my jdbc interface.
    my java code for jdbc is:
    Created on May 7, 2008
    TODO To change the template for this generated file go to
    Window - Preferences - Java - Code Style - Code Templates
    package XiMappingDB2.com.xi.test;
    @author miracle
    TODO To change the template for this generated type comment go to
    Window - Preferences - Java - Code Style - Code Templates
    Created on May 2, 2008
    To change the template for this generated file go to
    Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
    package com.xi.test;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    import java.util.HashMap;
    import java.util.Map;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import com.sap.aii.mapping.api.AbstractTrace;
    import com.sap.aii.mapping.api.MappingTrace;
    import com.sap.aii.mapping.api.StreamTransformation;
    import com.sap.aii.mapping.api.StreamTransformationConstants;
    import com.sap.aii.mapping.api.StreamTransformationException;
    @author kotla
    To change the template for this generated type comment go to
    Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
    public class NameMerge implements StreamTransformation  {
         private Map param = null;   
         private MappingTrace trace = null;
         public void setParameter(Map param){       
         this.param = param;
         if (param == null) { 
         this.param = new HashMap();
         public void execute(InputStream input, OutputStream output)      
         throws StreamTransformationException {
         AbstractTrace trace = null;     
         String RESULT = new String();
         trace =      
         (AbstractTrace) param.get(             
         StreamTransformationConstants.MAPPING_TRACE);
         try {          
        //Create DOM parser
        DocumentBuilderFactory factory =   
        DocumentBuilderFactory.newInstance();     
        DocumentBuilder builder = factory.newDocumentBuilder();
         //Parse input to create document tree
         Document doc = builder.parse(input);
                    trace.addInfo(doc.toString());
          //          Map the elements          
        Node root = doc.getFirstChild(); // gets the root element
         NodeList children = root.getChildNodes();
          for (int item = 0; item < children.getLength(); item++) {
          if (children.item(item) instanceof Element) {
          root = (Element) children.item(item);
          NodeList ch = root.getChildNodes();
          RESULT = RESULT.concat(ch.item(0).getNodeValue() + " ");
          trace.addInfo(RESULT); }
          catch (Exception e) {           
               trace.addDebugMessage(e.getMessage());      
       //Return the output document
       String document_exit = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:Person2 xmlns:ns0=\"urn:xxxxx.com:test:mapping:lookups\"><RESULT>" 
       + RESULT               
       + "</RESULT></ns0:Person2>";
         insertDB(RESULT);
       try
            output.write(document_exit.getBytes());
             catch (IOException e1) {
            trace.addDebugMessage(e1.getMessage());
    public void insertDB(String DETAILS){
        Statement stmt = null;
        Connection conn = null;
        try {
          conn = getConnection();
          conn.setAutoCommit(false);
          stmt = conn.createStatement();
          stmt.execute("insert into KUMAR(DETAILS) values ('"DETAILS"')");
          //System.out.println ('"DETAILS"');
          conn.commit();
          stmt.close();   
          conn.close();
        } catch (Exception e) {
          System.err.println("Error: " + e.getMessage());
          e.printStackTrace();
      public Connection getConnection() throws Exception {
        String driver = "com.ibm.db2.jcc.DB2Driver";
        String url = "jdbc:db2://172.17.4.24:50000/SAMPLE";
        String username = "miracle";
        String password = "sairam";
        Class.forName(driver);
        Connection conn = DriverManager.getConnection(url, username, password);
        return conn;
    but we are getting the following error:Linkage error occurred when loading class JavaDatabaseApp/XiMappingDB2/com/xi/test/NameMerge (http://FILE2JDBC_US, 7d7b3141-f4d1-11dc-b25e-d5d5c0a80198, -1)
    Start of test
    LinkageError at JavaMapping.load(): Could not load class: JavaDatabaseApp/XiMappingDB2/com/xi/test/NameMerge
    java.lang.NoClassDefFoundError: JavaDatabaseApp/XiMappingDB2/com/xi/test/NameMerge (wrong name: XiMappingDB2/com/xi/test/NameMerge) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:539) at java.lang.ClassLoader.defineClass(ClassLoader.java:448) at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingLoader.findClass(RepMappingLoader.java:175) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at com.sap.aii.ibrep.server.mapping.ibrun.RepJavaMapping.load(RepJavaMapping.java:136) at com.sap.aii.ibrep.server.mapping.ibrun.RepJavaMapping.execute(RepJavaMapping.java:50) at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingHandler.run(RepMappingHandler.java:80) at com.sap.aii.ibrep.server.mapping.rt.MappingHandlerAdapter.run(MappingHandlerAdapter.java:107) at com.sap.aii.ibrep.server.mapping.ServerMapService.transformInterfaceMapping(ServerMapService.java:127) at com.sap.aii.ibrep.server.mapping.ServerMapService.transform(ServerMapService.java:104) at com.sap.aii.ibrep.sbeans.mapping.MapServiceBean.transform(MapServiceBean.java:40) at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0.transform(MapServiceRemoteObjectImpl0.java:167) at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0p4_Skel.dispatch(MapServiceRemoteObjectImpl0p4_Skel.java:104) at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:320) at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:198) at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:129) at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33) at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41) at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37) at java.security.AccessController.doPrivileged(Native Method) at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100) at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170).
    please solve this issue.

    Uday,
    May be you have uploaded class file into external definitions.
    You need to Zip the class file into .jar  and then upload into external definitions of integration repository
    Regards,
    Kiran Bobbala

  • Java mapping for Remove and Add of  DOCTYPE Tag

    HI All,
    i have one issue while the Java mapping for Remove and Add of  DOCTYPE Tag   in Operation Mapping .
    it says that , while am testing in Configuration Test "  Problem while determining receivers using interface mapping: Error while determining root tag of XML"
    Receiver Determination...
    error in SXMB MOni
    " SAP:Category>XIServer</SAP:Category>
      <SAP:Code area="RCVR_DETERMINATION">CX_RD_PLSRV</SAP:Code>
      <SAP:P1>Problem while determining receivers using interface mapping: Error while determining root tag of XML: '<!--' or '<![CDATA[' expected</SAP:P1>
    plz provide solutions
    Thanks in advance.

    Hi Mahesh,
    I understand, you are using extended Receiver Determination using Operational Mapping (which has Java Mapping). And, there is an error message u201CError while determining root tag of XMLu201D, when you are doing configuration test.
    Can you please test, the Operational Mapping (which has Java Mapping) separately in ESR, with payload which is coming now. It should produce a XML something like this [Link1|http://help.sap.com/saphelp_nwpi711/helpdata/en/48/ce53aea0d7154ee10000000a421937/frameset.htm]
    <Receivers>
    <Receiver>
      <Party agency="016" scheme="DUNS">123456789</Party>
      <Service>MyService</Service>
    </Receiver>
    <Receiver>
      <Party agency="http://sap.com/xi/XI" scheme="XIParty"></Party>
      <Service>ABC_200</Service>
    </Receiver>
    </Receivers>
    If it is not (I Think it will not), then there is some problem in Java Mapping coding. Please correct it. Last option, if your Java code is small in length; you may paste it here, so that we can have a look at the cause of issue.
    Regards,
    Raghu_Vamsee

  • Getting Error in java mapping: Parsing empty source. Root element expected!

    Hi Experts,
       I am using java mapping for schema validation of input message. I have followed all the standard procedures and implemented the java class in the interface mapping.
    My interface mapping is like this:
    OrderData --->Java Class ---SchemaValidate
                         Mesg Map ---OrderData_to_BAP --->BAPI Msg
    So first I want to validate the schema of the input message. If the input message is invalid then XI should throw an exception. Then I use the actual message mapping to map the input order data to the BAPI input parameters.
    In the java code I am using xerces parser.
    The java code works fine when I run it as a standalone application.
    The interface mapping also works fine if I don't include the java mapping. Ofcourse schema validation does not happen.
    But when I test the interface mapping by including the java mapping then I am getting the error:
    Call method execute of the application Java mapping SchemaValidate
    Java mapping SchemaValidate completed. (execute() of SchemaValidate
    com.sap.aii.utilxi.misc.api.BaseRuntimeException: Parsing an empty source. Root element expected!
    What am I doing wrong? Why it is not getting the root element?
    My Java code is as follows:
    import com.sap.aii.mapping.api.StreamTransformation;
    import com.sap.aii.mapping.api.StreamTransformationConstants;
    import com.sap.aii.mapping.api.StreamTransformationException;
    import java.io.*;
    import java.util.Map;
    import javax.xml.parsers.*;
    import org.xml.sax.helpers.*;
    import org.xml.sax.*;
    import org.apache.xerces.jaxp.*;
    Sample mapper for SAP-XI
    @author Gopal
    public class SchemaValidate implements StreamTransformation {
        //Constants when using XML Schema for SAX parsing.
         static final String JAXP_SCHEMA_LANGUAGE =
         "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
         static final String W3C_XML_SCHEMA =
         "http://www.w3.org/2001/XMLSchema";
         static final String JAXP_SCHEMA_SOURCE =
         "http://java.sun.com/xml/jaxp/properties/schemaSource";
    Injection of mapping parameters
    from integration engine
    @param map Map with configuration data
        public void setParameter(Map map) {
    Mapping implementation
    @param inputStream Input data from integration engine
    @param outputStream Output data to integration engine
        public void execute(InputStream inputStream,
                            OutputStream outputStream)
          throws StreamTransformationException {
            try {
                  // obtain an object of class javax.xml.parsers.SAXParser,
                  SAXParserFactory spf = SAXParserFactoryImpl.newInstance();
                  spf.setNamespaceAware(true);
                  spf.setValidating(true);
                  SAXParser sp = spf.newSAXParser();
                  // setup the schema file
                  sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                  sp.setProperty(JAXP_SCHEMA_SOURCE, new File("IOReqMsgSchema.xsd"));
                  //parse the input xml using the given schema
                  sp.parse(inputStream, new ParseErrorHandler());
            catch(SAXException se) {
              se.printStackTrace();
            catch ( Exception e ) {
              throw new StreamTransformationException( e.getMessage() );
    My input message is :
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:OrderCreate_request xmlns:ns0="mynamespace">
       <ORDER>HTEST1234567</ORDER>
       <ORDER_TYPE>z001</ORDER_TYPE>
       <ORDER_NAME>Test Order</ORDER_NAME>
       <CO_AREA>INTC</CO_AREA>
       <CCTR_POSTED>1234567890888888888</CCTR_POSTED>
       <CURRENCY>USD</CURRENCY>
       <PERSON_RESP>12345679</PERSON_RESP>
    </ns0:OrderCreate_request>
    Kindly help! please this is urgent!!!!!!
    Thanks
    Gopal
    Edited by: gopalkrishna baliga on Feb 28, 2008 9:34 AM

    Hi Stefan,
       I did the code changes to return output stream and the java code works perfectly in standalone mode in my PC.
       But when I use the same in the Java mapping with XI then It throws an error "Getting Error in java mapping: Parsing empty source. Root element expected!".
    My XI J2EE server has JDK1.4.3.11.
    Is there any limitation of using SAX parser in XI? If Yes, then which parser should be used for schema validation in XI?
    I have included the XSD file for schema validation along with class files in the .jar file. This jar file is then imported in XI repository. Is the XI engine not able to read the XSD file?
    Do I have to handle reading XSD file differently? Any suggession how?
    Is this parser error due to some security access?
    Kindly help me! I have been struggling with this problem since 2 weeks. I will be greatfull to you if you can help me.
    Thanks
    Gopal

  • Java Mapping for Flat file

    hello SDNers,
    I am using JAVA mapping for converting FlatFlie IDoc to IDoc and i am using metadata for this.While downloading metadata from SAP system, the first segment in the data record is having level 2.
    1) What is the use of Level in metadata?
    2)  What is the Level for first segment in data record of metadata. Is it Level 1 or Level 2?
    3) I am facing an error while appending the node. Is it because of Level differs?
    Plese help me out and thanks in advance

    Hi,
    >>>I am using JAVA mapping for converting FlatFlie IDoc to IDoc and i am using metadata for thi
    why do you develop is from scratch is the code is already there - just copy and paste...
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/46759682-0401-0010-1791-bd1972bc0b8a
    >>>1) What is the use of Level in metadata?
    this shows how the nested segments in IDOC are to be understood
    >>>3) I am facing an error while appending the node. Is it because of Level differs?
    no, it becase your code is incorrect - the level velidation will be done at the receiver
    Regards,
    Michal Krawczyk

  • Executing Java mapping for SAP XI using eclipse.

    Hi Experts,
    I want to create a java mapping for XI scenario in Eclipse IDE.
    Actually I need to import some jar files to get the following packages
    import com.sap.aii.mapping.api.*;
    import com.sap.engine.lib.xml.util.*;
    Can anybody tell me, where can I get these packages so that I can test my java mapping.
    Regards,
    Shri

    Hi Shripad,
    for location of jar files:->
               Ref : michal weblogs Frequently asked question.
    How to write java mapping and test->
               Ref:  Stefan weblog  How test simple java mapping.
    Before putting a forum, first go for search.
    Regards,
    Deviprasad.

  • Error in codepage mapping for source system

    Hi Experts,
    I am getting the following error while loading data from ECC only for Account COPA datasource.
    Error in codepage mapping for source system. Error text:
    Message no. RSDS_ACCESS013
    Regards,
    Sandeep Sharma

    Hi Sandeep,
    This is a issue related to idocsRFC connections from teh sourcesystem....
    U can contact ur BASIS team to solve this...
    From their end they have to chk the unprocessed/errored idocs in BD87...
    They have to run a report:RBDAGAIN to process the errored idoc's in the source which are in STATUS:'02'.
    This is a solution for temporarilrly basis...
    If this occurs regularly they have to change the settings in SM59 which is so important...
    Refer exact note for this: 784381
    The SAP note 613389 may also be relevant for the error message "Could not find code page for receiving system", please check the information given in the note and see if you can use it to resolve the problem.
    Regards,
    Marasa.

  • Error in codepage mapping for source system. Error

    Hi BW Experts,
    I am facing following error:
    Error message: Error in codepage mapping for source system. Error text:
    Details: Inbound Processing ( 1000  Records ) : Errors occurred
                Error in codepage mapping for source system. Error text:
                Update PSA ( 0 Records posted ) : Missing messages
    I repeated the delta working and everything fine.
    Does anybody know why this error occurs?

    Run rsa13 (for bi 7.0) find your source system which one you are using for data transfer and double  click on it and find special options there select  the optioned i mentioned already.
    Please search SDN you can fin threads related to this thread
    if not let me know.
    Regards.

  • Error in codepage mapping for source system. Error text:

    guyz,
    im facing the below issue in prod.
    Error in codepage mapping for source system. Error text:
    Message no. RSDS_ACCESS013
    Collection in source system ended
    Error message during processing in BI
    Diagnosis
    An error occurred in BI while processing the data. The error is documented in an error message.
    System Response
    A caller 01, 02 or equal to or greater than 20 contains an error meesage.
    Further analysis:
    The error message(s) was (were) sent by:
    Inbound Processing
    Procedure
    Check the error message (pushbutton below the text).
    Select the message in the message dialog box, and look at the long text for further information.
    Follow the instructions in the message.
    need your guidance,
    cheerz,
    raps.
    Edited by: raps on Mar 1, 2012 9:39 AM

    Hi ,
    Kindly go throught the following threads for your issue resolution::
    Error in code page mapping for Source System
    Erroe in source system
    Regards,
    Arpit

  • JAVA Mapping for XML conversion during runtime

    Dear SAP JAVA experts,
    For quite I have been struggling to keep the JAVA code in place for JSON to XML conversion being a newbie.
    Following is the code snippet.
    import java.io.InputStream;
    import net.sf.json.JSON;
    import net.sf.json.JSONSerializer;
    import net.sf.json.xml.XMLSerializer;
    import org.apache.commons.io.IOUtils;
    import com.sap.aii.mapping.api.AbstractTransformation;
    import com.sap.aii.mapping.api.StreamTransformationException;
    import com.sap.aii.mapping.api.TransformationInput;
    import com.sap.aii.mapping.api.TransformationOutput;
    import com.sap.aii.utilxi.core.io.IOUtil;
    public class RuntimeJSONtoXML extends AbstractTransformation {
      public void transform(TransformationInput input, TransformationOutput output)
      throws StreamTransformationException {
      try
    //InputStream is = JSONtoXML.class.getResourceAsStream("JSON.txt");
       String strJSON = "";
       InputStream inputStream = input.getInputPayload().getInputStream();
       inputStream.close();
       String jsonData = IOUtils.toString(strJSON);
               XMLSerializer serializer = new XMLSerializer();
               JSON json = JSONSerializer.toJSON( jsonData );
               String xml = serializer.write( json );
               //System.out.println(xml);
               output.getOutputPayload().getOutputStream().write(strJSON.getBytes());
      catch(Exception ie) { }
    Caught unaware of 2 queries.
    1.I have added the com.sap.aii.utilxi.core.io.IOUtil jar files from the PI server even though its displays error "The com.sap.aii.utilxi can not be resolved". Also I added the XPI libraries in NWDS but nothing moving to solve the issue.
    2. I have commented the line of code where I have placed a test file in the path to test it i.e. JSON.text. But when it is deployed as Archived files, then this code has to be replaced.
    The Method toString(InputStream) in the type IOUtils is not applicable for the arguments (String)
    Regards
    Rebecca..

    1.I have added the com.sap.aii.utilxi.core.io.IOUtil jar files from the PI server even though its displays error "The com.sap.aii.utilxi can not be resolved". Also I added the XPI libraries in NWDS but nothing moving to solve the issue.
    Which jar file did you add?
    /usr/sap/<<SID>>/DVEBMGS<<SYSNO>>/j2ee/cluster/bin/ext/com.sap.xi.util.misc/lib
    jar file name : com.sap.aii.utilxi.core.jar
    2. I have commented the line of code where I have placed a test file in the path to test it i.e. JSON.text. But when it is deployed as Archived files, then this code has to be replaced.
    The Method toString(InputStream) in the type IOUtils is not applicable for the arguments (String)
    To read the input stream you should have
    InputStream inputstream = transformationInput.getInputPayload().getInputStream();
    Please refer to below blog just to get an idea on working with input stream and output stream.
    Dynamic file name for pass-through scenario - Process Integration - SCN Wiki

  • Java mapping and no content conversion

    Hi all,
    I have a file to idoc scenario. The file is in flat idoc format and I've made my own java mapping that gets the flat file and converts it to idoc xml format.
    I don't use content conversion in the sender file adapter because I don't wan't the file to be converted to xml before the java mapping processes it. But with this configuration my scenario fails in the interface determination step, as it doesn't find an xml to apply the java mapping.
    Is there a way to make it work as I want? (with my java mapping and not applying content conversion?) If not, is there a way to put all the file in a single xml tag using content conversion?
    I mean something like this:
    <FILE>
    </FILE>
    This way it would be easy for my java mapping to remove the tags and work with the flat file as it does now.
    Thanks in advance.

    Thanks Stephan for your answer.
    In fact I have the defined that interface, as well as a dummy data type and message type that uses it. I still get the error though. My guess is that, as I don't use content conversion in file adapter (message protocol is file) the outbound message is in fact not in xml format, and it cannot identify it in interface determination. That's my guess but perhaps I'm wrong?
    This is the error I'm getting:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Interface Determination
      -->
    - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
      <SAP:Category>XIServer</SAP:Category>
      <SAP:Code area="IF_DETERMINATION">CX_ID_PLSRV</SAP:Code>
      <SAP:P1>No interface determination found for outbound interface http://********.****/EDELIVERY.SI_OUT_A_0596_RECADV: Error while determining root tag of XML: BOM / charset detection failed</SAP:P1>
      <SAP:P2 />
      <SAP:P3 />
      <SAP:P4 />
      <SAP:AdditionalText />
      <SAP:Stack>Error when determining the inbound interface: No interface determination found for outbound interface http://********.****/EDELIVERY.SI_OUT_A_0596_RECADV: Error while determining root tag of XML: BOM / charset detection failed No interface determination found for outbound interface http://********.****/EDELIVERY.SI_OUT_A_0596_RECADV: Error while determining root tag of XML: BOM / charset detection failed Error while determining root tag of XML: BOM / charset detection failed Error while parsing an XML stream: 'BOM / charset detection failed'.</SAP:Stack>
      <SAP:Retry>M</SAP:Retry>
      </SAP:Error>
    Any idea?

  • XSLT-transformation in Java-Mapping with javax.xml

    Hi,
    we wanna use javax.xml for transformations in Java-Mapping.
    Inside the Java-mapping we read in XSL-files to transform a XML-stream. With XSLT 1.0 everything works fine - but with XSLT 2.0 we are getting runtime errors.
    Is it possible that javax.xml only supports XSLT 1.0?
    Regards
    Wolfgang

    Hi ,
    Jaxp 1.3 is available in this link -
    http://java.sun.com/webservices/jaxp/
    Use these jar files to process XSLT 2.0.
    Nanda

  • Java mapping for XSD Validation

    Hello,
    I have developed a Java mapping to validate an XML based on XSD.
    I works fine and generates a message with error details.
    I would like to create a report with all errors encountered during this Validation and to stop this message from being sent to the partner.
    But this Java mapping stops at first error encountered and generates an error message with first error only even though document has more errors further.
    Can anyone please let me know if there is an option to log all errors without allowing the message to go through?
    Thanks.
    Best Regards,
    Shweta

    Yes, as abhishek mentioned when you validate the instance document (XML) using standard parsers then they validate based on the spec provided in XSD and they stop at the first error. The link given using dom parser via java code will also stop at the first error.
    If you really want to validate the entire instance document then you might have to create a custom validator class which does validation for each and every fields and store it in an object like Vector or List or Map object.  Then when you throw exception you can retrieve that Map object  in the catch block and read all the individual error messages and display in log. This requires additional effort. In this case you dont rely on parser validation. Completely custom based.
    Example:
    Vector errorList = new Vector();
    if the field name is  SSN and if you see any alpha characters you add error for that field in the errorList
    If(SSN.matches("[a-zA-Z]")){
        do nothing
    }else{
        errorList.add("The fieldName SSN contains other than alpha characters");
    Like that you have to add error string mesg in the errorList object and return the errorList at the end.

  • Java mapping - for reading the binary file contents and changing filename

    Hi,
    I have already gone through the various bolgs and threads and have not been able to find a solution to my problem.
    One blog did give some idea but did not help- "JAAPPING", an alternate way of reading a CSV file
    I am not very good in java but have been trying some out recently to fulfill the interface requirements.
    I would really appreciate if you could help am I am giving below the detailed scenario below.
    Part 1- working fine - The incoming file looks like:
    :20:STMEMU096868DUBE
    :25:001180256210
    :28C:00371/00001
    :60F:C090617AED742136,92
    :61:0906300630CD34,27FINTCREDIT INTEREST
    26MAY2009 TO 25JUN2009
    :62F:C090630AED742171,19
    :64:C090630AED742171,19
    The file name as received is:TCDE.BLQSAM.SAEA2682.C0084025.A9G24T58.20090724195908
    This file without any conversion is placed on XI server dircetory folder.
    Part 2 - need to develop
    The file should now be renamed according to the incoming value in 2nd line - specifically the 12 digit value 001180256210 and placed on the R/3 dircetory folder.
    The new file name in the above example should be:
    AC_NO_001180256210_datetime
    The module for the above was created and the last time I checked it was working.
    However, when I wanted to do final testing in Dev and move the changes further, the module has seemed to have stopped working so I need an alternate solution fast.
    I was thinking of doing the Java mapping as I will be more in control as to what is going on thereby reducing the dependency.
    There is no need to create any target xml structure as the file as it is needs to be placed in the target folder with a new name.
    I can get the file name in UDF which I have already created but i am not usre if it working.
    Can you please help?
    Any help will be greatly appreciated.
    Regards,
    Archana
    +44-7867636863

    Hi Stephen
    The xml must be getting added in the below part of the code. It is coming from arg[0]
    You can put a check and get it removed.
    while ((len = arg0.read(buffer)) != -1) {
      arg1.write(buffer, 0, len);
    Regards
    Osman

Maybe you are looking for