SAP PI映射中2字节UTF-8序列的无效字节2 [英] Invalid byte 2 of 2-byte UTF-8 sequence in SAP PI mapping
问题描述
这是SAP PI业务情景.该消息在2个系统之间交换.源系统:IPOS目标系统:ECC ..消息到达PI系统后,将生成一个与IPOS相对应的xml.我必须将IPOS结构映射到ECC结构.在这里,我正在使用DOM解析器..我正在使用main()进行测试.
This is SAP PI scenario. The message is exchanged between 2 systems. Source System: IPOS Target system: ECC.. Once the message reaches PI system an xml corresponding to IPOS is generated. I have to map the IPOS structure to ECC structure. Here I am using DOM parser.. I am using main() for testing purpose.
public static void main (String str[]) throws FileNotFoundException, StreamTransformationException {
ZcreateHomeDelivery obj = new ZcreateHomeDelivery();
try {
InputStream inputStream = new FileInputStream("C:/Users/XYZ/workspace/input.xml");
FileOutputStream newOut = new FileOutputStream("C:/Users/XYZ/workspace/output.xml");
obj.execute(inputStream, newOut);
}catch (Exception e ) {
e.printStackTrace();
}}
我已经导入了所有必需的软件包.
I have imported all the required packages..
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.StreamTransformation;
我面临的问题是当我执行代码时,出现错误信息
The problem I am facing is when I execute the code, I am getting error as
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at com.sap.nw.rr.hd.ZcreateHomeDelivery.execute(ZcreateHomeDelivery.java:85)
at com.sap.nw.rr.hd.ZcreateHomeDelivery.main(ZcreateHomeDelivery.java:801)
java.lang.NullPointerException
at com.sap.nw.rr.hd.ZcreateHomeDelivery.execute(ZcreateHomeDelivery.java:101)
at com.sap.nw.rr.hd.ZcreateHomeDelivery.main(ZcreateHomeDelivery.java:801)
我尝试过的解决方案是
try
{
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");// added
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
DOMSource source = new DOMSource(outdoc);
StreamResult result = new StreamResult(outputStream);
transformer.transform(source, result);
} catch (Exception e) {
e.printStackTrace();
throw new StreamTransformationException("Mapping failed:Check input file", e);
}
*已添加(在上面的代码中作了注释)来解决此问题-但它有帮助.我必须添加UTF-8,但是在哪里添加呢?
*added(Commented in the above code) to resolve the issue- But it dint help. I have to add UTF-8 , But where to add it ?
这已解决:解决方案是
1)在记事本中打开xml
2)确保文档的开头和结尾没有多余的空间.
3)选择文件->另存为
4)选择保存类型->所有文件
5)输入文件名称为filename.xml
6)选择编码"-UTF-8
->单击保存"
This is resolved : solution is
1)Open the xml
in notepad
2)Make sure you dont have extra space at the beginning and end of the document.
3)Select File -> Save As
4)select save as type -> All files
5)Enter file name as filename.xml
6)select Encoding - UTF-8
-> Click Save
推荐答案
Hi you can find here a reference to the problem. The problem is that the xml file declares a different encoding from the one used for saving the file. If the files are encoded using iso-8859-1 and in the file it's declared as UTF-8 you can read the file using a reader and force the encoding to the correct one. the link shows the api for doing this.
这篇关于SAP PI映射中2字节UTF-8序列的无效字节2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!