Writing to response and issuing sendError

2012-11-28 Thread Michael-O

Hi,

I am having again trouble with the respone.sendError method. The docs 
say that an IllegalStateException is thrown if response has already been 
committed. So this should cause an exception:


protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {

  PrintWriter out = response.getWriter();
  out.println(ERROR);
  out.flush();
  response.sendError(404);
}

The exception is thrown out to the console but the response is still 
written. If I leave out the flush (which commits the response). The 
error page comes up.


Is this undefined behavior or some missing code path to transform the 
ISE to a HTTP 500 error response?


I am on Tomcat 6.0.35

Thanks,

Mike

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Writing to response and issuing sendError

2012-11-28 Thread Mark Thomas
On 28/11/2012 20:34, Michael-O wrote:
 Hi,
 
 I am having again trouble with the respone.sendError method. The docs
 say that an IllegalStateException is thrown if response has already been
 committed. So this should cause an exception:
 
 protected void doGet(HttpServletRequest request, HttpServletResponse
 response) throws ServletException, IOException {
   PrintWriter out = response.getWriter();
   out.println(ERROR);
   out.flush();
   response.sendError(404);
 }
 
 The exception is thrown out to the console but the response is still
 written. If I leave out the flush (which commits the response). The
 error page comes up.
 
 Is this undefined behavior or some missing code path to transform the
 ISE to a HTTP 500 error response?

Nope. Think about it. Once the response has been committed the response
status line and the headers have been written to the client as well as
at least some if not all of the response body. Tomcat can't take back
the data it has already sent.

Mark


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Writing to response and issuing sendError

2012-11-28 Thread Caldarale, Charles R
 From: Michael-O [mailto:1983-01...@gmx.net] 
 Subject: Writing to response and issuing sendError

 The exception is thrown out to the console but the response is still 
 written.

As it should be - it's already committed, and may well have been delivered.

 If I leave out the flush (which commits the response). The 
 error page comes up.

Also as it should be.

 Is this undefined behavior

No, it's operating as required by the spec.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Writing to response and issuing sendError

2012-11-28 Thread Michael-O

Am 2012-11-28 21:39, schrieb Mark Thomas:

On 28/11/2012 20:34, Michael-O wrote:

Hi,

I am having again trouble with the respone.sendError method. The docs
say that an IllegalStateException is thrown if response has already been
committed. So this should cause an exception:

protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
   PrintWriter out = response.getWriter();
   out.println(ERROR);
   out.flush();
   response.sendError(404);
}

The exception is thrown out to the console but the response is still
written. If I leave out the flush (which commits the response). The
error page comes up.

Is this undefined behavior or some missing code path to transform the
ISE to a HTTP 500 error response?


Nope. Think about it. Once the response has been committed the response
status line and the headers have been written to the client as well as
at least some if not all of the response body. Tomcat can't take back
the data it has already sent.


Sigh, I forgot that the body has already been sent over the wire. Your 
explanation makes perfectly sense then. sendError is coming too late.


I'd prefer that this ISE would have a message. The source contains a 
commented exception message.


Thanks,

Mike

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Writing to response and issuing sendError

2012-11-28 Thread Michael-O

Am 2012-11-28 21:41, schrieb Caldarale, Charles R:

From: Michael-O [mailto:1983-01...@gmx.net]
Subject: Writing to response and issuing sendError



The exception is thrown out to the console but the response is still
written.


As it should be - it's already committed, and may well have been delivered.


If I leave out the flush (which commits the response). The
error page comes up.


Also as it should be.


Is this undefined behavior


No, it's operating as required by the spec.


Yes, thanks!


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org