Problem in Java Mapping

Hi,
      I was trying out a simple Java mapping example.
Example of source structure is -
<?xml version="1.0"?>
<ns0:MT_SRC xmlns:ns0="http://www.sap-press.com/xi/training/00">
<organization>
<employee>
<firstname>Jack</firstname>
<lastname>Rose</lastname>
</employee>
<employee>
<firstname>Paul</firstname>
<lastname>McNealy</lastname>
</employee>
<employee>
<firstname>Vaibhav</firstname>
<lastname>Pandey</lastname>
</employee>
</organization>
</ns0:MT_SRC>
Example of target structure is -
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_TRGT xmlns:ns0="http://www.sap-press.com/xi/training/00"><Organization><employee><name>JackRose</name></employee><employee><name>PaulMcNealy</name></employee><employee><name>VaibhavPandey</name></employee></Organization></ns0:MT_TRGT>
and here's the code I'm using
package com.mapping;
import java.io.*;
import java.util.Map;
import java.util.HashMap;
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.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.api.MappingTrace;
import com.sap.aii.mapping.api.StreamTransformation;
public class JavaMap 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 in, OutputStream out) {
               OutputStreamWriter buf_writer = new OutputStreamWriter(out);        
               InputStreamReader buf_reader = new InputStreamReader(in);
               String mat = new String();
               String extmat = new String();
               try {
                    buf_writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>" ,0,56);
                    buf_writer.write("<ns0:MT_TRGT xmlns:ns0=\"http://www.sap-press.com/xi/training/00\">");
                    buf_writer.write("<Organization>",0,20);
                    buf_writer.flush();
              } catch(IOException e){};
              try {
                   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();          
                   factory.setValidating(false);          
                   DocumentBuilder builder = factory.newDocumentBuilder();          
                   Document doc = builder.parse(in);
                    String fname = null;
                    String lname = null;
                    doc.getDocumentElement().normalize();
                    //System.out.println("Root element " + doc.getDocumentElement().getNodeName());
                    NodeList nodeLst = doc.getElementsByTagName("employee");
                    //System.out.println("Information of all employees");
                    for (int s = 0; s < nodeLst.getLength(); s++) {
                    Node fstNode = nodeLst.item(s);
                    if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
                         buf_writer.write("<employee>");     
                    Element fstElmnt = (Element) fstNode;
                    NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("firstname");
                    Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
                    NodeList fstNm = fstNmElmnt.getChildNodes();
                    //System.out.println("First Name : " + ((Node) fstNm.item(0)).getNodeValue());
                    fname = fstNm.item(0).getNodeValue();
                    NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("lastname");
                    Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
                    NodeList lstNm = lstNmElmnt.getChildNodes();
                    //System.out.println("Last Name : " + ((Node) lstNm.item(0)).getNodeValue());
                    lname = lstNm.item(0).getNodeValue();
                    buf_writer.write("<name>"fname" "lname"</name>");
                    buf_writer.write("</employee>");
                    buf_writer.write("</Organization>");
                    buf_writer.write("</ns0:MT_TRGT>");
                    TransformerFactory tFactory = TransformerFactory.newInstance();
                 Transformer transformer = tFactory.newTransformer();
                 transformer.setOutputProperty("indent", "yes");
                 DOMSource source = new DOMSource(doc);
                 StreamResult result = new StreamResult(out);
                 transformer.transform(source, result);
                    } catch (Exception e) {
                    e.printStackTrace();
However, when I'm testing my Interface mapping, I'm getting the following error -
Call method execute of the application Java mapping com.mapping.JavaMap
Error during appliction Java mapping com/mapping/JavaMap
java.lang.StringIndexOutOfBoundsException at java.lang.String.getChars(String.java:672)
Could anyone please help me out with this?
Thanks and Regards,
Shiladitya

HI,
It looks to be that your JavaMap class have one field whihc will be not getting the proper value as input thus its creating the array Index out of bound exception.
Please can you verify if you have assigned the proper String size for all the fields.
Or probably you are getting the blank value which have created the execption.
Also can you narrow down and let me know about the line String.getChars(String.java:672)
Here you have used the try and catch option but may be the exact line no. can give better idea about the problem.
Thanks
swarup

Similar Messages

  • Problems with Java Mapping in Bpm

    Hello to All.
    I have a simple scenario...
    1) Receiver ( XML1)
    2) Transformation
    3) Sender (XML3)
    I have 3 variables.  
    Variable 1  XML1
    Variable 2  XML2
    Variable 3  XML3
    In my transformation have two source.. an XML and XML2 and my mapping program is java mapping.
    The java mapping modify the XML1 according the XML2 and transform in XML3.
    When I run BPM . I have problem , because the flow stop in transformation.

    Yes I have tested. But I found the solution.. The java mapping generate a header like <xsi : Message1></>... <xsi : Message2> </>
    Thanks.

  • Problem in java mapping - request reject when enter to the XI

    hello
    I have WS 2 RFC with JAVA MAPPING. I try to run it and recieve an error in the sxmb:
      <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Request Message Mapping
      -->
    - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
      <SAP:Category>XIServer</SAP:Category>
      <SAP:Code area="MAPPING">JCO_SYSTEM_FAILURE</SAP:Code>
      <SAP:P1>Exception in method processFunction.</SAP:P1>
      <SAP:P2 />
      <SAP:P3 />
      <SAP:P4 />
      <SAP:AdditionalText />
      <SAP:ApplicationFaultMessage namespace="" />
      <SAP:Stack>&quot;SYSTEM FAILURE&quot; during JCo call. Exception in method processFunction.</SAP:Stack>
      <SAP:Retry>N</SAP:Retry>
      </SAP:Error>
    in the xml spy the return is:
                             <text><![CDATA[
    com.sap.aii.af.ra.ms.api.DeliveryException: XIServer:JCO_SYSTEM_FAILURE:
         at com.sap.aii.adapter.xi.ms.XIEventHandler.onTransmit(XIEventHandler.java:455)
         at com.sap.aii.af.ra.ms.impl.core.queue.CallConsumer.onMessage(CallConsumer.java:133)
         at com.sap.aii.af.ra.ms.impl.core.queue.Queue.run(Queue.java:850)
         at com.sap.aii.af.ra.ms.runtime.MSWorkWrapper.run(MSWorkWrapper.java:56)
         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)
              ]]></text>
    any suggestion why the xi doesnt recieve the request:
    Thanks
    Kfir

    Test RFC destination AI_RUNTIME_JCOSERVER. You may delete and recreate it.
    how exactly do I test it? in the XID or the SAP DEV?
    how can I delete and recreate?
    since I never did it, details will be appreciated.
    Kfir

  • Problem with Java Mapping

    Hello experts,
    I developed a Java Mapping Programm for reading filename of a pdf file and giving filename to a rfc structure for calling a rfc module. Thus, I test it via testing interface method and implementing a main method in my mapping class, which works, but if I run it in the integration server  I get the following exception:
    MP: Exception caused of com.sap.aii.af.ra.ms.api.RecoverableException: java.lang.StringIndexOutOfBoundsException: String index out of range: -7: com.sap.aii.af.rfc.afcommunication.RfcAFWException: java.lang.StringIndexOutOfBoundsException: String index out of range: -7
    That is the execute method of my class:
         public void execute(InputStream inputStream, OutputStream outputStream)
              throws StreamTransformationException {
              // TODO Auto-generated method stub
              try { //The following is for the FileName in the File Adapter
                   DynamicConfiguration dynamicconfiguration =
                        (DynamicConfiguration) map.get("DynamicConfiguration");
                   DynamicConfigurationKey key =
                        DynamicConfigurationKey.create(
                             "http://sap.com/xi/XI/System/File",
                             "FileName");
                   String myFileName = dynamicconfiguration.get(key);
                   MappingTrace trace = null;
                   trace.addInfo(myFileName);
                   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                   DocumentBuilder db = dbf.newDocumentBuilder();
                   TransformerFactory tf = TransformerFactory.newInstance();
                   Transformer transform = tf.newTransformer();
                   Document docout = db.newDocument();
                   Element root = docout.createElement("Z_SD_WEB_HP_INVOICE_STATUS");
                   root.setAttribute(
                        "xmlns:ns1",
                        "urn:sap-com:document:sap:rfc:functions");
                   docout.appendChild(root);
                   Element docName = docout.createElement("IM_DOCNAME");
                   root.appendChild(docName);
                   Text srcxml = docout.createTextNode(myFileName);
                   docName.appendChild(srcxml);
                   DOMSource domS = new DOMSource(docout);
                   transform.transform((domS), new StreamResult(outputStream));
              } catch (Throwable throwable) {
                   throwable.printStackTrace();
    If I test via main method and testing interface mapping  the generated xml is like:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?><Z_SD_WEB_HP_INVOICE_STATUS xmlns:ns1="urn:sap-com:document:sap:rfc:functions"><IM_DOCNAME>232132.pdf</IM_DOCNAME></Z_SD_WEB_HP_INVOICE_STATUS>
    I do not understand why I get this error in real environment.
    Kind regards,
    Erkan

    Hello experts,
    I found the solution. I will also publish this solution, this is also a point which I sometimes missing here in this forum:
    In creating the rfc-xml with java mapping, so a prefix should be add to the name of the rfc-structure e.g.
    ns1:Z_RFC_CALL. If this prefix is missing, then you get this error:
    com.sap.aii.af.ra.ms.api.RecoverableException: java.lang.StringIndexOutOfBoundsException: String index out of range: -7: com.sap.aii.af.rfc.afcommunication.RfcAFWException: java.lang.StringIndexOutOfBoundsException: String index out of range: -7
    To find this I create a grafical test mapping and I check the test rfc-xml with the java created xml.
    Anyway thanks all for the published recommendations.
    Kind regards,
    Erkan

  • 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

  • SOAP Adapter with JAVA Mapping.

    Hi,
    I am trying a scenario,
    file->SOAP Receiver->SOAP Sender->IDOC
    in this I have used two interface mapping(and two mapping also).
    In first mapping i used Java mapping. so the WSDL of this is of no use for me.
    and in second mapping graphical mapping is performed.
    but my scenario is not woking completely. only one messge in SXMB_MONI is displayed. but it should be two. I think there is some problem in java mapping.
    in java mapping i have generated XML output, which will be input of SOAP sender.
    plaese suggest me the format which should be generated by java mapping.

    Sandeep,
    Let me try to put your requiremen,
    You have 2 scenariom
    FILE to SOAP
    SOAP to Idoc
    When the file becomes availbale, the Scenario 1 triggers of Scenario 2. Scenario 2 provides you a WSDL and so scneario 1 's output should be of the format of this WSDL.
    Hope I am on the correct track.
    If yes, just import this WSDL into your IR, and see the format in which it expects the data by using it as a message type in some mapping ( dummy mapping ) and then in your Java Mapping create a output of the same format, with the same namespace etc.
    Regards,
    Bhavesh

  • Generic Exception in java mapping

    hi all,
    i'm using xerces api inorder to validate the outbound xml with its corresponding xsd using java mapping . when mapping is executed , i get "Generic Exception". it does'nt leave any  trace other than the word "Generic Exception". i use same jdk version used by  XI.kindly help me regarding this issue.
    Thanks and Regards
    kausik

    hello kausik,
    i have the same problem in java mapping by validating incoming xml files.
    could you solve the problem?
    can you tell me how to solve the problem?
    you can write me an email with the solution ([email protected])? or post it here?
    thanks a lot
    ciao alex

  • Special Character being replaced by Question Marks in Java Mapping

    Hi All,
    I need some help on Java Mapping related to special characters.
    The problem is that i'm using a Java Mapping to add some information to the XML inside the Interface Mapping. This works fine on our development environment but, in our production environment, it replaces the special character with question marks (eg.: á --> ??).
    I'm suspecting of some configuration on the Java Virtual Machine that sets the encoding, but i don't have access to it. Does anyone have any clues about this problem?
    Thanks a lot,
    Leonardo

    Hi Leonardo
    Have a look at this forum thread, this might help you to solve your problem.
    Java Map Causing error because of ampersand &

  • Java Mapping problem...

    Hi Guru’s,
    I am using the Java mapping in my XI system and it works fine in my Development.
    I just moved all my objects in to QA and I am getting some problem in my Java mapping.  It is not behaving like the dev the output format.
    Is their anything have to do for Java mapping while importing in to the QA system.
    I did the file transport and imported in to my QA.
    Please give me your comments and solution to resolve this issue.
    Thanks,
    Jane.

    Getting the below error in my response.
    - <ResponseMessage>
    - <Status>
      <StatusCode>500</StatusCode>
      <StatusText>Error while parsing the input</StatusText>
    - <Errors>
    - <Error type="Error">
      <ErrorMessage>Fatal Error: Internal server error - 1187224995259871</ErrorMessage>
      </Error>
      </Errors>
      </Status>
      </ResponseMessage>
    Thanks,
    Jane.

  • 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();

  • Strange problem with jars in Java Mapping

    Hi All,
    I'm trying to implement a Java Mapping that uses Xerces. I'm using xercesImpl.jar.
    I put the xercesImpl.jar file in the folder containing the .class file (the Java Mapping program), and zipped the folder.I imported the zip file as an archive and used it in the Interface Mapping.
    My code uses the org.apache.xerces.parsers.<b>SAXParser</b> class.
    However, while trying to execute the Interface Mapping, it gives error: <b>Unable to find resource:'org/apache/xerces/parsers/SAXParser.class'</b>.
    The same method works when I'm using xerces.jar and using classes javax.xml.parsers.<b>DocumentBuilder</b> and
    javax.xml.parsers.DocumentBuilderFactory.
    I can't figure out what the problem is.
    Any ideas?
    Regards,
    Puloma.

    Hi All,
    I tried all the methods suggested. Mow my problem is that I get the following error, when I try to instantiate the SAXParser class:
    Unable to find resource:
    <b>META-INF/services/org.apache.xerces.xni.parser.XMLParserConfiguration</b>
    The XMLParserConfiguration class is actually in org.apache.xerces.xni.parser. Why does XI try to find it in the wrong sub-directory?
    My code works just fine on standalone.
    Regards,
    Rahul.

  • Problem by adding attachments in Java Mapping

    Hi,
    we have to add some attachments in Java Mapping.
    So we are using the Java Mapping API.
    But it doesn't work correctly.
    We got the following error in sxmb_moni:
    Attribute Manifest ExampleAttachment is initial
    So we checked what happened in the Manifest and in the SAP SOAP Envelope and we see that there is an inconsistence.
    In the SAP Manifest we find the following entries:
    <SAP:Manifest xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:wsu="http://www.docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="wsuid-manifest-5CABE13F5C59AB7FE10000000A1551F7">
         <SAP:Payload xlink:href="cid:payload-79a6e3c088db11dfa4dd0017a477c1e8<at>sap.com">
              <SAP:Name>MainDocument</SAP:Name>
              <SAP:Description/>
              <SAP:Type>Application</SAP:Type>
         </SAP:Payload>
         <SAP:Payload xlink:href="ExampleAttachment">
              <SAP:Name>ExampleAttachment</SAP:Name>
              <SAP:Description/>
              <SAP:Type>ApplicationAttachment</SAP:Type>
         </SAP:Payload>
    </SAP:Manifest>
    For us it seems the entry for our ExampleAttachment is wrong. I think there must be a real content id for the attachment like the cid for the MainDocument. In the SOAP Envelope you can find the following entry for the attachment:
    content-type:text/plain
    content-length:45
    content-id:payload-79a6e3c088db11dfa4dd0017a477c1e8<at>sap.com
    This is an example for an attachment!
    --SAP_0017A477C1EC1DEFA3D200A5CB55CE04_END--
    So here you can see a real content ID, but you can't find it in the Manifest.
    So do we anything wrong in our source code or is it a bug of the SAP API?
    Do you have any ideas?
    Here the Java Mapping we're using for adding an attachment (as a test):
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import com.sap.aii.mapping.api.AbstractTransformation;
    import com.sap.aii.mapping.api.DynamicConfiguration;
    import com.sap.aii.mapping.api.DynamicConfigurationKey;
    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.mapping.api.Attachment;
    public class SUSAttaHandler extends AbstractTransformation {
         private static final DynamicConfigurationKey KEY_FILENAME    = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
         // Transform Method
         public void transform(TransformationInput in, TransformationOutput out)
                   throws StreamTransformationException {
              // An info message is added to trace
              getTrace().addWarning("JAVA Mapping AttaHandler called!");
              // Input payload
              String inData = convertStreamToString(in.getInputPayload().getInputStream());
              // dynamic configuration
              DynamicConfiguration conf = in.getDynamicConfiguration();
              String fileName          = conf.get(KEY_FILENAME);
              getTrace().addWarning("AttaHandler: FileName = " + fileName);
              String text = new String("This is an example for an attachment!");
              Attachment atta = out.getOutputAttachments().create("ExampleAttachment", "text/plain", text.getBytes());
              out.getOutputAttachments().setAttachment(atta);
              String outData = inData;
              try {
                   out.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8"));
              catch(Exception exception1) { }
         // convert Stream to String
         public String convertStreamToString(InputStream in){
              StringBuffer sb = new StringBuffer();
              try {
                   InputStreamReader isr = new InputStreamReader(in);
                   Reader reader = new BufferedReader(isr);
                   int ch;
                   while((ch = in.read()) > -1) {
                        sb.append((char)ch);}
                        reader.close();
              } catch(Exception exception) { }
              return sb.toString();
    Thanks for your help,
    Thorsten

    Hi,
    we created an OSS ticket for this problem and SAP created a SAP note.
    Here the number of the note: 0001501345
    I hope this will help you.
    Thorsten

  • Problems with Java DOM Mapping

    Hi Experts,
    as part of my diploma-thesis I have to write a java DOM-Mapping, which mapps the following incoming message:
    <mt_MappingOUT>
    <set>
    <set_Element_01>...</set_Element_01>
    <set_Element_02>... </set_Element_02>
    <set_Element_03>... </set_Element_02>
    <set_Element_10>  </set_Element_10>
    </set>
    </mt_MappingOUT>
    to the following outgoinig message:
    <mt_MappingIN>
    <TABLE>
    <item>
    <item_FIELD_01>  </item_FIELD_01>
    <item_FIELD_10>  <item_FIELD_10>
    <i/tem>
    </TABLE>
    </mt_MappingIN>
    I am not a very experienced Java-Developer. You can see my code down there, which I tried to implement according to some bloggs; unfortunately the result is not what I want to have
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.Map;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    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.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Text;
    import org.xml.sax.SAXException;
    import com.sap.aii.mapping.api.StreamTransformation;
    import com.sap.aii.mapping.api.StreamTransformationException;
    public class DOMMAPPING implements StreamTransformation{
         public static void main(String[] args) throws Exception
              try
                   FileInputStream fin =
                        new FileInputStream("C:/mt_MappingOut.xml");
                   FileOutputStream fout =
                        new FileOutputStream("C:/target.xml");
                   DOMMAPPING mapping = new DOMMAPPING();
                   mapping.execute(fin, fout);
              catch (Exception e)          {
                   e.printStackTrace();
    public void setParameter (Map param) {}
    public void execute (InputStream in, OutputStream out)
         throws com.sap.aii.mapping.api.StreamTransformationException {
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              Document documentIn = null;
              DocumentBuilder builder = null;
              try {
                        builder = factory.newDocumentBuilder();
                   } catch (ParserConfigurationException e1) {
                        e1.printStackTrace();
              try {
                   Element itemNode = null;
                   NodeList[] list_f=new NodeList[10];
                   Element[] field=new Element[10];
                   documentIn = builder.parse(in);
                   Document documentOut = builder.newDocument();
                   Element rootNode = documentOut.createElementNS("urn:agrp:xi:geissseb","ns0:mt_MappingIn");
                   documentOut.appendChild(rootNode);
                   Element tableNode = documentOut.createElement("TABLE");
                   rootNode.appendChild(tableNode);
                   NodeList list_Set=documentIn.getElementsByTagName("set");
                   System.out.println(list_Set.getLength());
                   for(int j=1;j<10;j++){
                        list_f[j-1]=documentIn.getElementsByTagName("set_ELEMENT_01"+j);
                list_f[9]=documentIn.getElementsByTagName("set_ELEMENT_10");
                   //NodeList list_f01=documentIn.getElementsByTagName("f01");
                   for (int i=0;i<list_Set.getLength();i++)
                        itemNode=documentOut.createElement("item");
                        tableNode.appendChild(itemNode);
                        for(int k=0; k<10;k++){
                             Node f=list_f[k].item(i);
                             f=f.getFirstChild();
                             String str_f=f.getNodeValue();
                             Text text_f=documentOut.createTextNode(str_f);
                             field[k]=documentOut.createElement("item_FIELD_"(k1));
                             field[k].appendChild(text_f);
                             itemNode.appendChild(field[k]);
                   TransformerFactory tf = TransformerFactory.newInstance();
                   Transformer transform = tf.newTransformer();
                   transform.transform(new DOMSource(documentOut), new StreamResult(out));
                   } catch (SAXException e2) {
                        e2.printStackTrace();
                   } catch (IOException e2) {
                        e2.printStackTrace();
                   }catch (Throwable t) { throw new StreamTransformationException("error", t); }
    Unfortunately there seems to be at least one error in there because the result I get is just the following:
      <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    - <ns0:mt_MappingIn xmlns:ns0="urn:agrp:xi:geissseb">
      <TABLE />
      </ns0:mt_MappingIn>
    Below you will find my source message:
    <?xml version="1.0" encoding="UTF-8" ?>
    - <xsd:schema targetNamespace="urn:agrp:xi:geissseb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:agrp:xi:geissseb">
      <xsd:element name="mt_MappingOut" type="dt_MappingOut" />
    - <xsd:complexType name="dt_MappingOut">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">a7a28830bebf11dc81aa001a4b0af224</xsd:appinfo>
      </xsd:annotation>
    - <xsd:sequence>
    - <xsd:element name="Set">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b366510aeda11dcb3bb00174205b856</xsd:appinfo>
      </xsd:annotation>
    - <xsd:complexType>
    - <xsd:sequence>
    - <xsd:element name="f01" type="xsd:string">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b366511aeda11dcaf2600174205b856</xsd:appinfo>
      </xsd:annotation>
      </xsd:element>
    - <xsd:element name="set_ELEMENT_02" type="xsd:string">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b366512aeda11dc84d400174205b856</xsd:appinfo>
      </xsd:annotation>
      </xsd:element>
    - <xsd:element name="set_ELEMENT_03" type="xsd:string">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b366513aeda11dcbcab00174205b856</xsd:appinfo>
      </xsd:annotation>
      </xsd:element>
    - <xsd:element name="set_ELEMENT_04" type="xsd:string">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b366514aeda11dc96a300174205b856</xsd:appinfo>
      </xsd:annotation>
      </xsd:element>
    - <xsd:element name="set_ELEMENT_05" type="xsd:string">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b366515aeda11dca77700174205b856</xsd:appinfo>
      </xsd:annotation>
      </xsd:element>
    - <xsd:element name="set_ELEMENT_06" type="xsd:string">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b366516aeda11dc8f7d00174205b856</xsd:appinfo>
      </xsd:annotation>
      </xsd:element>
    - <xsd:element name="set_ELEMENT_07" type="xsd:string">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b366517aeda11dcc24b00174205b856</xsd:appinfo>
      </xsd:annotation>
      </xsd:element>
    - <xsd:element name="set_ELEMENT_08" type="xsd:string">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b366518aeda11dc92cd00174205b856</xsd:appinfo>
      </xsd:annotation>
      </xsd:element>
    - <xsd:element name="set_ELEMENT_09" type="xsd:string">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b366519aeda11dcc9b100174205b856</xsd:appinfo>
      </xsd:annotation>
      </xsd:element>
    - <xsd:element name="set_ELEMENT_10" type="xsd:string">
    - <xsd:annotation>
      <xsd:appinfo source="http://sap.com/xi/TextID">0b36651aaeda11dcc5a700174205b856</xsd:appinfo>
      </xsd:annotation>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:schema>
    When I had problems withe Java SAX Mapping, I got great hints in the forum. So I hope you can help me out again...
    Cheers Sebastian

    Here you go.
    Code
    package com.sap.test;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.Map;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.apache.crimson.tree.TextNode;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Text;
    import org.xml.sax.SAXException;
    import com.sap.aii.mapping.api.StreamTransformationException;
    public class DomTest {
         Document documentOut = null;
         public static void main(String[] args) throws Exception
         try
         FileInputStream fin =      new FileInputStream("test.xml");
         FileOutputStream fout = new FileOutputStream("test_out.xml");
         DomTest mapping = new DomTest();
         mapping.execute(fin, fout);
         catch (Exception e) {
         e.printStackTrace();
         public void setParameter (Map param) {}
         public void execute (InputStream in, OutputStream out)
         throws com.sap.aii.mapping.api.StreamTransformationException {
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         Document documentIn = null;
         DocumentBuilder builder = null;
         try {
         builder = factory.newDocumentBuilder();
         } catch (ParserConfigurationException e1) {
         e1.printStackTrace();
         try {
         Element itemNode = null;
         //NodeList[] list_f=new NodeList10;
         //Element[] field=new Element10;
         documentIn = builder.parse(in);
         documentOut = builder.newDocument();
         Element rootNode = documentOut.createElementNS("urn:agrp:xi:geissseb","ns0:mt_MappingIn");
         rootNode.setAttribute("xmlns:ns0", "urn:agrp:xi:geissseb");
         documentOut.appendChild(rootNode);
         Element tableNode = documentOut.createElement("TABLE");
         rootNode.appendChild(tableNode);
         NodeList list_Set = documentIn.getElementsByTagName("set");
         System.out.println(list_Set.getLength());
         for(int j = 0 ; j < list_Set.getLength() ;j++){
              Element setNode = (Element)list_Set.item(j);
              NodeList children = setNode.getChildNodes();
              for(int index = 0; index < children.getLength(); index++)
                   Node child = children.item(index);
                   if (child instanceof Element) {
                        Element element = (Element) child;
                        if(element.getNodeName().startsWith("set_ELEMENT"))
                             createItemFeildNode(tableNode,element);
         //list_f[9]=documentIn.getElementsByTagName("set_ELEMENT_10");
    //     NodeList list_f01=documentIn.getElementsByTagName("f01");
         /*for (int i=0;i<list_Set.getLength();i++)
         itemNode=documentOut.createElement("item");
         tableNode.appendChild(itemNode);
         for(int k=0; k<10;k++){
         Node f=list_f[k].item(i);
         f=f.getFirstChild();
         String str_f=f.getNodeValue();
         Text text_f=documentOut.createTextNode(str_f);
         field[k]=documentOut.createElement("item_FIELD_"(k1));
         field[k].appendChild(text_f);
         itemNode.appendChild(field[k]);
         TransformerFactory tf = TransformerFactory.newInstance();
         Transformer transform = tf.newTransformer();
         transform.transform(new DOMSource(documentOut), new StreamResult(out));
         transform.transform(new DOMSource(documentOut), new StreamResult(System.out));
         } catch (SAXException e2) {
         e2.printStackTrace();
         } catch (IOException e2) {
         e2.printStackTrace();
         }catch (Throwable t) { throw new StreamTransformationException("error", t); }
         private void createItemFeildNode(Element root, Element element) {
              String inName = element.getNodeName();
              int temp = inName.lastIndexOf('_');
              if (temp == -1)
                   return;
              String index = inName.substring(temp+1);
              String nodeName = "Item_FIELD_" + index;
              String nodeVal = element.getFirstChild().getNodeValue();
              Element newElement = documentOut.createElement(nodeName);
              Text txtNode = documentOut.createTextNode(nodeVal);
              newElement.appendChild(txtNode);
              root.appendChild(newElement);          
    Input
    <?xml version="1.0" encoding="UTF-8" ?>
    <mt_MappingOut xmlns="urn:agrp:xi:geissseb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:agrp:xi:geissseb file:/D:/Eclipse/workspace/SDN/test.xsd">
    <set xmlns="">
      <set_ELEMENT_01>E1</set_ELEMENT_01>
      <set_ELEMENT_02>E2</set_ELEMENT_02>
      <set_ELEMENT_03>E3</set_ELEMENT_03>
      <set_ELEMENT_04>E4</set_ELEMENT_04>
      <set_ELEMENT_05>E5</set_ELEMENT_05>
      <set_ELEMENT_06>E6</set_ELEMENT_06>
      <set_ELEMENT_07>E7</set_ELEMENT_07>
      <set_ELEMENT_08>E8</set_ELEMENT_08>
      <set_ELEMENT_09>E9</set_ELEMENT_09>
      <set_ELEMENT_10>E10</set_ELEMENT_10>
      </set>
      </mt_MappingOut>
    Output
    <?xml version="1.0" encoding="UTF-8" ?>
    <ns0:mt_MappingIn xmlns:ns0="urn:agrp:xi:geissseb">
    <TABLE>
      <Item_FIELD_01>E1</Item_FIELD_01>
      <Item_FIELD_02>E2</Item_FIELD_02>
      <Item_FIELD_03>E3</Item_FIELD_03>
      <Item_FIELD_04>E4</Item_FIELD_04>
      <Item_FIELD_05>E5</Item_FIELD_05>
      <Item_FIELD_06>E6</Item_FIELD_06>
      <Item_FIELD_07>E7</Item_FIELD_07>
      <Item_FIELD_08>E8</Item_FIELD_08>
      <Item_FIELD_09>E9</Item_FIELD_09>
      <Item_FIELD_10>E10</Item_FIELD_10>
      </TABLE>
      </ns0:mt_MappingIn>

  • Problem in Uploading Java mapping Code

    Hi Guys,
                  I never work on Java mapping before, i got the code required for my progrmme in these forums.So i saved it as a text file. now i want to import that fileintomy programme as Java class. i think i have to use Netweaver Studio. what exactly i have o do it.
    Thanks in advance.
    Kartik

    Hello Kartik,
    If your code is handling the Required Mapping.Then what is you need to do is  :
    Create the Jar file using any Java IDE (or) use Netweaver developer studio.
    Before creating the u201Cjaru201D file just make sure that the "path" of the class file in the imported archive. It should be the
    same as your "package" path.
    Once the class file is created, we have to create the jar file with all the necessary files. After creating the jar file, it
    has to be deployed to XI.
    Import the Jar file using Imported Archive  in IR under Mapping Objects.
    See this blog it explains how to load :
    Java Mapping (Part III)
    After doing the necessary setps you can test the Mapping.
    regards
    Gangaprasad

  • Error while doing java mapping

    Hi,
    I have written a java mapping code .But i have a small doubt when i compile it it is showing errors that package com.sap.aii.mapping.api does not exist.How can i solve the problem.Please help me in this issue.
    Thanks,
    Bhargav

    Hi ,
    check this thread, it may help you.
    https://forums.sdn.sap.com/click.jspa?searchID=3558715&messageID=3229273
    Regards,
    Ramesh.

Maybe you are looking for

  • ITMS Music Download (err = -50)

    I've purchased many songs from the iTMS. I'm trying to download a whole album and getting this error message during each song download: +++++++++++++++++++++ There was a problem downloading "song title/Band/Album". An unknown error occurred (-50). Pl

  • Photosmart - C4388 - Not printing correctly - PDF document

    Photosmart 4388 is not printing correctly when a PDF document is printed from Adobe Reader/ Adobe Acrobat Version 10 (Latest Version). Same line / part of line gets printed more than once for some lines. OS: Vista Home Premium (32 Bit) Hardware : Del

  • OLE 2.0, where to find?

    I need to convert some old Quark 3.11 docs to Indesign. It goes by first converting them to PageMaker files by PageMaker´s QuarkXPress Converter. The converter worked in classic in my old mac, but now it does not run but tells that OLE 2.0 needs to b

  • ESSSVR consuming too much memory

    I was concerned about the memory consumption of the ESSSVR.exe process and I think there might be a problem with it. I have two instances available to me with the exact OS / Hardware / Environment configuration and the exact same configuration when i

  • What happened to the tool bar & why did you switch my browser from Google to Yahoo?

    When I downloaded Firefox 4 you switched my search engine from Google to Yahoo. I much prefer Google. Secondly, at the same time, my toolbar disappeared. When I wanted to print out a mutual fund activity confirmation, there was no means to do it. Unl