[英]org.xml.sax.SAXParseException; Premature end of file when trying to get an xml input from request
I'm trying to parse a big xml from request using the following code:我正在尝试使用以下代码从请求中解析一个大的 xml:
String eD = IOUtils.toString(request.getReader());
DocumentBuilder db = null;
try {
db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (ParserConfigurationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(eD));
Document doc = null;
try {
doc = db.parse(is);
} catch (SAXException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
I get the following error in line where doc = db.parse(is);
我在
doc = db.parse(is);
行中收到以下错误is.是。 I checked the
eD
string of the first line of code and is empty.我检查了第一行代码的
eD
字符串,是空的。 How can I get the input from HttpServletRequest?如何从 HttpServletRequest 获取输入?
[Fatal Error] :1:1: Premature end of file.
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
When I'm trying to print eD I got an empty string.当我尝试打印 eD 时,我得到了一个空字符串。
A snapshot of the xml input is: xml 输入的快照是:
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:epsos="urn:epsos-org:ep:medication" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<typeId extension="POCD_HD000040" root="2.16.840.1.113883.1.3"/>
<templateId root="1.3.6.1.4.1.12559.11.10.1.3.1.1.2"/>
<templateId root="1.3.6.1.4.1.19376.1.5.3.1.1.1"/>
<id extension="5LMLbecMdsVlpoSA" root="2.16.840.1.113883.2.25.3.4.1.4.1"/>
<code code="60593-1" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" codeSystemVersion="2.59" displayName="Medication dispensed.extended Document">
<translation code="60593-1" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="eDispensation"/>
</code>
<title>Medication dispensed</title>
<effectiveTime value="20201109112323+0200"/>
<confidentialityCode code="N" codeSystem="2.16.840.1.113883.5.25" codeSystemName="Confidentiality" codeSystemVersion="913-20091020" displayName="normal"/>
<languageCode code="el-GR"/>
<setId nullFlavor="NI"/>
<recordTarget>
<patientRole>
<id extension="1990-01-01_1" root="2.16.17.710.860.1000.990.1"/>
<addr>
<country>CY</country>
<streetAddressLine>21, Dimokritou, 1000, Strovolos, Nicosia</streetAddressLine>
</addr>
<telecom use="H" value="tel:+99000000"/>
<telecom use="H" value="mailto:l.petr@testmail.com"/>
<patient>
<name>
<given>Leonidas</given>
<family>Petrou</family>
</name>
<administrativeGenderCode code="M" codeSystem="2.16.840.1.113883.5.1" codeSystemName="AdministrativeGender" codeSystemVersion="913-20091020" displayName="Male"/>
<birthTime value="19900101"/>
<languageCommunication>
<templateId root="1.3.6.1.4.1.19376.1.5.3.1.2.1"/>
<languageCode code="en-GB"/>
</languageCommunication>
</patient>
</patientRole>
</recordTarget>
<author typeCode="AUT">
<functionCode code="2262" codeSystem="2.16.840.1.113883.2.9.6.2.7" codeSystemName="ISCO" codeSystemVersion="2008" displayName="Pharmacists"/>
<time value="20201109112323+0200"/>
</author>
<inFulfillmentOf>
<order moodCode="RQO">
<id extension="ePid.1006.1.cda" root="2.16.196.1.101.10.3.29.54290"/>
</order>
</inFulfillmentOf>
<relatedDocument typeCode="APND">
<parentDocument classCode="DOCCLIN">
<id extension="ePid.1006.1.cda" root="2.16.196.1.101.10.3.29.54290"/>
</parentDocument>
</relatedDocument>
<component>
<structuredBody>
<component>
<section>
<templateId root="2.16.840.1.113883.10.20.1.8"/>
<templateId root="1.3.6.1.4.1.12559.11.10.1.3.1.2.2"/>
<id extension="D-ePid.1006.1.cda" root="2.16.840.1.113883.2.25.3.4.1.4.1"/>
<code code="60590-7" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" codeSystemVersion="2.59" displayName="Medication dispensed.brief Document">
<translation code="60590-7" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="Medication dispensed"/>
</code>
<title>Dispensation: D-ePid.1006.1.cda</title>
<text>
<table width="100%">
<thead>
<tr>
<th>Active Ingredient (ATC)</th>
<th>Pharmaceutical Dose Form</th>
<th>Strength</th>
<th>Number of Units per intake</th>
<th>Frequency of Intake</th>
<th>Duration of treatment</th>
<th>Number of Prescribed Packages</th>
<th>Size of the package prescribed and package type</th>
<th>Route of Administration</th>
<th>Substitution</th>
<th>Onset Date of treatment</th>
<th>Instructions to patient</th>
<th>Advise to the dispenser</th>
</tr>
</thead>
<tbody>
<tr ID="medicine.1">
<td>teriparatide (ATC: H05AA02)</td>
<td>Solution for injection</td>
<td>20 ug</td>
<td>1</td>
<td>1 per day</td>
<td>60 days</td>
<td>1</td>
<td>2 x 28 ug , Pre-filled pen</td>
<td>Subcutaneous use</td>
<td>Generic</td>
<td>2020-11-02</td>
<td>NA</td>
<td>NA</td>
</tr>
</tbody>
</table>
</text>
</section>
</component>
</structuredBody>
</component>
</ClinicalDocument>
From the :1:1:
position marker in your error output, you parsed an empty string.从错误 output 中的
:1:1:
position 标记中,您解析了一个空字符串。
Your document is ending on the first character of the first line, which is probably the simulated end of file
sentinel that marks no more input is available.您的文档以第一行的第一个字符结尾,这可能是模拟
end of file
标记,标志着不再有可用的输入。
The problem is not within this code, it is within the code that puts characters into the eD
string.问题不在于此代码,而在于将字符放入
eD
字符串的代码。
Since the request.getReader()
populated eD
, odds are you have an issue with your request.由于
request.getReader()
填充eD
,因此您的请求很可能有问题。 Either it returned a 404
or the web server returned a 300
series redirect, or some other issue (assuming it is HTTP) that would normally have an empty body.它要么返回
404
,要么 web 服务器返回300
系列重定向,或者其他一些通常具有空正文的问题(假设是 HTTP)。
Inspect the return code of your request before grabbing the contents of its body.在获取请求正文的内容之前检查请求的返回代码。 It will tell you what you need to know to seek the right answers to fixing this.
它将告诉您需要知道什么才能找到解决此问题的正确答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.