cancel
Showing results for 
Search instead for 
Did you mean: 

Problem exporting XML via RFC

Former Member
0 Kudos

Hi everyone

I am using RFC to send XML data from CRM to XI.

My function modules (/MARS/CPE_IMPORT_CRM_CATALOG) contains only one parameter (IV_CATALOG) declared as a string so all XML data is put in this string.

If I try sending the following string from CRM:

<TEST>GREG</TEST>

The payload on XI looks like this:

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

<rfc:_-MARS_-CPE_IMPORT_CRM_CATALOG xmlns:rfc="urn:sap-com:document:sap:rfc:functions">

<IV_CATALOG>&#60;TEST&#62;GREG&#60;/TEST&#62;</IV_CATALOG></rfc:_-MARS_-CPE_IMPORT_CRM_CATALOG>

As you can see < is converted into &#60; and > into &#62;

Where and how do I specify that the content of the parameter must not be interpreted?

Thanks

Greg

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

We found out that The RFC adapter serializes the content of the paramters (for instance the characters < and >) in order to avoid conflicts with real XML tags. Else you could easily create non valid XML.

Here is the workaround:

Add the following mapping between the adapter and your real mapping. This mapping simply converts the &#60; resp. &#62; into < resp. >. It is then possible to send XML into the RFC parameters. Be carefull as if the XML sent in the parameter is no well formed, the message will be rejected by XI.

package com.sap.mymappings;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.util.Map;

import com.sap.aii.mapping.api.StreamTransformation;

public class DecodeXml implements StreamTransformation {

private Map map;

private OutputStream out;

/**

*/

public DecodeXml() {

super();

// Auto-generated constructor stub

}

/**

  • method setParamters is required, but we do not anything with it

*/

public void setParameter(Map param) {

map = param;

}

/**

  • method execute is called by the XI mapping program

*/

public void execute(InputStream in, OutputStream out)

throws com.sap.aii.mapping.api.StreamTransformationException {

InputStreamReader inReader = new InputStreamReader(in);

// 2. Helper classes to read in data

BufferedReader bufReader = new BufferedReader(inReader);

String s;

String helpString = new String();

String resString = new String();

int i = 0;

try {

while ((s = bufReader.readLine()) != null) {

helpString = s.replaceAll("&#60;", "<");

helpString = helpString.replaceAll("&#62;", ">");

resString = resString + helpString;

i++;

}

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

try {

bufReader.close();

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

// 4. Write data to OutputStream

byte[] resByte = resString.getBytes();

try {

out.write(resByte, 0, resByte.length);

} catch (IOException e2) {

// TODO Auto-generated catch block

e2.printStackTrace();

}

}

}

udo_martens
Active Contributor
0 Kudos

Hi Gregory,

everything is working allright. If ur '<' would not have been transcripted, ur XML at XI would not be wellformed :(.

Regards,

Udo

Former Member
0 Kudos

Hi Udo

I don't understand why it wouldn't be wellformed...

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

<rfc:_-MARS_-CPE_IMPORT_CRM_CATALOG xmlns:rfc="urn:sap-com:document:sap:rfc:functions">

<IV_CATALOG><TEST>GREG</TEST></IV_CATALOG></rfc:_-MARS_-CPE_IMPORT_CRM_CATALOG>

is a valid XML.

Morevover I can see on a post from Dirk Meinhard called "Imported RFC with problem in converting to XML" that he was able to send the following data via RFC:

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

- <rfc:Z_BI_SEND_DATA_512 xmlns:rfc="urn:sap-com:document:sap:rfc:functions">

<SYSID_HOME>AAA</SYSID_HOME>

<TARGETSYS>BBB</TARGETSYS>

- <DATA>

- <item>

<WA>test1</WA>

</item>

- <item>

<WA>test2</WA>

</item>

- <item>

<WA>test3</WA>

</item>

</DATA>

</rfc:Z_BI_SEND_DATA_512>

So I assume what I aim to do is possible!

Any idea?

Thanks!

Greg

MichalKrawczyk
Active Contributor
0 Kudos

Hi Gregory,

try any graphical mapping in XI

and in one tag set <TEST>GREG</TEST>

as input value

do the test and take a look at the result

with the <b>source document view</b>

Regards,

michal