Ejemplo n.º 1
0
  /**
   * Recovers the desktop if possible. It is called if {@link #getDesktop} returns null.
   *
   * <p>The default implementation will look for any failover manager ({@link FailoverManager}) is
   * registered, and forward the invocation to it if found.
   *
   * @return the recovered desktop, or null if failed to recover
   * @since 5.0.3
   */
  protected Desktop recoverDesktop(
      Session sess,
      HttpServletRequest request,
      HttpServletResponse response,
      WebAppCtrl wappc,
      String dtid) {
    final FailoverManager failover = wappc.getFailoverManager();
    if (failover != null) {
      Desktop desktop = null;
      final ServletContext ctx = getServletContext();
      try {
        if (failover.isRecoverable(sess, dtid)) {
          desktop = WebManager.getWebManager(ctx).getDesktop(sess, request, response, null, true);
          if (desktop == null) // forward or redirect
          throw new IllegalStateException("sendRediect or forward not allowed in recovering");

          wappc
              .getUiEngine()
              .execRecover(new ExecutionImpl(ctx, request, response, desktop, null), failover);
          return desktop; // success
        }
      } catch (Throwable ex) {
        log.error("Unable to recover " + dtid, ex);
        if (desktop != null) ((DesktopCtrl) desktop).recoverDidFail(ex);
      }
    }
    return null;
  }
Ejemplo n.º 2
0
 private ClassWebResource getClassWebResource() {
   return WebManager.getWebManager(getServletContext()).getClassWebResource();
 }
Ejemplo n.º 3
0
  // Servlet//
  public void init() throws ServletException {
    final ServletConfig config = getServletConfig();
    final ServletContext ctx = getServletContext();
    ctx.setAttribute(ATTR_UPDATE_SERVLET, this);

    final WebManager webman = WebManager.getWebManager(ctx);
    String param = config.getInitParameter("compress");
    _compress = param == null || param.length() == 0 || "true".equals(param);
    if (!_compress) webman.getClassWebResource().setCompress(null); // disable all

    // Copies au extensions defined before DHtmlUpdateServlet is started
    final WebApp wapp = webman.getWebApp();
    final Map aues = (Map) wapp.getAttribute(ATTR_AU_PROCESSORS);
    if (aues != null) {
      for (Iterator it = aues.entrySet().iterator(); it.hasNext(); ) {
        final Map.Entry me = (Map.Entry) it.next();
        addAuExtension((String) me.getKey(), (AuExtension) me.getValue());
      }
      wapp.removeAttribute(ATTR_AU_PROCESSORS);
    }

    // ZK 5: extension defined in init-param has the higher priority
    for (int j = 0; ; ++j) {
      param = config.getInitParameter("extension" + j);
      if (param == null) {
        param = config.getInitParameter("processor" + j); // backward compatible
        if (param == null) break;
      }
      final int k = param.indexOf('=');
      if (k < 0) {
        log.warning("Ignore init-param: illegal format, " + param);
        continue;
      }

      final String prefix = param.substring(0, k).trim();
      final String clsnm = param.substring(k + 1).trim();
      try {
        addAuExtension(prefix, (AuExtension) Classes.newInstanceByThread(clsnm));
      } catch (ClassNotFoundException ex) {
        log.warning("Ignore init-param: class not found, " + clsnm);
      } catch (ClassCastException ex) {
        log.warning("Ignore: " + clsnm + " not implement " + AuExtension.class);
      } catch (Throwable ex) {
        log.warning("Ignore init-param: failed to add an AU extension, " + param, ex);
      }
    }

    if (getAuExtension("/upload") == null) {
      try {
        addAuExtension("/upload", new AuUploader());
      } catch (Throwable ex) {
        final String msg = "Make sure commons-fileupload.jar is installed.";
        log.warningBriefly("Failed to configure fileupload. " + msg, ex);

        // still add /upload to generate exception when fileupload is used
        addAuExtension(
            "/upload",
            new AuExtension() {
              public void init(DHtmlUpdateServlet servlet) {}

              public void destroy() {}

              public void service(
                  HttpServletRequest request, HttpServletResponse response, String pi)
                  throws ServletException, IOException {
                if (Sessions.getCurrent(false) != null)
                  throw new ServletException("Failed to upload. " + msg);
              }
            });
      }
    }

    if (getAuExtension("/view") == null) addAuExtension("/view", new AuDynaMediar());
  }