File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Continue after Server returned HTTP response code: 500 for URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Continue after Server returned HTTP response code: 500 for URL" Watch "Continue after Server returned HTTP response code: 500 for URL" New topic
Author

Continue after Server returned HTTP response code: 500 for URL

Mark Nicholas
Greenhorn

Joined: Jul 22, 2002
Posts: 13
This is probably a more low level error handle question:
The following code is used to get the contents of multiple url's, however when the server returns a 500 response code the program exits:
So my question is how do you contine / handle the 500 exception more gracefully ?
java.io.IOException: Server returned HTTP response code: 500 for URL: http://www.some.url
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:691)
at java.net.URL.openStream(URL.java:955)
at com.jm.utils.UrlReader.<init>(UrlReader.java:36)
at com.jm.prj.webgrab.ex01.WebGrabEX01.grab(WebGrabEX01.java:42)
at com.jm.prj.webgrab.ex01.WebGrabEX01.main(WebGrabEX01.java:29)

[ October 08, 2002: Message edited by: Mark Nicholas ]
[ October 08, 2002: Message edited by: Mark Nicholas ]
[ October 08, 2002: Message edited by: Mark Nicholas ]
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
What is ungraceful about the way it works? When an error occurs, an exception is thrown. This is entirely as it should be In your case, you can catch the exception within the hosts loop, log it, and continue with the next iteration (and a fresh URL object).
- Peter
Mark Nicholas
Greenhorn

Joined: Jul 22, 2002
Posts: 13
Actually it hangs because when the server throws a 500 the 'is' stream variable is null and I forgot to wrap the is.close() with a checking if is != null. Otherwise your right on the money.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Continue after Server returned HTTP response code: 500 for URL