Some devices (e.g. webrelays) return raw XML in response to HTTPGet requests. That is, the reply contains no valid HTTP header. For many years I have retrieved information from such devices using code like this:
private InputStream doRawGET(String url) throws MalformedURLException, IOException
{
try
{
URL url = new URL(url);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setConnectTimeout(5000);
con.setReadTimeout(5000);
return con.getInputStream();
}
catch (SocketTimeoutException ex)
{
throw new IOException("Timeout attempting to contact Web Relay at " + url);
}
}
In openJdk 7 the following lines have been added to sun.net.www.protocol.http.HttpURLConnection, which mean any HTTP response with an invalid header generates an IOException:
1325 respCode = getResponseCode();
1326 if (respCode == -1) {
1327 disconnectInternal();
1328 throw new IOException ("Invalid Http response");
1329 }
How do I get 'headless' XML from a server which expects HTTPGet requests in the new world of Java 7?