Thanks Peter Thats works fine, I'm not using getWriter() as that was just an example, I forward to a JSP for displaying the error message.
Erik On 11/11/05, Peter Menzel <[EMAIL PROTECTED]> wrote: > Erik Eide schrieb: > Hi > > > > I've a small REST web service, I'd like to deploy in Tomcat 5.5.12. > > > > When I try and return status code 409 (Conflict) and an error message > > in the response body for a POST operation, Tomcat seems to overwrite > > the status code with a 404 (Not Found). > > > > If I do not return a response body, the original status code 409 is > > retained. RFC 2616 seems to suggest that its cool to return a response > > body with a 409, so I wonder if there is something else I'm doing > > incorrectly or have forgotten to configure ? > > > > Sample: > > > > public void doPost(HttpServletRequest request, HttpServletResponse > > response) > > throws ServletException, IOException { > > OutputStreamWriter writer = new > > OutputStreamWriter(response.getOutputStream()); > > writer.write("Entity already exists"); > > response.setStatus(HttpServletResponse.SC_CONFLICT); > > } > > > Try setting the status code before writing to the response. > Btw: why don't you use response.getWriter()? > This sends the correct response with body on my tomcat (5.5.12): > > public void doPost(HttpServletRequest request, HttpServletResponse > response) throws ServletException { > try { > hsrs.setStatus(HttpServletResponse.SC_CONFLICT); > PrintWriter pw = hsrs.getWriter(); > pw.write("do post has a conflict"); > > } catch (IOException e) { > log.severe(e.getMessage()); > } > } > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]