Mahesh Pachpande
Mahesh Pachpande

Reputation: 1

Premature end of file while marshaling xml

I am facing strange issue "Premature end of file." exception for last few days on one of our azure application. Its a spring boot application. I am using spring boot version 2.6.3 (embedded tomcat). This code has been working for past 8 months but its not working anymore. Only changes I did for Java 8 to Java 11 version update on the azure app service.

We are using "Java 11 on JAVA SE linux stack" in app service. We are getting an exception on below line (setting new schema), Schema schema = sf.newSchema(file);

Here is the Java code which was working before.

 public static <T> String marshal(Class<T> beanClass, Object object, String xsdSchemaPath)
        throws JAXBException, SAXException{
    JAXBContext jaxbContext = JAXBContext.newInstance(beanClass);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    
    File file = new File(xsdSchemaPath);
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(xsdSchemaPath);
    try {
        FileUtils.copyInputStreamToFile(in, file);
    } catch (IOException e) {
        logger.error("Error occured in Marshalling the object", e.getMessage());
        throw new SriException(xsdSchemaPath + " not found ");
    }
    
    Schema schema = sf.newSchema(file);
    jaxbMarshaller.setSchema(schema);

I have already verified xsd and its valid. Please let me know if there are any leads.

Upvotes: 0

Views: 340

Answers (1)

Thiago Custodio
Thiago Custodio

Reputation: 18387

the only thing I can think about it's a max size issue or timeout. Take a look in the following and try changing the parameters:

In conf\server.xml

<Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
                maxPostSize="67589953" />

In webapps\manager\WEB-INF\web.xml

<multipart-config>
  <!-- 52MB max -->
  <max-file-size>52428800</max-file-size>
  <max-request-size>52428800</max-request-size>
  <file-size-threshold>0</file-size-threshold>
</multipart-config>

HttpRequest maximum allowable size in tomcat?

Upvotes: 0

Related Questions