How can we know if a HttpServletResponse has been redirected ?

Discussion in 'Java' started by Bruno Thomas, Sep 7, 2005.

  1. Bruno Thomas

    Bruno Thomas Guest

    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
     
    Bruno Thomas, Sep 7, 2005
    #1
    1. Advertising

  2. Re: How can we know if a HttpServletResponse has been redirected?

    Bruno Thomas wrote:

    > 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.

    --
    John Bollinger
     
    John C. Bollinger, Sep 8, 2005
    #2
    1. Advertising

  3. Bruno Thomas

    Bruno Thomas Guest

    John C. Bollinger wrote:

    > Bruno Thomas wrote:
    >
    >> Maybe this topic has already been treated but I havent found answers....

    >
    > 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 ?

    >> 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.


    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
     
    Bruno Thomas, Sep 13, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michele Simionato
    Replies:
    11
    Views:
    459
    vasudevram
    Dec 23, 2006
  2. Bruno Desthuilliers
    Replies:
    12
    Views:
    488
    Raymond Hettinger
    Sep 24, 2007
  3. lichaoir
    Replies:
    3
    Views:
    447
    bruce barker
    Jul 18, 2008
  4. Replies:
    2
    Views:
    120
  5. Michele Dondi

    How can I know if STDOUT has been redirected?

    Michele Dondi, Oct 20, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    348
    Michele Dondi
    Oct 21, 2004
Loading...

Share This Page