/*
   * (non-Javadoc)
   *
   * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal
   * (javax.servlet .http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {
    Catalog catalog = (Catalog) getApplicationContext().getBean("catalog");

    String fmId = request.getParameter("fmId");

    ModelAndView mav = new ModelAndView("flowinfo");
    FileBasedFlowManager fm = catalog.getResource(fmId, FileBasedFlowManager.class);

    mav.addObject("flowManager", fm);

    Set<BaseEventConsumer> tree = fm.getEventConsumers();

    mav.addObject("ecList", tree.toArray());

    return mav;
  }
  @Override
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    catalog = (Catalog) getApplicationContext().getBean("catalog");

    final String fmId = request.getParameter(FLOW_MANAGER_ID_KEY);
    final String ecId = request.getParameter(CONSUMER_ID_KEY);

    if (fmId == null || fmId.isEmpty()) {
      throw new IllegalArgumentException("fmId parameter is null or empty");
    }
    if (ecId == null || ecId.isEmpty()) {
      throw new IllegalArgumentException("ecId parameter is null or empty");
    }

    final ModelAndView mav = new ModelAndView(MAV_NAME_KEY);
    mav.addObject("flowManagers", catalog.getFlowManagers(FileBasedFlowManager.class));

    final FileBasedFlowManager fm = catalog.getResource(fmId, FileBasedFlowManager.class);
    handleFlowManager(mav, fm);

    final EventConsumer consumer = fm.getConsumer(ecId);
    handleConsumer(mav, consumer);

    // final Collection<FileBasedEventConsumer>
    // consumers=fm.getEventConsumers();
    // final Iterator<FileBasedEventConsumer> it=consumers.iterator();
    // while (it.hasNext()){
    // final FileBasedEventConsumer consumer=it.next();
    // if (consumer == null)
    // {
    // mav.addObject("error", "Flow instance '" + consumer.getId() +
    // "' not found");
    // } else {
    // runStuff(mav, consumer);
    // }
    //
    // }

    return mav;
  }