Package org.apache.wicket.request

Examples of org.apache.wicket.request.Url

The Url class takes care of encoding and decoding of the segments and parameters. @author Matej Knopp @author Igor Vaynberg

   * TODO: simplify the code below. See WICKET-3347
   */
  @Override
  public void respond(RequestCycle requestCycle)
  {
    Url currentUrl = requestCycle.getUrlRenderer().getBaseUrl();
    Url targetUrl = requestCycle.mapUrlFor(getRenderPageRequestHandler());

    //
    // the code below is little hairy but we have to handle 3 redirect policies,
    // 3 rendering strategies and two kind of requests (ajax and normal)
    //

    // try to get an already rendered buffered response for current URL
    BufferedWebResponse bufferedResponse = getAndRemoveBufferedResponse(currentUrl);

    if (bufferedResponse != null)
    {
      logger
        .warn("The Buffered response should be handled by BufferedResponseRequestHandler");
      // if there is saved response for this URL render it
      bufferedResponse.writeTo((WebResponse)requestCycle.getResponse());
    }
    else if (shouldRenderPageAndWriteResponse(requestCycle, currentUrl, targetUrl))
    {
      BufferedWebResponse response = renderPage(currentUrl, requestCycle);
      if (response != null)
      {
        response.writeTo((WebResponse)requestCycle.getResponse());
      }
    }
    else if (shouldRedirectToTargetUrl(requestCycle, currentUrl, targetUrl))
    {
     
      redirectTo(targetUrl, requestCycle);

      // note: if we had session here we would render the page to buffer and then
      // redirect to URL generated *after* page has been rendered (the statelessness
      // may change during render). this would save one redirect because now we have
      // to render to URL generated *before* page is rendered, render the page, get
      // URL after render and if the URL is different (meaning page is not stateless),
      // save the buffer and redirect again (which is pretty much what the next step
      // does)
    }
    else
    {
      if (isRedirectToBuffer() == false && logger.isDebugEnabled())
      {
        String details = String
          .format(
            "redirect strategy: '%s', isAjax: '%s', redirect policy: '%s', "
              + "current url: '%s', target url: '%s', is new: '%s', is stateless: '%s', is temporary: '%s'",
            Application.get().getRequestCycleSettings().getRenderStrategy(),
            isAjax(requestCycle), getRedirectPolicy(), currentUrl, targetUrl,
            isNewPageInstance(), isPageStateless(), isSessionTemporary());
        logger
          .debug("Falling back to Redirect_To_Buffer render strategy because none of the conditions "
            + "matched. Details: " + details);
      }

      // force creation of possible stateful page to get the final target url
      getPage();

      Url beforeRenderUrl = requestCycle.mapUrlFor(getRenderPageRequestHandler());

      // redirect to buffer
      BufferedWebResponse response = renderPage(beforeRenderUrl, requestCycle);

      if (response == null)
      {
        return;
      }

      // the url might have changed after page has been rendered (e.g. the
      // stateless flag might have changed because stateful components
      // were added)
      final Url afterRenderUrl = requestCycle
        .mapUrlFor(getRenderPageRequestHandler());

      if (beforeRenderUrl.getSegments().equals(afterRenderUrl.getSegments()) == false)
      {
        // the amount of segments is different - generated relative URLs
        // will not work, we need to rerender the page. This can happen
        // with IRequestHandlers that produce different URLs with
        // different amount of segments for stateless and stateful pages
View Full Code Here


  {
    Args.notNull(url, "url");

    UrlRenderer urlRenderer = getUrlRenderer();

    Url originalUrl = Url.parse(url);

    /*
      WICKET-4645 - always pass absolute url to the web container for encoding
      because when REDIRECT_TO_BUFFER is in use Wicket may render PageB when
      PageA is actually the requested one and the web container cannot resolve
      the base url properly
     */
    String fullUrl = urlRenderer.renderFullUrl(originalUrl);
    String encodedFullUrl = httpServletResponse.encodeURL(fullUrl);

    final String encodedUrl;
    if (originalUrl.isFull())
    {
      encodedUrl = encodedFullUrl;
    }
    else
    {
      if (fullUrl.equals(encodedFullUrl))
      {
        // no encoding happened so just reuse the original url
        encodedUrl = url.toString();
      }
      else
      {
        // get the relative url with the jsessionid encoded in it
        Url _encoded = Url.parse(encodedFullUrl);
        encodedUrl = urlRenderer.renderRelativeUrl(_encoded);
      }
    }
    return encodedUrl;
  }
View Full Code Here

  {
    Args.notNull(url, "url");

    UrlRenderer urlRenderer = getUrlRenderer();

    Url originalUrl = Url.parse(url);

    /*
     * WICKET-4645 - always pass absolute url to the web container for encoding because when
     * REDIRECT_TO_BUFFER is in use Wicket may render PageB when PageA is actually the requested
     * one and the web container cannot resolve the base url properly
     */
    String fullUrl = urlRenderer.renderFullUrl(originalUrl);
    String encodedFullUrl = httpServletResponse.encodeRedirectURL(fullUrl);

    final String encodedUrl;
    if (originalUrl.isFull())
    {
      encodedUrl = encodedFullUrl;
    }
    else
    {
      if (fullUrl.equals(encodedFullUrl))
      {
        // no encoding happened so just reuse the original url
        encodedUrl = url.toString();
      }
      else
      {
        // get the relative url with the jsessionid encoded in it
        Url _encoded = Url.parse(encodedFullUrl);
        encodedUrl = urlRenderer.renderRelativeUrl(_encoded);
      }
    }
    return encodedUrl;
  }
View Full Code Here

        if (redirectCount++ >= 100)
        {
          fail("Possible infinite redirect detected. Bailing out.");
        }

        Url newUrl = Url.parse(lastResponse.getRedirectLocation(),
          Charset.forName(request.getCharacterEncoding()));

        if (isExternalRedirect(lastRequest.getUrl(), newUrl))
        {
          // we can't handle external redirects here
          // just bail out here and let the user's test code
          // check #assertRedirectUrl
          return true;
        }

        if (newUrl.isFull() || newUrl.isContextAbsolute())
        {
          request.setUrl(newUrl);

          final String protocol = newUrl.getProtocol();

          if (protocol != null)
          {
            request.setScheme(protocol);
          }

          request.setSecure("https".equals(protocol));

          if (newUrl.getHost() != null)
          {
            request.setServerName(newUrl.getHost());
          }
          if (newUrl.getPort() != null)
          {
            request.setServerPort(newUrl.getPort());
          }
        }
        else
        {
          // append redirect URL to current URL (what browser would do)
          Url mergedURL = new Url(lastRequest.getUrl().getSegments(),
            newUrl.getQueryParameters());
          mergedURL.concatSegments(newUrl.getSegments());

          request.setUrl(mergedURL);
        }

        processRequest(null, null, true);
View Full Code Here

   * @param handler
   * @return {@link Url} for handler.
   */
  public Url urlFor(final IRequestHandler handler)
  {
    Url url = application.getRootRequestMapper().mapHandler(handler);
    return transform(url);
  }
View Full Code Here

   */
  public String urlFor(Link<?> link)
  {
    Args.notNull(link, "link");

    Url url = Url.parse(link.urlFor(ILinkListener.INTERFACE, new PageParameters()).toString());
    return transform(url).toString();
  }
View Full Code Here

    // there are two ways to do this. RequestCycle could be forced to call the handler
    // directly but constructing and parsing the URL increases the chance of triggering bugs
    IRequestHandler handler = new ListenerInterfaceRequestHandler(new PageAndComponentProvider(
      component.getPage(), component), listener);

    Url url = urlFor(handler);
    request.setUrl(url);

    // Process the request
    processRequest(request, null);
  }
View Full Code Here

   */
  public void executeBehavior(final AbstractAjaxBehavior behavior)
  {
    Args.notNull(behavior, "behavior");

    Url url = Url.parse(behavior.getCallbackUrl().toString(),
      Charset.forName(request.getCharacterEncoding()));
    transform(url);
    request.setUrl(url);
    request.addHeader(WebRequest.HEADER_AJAX_BASE_URL, url.toString());
    request.addHeader(WebRequest.HEADER_AJAX, "true");

    if (behavior instanceof AjaxFormSubmitBehavior)
    {
      AjaxFormSubmitBehavior formSubmitBehavior = (AjaxFormSubmitBehavior)behavior;
View Full Code Here

   * @return Url
   */
  public Url urlFor(final AjaxLink<?> link)
  {
    AbstractAjaxBehavior behavior = WicketTesterHelper.findAjaxEventBehavior(link, "onclick");
    Url url = Url.parse(behavior.getCallbackUrl().toString(),
      Charset.forName(request.getCharacterEncoding()));
    return transform(url);
  }
View Full Code Here

   *            path to component
   */
  public void submitForm(String path)
  {
    Form<?> form = (Form<?>)getComponentFromLastRenderedPage(path);
    Url url = Url.parse(
      form.getRootForm()
        .urlFor(IFormSubmitListener.INTERFACE, new PageParameters())
        .toString(), Charset.forName(request.getCharacterEncoding()));

    // make url absolute
View Full Code Here

TOP

Related Classes of org.apache.wicket.request.Url

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.