dom 解析器中的 java.lang.StackOverflowError

发布于 2024-12-27 09:19:59 字数 6634 浏览 1 评论 0原文

以下是我的应用程序中的许多线程将访问的方法。

public static String getXMLAsString(org.dom4j.Document dom4jDocument)
    {

        String strXML="";
        try {
            strXML = dom4jDocument.asXML();             

            }
            catch(Exception e){
            e.printStackTrace();
            System.out.println("XMLUtility : General Exception :- "+e.getMessage());
        }       

        return strXML;
    }

成功执行某个线程后,会出现以下错误。

java.lang.StackOverflowError
    at java.lang.String.indexOf(String.java:1352)
    at org.apache.xerces.dom.ElementNSImpl.getPrefix(Unknown Source)
    at org.dom4j.io.DOMReader.readElement(DOMReader.java:169)
    .........................................................
    .........................................................

以下是成功执行线程的上定义方法的结果

<?xml version="1.0" encoding="UTF-8"?>
<action_script>
<command>SUSPEND^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header/>
    <soapenv:Body>
        <spi:updateService>
            <spi:request>
                <spi:service>
                    <spi:serviceIdentifier>
                        <spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
                    </spi:serviceIdentifier>
                    <spi:attributes>
                    <spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">OCS</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:boolean">true</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
                        <spi:value xsi:type="xsd:string">{username}</spi:value>
                      </spi:attribute>
                        </spi:attributes>
                </spi:service>
            </spi:request>
        </spi:updateService>
    </soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
<command>DEACTIVATE^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header/>
    <soapenv:Body>
        <spi:updateService>
            <spi:request>
                <spi:service>
                    <spi:serviceIdentifier>
                        <spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
                    </spi:serviceIdentifier>
                    <spi:attributes>
                    <spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">OCS</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:boolean">true</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
                        <spi:value xsi:type="xsd:string">{username}</spi:value>
                      </spi:attribute>
                        </spi:attributes>
                </spi:service>
            </spi:request>
        </spi:updateService>
    </soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
<command>ACTIVATE^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header/>
    <soapenv:Body>
        <spi:updateService>
            <spi:request>
                <spi:service>
                    <spi:serviceIdentifier>
                        <spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
                    </spi:serviceIdentifier>
                    <spi:attributes>
                    <spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">OCS</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:boolean">false</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
                        <spi:value xsi:type="xsd:string">{username}</spi:value>
                      </spi:attribute>
                        </spi:attributes>
                </spi:service>
            </spi:request>
        </spi:updateService>
    </soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
</action_script>

Following is the method that will be accessed by many threads in my application.

public static String getXMLAsString(org.dom4j.Document dom4jDocument)
    {

        String strXML="";
        try {
            strXML = dom4jDocument.asXML();             

            }
            catch(Exception e){
            e.printStackTrace();
            System.out.println("XMLUtility : General Exception :- "+e.getMessage());
        }       

        return strXML;
    }

After successfully executing some thread it will give following error.

java.lang.StackOverflowError
    at java.lang.String.indexOf(String.java:1352)
    at org.apache.xerces.dom.ElementNSImpl.getPrefix(Unknown Source)
    at org.dom4j.io.DOMReader.readElement(DOMReader.java:169)
    .........................................................
    .........................................................

Following is the result of upper defined method for successfully executed thread

<?xml version="1.0" encoding="UTF-8"?>
<action_script>
<command>SUSPEND^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header/>
    <soapenv:Body>
        <spi:updateService>
            <spi:request>
                <spi:service>
                    <spi:serviceIdentifier>
                        <spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
                    </spi:serviceIdentifier>
                    <spi:attributes>
                    <spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">OCS</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:boolean">true</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
                        <spi:value xsi:type="xsd:string">{username}</spi:value>
                      </spi:attribute>
                        </spi:attributes>
                </spi:service>
            </spi:request>
        </spi:updateService>
    </soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
<command>DEACTIVATE^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header/>
    <soapenv:Body>
        <spi:updateService>
            <spi:request>
                <spi:service>
                    <spi:serviceIdentifier>
                        <spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
                    </spi:serviceIdentifier>
                    <spi:attributes>
                    <spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">OCS</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:boolean">true</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
                        <spi:value xsi:type="xsd:string">{username}</spi:value>
                      </spi:attribute>
                        </spi:attributes>
                </spi:service>
            </spi:request>
        </spi:updateService>
    </soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
<command>ACTIVATE^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header/>
    <soapenv:Body>
        <spi:updateService>
            <spi:request>
                <spi:service>
                    <spi:serviceIdentifier>
                        <spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
                    </spi:serviceIdentifier>
                    <spi:attributes>
                    <spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">OCS</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
                            <spi:value xsi:type="xsd:boolean">false</spi:value>
                        </spi:attribute>
                        <spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
                        <spi:value xsi:type="xsd:string">{username}</spi:value>
                      </spi:attribute>
                        </spi:attributes>
                </spi:service>
            </spi:request>
        </spi:updateService>
    </soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
</action_script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不一样的天空 2025-01-03 09:19:59

可能只是因为您的 XML 文档太大,以至于尝试将其全部放入一个字符串中会导致大量的链式方法调用,并且您的堆栈内存已满。尝试通过以下方式分配更多堆栈内存:

-Xss10m

JVM 参数

(如果从 Eclipse 执行:右键单击项目 -> 运行方式... -> 运行配置 -> 参数选项卡 -> VM 参数 -> -Xss1m)

It might simply be that your XML document is so big that trying to get it all into one String makes alot of chanined method calls and your stack memory gets full. Try allocating more stack memory via:

-Xss10m

JVM argument

(if executing from Eclipse: right click on project -> Run As... -> Run configurations -> Arguments tab -> VM Arguments -> -Xss1m)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文