Soumya
Soumya

Reputation: 127

Disable FEATURE SECURE PROCESSING in Stax Java Parser for XML

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 ?

Upvotes: 3

Views: 3677

Answers (2)

Soumya
Soumya

Reputation: 127

Using this workaround helped

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

Upvotes: 2

RealHowTo
RealHowTo

Reputation: 35372

Try

factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,false)

ref : https://docs.oracle.com/javase/tutorial/jaxp/properties/scope.html

Upvotes: 1

Related Questions