Output encoding in Java mapping ?

Hello,
I have written a Java mapping which reads an input document and creates an output document. My problem is, the German special characters are lost in the output document (wrong characters). This is strange, because I am only using regular DOM methods for adding the output nodes and values. Anybody has an idea where I have to explicitly define the output encoding ? XI automatically uses UTF-8, I am using the StandardDOMWriter class of the com.inqmy.lib.xml package from XI, and DocumentBuilder from javax.xml.parsers.
But the output is wrong nevertheless. I think the encoding is already set in the OutputStream input variable of the execute methods. So no need to be changed (?)
Code sample below:
public void execute(InputStream in, OutputStream out)  throws StreamTransformationException {
       DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
       DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
       Document idoc = documentBuilder.parse(in);   // input document           
       Document odoc = documentBuilder.newDocument();     // output document
       // create some elements and values with helper method below
      // write output document to stream
      odoc.appendChild(oRoot);
      StandardDOMWriter sdw = new StandardDOMWriter();
      sdw.write(odoc, out, null);               
    private Element createElement(String elementName, String value, Element parent, Document doc) {   
      Element element = createElement(elementName, parent, doc);
      // here we put the input content to output value
      element.appendChild(doc.createTextNode(value));     
      // ok, special character still there:
       trace.addInfo("Read back: " + getNodeValue(element));
      return element;
CSY

I solved the problem. For some reason, the inqmy parser does not work correctly. If I remember correctly, the SapXMLToolkit (from where it comes), is deprecated anyway.
Instead I use now standard JAXP transform streaming, and that works fine:
      // commented code does not convert german special characters correctly:
      //StandardDOMWriter sdw = new StandardDOMWriter();     
      //sdw.write(odoc, out, null);
     // Serialisation through Transform.
     DOMSource domSource = new DOMSource(odoc);
     StreamResult streamResult = new StreamResult(out);
     TransformerFactory tf = TransformerFactory.newInstance();
     Transformer serializer = tf.newTransformer();
     serializer.setOutputProperty(OutputKeys.ENCODING,"UTF-8");    
     serializer.setOutputProperty(OutputKeys.INDENT,"yes");
     serializer.transform(domSource, streamResult);                            
CSY

Similar Messages

  • XML not well formed - Java Mapping, Webservice to RFC Scenario

    Hello All Experts,
    I have facing a strange type of error. I have written a Java Mapping which implements a DOM parser to take a request from a Webservice and validate it on the basis of some prerequisites. i.e. If data in the incoming request is valid, it creates a message of the same structure type as the input. If the incoming data is incorrect or incomplete; It generates an Error response structure.
    When I run and test the same mapping program using Editplus Java editor for the error scenario; it executes perfectly and creates the correct error XML structure. (I checked it by importing the structure in the XI Message mapping test tab). But when I create jar of my java mapping program and test it in my interface mapping, it gives me "XML not well formed error" (Problem while building the tree).
    Any idea as to why is it behaving in such a way? There are 2 reasons which come to my mind as of now:
    1. The initilization of my input and output streams in the public static void main:
                InputStream in = new FileInputStream(new File("Input.xml"));
               OutputStream out = new FileOutputStream(new File("Output.xml"));
               validateXML myMapping = new ValidateXML();
                myMapping.execute(in, out);
    The Output.xml has the xml structure for the correct case, do I have to initialize my outputstream for the error file? say error.xml
    2. My Webservice interface is a sychronous interface (Request / Response) and output of the Java mapping program are two asynchronous interface. (I'll use a synch-asynch bridge when this works) - Is that causing a problem?
    Please help.
    Best regards,
    Varun

    Hello Varun,
    it gives me "XML not well formed error" (Problem while building the tree).
    I have come across the same error message while testing in interface mapping. My problem was when an exception occured in java mapping, the execution terminates with the messages XML not well formed error". In order to solve this issue what i did was catch the exception type TransformerException and in that catch block throw StreamTransformationException exception in main methos of mapping program i.e execute().
    eg:-                                                                               
    catch (TransformerException e) {
                   throw new StreamTransformationException("Can not write XML.", e);
    By doing this you will see the exception raised , because some times when you execute your mapping with mail() method, though it create the file, when you try to open it will give error if any exceptions occured in mapping. By using the above notation you can handle those in java mapping.
    Hope you have gone through this blog.
    [Handling and Tracing Exceptions in java mapping|http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417700)ID1055371050DB01666765031379427182End?blog=/pub/wlg/15061]
    Regards,
    Prasanna

  • Can a Java Mapping be used on non-xml data

    I would like to use a java mapping to transform non-xml formatted data to an IDOC or XML format.
    1) Does the input or output of a Java Map have to be XML.
    2) If possible can the test feature be used to load and test a non-xml data file.
    3) Any comments or lessons learned in this area.

    Hi Johan,
    below are some suggestions for your scenario:
    <i>
    1) Structured flat picked up using J2EE FTP adapter.</i>
    Indeed; you can use the file adapter to receive/retrieve this file from "any" third party system.
    <i>2) Structured flat converted to XML (Using JAVA mapping?)</i>
    When you send any message to XI, it's the adapter's task to convert this message into a XI understandable format i.e. SOAP. So the flat file to XML conversion is not your concern.
    However, if you need to perform any data transformation (input file to IDOC) then you can opt for XSLT (XML stylesheets),  Java mappings or the XI mapping tool within the repository. Based on my own experience with IDOC mapping, I can tell you that XSLT and/or Java mapping is the best way to achieve this kind of mapping.
    <i>3) XML mapped to SAP IDoc using graphical editor.</i>
    See comments point 2)
    Cheers,
    Rob.
    Message was edited by: Rob Viana

  • Fill Container Object in Java Mapping

    Hi Everyone,
    I use BPM and defined a container object of type integer. Now I want to fill this container object in Java Mapping. After I fill it in the next step there is a switch using the value of the container.
    How can I fill the container in Java Mapping?
    Thanks for the input.

    How can I fill the container in Java Mapping?
    Mandatory to fill the container in JAVA Mapping? If not then you can try the below:
    1) Define a Container Object...already done
    2) Let the JAVA Mapping create the required message....transformation step.
    3) include a Container Operation before the Switch step (and after the Transformation)
    4) Mode as Assign...Target will  be your Container Object (integer)....Expression will be the node from the output message of JAVA mapping.
    Regards,
    Abhishek.

  • Java Mapping XML Encoding Error.

    Hi All,
    I hav an IDoc XML coming out of R/3 whose encoding technique is UTF-8. I hav to change it to ISO-8859-1 before parsing the xml in the java mapping program. i have seen this problem repeating among many people but i cud not find any solution on the SDN. Can any one help me out in this regard?
    Thnx in Adv.
    Anil

    Hi Anil,
    put following XSLT a first place of interface mapping:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
         <xsl:output encoding="ISO-8859-1"/>
         <xsl:template match="/">
              <xsl:copy-of select="*"/>
         </xsl:template>
    </xsl:stylesheet>
    Regards,
    Udo

  • How can I get the output of graphical mapping as an input to java mapping?

    Hi Experts,
    I am using graphical mapping in my scenario to get an xml at the end, now after this i want to use java mapping and then do encryption on this input. I am using both the mappings in the same interface
    Here the thing is, the input to the java mapping should be the output of the first graphical mapping.
    How can I link the java mapping and graphical mapping so that Ill get the output of the graphical mapping as the input to the java mapping?
    Some pointers to similar kind of implementations is highly appreciated.
    Thanks in advance,
    Thomas
    Edited by: Thomas Varghese on Jan 22, 2009 11:35 AM

    hi,
    the input to the jave mapping will be exaclty the same as if you don't have
    any mapping before that
    the only different is that the input will be XML of the output of the message mapping
    have a look at my blog to see how to combine two mappings:
    /people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping
    that's all
    Regards,
    Michal Krawczyk

  • JAVA mapping, output...

    Hello guys,
    Again here I am with some simple and easy doubts.
    When I'm creating a mapping between two interfaces with JAVA, I'll have a call to :
    execute(InputStream in, OutputStream out).
    The questions are, these two arguments are two XML files. The first will be the file we want to send, but the second how will it be?
    If I'm using a call to a RFC, the structure of the second file will have the importing, exporting and tables arguments of the RFC? And how are they disposed...?
    The idea is to perform the correspondence from the original file to the parameters of the RFC, but how will the RFC load the parameters from the file...?
    I know it's a really simple doubt but can anyone clear my mind?
    Thanks a lot in advance...

    > Hello guys,
    >
    > The questions are, these two arguments are two XML
    > files. The first will be the file we want to send,
    > but the second how will it be?
    These arguments dont necessarily need to be XML structures, in fact this method accepts any kind of input i.e. flat structure, strings, etc.. However, you are using this mapping within a message mapping so most likely you will pass an XML structure to it. The first parameter is the input (the source) and the second one is the resultt of your Java mapping.
    > If I'm using a call to a RFC, the structure of the
    > second file will have the importing, exporting and
    > tables arguments of the RFC? And how are they
    > disposed...?
    The RFC structure you have to download it from the R/3 system where you want to call this RFC. You do this from your SWCV in the repository. After you have downloaded the RFC metadata you will see both messages, the request and the response message.
    > The idea is to perform the correspondence from the
    > original file to the parameters of the RFC, but how
    > will the RFC load the parameters from the file...?
    Here is where your message mapping (enhanced with your Java mapping) will come into picture.
    PS: Without knowiing your requirements I think you can do this mapping from file to RFC call without the use of a Java mapping. i.e. message mapping.
    >
    > I know it's a really simple doubt but can anyone
    > clear my mind?
    >
    > Thanks a lot in advance...
    Good Luck,
    Roberto
    Message was edited by: Roberto Viana
    Message was edited by: Roberto Viana

  • 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!!

  • Java Mapping for HTTP Post

    Hi
    Im following this blog http://scn.sap.com/community/pi-and-soa-middleware/blog/2014/09/12/html-form-upload-using-http-plain-adapter-with-java-mapping but I have encountered an issue which I cannot solve.
    My issue is, in addition to the required output, I am also getting unwanted XML added, which originates from the Message Type in the source Service Interface,
    i.e.
    Content-Type: multipart/form-data; boundary=--ejjeeffe1
    --ejjeeffe1
    Content-Disposition: form-data; name="event"
    Content-Type: text/plain
    Import File
    --ejjeeffe1
    Content-Disposition: form-data; name="Filename"
    Content-Type: text/plain
    TestFile.zip
    --ejjeeffe1
    Content-Disposition: form-data; name="content";filename="TestFile.zip"
    Content-Type: application/zip
    Content-Transfer-Encoding: binary
    <?xml version="1.0" encoding="UTF-8"?><__EmptyDoc></__EmptyDoc>
    --ejjeeffe1
    Any suggestions much appreciated.
    Regards
    Steve

    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

  • 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

  • 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

  • Problem in SAX Java mapping

    Hi,
    I'm using SAX Java mapping in one scenario. Problem is when I get some Croatina characters, like Đ or u0160,
    output XML is not valid. XML Spy complains, IE complains and so on. Customer is sure  that data ( XML in CLOB field in Oracle DB) is UTF-8? What could be a problem?
    What I'm doing is reading entire XML into string with help of BufferedReader, then do some manipulation and write String into byte array with:
                   byte[] bytes = file.toString().getBytes("UTF-8");
                   saxParser.parse(new ByteArrayInputStream(bytes), handler);
    and then of course parse XML. readLine method reads data and problematic is "Ä�" - ￯0 - 0xC490.
    For this character XML Spy doesn't complain, IE also. After conversion, this character looks like "Ä?" - 0xC43F, and this is not good any more. Why?

    Hi Stefan,
    I've finally done it. Code as foollws:
         public void execute(InputStream in, OutputStream out)
                   throws com.sap.aii.mapping.api.StreamTransformationException {
              DefaultHandler handler = this;
              SAXParserFactory factory = SAXParserFactory.newInstance();
              try {
                   SAXParser saxParser = factory.newSAXParser();
                   fStreamOut = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
                   encoding = "UTF-8";
                   if (map != null) {
                        mappingTrace = (MappingTrace) map
                                  .get(StreamTransformationConstants.MAPPING_TRACE);
                   InputStreamReader is = new InputStreamReader(in, "UTF8");
                   BufferedReader reader = new BufferedReader(is);
                   StringBuffer file = new StringBuffer();
                   String line = new String();
                   try {
                        while ((line = reader.readLine()) != null) {
                             file.append(line);
                   } catch (IOException e) {
                        e.printStackTrace();
                   } finally {
                        try {
                             in.close();
                        } catch (IOException e) {
                             e.printStackTrace();
                   Date d4 = new Date();
                   file = replaceREGEX(
                             "<\\?xml version=\"1\\.0\" encoding=\"UTF-8\"\\?>", "",
                             file);
                   char[] cArray = file.toString().toCharArray();
                   Date filedat = new Date();;
                   SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
                   String fName = df.format(filedat) + "_El_Invoice.xml";
                   Writer out1 = new BufferedWriter(new OutputStreamWriter(
                             new FileOutputStream(fName), "UTF8"));
                   try {
                        out1.write(file.toString().toCharArray());
                        out1.close();
                   } catch (UnsupportedEncodingException e) {
                   } catch (IOException e) {
                   saxParser.parse(fName, handler);
                   File outFile = new File(fName);
                   outFile.delete();
              } catch (Throwable t) {
                   if (mappingTrace != null) {
                        mappingTrace.addInfo(t.toString());
                   t.printStackTrace();
    problem was also in method for writing in output stream, so I've changed it:
         private void printOutPut(String sOP) {
              try {
                      //    fStreamOut.write(sOP.getBytes());
                   fStreamOut.write(sOP);
              } catch (IOException e) {
                   e.notify();

  • Message and Java Mapping

    Hello -
    I have a java mapping and a message mapping implemented in one interface.
    Java mapping basically adds a header and does nothing else.
    Message mapping has all the mapping. Its not complex but straight.
    I have the Message mapping first and then the Java mapping in the Interface Mapping.
    what happens is i could see the headers written through Java mapping in my output xml file which is good but i cannot view the message mapping output in the file.
    Any ideas.
    Thanks,
    Tirumal

    Hi
    I am generating the headers in the java mapping using this:
    public void startDocument ()
    throws SAXException {               
    write("<?xml version='1.0' encoding='UTF-8'?>");
    write("<!DOCTYPE cXML SYSTEM 'http://xml.cxml.org/schemas/cXML/1.1.008/cXML.dtd'>");
    Maintain Order at Runtime is checked in the Interface Determination.
    Ok, in the interface Mapping Editor i get 2 messages:
    1.
    11:09:48 Start of test
    Call method execute of the application Java mapping com.sap.xi.tf._Orders_MM_
    Java mapping com/sap/xi/tf/_Orders_MM_ completed. (execute() of com.sap.xi.tf._Orders_MM_
    Call method execute of the application Java mapping com.sap.aii.mapping.api.SampleWithSaxParser
    Java mapping com/sap/aii/mapping/api/SampleWithSaxParser completed. (execute() of com.sap.aii.mapping.api.SampleWithSaxParser
    Executed successfully
    11:09:48 End of test
    2. XML not well formed
    None of the above messages seem to be of Message Mapping don't know why its not getting written in the output.
    Thanks,
    Tirumal

  • XML to string using xslt or java mapping

    Hi Experts,
    I want to put xml into string and i need to change lessthan symbol to "&lt"   and greaterthan symbol to "&gt" , can anyone please help me how to do this??? can you provide code for java mapping or XSLT mapping to achive this.
    SOURCE
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:source_mt xmlns:ns0="urn:ppp:prototype">
       <row>
          <name1>IT</name1>
          <name2>SOLUTIONS</name2>
       </row>
    </ns0:source_mt>
    TARGET
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:target_mt xmlns:ns0="urn:ppp:prototype">
       <row>
          <Body>"&lt"name1"&gt" IT"&lt"/name1"&gt" "&lt"name2"&gt" SOLUTIONS"&lt";/name2"&gt" </Body>
       </row>
    </ns0:target_mt>

    Hi ,
          here is the XSLT code to obtain the desired output
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <xsl:template match="/">
    <ns0:target_mt xmlns:ns0="urn:ppp:prototype">
         <xsl:for-each select="//row">
              <row>
                   <Body>
                        <xsl:for-each select="name1">
                                  <xsl:value-of select="concat('*&quot;&lt;&quot;name1&quot;&gt;&quot;*',normalize-space(.),'*&quot;&lt;&quot;/name1&quot;&gt;&quot;*')"></xsl:value-of>
                        </xsl:for-each>     
                        <xsl:for-each select="name2">
                                  <xsl:value-of select="concat('*&quot;&lt;&quot;name2&quot;&gt;&quot;*',normalize-space(.),'*&quot;&lt;&quot;/name2&quot;&gt;&quot;*')"></xsl:value-of>
                        </xsl:for-each>
                   </Body>
              </row>
         </xsl:for-each>
    </ns0:target_mt>      
    </xsl:template>
    </xsl:stylesheet>
    output produced as viewed in browser is
    http://postimage.org/image/1lqbgw8kk/
    Now to obtain exactly the output you posted earlier here is the code
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <xsl:template match="/">
    <ns0:target_mt xmlns:ns0="urn:ppp:prototype">
         <xsl:for-each select="//row">
              <row>
                   <Body>
                        <xsl:for-each select="name1">
                                  <xsl:value-of select="concat('*&quot;&amp;lt&quot;name1&quot;&amp;gt&quot;*',normalize-space(.),'*&quot;&amp;lt&quot;/name1&quot;&amp;gt&quot;*')"></xsl:value-of>
                        </xsl:for-each>     
                        <xsl:for-each select="name2">
                                  <xsl:value-of select="concat('*&quot;&amp;lt&quot;name2&quot;&amp;gt&quot;*',normalize-space(.),'*&quot;&amp;lt&quot;/name2&quot;&amp;gt&quot;*')"></xsl:value-of>
                        </xsl:for-each>
                   </Body>
              </row>
         </xsl:for-each>
    </ns0:target_mt>      
    </xsl:template>
    </xsl:stylesheet>
    output you can see from link below
    http://postimage.org/image/2c7bzo478
    Hope this helps.
    Hi,
        Could you please kindly let us know if the solution is working properly as per your requirement?
    regards
    Anupam
    Edited by: anupamsap on Jul 26, 2011 6:29 AM
    Edited by: anupamsap on Jul 26, 2011 4:10 PM

  • 1:n Transformation using JAVA Mapping Scenario

    Hi Frnds,
    I done a scenario using 1:n Transformation Scenario using XSLT,Graphical Mapping.
    But i want to develop scenario Using JAVA Mapping.
    Can anybody done the same scenario using JAVA Mapping share the links..
    Regards,
    Raj Sekhar

    You can use SAX parser for this
    firstly create a StringBuffer sb object which will store our target output
    when startDocument() gets called append the xml declaration in this method
    sb.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
    sb.append("<Root>");
    next for the Test element you have your startElement() method called which will contain the name of your source tag i.e Test
    for this , you will need to set a variable boolean isTest to true which was initialised as a false value.
    in the characters method you will get the value present in this tag.
    test the variable isTest for true value.
    if it is true then append the following
    sb.append("<Test1>"name"</Test1>"); //name is the buffer passed in characters method
    sb.append("<Test2>"name"</Test2>");
    sb.append("<Test3>"name"</Test3>");
    at the end your endelement() will be called
    here reset the value of isTest to false.
    in your endDocument()
    sb.append("</Root>");
    lastly convert to byte[] and then to outputStream format
    Edited by: Progirl Progirl on Jul 4, 2008 2:00 PM

Maybe you are looking for

  • How to display Success Message on the Left side of Screen

    I am displaying a Process Success Message after the ApplyMRU process, *#MRU_COUNT# row(s) updated*. By default, this message is displayed at the center of the screen. I would like to display this message at the left hand side of the screen. I am usin

  • Do you want to live in a world where people are not allowed opinions?

    Do you remember when Americans were free to have an opinion, and we would accept those with different opinions than our own? I'm in my mid-20s, but I remember that time. It seems to be gone now. You have forced your CEO to "resign" from his position

  • Table DataType

    Is there any equivalent datatype for creating a table inside a stored procedure or a package and the table being only valid in the stored procedure or package. Something like this [http://www.developer.com/db/article.php/3414331/Using-the-Table-Data-

  • MacBook Pro Retina Mountain Lion + Dell U2713hm hangs after wake-up

    This is a more specific description of my problems here: https://discussions.apple.com/thread/4385171 I use a Dell U2713hm together with a MacBookPro Retina under Mountain Lion. The Dell is connected via the Thunderboldt to DVI-D adapter that is sold

  • I dropped my Iphone 5 in the toilet what do I do?

    I was at work and I went to the toilet and I forgot I had my phone in my back pocket. I herd a massive plop! and i immediatley looked round and shouted noooo and grabbed my phone out the water! I wrapped it in tons of tissue and tried seeing if i cou