From one day to the next I'm getting a java.io.FileNotFoundException error when returning an InputStream from an URL object.
This happens ONLY with some URLs of the site I'm scanning with JSoup. The URL address is correct, since by copying the address into the browser it returns me the correct page.
This is frustrating, since I have not made any changes to the code. Did the site detect my page-scanning and blocked my requests?
The code:
public Document getDocument( String source ) {
Document doc = null;
InputStream is = null;
URL newUrl = null;
try {
newUrl = new URL( source );
is = newUrl.openStream();
Connection conn = Jsoup.connect( source );
conn.timeout( 0 );
doc = Jsoup.parse( is, "CP1252", source );
}
catch ( IOException ioe ) {
ioe.printStackTrace();
}
return doc;
}
The error:
java.io.FileNotFoundException: http://www.ratebeer.com/breweries/antigua-barbuda/0/9/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at beerparser.web.RateBeerParser.getDocument(RateBeerParser.java:389)
Line 389 is the InputStream object assignment.