On 23/11/2012 21:23, Michael-O wrote: > Am 2012-11-23 22:16, schrieb Mark Thomas: >> On 23/11/2012 21:09, Michael-O wrote: >>> Hi, >>> >>> I've been struggling recently with this builtin valve and some >>> Spring-based REST services. I some cases I do return states like 404 or >>> 400. SendError seems to be the right thing to do but Tomcat alters the >>> response with the HTML page. Which is highly unwanted for a REST API. >>> >>> I have checked Oracle's original JavaDocs for #sendError(int) + Servlet >>> Spec 2.5 and 3.0 all three of them, do not explicitly mention that an >>> error HTML response is returned with this method. The JavaDoc [1] says: >>> "...If an error-page declaration has been made for the web application >>> corresponding to the status code passed in, it will be served back the >>> error page..." >>> >>> I did not define a custom error page. >>> >>> Where as the #sendError(int,String) says: >>> "... The server defaults to creating the response to look like an >>> HTML-formatted server error page containing the specified message, >>> setting the content type to "text/html"." >>> >>> This one is crystal clear. >>> sendError(int) simply calls sendError(int,String) with a null string >>> arg. >>> >>> Am I misunderstanding the the definition? Should I avoid sendError >>> alltogher and resort to setStatus? What would be the implications? >>> I do know that sendError commits and closes the response immediately. >>> >>> A clarification is highly appreciated. >> >> Use Tomcat 7 and define a custom, default error page. You'll then remain >> in complete control of the error response. > > Well, I am still on Tomcat 6 but I would do the following: > > 1. Define a @Controller > 2. Define @RequestMapping on a method > 3. Map that controller in the web.xml > > Now here's the problem, that method would return ModelAndView or simply > a view's string name. But I would like to use ResponseEntity as it would > be necessary for REST. > > Did you had this in mind? Otherwise would "produces" with distinct > methods work for such an error page?
Sorry, I know next to nothing about Spring (and yes, I do work for SpringSource). For Tomcat 6 I'd define my own error valve but that is not portable. You could also define error pages for each error code you use and for java.lang.Exception My reading of the specification text quoted above is that the server is expected to create HTML error pages unless the user defines a custom error page in web.xml. I don't see any room for an alternative interpretation. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org