I'm getting a 503 response from a server that I'm trying to communicate with. Now, it shows me this in the log, but, I want to catch the IOException that it fires and deal with it if and only if the response code is 503, and nothing else. How would I do this?
EDIT:
Here's part of my code:
inURL = new BufferedReader(new InputStreamReader(myURL.openStream()));
String str;
while ((str = inURL.readLine()) != null) {
writeTo.write(str + "\n");
}
inURL.close();
If using
java.net.HttpURLConnection
, use the methodgetResponseCode()
If using
org.apache.commons.httpclient.HttpClient
,executeMethod(...)
returns the response codeHandle the case you want in you IOEXception catch clause if it falls into that code section.
Check the http status code if it is 503 handle it the way you want, if not throw the exception again.
here's an HTTPClient I have done :
Maybe it can help you.