XML to Java mapping pattern

hi all,
i have to implement a component that performs translation from a Custom Format to a Java Object and vice versa.
We planned to use XML in the process, so the whole process will be, for example:
Custom Format ---> XML ------> Java Object
the Java Object produced are usecase specific.
now, i want to keep all my options open for XML2J, so i decided to use an XML2JMapper interface that will convert automatically XML 2 java object and vice versa.
this is the only component, across all usecases, that i want to be able to replace whenever i want dynamically.
The step left is how to go from CustomFormat to XML and vice versa, so i decided again to write an interface, Normalizer, which takes care of converting between Custom Format and XML.
the Normalizer is usecase specific, while the XML2JMapper is replaceable, and not usecase dependent.
The component that i have to write is made of Normalizer and XML2JMapper, so i was wondering if there was a particular design pattern that can help me...
I have thought about Builder, but i want to be able to parametrize the XML2JMapper used (that is usecase independent)
has anyone any suggestions?
what about Builder together with Mediator?
thanx in advance and regards
marco

Why not something like the following:
Custom Format -> Java object <- XML
Implement IParser that will take either XML or the custom format and turn it into the Java object. Implement ISerializer to do the reverse. You could also stack on a Factory pattern to determine which parser and serializer to use (as they may be different).
XML2J is simply used in one parser implementation (or as a helper for other implementations). Your design is freed up. You don't have to go from Custom format -> XML -> Java object (why do the middle step?). And you can easily add new parsers or serializers to your framework as needed.
- Saish
"My karma ran over your dogma." - Anon

