cancel
Showing results for 
Search instead for 
Did you mean: 

JAVA MAPPING

Former Member
0 Kudos

hello experts

I have a scenario xml file to RFC. I would like to insert all the XML to an element in the RFC

so in that element I will have the all XML file.

does any one knows the JAVA code in order to do a JAVA MAPPING for XML file into the RFC?

help is needed

Kfir

Accepted Solutions (1)

Accepted Solutions (1)

former_member200962
Active Contributor
0 Kudos

Hi,

Is it necessary for you to use a JAVA mapping?...if not i would have preffered a XSLT mapping

For the required JAVA Mapping try this link:

https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/javaMapping-ConverttheInputxmlto+String

Regards,

Abhishek.

Edited by: abhishek salvi on Nov 25, 2008 7:24 PM

Answers (15)

Answers (15)

Former Member
0 Kudos

fixed

Former Member
0 Kudos

hello

after not succedding with XSL, I decided to try JAVA MAPPING.

I am using this code(that was offered before). the code is from an example file 2 file, but i dont think it is matter to me that I have WS 2 RFC, to a specific element in the RFC. again, I am trying to take the all XML file that I recieve in the DT and insert it as string to the element in the RFC

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.StreamTransformation;

/**

  • @author santhosh.vellingiri

*/

public class xmlpayload implements StreamTransformation {

public static void main(String args[]) throws Exception {

FileInputStream inFile =

new FileInputStream("C:/Documents and Settings/santhosh.vellingiri/Desktop/SGD/xmlin.XML");

FileOutputStream outFile =

new FileOutputStream("C:/Documents and Settings/santhosh.vellingiri/Desktop/SGD/xmlout.XML");

xmlpayload xml = new xmlpayload();

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

}

}

}

and recieve this error.

<?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>Application</SAP:Category>

<SAP:Code area="MAPPING">LINKAGE_ERROR</SAP:Code>

<SAP:P1>xmlpayload</SAP:P1>

<SAP:P2>http://Migdal.co.il/CRM/SAP-CRM/ProposalDeatailsS~</SAP:P2>

<SAP:P3>d7e31f30-53be-11dc-8fbd-ee09c0a8664d</SAP:P3>

<SAP:P4>-1</SAP:P4>

<SAP:AdditionalText />

<SAP:ApplicationFaultMessage namespace="" />

<SAP:Stack>Class versions are incompatible (linkage error)</SAP:Stack>

<SAP:Retry>N</SAP:Retry>

</SAP:Error>

as I can see sometthing is missing and I dont know what exactly.

help is needed

Thanks

Kfir

Former Member
0 Kudos

the xsl that I am using is:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://Migdal.co.il/CRM/SAP-CRM/ProposalDeatailsService">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>

<xsl:template match="/">

<ZRFC_IY_NTR>

<IV_UNDERWRITINGSTATUSENUM>

<xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[]]></xsl:text>

<xsl:copy-of select="."/>

<xsl:text disable-output-escaping="yes"><![CDATA[]]]]></xsl:text>

<xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>

</IV_UNDERWRITINGSTATUSENUM>

</ZRFC_IY_NTR>

</xsl:template>

</xsl:stylesheet>

Former Member
0 Kudos

I tried a few things, and now my code look like this

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>

<xsl:template match="/">

<ZRFC_IY_NTR>

<IV_UNDERWRITINGSTATUSENUM>

<xsl:text disable-output-escaping="yes"><![CDATA[<!CDATA[]></xsl:text>

<xsl:copy-of select="."/>

<xsl:text disable-output-escaping="yes"><!CDATA[]]]></xsl:text>

<xsl:text disable-output-escaping="yes"><![CDATA>]></xsl:text>

</IV_UNDERWRITINGSTATUSENUM>

</ZRFC_IY_NTR>

</xsl:template>

</xsl:stylesheet>

and the error is:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<!-- Call Adapter

-->

<SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">

<SAP:Category>XIAdapterFramework</SAP:Category>

