Error Page Return a Status Code 200 default response?

There are two methods form setting the HTTP status of a response: setStatus() will just set the status sendError() will set the status and trigger the error-page mechanism Javadoc for sendError says the response should be considered to be committed after calling sendError (this could explain the behavior of your appserver) Implementing a custom HttpServletResponseWrapper would allow you to enforce the behavior you need for sendError (and maybe buffer the whole request in memory, so that you can send "passbacks" for exceptions occurring after the point the request would be usually committed).

There are two methods form setting the HTTP status of a response: setStatus() will just set the status sendError() will set the status and trigger the mechanism Javadoc for sendError says the response should be considered to be committed after calling sendError (this could explain the behavior of your appserver). Implementing a custom HttpServletResponseWrapper would allow you to enforce the behavior you need for sendError (and maybe buffer the whole request in memory, so that you can send "passbacks" for exceptions occurring after the point the request would be usually committed).

Can you not just use the standard web. Xml configuration: 500 /error. Jsp /error.

Jsp java.lang. Exception I cant see what else you're trying to do that this doesn't already cater for? If it's just the error code, then I think that you can set this using the response object.

The default error-page handler (which we tried) doesn't appear to allow us to override the status code. The status code is a big part of what we're trying to handle, and at least in Glassfish, the response object does not seem to allow you to set the status code on an error response. Since these are server-to-server responses (and not user browser in most cases) the status code can be pretty significant for RESTful responses.

– jayshao Jul 19 '10 at 3:11.

If I remember correctly, you should not be calling chain.doFilter() if you do not want anything else to process the request. The filter will get executed in every case, but chain.doFilter() will ensure that all other filters are called. In order to properly block an exception from getting to the user, you need to stop the request/response handling.

You could take a different route as well by using a framework like Spring and its Interceptors (just like a Filter). Spring gives you a lot of control over the Interceptors and how responses get handled. Granted, this is a bit heavy of a solution to your question.In response to the comment, according to java.sun.com/products/servlet/Filters.html: The most important method in the Filter interface is the doFilter method...This method usually performs some of the following actions: If the current filter is the last filter in the chain that ends with the target servlet, the next entity is the resource at the end of the chain; otherwise, it is the next filter that was configured in the WAR.

It invokes the next entity by calling the doFilter method on the chain object (passing in the request and response it was called with, or the wrapped versions it may have created). Alternatively, it can choose to block the request by not making the call to invoke the next entity.In the latter case, the filter is responsible for filling out the response. The idea being that this "fault barrier" needs to stop all other filters from executing, and just handle the request/response in the manner it deems necessary.

You should not call FilterChain#doFilter() whenever you've called RequestDispatcher#forward() or HttpServletResponse#sendRedirect() before in the Filter#doFilter() method. This is not the case here. – BalusC Jul 28 '10 at 0:05 Since the goal is to catch the exception being thrown, but have a generic filter, we definitely need to call doFilter - this got kind of backburnered though, so for now we're looking to see if a abstract/dispatcher servlet gets us what we want.

– jayshao Jul 28 '10 at 3:23.

The RESTEasy framework allows you to select what your response code will be using ExceptionMappers. It may be that you're reluctant to use it, but I've found it to be very quick and efficient. The JBoss documentation covering ExceptionMappers docs.jboss.org/resteasy/docs/2.0.0.GA/us... My blog article showing a snippet of general purpose RESTEasy code gary-rowe.com/agilestack/2010/08/22/my-c....

I don't know if I'd describe us as being reluctant to use it, though it does seem like overkill in this one case to think about switching dev frameworks. – jayshao Aug 30 '10 at 22:31 I wouldn't go changing a dev framework that everyone is familiar with unless there is a compelling reason (hence "reluctant to use it") but it may be that the transition is relatively painless. – Gary Rowe Aug 31 '10 at 14:59.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions