コード例 #1
0
ファイル: ShowMonitors.java プロジェクト: jr42/iaf
  public void initForm(DynaActionForm monitorForm) {
    MonitorManager mm = MonitorManager.getInstance();

    monitorForm.set("monitorManager", mm);
    List destinations = new ArrayList();
    for (int i = 0; i < mm.getMonitors().size(); i++) {
      Monitor m = mm.getMonitor(i);
      Set d = m.getDestinationSet();
      for (Iterator it = d.iterator(); it.hasNext(); ) {
        destinations.add(i + "," + it.next());
      }
    }
    String[] selDest = new String[destinations.size()];
    selDest = (String[]) destinations.toArray(selDest);
    monitorForm.set("selDestinations", selDest);
    monitorForm.set("enabled", new Boolean(mm.isEnabled()));
    monitorForm.set("eventTypes", EventTypeEnum.getEnumList());
    monitorForm.set("severities", SeverityEnum.getEnumList());
  }
コード例 #2
0
ファイル: ShowMonitors.java プロジェクト: jr42/iaf
  public ActionForward executeSub(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws IOException, ServletException {

    // Initialize action
    initAction(request);

    if (null == config) {
      return (mapping.findForward("noconfig"));
    }

    String forward = null;
    DynaActionForm monitorForm = getPersistentForm(mapping, form, request);

    if (isCancelled(request)) {
      log.debug("edit is canceled");
      forward = determineExitForward(monitorForm);
    } else {

      // debugFormData(request,form);

      String action = request.getParameter("action");
      String indexStr = request.getParameter("index");
      String triggerIndexStr = request.getParameter("triggerIndex");
      int index = -1;
      if (StringUtils.isNotEmpty(indexStr)) {
        index = Integer.parseInt(indexStr);
      }
      int triggerIndex = -1;
      if (StringUtils.isNotEmpty(triggerIndexStr)) {
        triggerIndex = Integer.parseInt(triggerIndexStr);
      }

      MonitorManager mm = MonitorManager.getInstance();
      if ("getStatus".equals(action)) {
        response.setContentType("text/xml");
        PrintWriter out = response.getWriter();
        out.print(mm.getStatusXml().toXML());
        out.close();
        return null;
      }
      Lock lock = mm.getStructureLock();
      try {
        lock.acquireExclusive();
        forward = performAction(monitorForm, action, index, triggerIndex, response);
        log.debug("forward [" + forward + "] returned from performAction");
        mm.reconfigure();
      } catch (Exception e) {
        error(
            "could not perform action ["
                + action
                + "] on monitorIndex ["
                + index
                + "] triggerIndex ["
                + triggerIndex
                + "]",
            e);
      } finally {
        lock.releaseExclusive();
      }
      if (response.isCommitted()) {
        return null;
      }
    }
    if (StringUtils.isEmpty(forward)) {
      log.debug("replacing empty forward with [success]");
      forward = "success";
    }

    initForm(monitorForm);

    ActionForward af = mapping.findForward(forward);
    if (af == null) {
      throw new ServletException("could not find forward [" + forward + "]");
    }
    // Forward control to the specified success URI
    log.debug("forward to [" + forward + "], path [" + af.getPath() + "]");
    return (af);
  }