<SAP:Code area="MESSAGE">GENERAL</SAP:Code>

<SAP:P1 />

<SAP:P2 />

<SAP:P3 />

<SAP:P4 />

<SAP:AdditionalText>com.sap.aii.af.ra.ms.api.DeliveryException: error while processing message to remote system:com.sap.aii.af.rfc.core.client.RfcClientException: functiontemplate from repository was <null></SAP:AdditionalText>

<SAP:ApplicationFaultMessage namespace="" />

<SAP:Stack />

<SAP:Retry>M</SAP:Retry>

</SAP:Error>

I looked at the SDN and didnt see any thing. does any one know how to fix this?

Thanks

Kfir

former_member200962
Active Contributor
0 Kudos

Hi,

Try refering these discussions...somewhat similar (not same) issue is discussed here:

Regards,

Abhishek.

Former Member
0 Kudos

I used the XSL mapping as you suggested, and it seems to insert the the xml file as a string to the element (at list this is what I see in the sxmb). in the RFC we dont see any data (it is empty). more over, I see an error in the sxmb (see below). any suggestions?

error message:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<!-- Call Adapter

-->

<SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">

<SAP:Category>XIAdapterFramework</SAP:Category>

<SAP:Code area="MESSAGE">GENERAL</SAP:Code>

<SAP:P1 />

<SAP:P2 />

<SAP:P3 />

<SAP:P4 />

<SAP:AdditionalText>com.sap.aii.af.ra.ms.api.DeliveryException: error while processing message to remote system:com.sap.aii.af.rfc.core.client.RfcClientException: could not convert request from XML to RFC:com.sap.mw.jco.JCO$Exception: (130) JCO_ERROR_XML_PARSER: Expecting a tag to begin with '<'2', in "Agent><ID>237cb1f3-1"</SAP:AdditionalText>

<SAP:ApplicationFaultMessage namespace="" />

<SAP:Stack />

<SAP:Retry>M</SAP:Retry>

</SAP:Error>

xsl mapping:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://Migdal.co.il/CRM/SAP-CRM/ProposalDeatailsService" targetNamespace="http://Migdal.co.il/CRM/SAP-CRM/ProposalDeatailsService" xmlns:a="TargetNamespace" xmlns:b="SourceNamespace">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>

<xsl:template match="/">

<a:ZRFC_IY_NTR>

<a:IV_UNDERWRITINGSTATUSENUM>

<xsl:text disable-output-escaping="yes"><![CDATA[<!CDATA[]></xsl:text>

<xsl:copy-of select="."/>

<xsl:text disable-output-escaping="yes"><!CDATA[]]]></xsl:text>

<xsl:text disable-output-escaping="yes"><![CDATA>]></xsl:text>

</a:IV_UNDERWRITINGSTATUSENUM>

</a:ZRFC_IY_NTR>

</xsl:template>

</xsl:stylesheet>

former_member200962
Active Contributor
0 Kudos

Hi,

Instead of the following:

<xsl:copy-of select="."/>

have something like:

<xsl:copy-of select="b:/path_of_sourcenode"/>

One more thing that you can do is instead of a: and b: give the exact prefixes; exact means the one that you see when you view the source of your message in IR....

Just tried a similar mapping and it is working fine for me :(.......

OPTIONAL:

if you do some more R&D you can even have only the data within the nodes....

E.g:

<SRC>

<node1>abcd</node1>

<node2>xyz</node2>

</SRC>

Then you can even have your output as:

<TRG>

<node>abcd xyz</node>

</TRG>

Just a little modification to the code that I have given and you should be done with your mapping :)....

Regards,

Abhishek.

Former Member
0 Kudos

Abhishek

first I would like to thank you for the detailed answer. I am trying to do exactly as you wrote.

I still have a Q in the XSL. I took an XSL that been suggested and didnt know what to change (I am not quite familiar with XSLT programming). this is what I wrote:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[]]></xsl:text>

<xsl:copy-of select="a:sdn.sap.com/exchangeforums"/>

