Please review r998677.
I implemented the logic we discussed in IRC with you before your change.

On Mon, Sep 20, 2010 at 10:24 AM, Peter Ertl <[email protected]> wrote:

> Hi Martin,
>
> I am aware of that uglyness but I could not figure out a clean way to get
> around it.
>
> When fixing WICKET-3048 I needed a way to detect if the current request is
> of type 'ajax'.
>
> However the ctor from ServletWebResponse is
>
>        public ServletWebResponse(HttpServletRequest httpServletRequest,
>                HttpServletResponse httpServletResponse)
>
> To change it to
>
>        public ServletWebResponse(ServletWebRequest servletWebRequest,
>                HttpServletResponse httpServletResponse)
>
> you would need to instantiate
>
>        public ServletWebRequest(HttpServletRequest httpServletRequest,
> String filterPrefix)
>
> However there's no easy way to get 'filterPrefix' in the relevant places so
> I was kind of stuck there.
>
> Note my TODO in ServletWebRequest line 389 :-(
>
> If you can figure out a clean way to get this done I will appreciate that
> :-)
>
>
>
>
>
>
> Am 19.09.2010 um 16:22 schrieb Martin Grigorov:
>
> > Hi Peter,
> >
> > On Thu, Sep 16, 2010 at 12:40 AM, <[email protected]> wrote:
> >
> >> Author: pete
> >> Date: Wed Sep 15 22:39:59 2010
> >> New Revision: 997528
> >>
> >> URL: http://svn.apache.org/viewvc?rev=997528&view=rev
> >> Log:
> >> fixed non-working ajax redirects: WICKET-3048
> >>
> >> Modified:
> >>
> >>
> wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/http/WebRequest.java
> >>
> >>
> wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
> >>
> >>
> wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebResponse.java
> >>
> >> Modified:
> >>
> wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/http/WebRequest.java
> >> URL:
> >>
> http://svn.apache.org/viewvc/wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/http/WebRequest.java?rev=997528&r1=997527&r2=997528&view=diff
> >>
> >>
> ==============================================================================
> >> ---
> >>
> wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/http/WebRequest.java
> >> (original)
> >> +++
> >>
> wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/http/WebRequest.java
> >> Wed Sep 15 22:39:59 2010
> >> @@ -104,8 +104,8 @@ public abstract class WebRequest extends
> >>       /**
> >>        * Marker parameter for AjaxRequest.
> >>        */
> >> -       private static final String PARAM_AJAX = "wicket:ajax";
> >> -       private static final String HEADER_AJAX = "Wicket-Ajax";
> >> +       protected static final String PARAM_AJAX = "wicket:ajax";
> >> +       protected static final String HEADER_AJAX = "Wicket-Ajax";
> >>
> >>       /**
> >>        * Returns whether this request is an Ajax request. This
> >> implementation only checks for value of
> >>
> >> Modified:
> >>
> wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
> >> URL:
> >>
> http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java?rev=997528&r1=997527&r2=997528&view=diff
> >>
> >>
> ==============================================================================
> >> ---
> >>
> wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
> >> (original)
> >> +++
> >>
> wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
> >> Wed Sep 15 22:39:59 2010
> >> @@ -371,4 +371,23 @@ public class ServletWebRequest extends W
> >>       {
> >>               return RequestUtils.getCharset(httpServletRequest);
> >>       }
> >> +
> >> +       @Override
> >> +       public boolean isAjax()
> >> +       {
> >> +               return isAjax(httpServletRequest);
> >> +       }
> >> +
> >> +       /**
> >> +        * check if random http servlet request is an ajax request
> >> +        *
> >> +        * @param httpServletRequest web request
> >> +        * @return <code>true</code> if ajax, <code>false</code> if
> regular
> >> request
> >> +        */
> >> +       public static boolean isAjax(HttpServletRequest
> httpServletRequest)
> >> +       {
> >> +               // TODO there is some redundancy in this method and
> >> WebRequest#isAjax - can this be eliminated?
> >> +               return
> >> Strings.isTrue(httpServletRequest.getHeader(HEADER_AJAX)) ||
> >> +
> >> Strings.isTrue(httpServletRequest.getParameter(PARAM_AJAX));
> >> +       }
> >>
> > What is the reason to add this method at all ?
> > Why not use WebRequest#isAjax() ?
> >
> > Why 'static' ? ServletWebRequest has a reference to its
> HttpServletRequest.
> > Why do you want to check some other HttpServletRequest ?!
> >
> >> }
> >>
> >> Modified:
> >>
> wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebResponse.java
> >> URL:
> >>
> http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebResponse.java?rev=997528&r1=997527&r2=997528&view=diff
> >>
> >>
> ==============================================================================
> >> ---
> >>
> wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebResponse.java
> >> (original)
> >> +++
> >>
> wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebResponse.java
> >> Wed Sep 15 22:39:59 2010
> >> @@ -31,7 +31,7 @@ import org.apache.wicket.util.lang.Args;
> >>
> >> /**
> >> * WebResponse that wraps a {...@link ServletWebResponse}.
> >> - *
> >> + *
> >> * @author Matej Knopp
> >> */
> >> public class ServletWebResponse extends WebResponse
> >> @@ -41,7 +41,7 @@ public class ServletWebResponse extends
> >>
> >>       /**
> >>        * Construct.
> >> -        *
> >> +        *
> >>        * @param httpServletRequest
> >>        * @param httpServletResponse
> >>        */
> >> @@ -57,7 +57,7 @@ public class ServletWebResponse extends
> >>
> >>       /**
> >>        * Returns the wrapped response
> >> -        *
> >> +        *
> >>        * @return wrapped response
> >>        */
> >>       public final HttpServletResponse getHttpServletResponse()
> >> @@ -223,25 +223,35 @@ public class ServletWebResponse extends
> >>       @Override
> >>       public void sendRedirect(String url)
> >>       {
> >> -               sendRedirect(url, false);
> >> -       }
> >> -
> >> -       private void sendRedirect(String url, boolean cacheable)
> >> -       {
> >> -               redirect = true;
> >> -               url = getAbsoluteURL(url);
> >> -               url = httpServletResponse.encodeRedirectURL(url);
> >> -
> >>               try
> >>               {
> >> -                       // proxies eventually cache '302 temporary
> >> redirect' responses:
> >> -                       // for most wicket use cases this is fatal since
> >> redirects are
> >> -                       // usually highly dynamic and can not be
> statically
> >> mapped
> >> -                       // to a request url in general
> >> -                       if (cacheable == false)
> >> -                               this.disableCaching();
> >> +                       redirect = true;
> >> +                       url = getAbsoluteURL(url);
> >> +                       url =
> httpServletResponse.encodeRedirectURL(url);
> >> +
> >> +                       // wicket redirects should never be cached
> >> +                       this.disableCaching();
> >> +
> >> +                       if
> (ServletWebRequest.isAjax(httpServletRequest))
> >> +                       {
> >> +
> >> httpServletResponse.addHeader("Ajax-Location", url);
> >> +
> >> +                               /*
> >> +                                * usually the Ajax-Location header is
> >> enough and we do not need to the
> >> +                                * redirect url into the response, but
> >> sometimes the response is processed
> >> +                                * via an iframe (eg using multipart
> ajax
> >> handling) and the headers are not
> >> +                                * available because XHR is not used and
> >> that is the only way javascript has
> >> +                                * access to response headers.
> >> +                                */
> >> +                               httpServletResponse.getWriter().write(
> >> +                                       "<ajax-response><redirect>" +
> url +
> >> "</redirect></ajax-response>");
> >>
> >> -                       httpServletResponse.sendRedirect(url);
> >> +                               setContentType("text/xml;charset=" +
> >> httpServletRequest.getCharacterEncoding());
> >> +                       }
> >> +                       else
> >> +                       {
> >> +                               httpServletResponse.sendRedirect(url);
> >> +                       }
> >>               }
> >>               catch (IOException e)
> >>               {
> >>
> >>
> >>
>
>

Reply via email to