示例#1
0
  protected void processAjaxRequest(
      Form form, HttpServletRequest request, HttpServletResponse response) throws IOException {

    AjaxResponse ajaxResponse = new AjaxResponse(response);
    if (form != null) {
      form.getFormContext().setWriter(response.getWriter());
      form.setFormListener(ajaxResponse);
      if (isEventRequest(request)) {
        processEventRequest(form, request);
      } else {
        processForm(form, request);
      }
      form.setFormListener(null);
    } else {
      String message =
          messageSource.getMessage(
              "error.sessionExpired",
              null,
              "Your session has expired",
              RequestContextUtils.getLocale(request));

      ajaxResponse.alert(message);
    }
    ajaxResponse.close();
  }
  private void checkResponse(AjaxRequestTarget target) {
    // Show cancel
    if (response.isCancelVisible()) {
      cancelDiv.setVisible(true);
      target.addComponent(cancelDiv);
    }
    // Show retry
    if (response.isRetryVisible()) {
      retryDiv.setVisible(true);
      target.addComponent(retryDiv);
    }

    // Show error Text
    if (PortalUtils.exists(response.getErrorMessage())) {
      errorMsg.setVisible(true);
      target.addComponent(errorMsg);
    }

    // Return to URL
    if (PortalUtils.exists(response.getReturnUrl()) && response.isRedirect())
      try {
        getWebRequestCycle()
            .getWebResponse()
            .getHttpServletResponse()
            .sendRedirect(response.getReturnUrl());
        isRedirected = true;
      } catch (IOException e) {
        LOG.error(
            "#An error occurred while redirecting to the return url["
                + response.getReturnUrl()
                + "]",
            e);
        return;
      }
  }
 public void handle(
     String method, String message, HttpServletRequest request, AjaxResponse response) {
   response.elementResponse(
       null,
       "<span class=\"error\">No implementation for "
           + method
           + " "
           + request.getParameter("member")
           + "</span>");
 }
  private void prepairResponse(AjaxResponse obj, Transaction txn) {
    if (LOG.isDebugEnabled())
      LOG.debug("Return Ajax status " + obj.getStatus() + " - " + obj.getErrorMessage());

    if (txn != null) {
      obj.setReturnUrl(txn.getReturnUrl());
      obj.setRetry(txn.getContinueRetryCounter());
      obj.setRedirect(true);

      if (LOG.isDebugEnabled()) {
        Date pollStart = (Date) txn.getContinueStartDate();
        Date currentTime = new Date();
        long dif = currentTime.getTime() - pollStart.getTime();
        LOG.debug(
            "Ajax Poll: [RetryCount="
                + (obj.getRetry())
                + "] [Elapsed Time="
                + (dif / 1000)
                + "s]");
      }
    }
    response = obj;
  }
 public JSPIncludeAjaxResponse(String jspName, String ev) {
   // For DOJO Based - Do not need elementID
   // ev = (ev != null ? "'" + ev.replaceAll("'", "\\\\'") + "'" : ev);
   this.jspName = jspName;
   super.setEvalCode(ev);
 }
  protected void checkStatus(AjaxRequestTarget target) {
    if (PortalUtils.exists(response)) {
      checkResponse(target);
    }
    // get current Thread
    SmsAuthenticationThread t = getMobiliserWebSession().getSmsThread();

    // if technical problem...
    // Thread not started
    if (t == null) {
      prepairResponse(new AjaxResponse(9999, "Thread not started"), null);
      return;
    }

    // exception was thrown from thread
    if (t.getException() != null) {
      prepairResponse(new AjaxResponse(9999, "Exception: " + t.getException().getMessage()), null);
      return;
    }

    // Still processing request
    if (t.isActive()) {
      prepairResponse(new AjaxResponse(-1, ""), null);
      return;
    }

    // Thread is finished

    // no answer from Mobiliser. Technical error
    if (t.getResponse() == null) {
      prepairResponse(new AjaxResponse(9999, "No response from Mobiliser"), null);
      return;
    }

    Transaction txn = getMobiliserWebSession().getTransaction();

    // check if second try is exceeded. Cancel Transaction by second
    // retry
    if (txn.getContinueRetryCounter() >= 2 && t.getResponse().getStatus().getCode() == 2853) {

      if (LOG.isDebugEnabled()) LOG.debug("retry count exceeded. Canceling transaction");

      try {
        // Fail transaction
        txn.failTransaction(2853);

      } catch (Exception e) {
        LOG.error("#failTransaction: " + e, e);
      }

      // Kill Session
      getMobiliserWebSession().invalidate();

      prepairResponse(new AjaxResponse(9999, "Cancel Response"), txn);
      return;
    }

    // check status of mobiliser response
    if (t.getResponse().getStatus() != null && t.getResponse().getStatus().getCode() != 0) {
      // Mobiliser request failed with an error code

      AjaxResponse response =
          new AjaxResponse(
              t.getResponse().getStatus().getCode(), t.getResponse().getStatus().getValue());

      switch (t.getResponse().getStatus().getCode()) {
        case 2853: // Transaction timed out
          response.setRetryVisible(true);

        default:
          response.setRedirect(true);
      }

      prepairResponse(response, txn);
      return;
    }

    // everything was OK
    prepairResponse(new AjaxResponse(0, "OK"), txn);
  }