<xsl:text disable-output-escaping="yes"><![CDATA[]]]]></xsl:text>

<xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>

</xsl:stylesheet>

I imported the XSL file (which placed inside a zip file) and creating another IM (beside the one that I already have).you wrote "now select the corresponding Source and Target Message Interfaces (corresponding to the Message Types that you have used in xslt mapping)" - as you can see what exactly I need to write in the XSL file. the name of the MT that enter to the XI (which I recieve in the WSDL) is p2.MortgageProposalRequest. the name of the target RFC is ZRFC_IY_NTR and the name of the element in the RFC that should be mapped to the root of the request is IV_UNDERWRITINGSTATUSENUM.

right now when I select in the new IM the xsl mapping, I dont have suggested in the drop down list the zip file that I added to the archive.

what is missing in the xsl file so it will be complete?

what could be the reasons for not knowing the xsl file that I added in the archive in the IM?

since I am adding another IM, will the original IM will also take place?

Kfir

former_member200962
Active Contributor
0 Kudos

Hi,

Try this code:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="TargetNamespace" xmlns:b="SourceNamespace">
	<xsl:template match="/">
		<a:ZRFC_IY_NTR>
<a:IT_PHONES>
<a:items>
				<a:PHONETYPE>
				<xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[
				
				]]
				>
			
		


	
]]>

Please remember the following points:

1) This code is developed kepping in mind that you want to convert the contents of the entire InsuranceFile node (it will include ID, Family etc) of source into string and to put it under the ZRFC_IY_NTR --> IT_PHONES --> items --> PHONETYPE

So you need to develop your mapping accordingly....you need to do some self-study also

2) Now regarding the confusion of where/ how to include the mapping:

You might have created a outbound MI with MortgageProposalRequest as the MT and an inbound MI with ZRFC_IY_NTR acting as the MT...

Now when you create an IM and include the source, target structures you hit the read operation button which displays the corresponding source and target MTs...then instead of selecting the Message Mapping, select the XSL option and then you can select your mapping program as usual....

Regards,

Abhishek.

Former Member
0 Kudos

here is a link to my mapping

https://wiki.sdn.sap.com/wiki/download/attachments/4384/untitled.JPG

as you can see, I have some elements in the XSD that mapped to the RFC, and I would like the root element of the XSD (that also the root element of the xml) to insert as a string of the all xml to one of the target elements in the RFC which is from type String.

Thanks

Kfir

Former Member
0 Kudos

Abhishek.

Thanks for the details respons. but after I write the XSL (with xmlSpy), I need to load it to the XI directory.

where exactly I need to load it in the XI in order for the root element of the XSD will be displayed in the RFC element?

more over, you describe an empty root where I put the XSL file, but since I dont edit the XSL I dont under stand where exactly will I see it.

since this is the first time I work with XSL I will appreciate if you direct me where exactly to load the xsl file in xi.

more over, the root XSD does not have a type, since it is the root. if I map it, the xml will perform from the root down?

Thanks

Kfir

former_member200962
Active Contributor
0 Kudos

Hi,

When you have completed the xslt mapping you need to zip it and then include it under the Imported Archives section in IR...it will be present under your respective namespace...after you have imported the mapping create a new Interface Mapping...now select the corresponding Source and Target Message Interfaces (corresponding to the Message Types that you have used in xslt mapping)....then you just need to select the XSL mapping option from the dropdown list (one present with the default as Message Mapping).....and select the mapping from imported archives...then you can test the mapping in Interface mapping itself..so that you can come to know about any errors.

Have a look at Michal's blog: ....it will answer all your Qs

Regards,

Abhishek.

Edited by: abhishek salvi on Nov 26, 2008 12:29 PM

Edited by: abhishek salvi on Nov 26, 2008 12:31 PM

Former Member
0 Kudos

how can I pass the structure of the RFC and the XSD?

how can I do paste of a picture in the forum?

do you have a mail?

Kfir

former_member200962
Active Contributor
0 Kudos

Hi,

