0

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>
chetan
  • 3,175
  • 20
  • 72
  • 113
  • 1
    Whats your data look like? Is it clean and valid xml? – Michael Dillon Jan 17 '12 at 16:02
  • 1
    Looks like an infinite recursion loop, don't know what causes it though... – esaj Jan 17 '12 at 16:05
  • Added to Michael comment, try to post sample xml you are getting as input for this code, if possible post here. – kosa Jan 17 '12 at 16:06
  • 1
    I'd be surprised if dom4j allowed it, but you haven't created an XML document when an element is its own ancestor? – Pete Kirkham Jan 17 '12 at 16:08
  • You should try debugging the code to look at what the stack trace looks like when the exception occurs. If there's a pattern of the same sequence of method calls repeating, seeing what the XML parser library is trying to do could help. – millimoose Jan 17 '12 at 16:20
  • does "chunking" up the retrieval of the xml make a difference? Instead of dumping all of the XML contents into a String in one step, could you try using a StringBuilder to get the contents from the XML document in chunks and then return StringBuilder.toString() at the end? – Zack Macomber Jan 17 '12 at 16:49
  • I was able to take the xml you posted and loop 1,000,000 times with calls to the "asXML()" method and I didn't get a stack overflow (see code below). Is the problem possibly elsewhere? SAXReader reader = new SAXReader(); Document document = reader.read("test.xml"); String test = ""; for (int x=0;x < 1000000; x++) { test = document.asXML(); } – Zack Macomber Jan 17 '12 at 17:39
  • You are using a `org.dom4j.io.DOMReader`. Why? This is surley the most ineffective use of DOM4J. – forty-two Feb 01 '12 at 15:14

1 Answers1

1

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)

Shivan Dragon
  • 15,004
  • 9
  • 62
  • 103
  • Myjbosss not working with stack size 10m so i have set 6m but still i am facing same error. – chetan Jan 19 '12 at 10:01