Example #1
0
    @Override
    public void respond(IRequestCycle requestCycle) {
      String location = url.toString();

      if (location.startsWith("/")) {
        // context-absolute url
        location = requestCycle.getUrlRenderer().renderContextRelativeUrl(location);
      }

      if (config.isPreferStateful()) {
        // we need to persist the session before a redirect to https so the session lasts
        // across both http and https calls.
        Session.get().bind();
      }

      WebResponse response = (WebResponse) requestCycle.getResponse();
      response.sendRedirect(location);
    }
Example #2
0
  private boolean shouldRedirectToPage(IRequestCycle requestCycle) {
    if (update.containsPage()) {
      return true;
    }

    if (((WebRequest) requestCycle.getRequest()).isAjax() == false) {
      // the request was not sent by wicket-ajax.js - this can happen when an Ajax request was
      // intercepted with #redirectToInterceptPage() and then the original request is re-sent
      // by the browser on a subsequent #continueToOriginalDestination()
      return true;
    }

    return false;
  }
Example #3
0
  /**
   * @see
   *     org.apache.wicket.core.request.handler.IPageRequestHandler#respond(org.apache.wicket.request.IRequestCycle)
   */
  @Override
  public final void respond(final IRequestCycle requestCycle) {
    final RequestCycle rc = (RequestCycle) requestCycle;
    final WebResponse response = (WebResponse) requestCycle.getResponse();

    if (shouldRedirectToPage(requestCycle)) {
      // the page itself has been added to the request target, we simply issue a redirect
      // back to the page
      IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
      final String url = rc.urlFor(handler).toString();
      response.sendRedirect(url);
      return;
    }

    respondersFrozen = true;

    for (ITargetRespondListener listener : respondListeners) {
      listener.onTargetRespond(this);
    }

    final Application app = page.getApplication();

    page.send(app, Broadcast.BREADTH, this);

    // Determine encoding
    final String encoding = app.getRequestCycleSettings().getResponseRequestEncoding();

    // Set content type based on markup type for page
    update.setContentType(response, encoding);

    // Make sure it is not cached by a client
    response.disableCaching();

    final StringResponse bodyResponse = new StringResponse();
    update.writeTo(bodyResponse, encoding);
    CharSequence filteredResponse = invokeResponseFilters(bodyResponse);
    response.write(filteredResponse);
  }