on 01-21-2014 10:08 AM
Hi all,
I want to generate .txt file at receiver with file format UTF-16LE & BOM( beginning of the file).
for this i have written below logic in my custom adapter module, but i was generating file without BOM.
Could you please help me.It's very urgent.
//Read XML from payload
// Adding BOM to output stream
byte[] BOMByte = {(byte)0xFF,(byte)0xFF};
out.write(BOMByte);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
//Converting into UTF-16LE Format.
transformer.setOutputProperty("encoding", "UTF-16LE");
Result result = new StreamResult(out);
Regards,
Satish
Hi
The code you have provided looks like for Java mapping not for the adapter module
are u using java mapping for your requirement?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Indrajit,
Thanks for your reply Indrajit.
we are implementing above requirement in PI7.0
Actually we have 2 option for my requirement.
1. adding BOM to the beginning of the file at message mapping level.
- for this i have written above code(i am not expert in java), but file was not generating BOM -at starting of the file.
can you please correct my code if possible?
2. Custom adapter Module.
Could you please suggest which option is best to achieve above requirement.
Regards,
Satish
Hi Satish
I Think java mapping will be good enough for your requirement. Also UTF-16 requires BOM not UTF-16LE
try this code
Document newdoc = tbuilder.newDocument();
write logic and update the input data to this newdoc.
byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
OutputStream out = arg1.getOutputPayload().getOutputStream();
out.write(bom);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer();
Source source = new DOMSource(newdoc);
Result output = new StreamResult(out);
transformer.setOutputProperty("encoding", "UTF-16");
transformer.transform(source, output);
Hi Indrajit,
Still i am getting error at receiver communication channel monitoring from RWB
like below.
---------------
Message processing failed. Cause: com.sap.aii.af.ra.ms.api.RecoverableException: Exception in XML Parser (format problem?):'com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: Unknown Byte-Order-Mark. XML MUST begin either with WhiteSpace or with '<?xml', and not: 'ÿÿþ'(:main:, row:1, col:0)(:main:, row=1, col=0) -> com.sap.engine.lib.xml.parser.ParserException: Unknown Byte-Order-Mark. XML MUST begin either with WhiteSpace or with '<?xml', and not: 'ÿÿþ'(:main:, row:1, col:0)': java.lang.Exception: Exception in XML Parser (format problem?):'com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: Unknown Byte-Order-Mark. XML MUST begin either with WhiteSpace or with '<?xml', and not: 'ÿÿþ'(:main:, row:1, col:0)(:main:, row=1, col=0) -> com.sap.engine.lib.xml.parser.ParserException: Unknown Byte-Order-Mark. XML MUST begin either with WhiteSpace or with '<?xml', and not: 'ÿÿþ'(:main:, row:1, col:0)'
----------------
I have written my java mapping code like :
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document xml = documentBuilder.parse(in);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty("encoding", "UTF-16LE");
// Adding BOM to output stream
byte[] BOMByte = {(byte)0xFF,(byte)0xFF};
out.write(BOMByte);
Result result = new StreamResult(out);
Source domSource = new DOMSource(xml);
transformer.transform(domSource, result);
is it correct code??
Regards,
Satish
qws
Hi Indrajit,
we are able to generating the file with :
byte[] BOMByte = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
transformer.setOutputProperty("encoding", "UTF-8");
But when you open out file in hexadecimal editor showing Normal file only, it doesn't showing ff & fe at the
beginning of the file. see below screen shot.
we want to generate file with ff&fe at starting of the file.
Please find below screen shot.
@if you open test file which they provided us in notepad++.
the encoding format as UCS-2 Little Endian.
Regards,
Satish
Hi Indrajit,
Now we are facing below error :
---------------------------------------------
Message processing failed. Cause: com.sap.aii.af.ra.ms.api.RecoverableException: Exception in XML Parser (format problem?):'com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: XMLParser: No data allowed here: (hex) 3f3c, 6d78, 206c(:main:, row:1, col:8)(:main:, row=1, col=8) -> com.sap.engine.lib.xml.parser.ParserException: XMLParser: No data allowed here: (hex) 3f3c, 6d78, 206c(:main:, row:1, col:8)': java.lang.Exception: Exception in XML Parser (format problem?):'com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: XMLParser: No data allowed here: (hex) 3f3c, 6d78, 206c(:main:, row:1, col:8)(:main:, row=1, col=8) -> com.sap.engine.lib.xml.parser.ParserException: XMLParser: No data allowed here: (hex) 3f3c, 6d78, 206c(:main:, row:1, col:8)'
Regards,
Satish
Hi Satish
What file type did you select at receiver CC "Text" or Binary
and also check the following blog that may help
Hi Batra,
1. we are using PI7.0 and actual file requirement is below.
- UTF-16 Little endian
- preceded with a byte order marker
- Windows lineendings
- Tab delimiter
- use windows line endings (the line ending is shown by the two byte LF sequence 0x0A 0x00, it needs to be the four byte CRLF sequence 0x0D 0x00 0x0A 0x00)
- include a byte order marker (two bytes - 0xFF 0xFE - at the start of the file)
------
2. i have used below parameters in CC at receiver side
File Type : Text
File Encoding : UTF-8
In Content Convertion Tab:
Field Separator : '0x09'
End Separator : 'nl'
Can you Please advise whether we can achive above required format?
Regards,
Satish
Hi Indrajit/Batra,
Can we achive below requirement using PI7.0?
Actual file requirement is below.
- UTF-16 Little endian
- preceded with a byte order marker
- Windows lineendings
- Tab delimiter
- windows line endings (the line ending is shown by the two byte LF sequence 0x0A 0x00, it needs to be the four byte CRLF sequence 0x0D 0x00 0x0A 0x00)
- include a byte order marker (two bytes - 0xFF 0xFE - at the start of the file)
Could you please advise me.
Regards,
Satish
Hi Satish
Do the following
Remove the encoding logic from Java mapping and pass the data as it is
In the receiver adapter choose the File Type as Text and encoding as UTF-16LE
Test and see if works or not.Then try this code in java mapping
byte[] BOMByte = new byte[] { (byte)0xFF, (byte)0xFE};
transformer.setOutputProperty("encoding", "UTF-16LE");
In the receiver adapter choose the File Type as Binary
The other parts you can handle it in the module tab
LF to CRLF you can use the module
http://blogs.prosoftgroup.com/common-utility-to-convert-end-of-line-in-sap-pi/
Hi Indrajit,
I have done same way, still we are faceing below error message at receiver side CC.
Error_Mesg :
------------------
Message processing failed. Cause: com.sap.aii.af.ra.ms.api.RecoverableException: Exception in XML Parser (format problem?):'com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: XMLParser: No data allowed here: (hex) feff, 3c, 3f(:main:, row:1, col:8)(:main:, row=1, col=8) -> com.sap.engine.lib.xml.parser.ParserException: XMLParser: No data allowed here: (hex) feff, 3c, 3f(:main:, row:1, col:8)': java.lang.Exception: Exception in XML Parser (format problem?):'com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: XMLParser: No data allowed here: (hex) feff, 3c, 3f(:main:, row:1, col:8)(:main:, row=1, col=8) -> com.sap.engine.lib.xml.parser.ParserException: XMLParser: No data allowed here: (hex) feff, 3c, 3f(:main:, row:1, col:8)'
------
Is there any alternative solution?
Regards,
Satish
Hi
Have u removed the BOM code from java mapping. Please remove the code for BOM and encoding and then test.
Code :
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document xml = documentBuilder.parse(in);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Result result = new StreamResult(out);
Source domSource = new DOMSource(xml);
transformer.transform(domSource, result);
In the receiver adapter choose the File Type as Text and encoding as UTF-16LE
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.