on 09-20-2007 7:16 AM
How to do the java mapping in a scenario?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Refer these blogs for java mapping
<a href="/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i Part I</a>
<a href="/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii Part II</a>
<a href="/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii Part III</a>
by Prasad Ulagappan
regards
preetha
Message was edited by:
Preetha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the sample code for ur reference...
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SOAP_Sender xmlns:ns0="http://sdn.com/XI/Demo/SOAP2File">
<Customer>
<Fname>AAA</Fname>
<Mname>BBB</Mname>
<Lname>CCC</Lname>
<CustID>12345</CustID>
<Address>ADD1</Address>
</Customer>
<Customer>
<Fname>XXX</Fname>
<Mname>YYY</Mname>
<Lname>ZZZ</Lname>
<CustID>12345</CustID>
<Address>ADD2</Address>
</Customer>
<Customer>
<Fname>RRR</Fname>
<Mname>SSS</Mname>
<Lname>TTT</Lname>
<CustID>12345</CustID>
<Address>ADD3</Address>
</Customer>
</ns0:MT_SOAP_Sender>
<b>Java Coding:</b>
package xi.mapping.java;
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.xml.sax.SAXException;
//import org.w3c.dom.Text;
//import sun.security.action.GetBooleanAction;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class JavaMapping implements StreamTransformation{
public void setParameter(Map map){}
public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(in);
NodeList custList = doc.getElementsByTagName("Customer");
NodeList fName[]= new NodeList[custList.getLength()];
NodeList lName[]= new NodeList[custList.getLength()];
NodeList mName[]= new NodeList[custList.getLength()];
NodeList custId[]= new NodeList[custList.getLength()];
NodeList address[]= new NodeList[custList.getLength()];
Element fnameElement [] = new Element[custList.getLength()];
Element mnameElement [] = new Element[custList.getLength()];
Element lnameElement [] = new Element[custList.getLength()];
String name[] = new String [custList.getLength()];
// for input...
for (int i=0; i <custList.getLength();i++){
Node custNode = custList.item(i);
Element element = (Element)custNode;
fName<i> = element.getElementsByTagName("Fname");
fnameElement<i> = (Element)fName<i>.item(0);
mName<i> = element.getElementsByTagName("Mname");
mnameElement<i> = (Element)mName<i>.item(0);
lName<i> = element.getElementsByTagName("Lname");
lnameElement<i> = (Element)lName<i>.item(0);
name<i> = fnameElement<i>.getChildNodes().item(0).getNodeValue()" " mnameElement<i>.getChildNodes().item(0).getNodeValue()+ " "+lnameElement<i>.getChildNodes().item(0).getNodeValue();
custId<i>= element.getElementsByTagName("CustID");
address<i> = element.getElementsByTagName("Address");
}
// for output
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>".getBytes());
out.write("<ns0:MT_File_Receiver xmlns:ns0=\"http://sdn.com/XI/Demo/SOAP2File\">".getBytes());
for (int j=0; j< custList.getLength();j++){
out.write("<Customer>".getBytes());
//out.write("<Name></Name>".getBytes());
//String name = fName[j].item(0).toString() + mName[j].item(0).toString() + lName[j].item(0).toString();
out.write(("<Name>" + name[j]+ "</Name>").getBytes());
out.write(custId[j].item(0).toString().getBytes());
out.write(address[j].item(0).toString().getBytes());
out.write("</Customer>".getBytes());
}
out.write("</ns0:MT_File_Receiver>".getBytes());
}
catch (SAXException saxexp){
System.out.println(saxexp);
}
catch(Exception e){
System.out.println(e);
}
}
}
Hi sankar,
A very important place where you will use JAVA in XI is while doing your Mapping. There will be cases when JAVA MAPPING is the best solution to go for. There are 2 types of Parsers available for JAVA Mapping. DOM Parser and SAX parser. Just got through the following links to understand more on Java Mapping and the APIs available.
http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/package-summary.html http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Document.html http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/package-frame.html /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
If you want you can also send java code as payload to do mapping in XI. For this go through the url:
/people/sap.user72/blog/2005/12/14/sending-java-code-as-payload-to-do-mapping-in-xi
JAVA mapping -
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
https://www.sdn.sap.com/irj/sdn/weblogs?
blog=/pub/wlg/1921
/people/amol.joshi2/blog/2006/03/10/think-objects-when-creating-java-mappings /people/sameer.shadab/blog/2005/09/29/testing-abap-mapping
sample code for java mapping
DOM PARSER API -
http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/package-frame.html
DOM ---
/people/thorsten.nordholmsbirk/blog/2006/08/10/using-jaxp-to-both-parse-and-emit-xml-in-xi-java-mapping-programs
For a tutorial on the methods of SAX and DOM http://java.sun.com/webservices/docs/1.1/tutorial/doc/
SAX AND dom PARSER ( BY thorsten) -
example /people/thorsten.nordholmsbirk/blog/2006/08/10/using-jaxp-to-both-parse-and-emit-xml-in-xi-java-mapping-programs java mapping example ( testing and debugging) /people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
reagrds
Biplab
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You need to have aii_map_api.jar in XI server and for Java mapping you must define a Java class that implements the Java interface After creating java program zip this file along with the class file and import it into XI Integration Repository as 'Imported Archives' under the mapping objects .After that create the Interface Mapping
These weblogs would help you
/people/thorsten.nordholmsbirk/blog/2006/08/10/using-jaxp-to-both-parse-and-emit-xml-in-xi-java-mapping-programs
/people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/frameset.htm
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
https://www.sdn.sap.com/sdn/weblogs.sdn?blog=/pub/wlg/1947. [original link is broken] [original link is broken] [original link is broken]
/people/ravikumar.allampallam/blog/2005/06/24/convert-any-flat-file-to-any-idoc-java-mapping
/people/michal.krawczyk2/blog/2005/02/25/simple-java-code-in-graphical-mapping--xi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can go thru these threads,
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
/people/alessandro.guarneri/blog/2007/03/25/xi-java-mapping-helper-dom
/people/rahul.nawale2/blog/2006/07/18/java-mapping-an-alternate-way-of-reading-a-csv-file
Regards,
Samson Rodrigues.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.