I am dealing with Apache mod_dav put together by myself server. My client is made-from-scratch custom HTTP parsing code in Java. I have used this server and code base for a long time, syncing gb of information around the server.

Today I went right into a problem which has never popped up before: the dreaded SAX "submissions are not permitted in trailing section" error. When you are performing WebDAV PROPFINDs throughout my whole server resource tree, I usually understand this error at same position.

I have examined and retested my HTTP parsing code, but it is really quite simple: Apache is delivering back chunked content, and also the portions indicate the amount of bytes to eat.

The area it fails may be the XML response that unexpectedly happens to use 110 portions---considerably bigger than other reactions (this can be a large directory). However, during my logs I can tell that there's no "trailing content"---each XML response (that creating a mistake and those that don't) finishes having a simple linefeed character.

But much more distressing: I've a port stream that parses the HTTP chunked content and transmits back an easy string of bytes. After I pass this input stream straight to the XML parser, I recieve the next error. However: basically go ahead and take same input stream and bleed all of the bytes from this, insert them in a ByteArrayInputStream, after which provide the ByteArrayInputStream (that ought to retain the identical data!) towards the parser, no error happens! What exactly is it about parsing from the incoming data that triggers the mistake?

My XML parser is fairly straightforward:

final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setValidating(false);

Anybody seen this before? (I looked for "mod_dav XML bug"---and merely got the unrelated bug I filed 5 years ago.)

This is actually the relevant area of the stack trace:

Cause:org.xml.sax.SAXParseException: Content is not allowed in trailing section.
    com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
    com.globalmentor.net.http.HTTPClientTCPConnection.readResponseBodyXML(HTTPClientTCPConnection.java:666)
    com.globalmentor.net.http.webdav.WebDAVResource.propFind(WebDAVResource.java:453)

Update: I have carried this out test again and again. Finally I added code just to walk the stack trace and print the SAX parse information I recieve:

Public Id: null System Id: null Line# 21937 Column# 1

I copy the XML in the log file, affirmed, line 21937 may be the finish from the file---but there's nothing there!!