How can we know if a HttpServletResponse has been redirected ?

B

Bruno Thomas

Hi all,


Maybe this topic has already been treated but I havent found answers....

I have a filter (let say a servlet filter) and I want to know if the
response has been redirected by the application before.

How can I know that ? (I havent found a getter like isRedirected or whatever
like getStatus() ) Am I obliged to set a header parameter to know that ?
(that I'd like to avoid)

Thank you for your answers.

Bruno Thomas
 
J

John C. Bollinger

Bruno said:
Maybe this topic has already been treated but I havent found answers....

That may be because you're asking the wrong question.
I have a filter (let say a servlet filter) and I want to know if the
response has been redirected by the application before.

How can I know that ? (I havent found a getter like isRedirected or whatever
like getStatus() ) Am I obliged to set a header parameter to know that ?
(that I'd like to avoid)

You shouldn't ever need to be concerned about it. If you're using a
Filter then only previous filters in the filter chain will have had an
opportunity to redirect the response before your filter sees it, and any
filter that does so is poorly designed indeed if it passes the
request/response pair on down the chain afterward. Request processing
is very likely heading for an internal server error otherwise.

More generally, there is no good way to determine whether a plain
ServletResponse or HttpServletResponse has been previously redirected,
but if you anticipate the need in advance then you can wrap the response
it in a custom wrapper (see ServletResponseWrapper /
HttpServletResponseWrapper) that will record or block such events.
 
B

Bruno Thomas

John said:
That may be because you're asking the wrong question.

Well maybe it was not properly written but it was not wrong, regarding our
needs. We must make a workaround for proxy bug that our provider don't plan
to fix. How could you know that ?
You shouldn't ever need to be concerned about it. If you're using a
Filter then only previous filters in the filter chain will have had an
opportunity to redirect the response before your filter sees it, and any
filter that does so is poorly designed indeed if it passes the
request/response pair on down the chain afterward. Request processing
is very likely heading for an internal server error otherwise.

I agree with you and I wrote "let say" because a servlet filter is a
standard object and I didn't want to go in further details. In fact it is a
view handler mapping interceptor (with springframework) and it is not
acting exactly as a filter. And this filter should set the content type
(that is a specific one), except if there has been a redirect set before
because the proxy has a bug and does not make redirects if the content type
is set to this specific one. That's all.

Actually if someone else is having the same problem, I solved it looking if
the key "Location" has been set before in the response header (it is done
by the sendRedirect() method -> it is in the ServletResponse specs).
More generally, there is no good way to determine whether a plain
ServletResponse or HttpServletResponse has been previously redirected,
but if you anticipate the need in advance then you can wrap the response
it in a custom wrapper (see ServletResponseWrapper /
HttpServletResponseWrapper) that will record or block such events.

Yep, this is another solution.

Thanks anyway for your answser.

Regards,

Bruno Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top