/**
   * @see wicket.request.compound.IExceptionResponseStrategy#respond(wicket.RequestCycle,
   *     java.lang.RuntimeException)
   */
  public final void respond(final RequestCycle requestCycle, final RuntimeException e) {
    // If application doesn't want debug info showing up for users
    final Session session = requestCycle.getSession();
    final Application application = session.getApplication();
    final IExceptionSettings settings = application.getExceptionSettings();
    final Page responsePage = requestCycle.getResponsePage();

    Page override = onRuntimeException(responsePage, e);
    if (override != null) {
      // we do not want to redirect - we want to inline the error output
      // and preserve the url so when the refresh button is pressed we
      // rerun the code that caused the error
      requestCycle.setRedirect(false);

      throw new RestartResponseException(override);
    } else if (e instanceof AuthorizationException) {
      // are authorization exceptions always thrown before the real render?
      // else we need to make a page (see below) or set it hard to a redirect.
      Class<? extends Page> accessDeniedPageClass =
          application.getApplicationSettings().getAccessDeniedPage();

      throw new RestartResponseAtInterceptPageException(accessDeniedPageClass);
    } else if (settings.getUnexpectedExceptionDisplay()
        != UnexpectedExceptionDisplay.SHOW_NO_EXCEPTION_PAGE) {
      // we do not want to redirect - we want to inline the error output
      // and preserve the url so when the refresh button is pressed we
      // rerun the code that caused the error
      requestCycle.setRedirect(false);

      // figure out which error page to show
      Class<? extends Page> internalErrorPageClass =
          application.getApplicationSettings().getInternalErrorPage();
      Class responseClass = responsePage != null ? responsePage.getClass() : null;

      if (responseClass != internalErrorPageClass
          && settings.getUnexpectedExceptionDisplay()
              == UnexpectedExceptionDisplay.SHOW_INTERNAL_ERROR_PAGE) {
        throw new RestartResponseException(internalErrorPageClass);
      } else if (responseClass != ExceptionErrorPortletPage.class) {
        // Show full details
        throw new RestartResponseException(new ExceptionErrorPortletPage(e, responsePage));
      } else {
        // give up while we're ahead!
        throw new WicketRuntimeException(
            "Internal Error: Could not render error page " + internalErrorPageClass, e);
      }
    }
  }
 public void onSubmit() {
   Note note = getModelObject();
   if (note == null) {
     BugeaterSession sess = (BugeaterSession) Session.get();
     IUserBean userBean = sess.getUserBean();
     if (newStatus == null) {
       // Create a plain ordinary note
       note =
           new Note()
               .setIssue(EditNotePage.this.getModelObject())
               .setText(textModel.getObject())
               .setUserID(userBean.getId());
     } else {
       // Change status with the given note text
       note =
           issueService
               .changeStatus(
                   EditNotePage.this.getModelObject(),
                   userBean,
                   newStatus,
                   textModel.getObject())
               .getNote();
     }
   } else {
     note.setText(textModel.getObject());
   }
   noteService.save(note);
   PageParameters params = new PageParameters();
   params.add(BugeaterConstants.PARAM_NAME_ISSUE_ID, String.valueOf(note.getIssue().getId()));
   setResponsePage(ViewIssuePage.class, params);
 }
  /**
   * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
   *     javax.servlet.FilterChain)
   */
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    HttpServletRequest httpServletRequest = ((HttpServletRequest) request);
    HttpSession httpSession = httpServletRequest.getSession(false);
    if (httpSession != null) {
      Session session = (Session) httpSession.getAttribute(sessionKey);
      if (session != null) {
        // set the session's threadlocal
        Session.set(session);

        if (log.isDebugEnabled()) {
          log.debug(
              "session "
                  + session
                  + " set as current for "
                  + httpServletRequest.getContextPath()
                  + ","
                  + httpServletRequest.getServerName());
        }
      } else {
        if (log.isDebugEnabled()) {
          log.debug(
              "could not set Wicket session: key "
                  + sessionKey
                  + " not found in http session for "
                  + httpServletRequest.getContextPath()
                  + ","
                  + httpServletRequest.getServerName());
        }
      }
    } else {
      if (log.isDebugEnabled()) {
        log.debug(
            "could not set Wicket session: no http session was created yet for "
                + httpServletRequest.getContextPath()
                + ","
                + httpServletRequest.getServerName());
      }
    }

    // go on with processing
    chain.doFilter(request, response);

    // clean up
    Session.unset();
  }
  /**
   * Encode a page target.
   *
   * @param requestCycle the current request cycle
   * @param requestTarget the target to encode
   * @return the encoded url
   */
  protected CharSequence encode(RequestCycle requestCycle, IPageRequestTarget requestTarget) {
    // Get the page we want a url from:
    Page page = requestTarget.getPage();

    // A url to a page is the IRedirectListener interface:
    CharSequence urlRedirect = page.urlFor(IRedirectListener.INTERFACE);

    // Touch the page once because it could be that it did go from stateless
    // to statefull or it was a internally made page where just a url must
    // be made for (frames)
    Session.get().touch(page);
    return urlRedirect;
  }