I have a REST application that uses a single controller servlet to parse path-based commands, and then return XML data based on the command. For example, I map my servlet to /MyApp/REST/*, and then /MyApp/REST/folder/12345 returns an XML representation of the folder with the id of 12345. /MyApp/REST/person/12345 returns an XML representation of the person who's ID is 12345.
When I initially wrote this app, I wrote it so if you used an invalid command (/MyApp/REST/folderrer/12345), it would return a help page showing what commands are available. That all worked fine. However, I am now trying to pull that data via AJAX, and I am seeing a problem where my app is returning a status of 200 regardless if the command is understood or not.
It looks like I need to use the HttpServletResponse.setStatus(int, String) method if I want to continue to write the response after setting the status. But my question is ... what status code should I use? Is it appropriate to use a 404 in this case? Or do I want to use something in the 5xx range? What have others done?
OCPJP
"In preparing for battle I have always found that plans are useless, but planning is indispensable."
-- Dwight D. Eisenhower
Bear Bibeault
Author and opinionated walrus
Marshal