you can try https://www.sdn.sap.com/irj/scn/wiki ...it is the wiki wing of sdn where you can post your docs/ pics....dont forget to remove the confidential/ client specific material from you doc/ pic..

Regards,

Abhishek.

former_member194786
Active Contributor
0 Kudos

Do you need to map other fields in the RFC as well, based upon the input xml file?

Thanks and Regards,

Sanjeev.

Former Member
0 Kudos

lets say I use XSL mapping.

I need an explanantion after I write an XSL file, where do I import it, how do I map the xml to a specific node, and all the actual steps in order to map it correctly.

Thanks

Kfir

former_member200962
Active Contributor
0 Kudos

Hi,

Suppose you use XSLT:

1) you will need an editor for it...say StylusStudio

2) open a new project in it and say the type as xslt document.

3) there you have an option to include the source and target message xsd

4) just map the root element of your source message to the appropriate element in the target structure (this should be the one you want to have the entire string).

5) after you map these two things you can see an empty mapping being formed...then use this code between the start and end tag of the desired target node...

				<xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[
				
				]]
				>]]>

This is a working model and should work in your case also.

6) Then check if you are getting the desired result...there is something called as Preview/ Debug...it will ask for a test xml file....

7) then zip this xslt file and include it in the interface mapping between the source and target structures.

Remember that you should place the source, target and .xslt file in the same folder...otherwise it will show source/ target not found message.

Regards,

Abhishek.

Edited by: abhishek salvi on Nov 25, 2008 7:52 PM

Former Member
0 Kudos

Sanjeev

I will try to be more specific. my xml that I recieve, I translate it to XSD, and some of the fields are mapped to the RFC. in advanced to that, I want to insert the all XML that I recieve to a specific element. as I said before, I think this is does by java mapping.

if I take your code, what exactly do I need to map in order to recieve the XML, beside to the specific fields that I map, to a specific element.

do I put it as UDF from the root of the XSD to the element?

what is the mapping that I need to do?

Thanks

Kfir

former_member194786
Active Contributor
0 Kudos

Kfir goldwasser,

<<<<I want to insert the all XML that I recieve to a specific element. as I said before, I think this is does by java mapping. >>>>>>

Yes that's what is exactly done by the code that i provided. But that code has to be a part of a Java Mapping. Let the XML come into XI and then the Java Mapping will be executed on it. So that you will have the input of the Java Mapping, your whole source message. Now when you have created your mapping and imported the .jar file in your imported archive you can provide your source message as input of Java mapping and Target as output of java mapping.

Regards,

Sanjeev.

former_member190389
Active Contributor
0 Kudos

Hi,

You mean to say that along with other fields of RFC there is one field whose value should be the whole XML , right ?

As well as you want that other fields in RFC to take values from the source XML?

Please share your RFC structure.

Former Member
0 Kudos

Sanjeev.

as I under stand I will put it in UDF the code that you told me.

do you want me to put the header root with UDF to the extra element?

how exactly do I need to map the UDF or what ever I need to do in order to map it correctly?

Thanks

Kfir

Former Member
0 Kudos

hello Sanjeev

yes. I am recieving XML file, and I would like to insert it to a single element in the RFC (string element)

Thanks

Kfir

former_member194786
Active Contributor
0 Kudos

Hi,

Use the following code for the same:

StringBuffer strbuffer = new StringBuffer();

byte[] b = new byte[4096];

for (int n; (n = in.read(b)) != -1;) {

strbuffer.append(new String(b, 0, n));

}

data = strbuffer.toString();

Here "in" is the InputStream.

now you have all the data in a single variable "data". Use data while producing the output xml and map it to the target field( RFC output field).

The code has to be used in the execute method.

Thanks and Regards,

Sanjeev.

dharamveer_gaur2
Active Contributor
0 Kudos

Hi

use this thread to convert your XML file into a single payload

XML string into single node

former_member194786
Active Contributor
0 Kudos

Hi Kfir Goldwasser,

You mean you need the whole payload in a single field?

Regards,

Sanjeev.