Disable FEATURE SECURE PROCESSING in Stax Java Parser for XML

Viewed 2329

I am using Stax parser to parse a very large xml file and this the code I have written

public class XmlWrite {
public static void main(String[] args) throws 
                                    IOException,XMLStreamException {
    FileWriter fw = null;
    FileReader page = new FileReader("pages142");
    XMLInputFactory factory = XMLInputFactory.newInstance();
  //factory.setProperty(XMLConstants.FEATURE_SECURE_PROCESSING,false);
    XMLEventReader eventReader = factory.createXMLEventReader(page);
    boolean flag = false;
    int no = 1;
    while(eventReader.hasNext()) {
        XMLEvent event = eventReader.nextEvent();
    .........

This code works fine on a small input file but for a large file it gives the following error

       Exception in thread "main" javax.xml.stream.XMLStreamException: 
       ParseError at [row,col]:[44018907,204]
       Message: JAXP00010004: The accumulated size of entities is 
       "50,000,001" that exceeded the "50,000,000" limit set by 
        "FEATURE_SECURE_PROCESSING".
          at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:604) at com.sun.xml.internal.stream.XMLEventReaderImpl.nextEvent(XMLEventReaderImpl.java:83) at XmlWrite.main(XmlWrite.java:28)

I tried the factory.setProperty but that too is not working.Is there any means to disable Secure processing throughout using jvm ?

2 Answers

Using this workaround helped

java -DentityExpansionLimit=2147480000 -DtotalEntitySizeLimit=2147480000 -Djdk.xml.totalEntitySizeLimit=2147480000 Code_Name

Related