on 02-04-2008 5:20 PM
Hi Guru's,
I am doing a FIle(XML) to Proxy scenario. Unfortunately the file sent by 3rd party system contains some special chars like "&".
Here is what I get into XI. <Program>FY08 Pilsner - National Media & Fees</Program>. When I manually change it to <Program><![CDATA[FY08 Pilsner - National Media & Fees]]></Program> it works.
After reading some of the forum threads I came to know that we can do this using JAVA mapping before doing the actual graphical mapping. I need to what exactly I should be doing in JAVA mapping and I need some sample JAVA mapping code if somebody has already implemented this solution.
Thanks.
Srini Vaidyam
Hi Srinivas,
Payload is not valid XML. What is your File sender system character set use it in the File Adapter for conversion.
& should be escaped (&) else you will face conversion errors.
Regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The java mapping code will look something like:
public class FixEncoding implements StreamTransformation {
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
String instr;
instr = parseIStreamToString(in);
instr = instr.replace( '&', '&amp;' );
instr = instr.replace( '>', '&gt;' );
instr = instr.replace( '<', '&lt;' );
instr = instr.replace( '\"', '&quot;' );
out.write(instr.getBytes());
}
public String parseIStreamToString(InputStream is) {
BufferedReader din = new BufferedReader(new InputStreamReader(is));
StringBuffer sb = new StringBuffer();
try {
String line = null;
while ((line = din.readLine()) != null) {
sb.append(line + "\n");
}
} catch (Exception ex) {
ex.getMessage();
} finally {
try {
is.close();
} catch (Exception ex) {
}
}
return sb.toString();
}
}
Note I have left out the includes and might need to handle some try/catches with error handling.
Regards,
Jason
Edited by: Jason Currey on Feb 5, 2008 1:28 AM
Edited by: Jason Currey on Feb 5, 2008 1:30 AM
Edited by: Jason Currey on Feb 5, 2008 1:31 AM
You should not use these lines of code:
instr = instr.replace( '>', '>' );
instr = instr.replace( '<'<' );
instr = instr.replace( '\"', '"' );
This would corrupt the XML.
The code must be more sophisticated, as you have to check, if an & amp; is already in your XML, then you would not change the &.
Regards
Stefan
Have you tried an XSL mapping??? As long as you map the field itself to it's proxy counterpart and do not save it to a memory variable for manipulation later, I believe the XSL mapping would be the way to go. I know I've done something similiar for proxy to JDBC and proxy to file but haven't gone file to proxy. Just a thought.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would suggest you do follow three things:
1.) Specify the character enconding at both sender and receiver side so that the file is successfully picked. The encoding must be in the xml declaration.
2.) Get the complete message (Main Window) in RWB and check, at which column i.e. (:main:, row:1, col:1) are you getting this error. Many times I attributed the error to special character but it turned out something else.
3.) Althogh, java mapping is an option but its not necessaily needed. (I tried a mapping with one field &&& and it worked OK).
But first confirm in trace that its & bothering you.
Regards,
AV.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for all the helpful answers. I awarded points for all those hints that were helpful.
Here is how I resolved it. I persued with the 3rd party who sent us the XML file to encode the 4 special characters. It was not that bad on their end to encode these special chars.
Thanks.
Srinivas Vaidyam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,we faced tghe same problem with & and #. to solve it, the encopndig was change to UTF-8 and the caracters was added to RKSC transaction.
do not reprocess the message, send it again.
Thanks
Rodrigo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Srinivas,
For this give either & or US-ASCII in FILE ENCODING in the file adapter.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Srinivas,
Jason's method would work, here is an alternative method of converting inputstream to string
try {
StringBuffer strbuffer = new StringBuffer();
byte[] b = new byte[4096];
for (int n;(n = in.read(b)) != -1;) {
strbuffer.append(new String(b, 0, n));
}
strXML = strbuffer.toString();
} catch (Exception e) {
System.out.println("Exception Occurred");
}
Thanks,
Anand
Edited by: Anand Gopinath on Feb 5, 2008 6:06 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
go to TCODE RSKC. in text box, delete ALL_CAPITAL and add "&"
Thanks
Rodrigo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The payload looks like OK, it should not cause any problem.
(I am assuming that the node is xsd:string)
Can you paste the error in trace ?
Liang
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Change the encoding to ISO-8859-1 and then try.
Sarvesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rodrigo,
I tried RSKC tcode and save the "&" as permitted character. Mapping still failed.
Sarvesh,
I tried to replace & with &. It did not work either.
Here is the error message
<?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="">
<SAP:Category>Application</SAP:Category>
<SAP:Code area="MAPPING">EXCEPTION_DURING_EXECUTE</SAP:Code>
<SAP:P1>com/sap/xi/tf/_PO_MCR_MM_</SAP:P1>
<SAP:P2>com.sap.aii.utilxi.misc.api.BaseRuntimeException</SAP:P2>
<SAP:P3>Fatal Error: com.sap.engine.lib.xml.parser.Parser~</SAP:P3>
<SAP:P4 />
<SAP:AdditionalText />
<SAP:ApplicationFaultMessage namespace="" />
<SAP:Stack>com.sap.aii.utilxi.misc.api.BaseRuntimeException thrown during application mapping com/sap/xi/tf/_PO_MCR_MM_: Fatal Error: com.sap.engine.lib.xml.parser.Parser~</SAP:Stack>
<SAP:Retry>M</SAP:Retry>
</SAP:Error>
Vaidyam,
I dont think it will create a problem. That should be fine. Can you paste the whole payload here.
Regards,
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The "&" create problem in my graphical mapping.
Here is the payload
<Report xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:///C:/Trandev50/models/MyModels/XSDFINAL.xsd"><Data>
<Row>
<Month>1</Month>
<Year>2008</Year>
<IncBrand>UR</IncBrand>
<MktArea></MktArea>
<MediaType>110</MediaType>
<PlanAmt>45704.5</PlanAmt>
<Program>FY08 Pilsner - National Media & Fees</Program>
</Row>
<Row>
<Month>2</Month>
<Year>2008</Year>
<IncBrand>UR</IncBrand>
<MktArea></MktArea>
<MediaType>110</MediaType>
<PlanAmt>25134.5</PlanAmt>
<Program>FY08 Pilsner - National Media & Fees</Program>
</Row>
<Row>
<Month>3</Month>
<Year>2008</Year>
<IncBrand>UR</IncBrand>
<MktArea></MktArea>
<MediaType>110</MediaType>
<PlanAmt>22316</PlanAmt>
<Program>FY08 Pilsner - National Media & Fees</Program>
</Row>
</Data>
</Report>
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.