Пример #1
0
  /**
   * Process the event. Note: it doesn't invoke EventThreadInit and EventThreadCleanup.
   *
   * <p>This method is to implement {@link org.zkoss.zk.ui.sys.EventProcessingThread}. See also
   * {@link org.zkoss.zk.ui.util.Configuration#isEventThreadEnabled}.
   */
  public void process() throws Exception {
    final ExecutionMonitor execmon = _desktop.getWebApp().getConfiguration().getExecutionMonitor();
    // Bug 1506712: event listeners might be zscript, so we have to
    // keep built-in variables as long as possible
    final Scope scope = Scopes.beforeInterpret(_comp);
    // we have to push since process0 might invoke methods from zscript class
    try {
      Scopes.setImplicit("event", _event);

      _event = ((DesktopCtrl) _desktop).beforeProcessEvent(_event);
      if (_event != null) {
        if (execmon != null) execmon.eventStart(_event);

        Scopes.setImplicit("event", _event); // _event might change
        ((ComponentCtrl) _comp).service(_event, scope);
        ((DesktopCtrl) _desktop).afterProcessEvent(_event);
      }
    } finally {
      final Execution exec = _desktop.getExecution();
      if (exec != null) // just in case
      ((ExecutionCtrl) exec).setExecutionInfo(null);
      if (execmon != null && _event != null) execmon.eventComplete(_event);
      Scopes.afterInterpret();
    }
  }
Пример #2
0
 /**
  * Setup this processor before processing the event by calling {@link #process}.
  *
  * <p>Note: it doesn't invoke {@link ExecutionCtrl#onActivate}
  */
 public void setup() {
   SessionsCtrl.setCurrent(_desktop.getSession());
   final Execution exec = _desktop.getExecution();
   ExecutionsCtrl.setCurrent(exec);
   ((ExecutionCtrl) exec).setCurrentPage(getPage());
 }
Пример #3
0
  /**
   * Process asynchronous update requests from the client.
   *
   * @since 3.0.0
   */
  protected void process(Session sess, HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    final String errClient = request.getHeader("ZK-Error-Report");
    if (errClient != null)
      if (log.debugable())
        log.debug("Error found at client: " + errClient + "\n" + Servlets.getDetail(request));

    // parse desktop ID
    final WebApp wapp = sess.getWebApp();
    final WebAppCtrl wappc = (WebAppCtrl) wapp;
    final AuDecoder audec = getAuDecoder(wapp);
    final String dtid = audec.getDesktopId(request);
    if (dtid == null) {
      // Bug 1929139: incomplete request (IE only)
      if (log.debugable()) {
        final String msg = "Incomplete request\n" + Servlets.getDetail(request);
        log.debug(msg);
      }

      response.sendError(467, "Incomplete request");
      return;
    }

    Desktop desktop = getDesktop(sess, dtid);
    if (desktop == null) {
      final String cmdId = audec.getFirstCommand(request);
      if (!"rmDesktop".equals(cmdId))
        desktop = recoverDesktop(sess, request, response, wappc, dtid);

      if (desktop == null) {
        response.setIntHeader("ZK-Error", response.SC_GONE); // denote timeout
        sessionTimeout(request, response, wapp, dtid);
        return;
      }
    }
    WebManager.setDesktop(request, desktop);
    // reason: a new page might be created (such as include)

    final String sid = request.getHeader("ZK-SID");
    if (sid != null) // Some client might not have ZK-SID
    response.setHeader("ZK-SID", sid);

    // parse commands
    final Configuration config = wapp.getConfiguration();
    final List aureqs;
    boolean keepAlive = false;
    try {
      final boolean timerKeepAlive = config.isTimerKeepAlive();
      aureqs = audec.decode(request, desktop);
      for (Iterator it = aureqs.iterator(); it.hasNext(); ) {
        final String cmdId = ((AuRequest) it.next()).getCommand();
        keepAlive = !(!timerKeepAlive && Events.ON_TIMER.equals(cmdId)) && !"dummy".equals(cmdId);
        // dummy is used for PollingServerPush for piggyback
        if (keepAlive) break; // done
      }
    } catch (Throwable ex) {
      log.warningBriefly(ex);
      responseError(request, response, Exceptions.getMessage(ex));
      return;
    }

    if (aureqs.isEmpty()) {
      final String errmsg = "Illegal request: cmd required";
      log.debug(errmsg);
      responseError(request, response, errmsg);
      return;
    }

    ((SessionCtrl) sess).notifyClientRequest(keepAlive);

    //		if (log.debugable()) log.debug("AU request: "+aureqs);
    final DesktopCtrl desktopCtrl = (DesktopCtrl) desktop;
    final Execution exec = new ExecutionImpl(getServletContext(), request, response, desktop, null);
    if (sid != null) ((ExecutionCtrl) exec).setRequestId(sid);

    final AuWriter out = AuWriters.newInstance();
    out.setCompress(_compress);
    out.open(
        request,
        response,
        desktop.getDevice().isSupported(Device.RESEND)
            ? getProcessTimeout(config.getResendDelay())
            : 0);
    // Note: getResendDelay() might return nonpositive
    try {
      wappc.getUiEngine().execUpdate(exec, aureqs, out);
    } catch (RequestOutOfSequenceException ex) {
      log.warning(ex.getMessage());
      response.setHeader("ZK-SID", sid);
      response.setIntHeader("ZK-Error", AuResponse.SC_OUT_OF_SEQUENCE);
    }
    out.close(request, response);
  }