You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Erik Eide <er...@gmail.com> on 2005/11/11 14:05:26 UTC
return status code 409 overwritten
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);
}
Env:
XP SP2, Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)
Regards
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: return status code 409 overwritten
Posted by Erik Eide <er...@gmail.com>.
Okay, my bad - I was forwarding to path missing a leading / so the 404
was probably from not finding the JSP to display the error.
Thanks for the quick reply
Erik
On 11/11/05, Erik Eide <er...@gmail.com> wrote:
> 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 <pe...@imise.uni-leipzig.de> 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: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: return status code 409 overwritten
Posted by Erik Eide <er...@gmail.com>.
Cool, thanks Peter - thats probably more approriate.
Cheers
Erik
On 11/11/05, Peter Menzel <pe...@imise.uni-leipzig.de> wrote:
> Erik Eide schrieb:
> > 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.
> >
>
> In this case I recommend not to set the status in the servlet and
> forward to the jsp manually.
> It would possibly more save using response.sendError(int errorCode) and
> declare an error-page, namley your jsp, in the web.xml for the
> appropriate status code.
> Like this:
>
> <error-page>
> <error-code>409</error-code>
> <location>/error.jsp</location>
> </error-page>
>
> Peter
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: return status code 409 overwritten
Posted by Peter Menzel <pe...@imise.uni-leipzig.de>.
Erik Eide schrieb:
> 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.
>
In this case I recommend not to set the status in the servlet and
forward to the jsp manually.
It would possibly more save using response.sendError(int errorCode) and
declare an error-page, namley your jsp, in the web.xml for the
appropriate status code.
Like this:
<error-page>
<error-code>409</error-code>
<location>/error.jsp</location>
</error-page>
Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: return status code 409 overwritten
Posted by Erik Eide <er...@gmail.com>.
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 <pe...@imise.uni-leipzig.de> 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: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: return status code 409 overwritten
Posted by Peter Menzel <pe...@imise.uni-leipzig.de>.
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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org