Similar Messages

  • JAX-RPC, derived XML to Java mapping.

    When studying table 4-2 of the JAX-RPC 1.1 specification one can see that e.g. xsd:gDay and xsd:token should be mapped to java.lang.String.
    However when generating Java using Axis for instance gDay is mapped to a specific Axis class, Day. Is this JAX-RPC compliant or should the gDay be mapped to a String (after checking that the format is OK with the gDay description) ?

    Why not something like the following:
    Custom Format -> Java object <- XML
    Implement IParser that will take either XML or the custom format and turn it into the Java object. Implement ISerializer to do the reverse. You could also stack on a Factory pattern to determine which parser and serializer to use (as they may be different).
    XML2J is simply used in one parser implementation (or as a helper for other implementations). Your design is freed up. You don't have to go from Custom format -> XML -> Java object (why do the middle step?). And you can easily add new parsers or serializers to your framework as needed.
    - Saish
    "My karma ran over your dogma." - Anon

  • WSDL/XML to Java Mapping.

    I am generating a web service from a WSDL file which has several attributes with type="xsd:double" as shown below.
    <s:complexType name="q_measure">
    <s:attribute name="uom" type="s:string"/>
    <s:attribute name="queryValue" type="s:double"/>
    </s:complexType>
    My understanding per jax-rpc standards is that since the default usage of the attribute is optional, the generated class should use the wrapper class of java.lang.Double instead of primitive type double. However the generated class is using the primitive java type. Even if I change the WSDL to specifically indicate use="optional", it still uses the primitive type.
    Am I missing something here or is this a problem with how jdeveloper is generating the classes. I have used the same WSDL with eclipse/xFire and Netbeans/JAX-RPC and they seem to correctly use the wraper class.

    Hi,
    i think this is clearly a bug and you should file it on metalink to get it solved....

  • 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

  • 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

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

  • 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

  • XML Validation with XSD in java mapping

    Hi experts,
    I have created an interface to send differents messages between bussines system, the bussiness system receiver is put in the message, to get this value I have a configuration file indicating the path of this field for each message type. In a java mapping I transform the message sent in this structure:
    <document>
    <message>HERE THE MESSAGE AS STRING</message>
    <parameters>
    <sender>HERE SENDER BUSSINESS SYSTEM</sender>
    <receiver>HERE RECEIVER BUSSINESS SYSTEM</receiver>
    </parameters>
    </document>
    the messaging interface works fine, but now I have to validate the XML vs XSD. I need doing in a java mapping because the messaging interface send the message and a email to sender in error case.
    To do this validation I have implemented two java mappings that works fine in my local, the first way is with class Validator of java 5, but my system PI 7.1 return an error with this class. The second way is with SAX parse:
    String schema = "XXXXXxsd";
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    docBuilderFactory.setNamespaceAware(true);
    docBuilderFactory.setValidating(true);
    docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage","http://www.w3.org/2001/XMLSchema");
    InputStream is = this.getClass().getClassLoader().getResourceAsStream(schema);
    docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",is);
    in my local works fine but in PI always return OK never fail.
    For this moment the schema is hardcoded to do proofs, in the future will be loaded from my configuration file.
    Any idea?
    Thanks in advance
    Jose

    hi Jose,
    PI 7.1 has a built in feature available called XML vaidations ..
    your source xml can be validated against a XSD placed at a specific location on the PI server..
    validation can be performed at adapter/integration engine
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d06dff94-9913-2b10-6f82-9717d9f83df1?quicklink=index&overridelayout=true

  • 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

  • Java Mapping with an xml array as input

    Hi Gurus,
    I have to perform a java mapping to map some input xml contained in an array with a target message type. I have found a good java mapping example here:
    Re: Please provide Java Mapping example
    but my mapping input is not a single XML, but an XML array, thus I have a doubt...
    How can I map multiple XML contained in an array with a target XML? I have to solve this problem into a Java mapping prospective.
    Thanks to all!
    Message was edited by:
            Gabriele Morgante

    Hey Stefan, I think he is refering to a n:1 multimapping.
    If that is indeed the case, Gabriele, you will have to consider the initial tags inserted by mapping runtime to treat multimappings.
    Suppose your XML message is like
    <myMT xmlns="urn:mynamespace">
      <value>xpto</value>
    </myMT>
    Then, if your source message interface occurrence is defined as unbounded in your interface mapping, your mapping program (message mapping, xslt, java mapping, whatever) will receive, from mapping runtime, a message like this:
    <Messages xmlns="http://sap.com/xi/XI/SplitAndMerge">
      <Message1>
        <myMT xmlns="urn:mynamespace">
          <value>xpto1</value>
        </myMT>
        <myMT xmlns="urn:mynamespace">
          <value>xpto2</value>
        </myMT>
        <myMT xmlns="urn:mynamespace">
          <value>xpto3</value>
        </myMT>
      </Message1>
    </Messages>
    Also, if you have more than 1 message type as source of your interface mapping, your mapping program will receive the other message types in <Message2>, <Message3>... tags.
    The <Messages> and <MessageX> tags will always be automatically generated by mapping runtime when dealing with multimappings, which are mappings from m XML messages to n XML messages, with either m, n or both different of 1 (note that this definition includes mappings from 1 type to 1 type, when either source, target or both message types have max occurrence = ubounded).
    Finally, remember that the output that your mapping program generates will also have to include these <Messages> and <MessageX> tags (with proper namespace), since mapping runtime will be expecting them. Message mappings treat those by default, but your xslt and java multimappings will have to explicitely include these tags in the output.
    Regards,
    Henrique.

  • 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

  • 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

  • Java mapping - XML name space

    Hi experts,
    I doing a java mapping to meet my requirement. I use the following code to produce the target XML
    String transactionId = ........................................
                  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();                              
    //               Create the output DOM
                Document docOut = builder.newDocument();
                Element dashboardInputTypeNode = docOut.createElement("dashboardInputType");
                docOut.appendChild(dashboardInputTypeNode);
               Element transactionIdNode = docOut.createElement(transactionId);
                dashboardInputTypeNode.appendChild(transactionIdNode); 
                Text transactionIdText = docOut.createTextNode("transactionId");
                transactionIdNode.appendChild(transactionIdText);
               // transform the new xml to the output stream
                TransformerFactory tf = TransformerFactory.newInstance();
                Transformer transform = tf.newTransformer();
                transform.transform(new DOMSource(docOut), new StreamResult(out));
    This code produces me the following XML
      <?xml version="1.0" encoding="UTF-8" ?>
      <dashboardInputType>
          <transactionId>transactionId</transactionId>
      </dashboardInputType>
    But, I need the XML to be produced with the following namespace
      <?xml version="1.0" encoding="UTF-8" ?>
      <ns1:dashboardInputType xmlns:ns1="http://www.watercorporation.com.au/dashboard">
          <ns1:transactionId>transactionId</ns1:transactionId>
      </ns1:dashboardInputType>
    what changes do I need to make in my code to get tge desired output?
    Reward points for the right answer or doco.
    Thanx heaps....
    Sabbir

    try this .
    docOut.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:ns1","http://www.watercorporation.com.au/dashboard"");

  • Java Mapping Using JAXB [Java Arch for XML Binding]

    Hi All,
    Anyone tried using JAXB  [Java Architecture for XML Binding API available with Java WebServices Pack] technique for XML processing in Java Mapping??
    I am facing the following problems..
    1. I am not able to generate namespace while marshalling target XML [In standalone mode and not tried in XI].
    2. What are the jar files we need to import?
       I tried importing the following jar files in XI.
    jaxb-api.jar,jaxb-impl.jar,jaxb-libs.jar,jax-qname.jar,namespace.jar,relaxngDatatype.jar
      and getting some errors while importing these files in XI.
    3. It throws error at runtime [Interface Mapping-Test Tab]
       like Resource not found:javax/xml/bind/Messages_en.properties,javax/xml/bind/Messages_en_US.properties
    4. Even after creating a copy of available file Messages.Properties with name: Messages_en.properties and Messages_en_US.properties.. it is not generating any messages in Target message tab
    Thanks in Advance,
    Ananth Chinnaraj

    Sravya ,
    I have searched wide and far for this, but no success.
    A lot on JAXB XI and Webdynpro, but nothing on JAXB, XI and mappings.
    Could you please post the url here ?
    Thanks and kind regards,
    Jan

  • XML Structure Conversion using JAVA Mapping

    Hi Experts,
    I am having a requirement in which i want to convert the contents of source xml structure into a string and map it to the target field.
    Source Structure:
    <SRC>
    <Node1>ABCD</Node>
    <Node2>XYZ</Node2>
    <Node3>1234</Node>
    </SRC>
    Target Structure:
    <TRG>
    <Node1>ABCDXYZ</Node1>
    </TRG>
    Both the source and target structures are in xml format only.....just the condition is that I have to use Java mapping to achieve it.
    The contents of Source node Node3 are not to be mapped.
    Since I have very less knowledge of Java it will be very helpful if you provide the complete code to me.
    Thanks,
    Abhishek.

    Hello Udo,
    Thank you for reply. It seems ABAP mapping is easier.
    What do you think about the idea of using Value Mapping for such conversion task? In this case is it obligatory to use Java coding? And how about performance - will it be better than in case of ABAP mapping, can you say?
    Thank you,
    Igor

Maybe you are looking for