XML to JAVA(JAXB)错误-“ SYSTEM”和系统标识符之间需要空格

时间:2018-09-03 09:17:07

标签: java jaxb websphere apache-httpclient-4.x

当使用具有以下提到的代码片段的JAXB将XML转换为JAVA对象时,我看到一个奇怪的行为(该代码片段组成的应用程序已部署到IBM WAS 8.0.0.6)。该代码在生产中可以正常工作约20天,然后在执行此操作时失败并显示以下错误。但是,如果我重新启动JVM,那么直到另外20天才会看到此错误。我怀疑内存泄漏并使用了探查器,但未发现任何令人震惊的信息。这个代码片段有问题吗?

感谢您的帮助!!

代码段:

HttpGet httpGet = new HttpGet(URL);
HttpResponse response = 
HttpClientWrapper.getInstance().execute(httpGet);
String httpGetResponse = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(response.getEntity());

StringReader stringReader = new StringReader(httpGetResponse);
JAXBContext jaxbContext = JAXBContext.newInstance(
POJO.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

POJO pojo = (
POJO) jaxbUnmarshaller.unmarshal(stringReader); // <- Error is thrown at this line

示例XML:

<?xml version="1.0" encoding="UTF-8"?>
<usercontext>
 <userdetails>
  <name>TEST CUSTOMER</name>
  <zipCode>48032</zipCode>
  <phone>2343253434</phone>
 </userdetails>
</usercontext>

堆栈跟踪

javax.xml.bind.UnmarshalException: White space is required between "SYSTEM" and the system identifier. 
at com.ibm.xml.xlxp2.jaxb.msg.JAXBMessageProvider.throwUnmarshalExceptionWrapper(JAXBMessageProvider.java:93) at 
com.ibm.xml.xlxp2.jaxb.unmarshal.impl.JAXBDocumentScanner.produceFatalErrorEvent(JAXBDocumentScanner.java:297) at 
com.ibm.xml.xlxp2.scan.DocumentScanner.reportFatalError(DocumentScanner.java:4886) at 
com.ibm.xml.xlxp2.scan.DTDScanner.reportFatalError(DTDScanner.java:444) at 
com.ibm.xml.xlxp2.scan.DTDScanner.scanDoctypeDeclCommon(DTDScanner.java:534) 
at com.ibm.xml.xlxp2.scan.DTDScanner.scanDoctypeDecl(DTDScanner.java:481) 
at com.ibm.xml.xlxp2.jaxb.unmarshal.impl.JAXBDocumentScanner$JAXBDTDSupport.scanDoctypeDecl(JAXBDocumentScanner.java:58) at 
com.ibm.xml.xlxp2.scan.DocumentScanner.scanProlog(DocumentScanner.java:1757) at 
com.ibm.xml.xlxp2.scan.DocumentScanner.nextEvent(DocumentScanner.java:1324) at 
com.ibm.xml.xlxp2.scan.DocumentScanner.parseDocumentEntity(DocumentScanner.java:1176) at 
com.ibm.xml.xlxp2.jaxb.unmarshal.impl.JAXBDocumentScanner.unmarshal(JAXBDocumentScanner.java:147) at 
com.ibm.xml.xlxp2.jaxb.unmarshal.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:158) at 
com.ibm.xml.xlxp2.jaxb.unmarshal.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:139) at 

0 个答案:

没有答案