« Return to Thread: Exception using Web Service API

Re: Exception using Web Service API

by XMaNIaC :: Rate this Message:

Reply to Author | View in Thread

It did. Thank you!

Regards

On Fri, Nov 13, 2009 at 10:33 AM, Simon Brandhof <simon.brandhof@...> wrote:
Hi Jose,

It's a good idea to check the Byte-Order Mark but that's not the problem. Indeed the file starts with 3C 3F 78, but UTF-8 BOM is EF BB BF.

The problem may come from the response format. I'm not sure that your unit test parses XML. A XML file is returned when opening the URL from a browser, because the HTTP request header 'Accept' is set to 'text/html,application/xhtml+xml,application/xml'. But if you try the same URL with wget, JSON format is returned.

I recommend you to force the XML format. Just add "format=xml" to the URL. Does it resolve your problem ?

Simon
----------------------------------------
Simon Brandhof
SonarSource.com
twitter.com/SonarSource
twitter.com/SimonBrandhof
----------------------------------------



On Fri, Nov 13, 2009 at 9:50 AM, Jose Noheda <jose.noheda@...> wrote:
Hi,

I'm trying to parse the content retrieved from


with Dom4J to no avail. The exception in question is: Content is not allowed in prolog

I've checked and it's pobably related to http://en.wikipedia.org/wiki/Byte_Order_Mark and should be solved by changing the encoding to ISO-8859-1 (instead of UTF-8). Can someone take care of this?

Code:

public static Document readUrl(URL url) throws DocumentException {
        SAXReader reader = new SAXReader();
        return reader.read(url);
}

Junit:

@Test
public void testReadUrl() throws Exception {
        assertNotNull("XML obtained from URL", server.readUrl(new URL(url)));
}


 « Return to Thread: Exception using Web Service API