簡體   English   中英

org.xml.sax.SAXParseException; 嘗試從請求中獲取 xml 輸入時文件過早結束

[英]org.xml.sax.SAXParseException; Premature end of file when trying to get an xml input from request

我正在嘗試使用以下代碼從請求中解析一個大的 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();
    }

我在doc = db.parse(is);行中收到以下錯誤是。 我檢查了第一行代碼的eD字符串,是空的。 如何從 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)

當我嘗試打印 eD 時,我得到了一個空字符串。

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>

從錯誤 output 中的:1:1: position 標記中,您解析了一個空字符串。

您的文檔以第一行的第一個字符結尾,這可能是模擬end of file標記,標志着不再有可用的輸入。

問題不在於此代碼,而在於將字符放入eD字符串的代碼。

由於request.getReader()填充eD ,因此您的請求很可能有問題。 它要么返回404 ,要么 web 服務器返回300系列重定向,或者其他一些通常具有空正文的問題(假設是 HTTP)。

在獲取請求正文的內容之前檢查請求的返回代碼。 它將告訴您需要知道什么才能找到解決此問題的正確答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM