swordapp / JavaClient2.0

A Java implementation of the SWORDv2 client responsibilities
http://www.swordapp.org
Other
8 stars 10 forks source link

org.swordapp.client.ErrorHandler #2

Open MistretzulPrietenos opened 9 years ago

MistretzulPrietenos commented 9 years ago

Hi Richard, I think there is a problem in the org.swordapp.client.ErrorHandler.java class

// try to parse the string as XML
Builder parser = new Builder();
try{
     Document doc = parser.build(errorBody);
     ...
}

The parser.build instruction will always throw an IOException. The method expects an URL but not an XML file :

Document nu.xom.Builder.build(String systemID) throws ParsingException, ValidityException, IOException

Parses the document at the specified URL.

Note that relative URLs generally do not work here, as there's no base to resolve them against. This includes relative URLs that point into the file system, though this is somewhat platform dependent. Furthermore, file URLs often only work when they adhere exactly to RFC 2396 syntax. URLs that work in Internet Explorer often fail when used in Java. If you're reading XML from a file, more reliable results are obtained by using the build method that takes a java.io.File object as an argument.

Parameters:
systemID an absolute URL from which the document is read. The URL's scheme must be one supported by the Java VM.
Returns:
the parsed Document
Throws:
ValidityException - if a validity error is detected. This is only thrown if the builder has been instructed to validate.
ParsingException - if a well-formedness error is detected
IOException - if an I/O error such as a broken socket prevents the document from being fully read

An easy fix would be

     Document doc = parser.build(IOUtils.toInputStream(errorBody));