basho-labs / riakcs-java-client

Java client for RiakCS and Amazon S3
Apache License 2.0
13 stars 14 forks source link

listObjects method in RiakCSClientImpl throws exception #10

Open rao-pathangi opened 8 years ago

rao-pathangi commented 8 years ago

When I call the listObjects method on the RiakCSClientImpl class, I get the following exception

org.xml.sax.SAXParseException: Premature end of file.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257) ~[na:1.8.0_45]
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348) ~[na:1.8.0_45]
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) ~[na:1.8.0_45]
    at com.basho.riakcs.client.impl.XMLUtils.parseToDocument(XMLUtils.java:69) ~[bin/:na]
    at com.basho.riakcs.client.impl.RiakCSClientImpl.listObjects(RiakCSClientImpl.java:496) ~[bin/:na]
    at com.basho.riakcs.client.impl.RiakCSClientImpl.listObjects(RiakCSClientImpl.java:475) ~[bin/:na]

I dug around a bit -- the issue seems to stem from the following parser activity

An InputSource object belongs to the application: the SAX parser shall never modify it in any way (it may modify a copy if necessary). However, standard processing of both byte and character streams is to close them on as part of end-of-parse cleanup, so applications should not attempt to re-use such streams after they have been handed to a parser.

Any thoughts on how to get around the issue? I tried to call reset() on the InputStream below but it threw an exception as well.

//com.basho.riakcs.client.impl.XMLUtils.parseToDocument

public static Document parseToDocument(InputStream is, boolean debugModeEnabled) throws Exception
    {
        DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
        DocumentBuilder builder= factory.newDocumentBuilder();
        Document document= builder.parse(is);
        if (debugModeEnabled) System.out.println("Body:\n" + serializeDocument(document) + "\n");

        return document;
    }
StephenDillon commented 8 years ago

Hello.

Have you tried checking the input stream is available and not already closed by a previous operation (is.isAvailable()). Also perhaps a unit test to check that the above function works with a simple input stream you define, perhaps that might shred some light on what is causing the issue