Esempio n. 1
0
  @Override
  protected synchronized RequestProcessor getRequestProcessor(ModuleConfig moduleConfig)
      throws ServletException {

    ServletContext servletContext = getServletContext();

    String key = Globals.REQUEST_PROCESSOR_KEY + moduleConfig.getPrefix();

    RequestProcessor requestProcessor = (RequestProcessor) servletContext.getAttribute(key);

    if (requestProcessor == null) {
      ControllerConfig controllerConfig = moduleConfig.getControllerConfig();

      try {
        requestProcessor =
            (RequestProcessor)
                InstanceFactory.newInstance(
                    ClassLoaderUtil.getPortalClassLoader(), controllerConfig.getProcessorClass());
      } catch (Exception e) {
        throw new ServletException(e);
      }

      requestProcessor.init(this, moduleConfig);

      servletContext.setAttribute(key, requestProcessor);
    }

    return requestProcessor;
  }
  /**
   * Initialize this request processor instance.
   *
   * @param servlet The ActionServlet we are associated with
   * @param moduleConfig The ModuleConfig we are associated with.
   * @throws ServletException If an error occurs during initialization
   */
  public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws ServletException {
    LOG.info(
        "Initializing composable request processor for module prefix '"
            + moduleConfig.getPrefix()
            + "'");
    super.init(servlet, moduleConfig);

    initCatalogFactory(servlet, moduleConfig);

    ControllerConfig controllerConfig = moduleConfig.getControllerConfig();

    String catalogName = controllerConfig.getCatalog();

    catalog = this.catalogFactory.getCatalog(catalogName);

    if (catalog == null) {
      throw new ServletException("Cannot find catalog '" + catalogName + "'");
    }

    String commandName = controllerConfig.getCommand();

    command = catalog.getCommand(commandName);

    if (command == null) {
      throw new ServletException("Cannot find command '" + commandName + "'");
    }

    this.setActionContextClassName(controllerConfig.getProperty(ACTION_CONTEXT_CLASS));
  }
  protected synchronized RequestProcessor getRequestProcessor(ModuleConfig config)
      throws ServletException {

    if (tileProcessor != null) {
      TilesRequestProcessor processor = (TilesRequestProcessor) super.getRequestProcessor(config);
      return processor;
    }

    // reset the request processor
    String requestProcessorKey = Globals.REQUEST_PROCESSOR_KEY + config.getPrefix();
    getServletContext().removeAttribute(requestProcessorKey);

    // create a new request processor instance
    TilesRequestProcessor processor = (TilesRequestProcessor) super.getRequestProcessor(config);

    tileProcessor = processor;

    try {
      // reload Tiles defs
      DefinitionsFactory factory = processor.getDefinitionsFactory();
      factory.init(factory.getConfig(), getServletContext());
      // System.out.println("reloaded tiles-definitions");
    } catch (DefinitionsFactoryException e) {
      e.printStackTrace();
    }

    return processor;
  }
  /**
   * Get Tiles RequestProcessor associated to the current module.
   *
   * @param request Current request.
   * @param servletContext Current servlet context.
   * @return The {@link TilesRequestProcessor} for the current request.
   */
  protected TilesRequestProcessor getRequestProcessor(
      HttpServletRequest request, ServletContext servletContext) {

    ModuleConfig moduleConfig = getModuleConfig(request, servletContext);

    return (TilesRequestProcessor)
        servletContext.getAttribute(Globals.REQUEST_PROCESSOR_KEY + moduleConfig.getPrefix());
  }
  public Object invoke(MethodInvocation invocation) throws Throwable {
    ActionConfig[] result = (ActionConfig[]) invocation.proceed();

    ModuleConfig config = (ModuleConfig) invocation.getThis();
    ModuleConfig reloadConfig = this.moduleConfigLoader.load(config.getPrefix());
    ActionConfig[] actionConfigs = reloadConfig.findActionConfigs();

    List mergeActionConfigs = new ArrayList();
    if (result != null) {
      mergeActionConfigs.addAll(Arrays.asList(result));
    }
    if (actionConfigs != null) {
      mergeActionConfigs.addAll(Arrays.asList(actionConfigs));
    }

    return mergeActionConfigs.toArray(new ActionConfig[mergeActionConfigs.size()]);
  }
Esempio n. 6
0
  /* (non-Javadoc)
   * @see org.apache.struts.action.PlugIn#init(org.apache.struts.action.ActionServlet, org.apache.struts.config.ModuleConfig)
   */
  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

    String absoltuePath = (servlet.getServletContext()).getRealPath("/");
    String prefix = config.getPrefix();
    String path = absoltuePath + prefix + confPath;

    InputStream is = null;
    try {
      is = new FileInputStream(path);
    } catch (FileNotFoundException e) {
      throw new ServletException("Cannot found or open the file : " + path);
    }

    //	Import preference data
    try {
      Preferences.importPreferences(is);
    } catch (InvalidPreferencesFormatException e) {
      System.err.println("InvalidPreferencesFormatException in PlugIn PrefsPlugin : " + e);
    } catch (IOException e) {
      System.err.println("IOException in PlugIn PrefsPlugin : " + e);
    }
  }
Esempio n. 7
0
  /**
   * Retrieve <code>MessageResources</code> for the module and bundle.
   *
   * @param application the servlet context
   * @param request the servlet request
   * @param bundle the bundle key
   */
  public static MessageResources getMessageResources(
      ServletContext application, HttpServletRequest request, String bundle) {

    if (bundle == null) {
      bundle = Globals.MESSAGES_KEY;
    }

    MessageResources resources = (MessageResources) request.getAttribute(bundle);

    if (resources == null) {
      ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request, application);
      resources = (MessageResources) application.getAttribute(bundle + moduleConfig.getPrefix());
    }

    if (resources == null) {
      resources = (MessageResources) application.getAttribute(bundle);
    }

    if (resources == null) {
      throw new NullPointerException("No message resources found for bundle: " + bundle);
    }

    return resources;
  }
  @Override
  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

    if (!initialized) {
      loadActionsFromFile(actionClasses);
      PartialTileDefinition.init();
      initialized = true;
    }

    final String modulePrefix = StringUtils.removeStart(config.getPrefix(), "/");

    for (Class<?> actionClass : actionClasses) {
      Mapping mapping = actionClass.getAnnotation(Mapping.class);
      if (mapping == null || !modulePrefix.equals(mapping.module())) {
        continue;
      }

      final ActionMapping actionMapping = createCustomActionMapping(mapping);
      if (actionMapping == null) {
        continue;
      }

      actionMapping.setPath(mapping.path());
      actionMapping.setType(actionClass.getName());
      actionMapping.setScope(mapping.scope());
      actionMapping.setParameter(mapping.parameter());
      actionMapping.setValidate(mapping.validate());

      if (mapping.formBeanClass() != ActionForm.class) {
        final String formName = mapping.formBeanClass().getName();
        createFormBeanConfigIfNecessary(config, mapping, formName);
        actionMapping.setName(formName);
      } else if (!mapping.formBean().isEmpty()) {
        actionMapping.setName(mapping.formBean());
      }

      if (mapping.input().isEmpty()) {
        actionMapping.setInput(findInputMethod(actionClass, mapping));
      } else {
        registerInput(actionMapping, mapping.input());
      }

      String defaultResourcesName = getDefaultResourcesName(config);
      Forwards forwards = actionClass.getAnnotation(Forwards.class);
      if (forwards != null) {
        for (final Forward forward : forwards.value()) {
          registerForward(actionMapping, forward, forwards, mapping, defaultResourcesName);
        }
      }
      registerSuperclassForwards(
          actionMapping, actionClass.getSuperclass(), mapping, defaultResourcesName);

      Exceptions exceptions = actionClass.getAnnotation(Exceptions.class);
      if (exceptions != null) {
        registerExceptionHandling(actionMapping, exceptions);
      }

      initializeActionMappingProperties(actionMapping, mapping.customMappingProperties());

      config.addActionConfig(actionMapping);
    }
  }
Esempio n. 9
0
  /**
   * Makes HttpSession and GrouperSession available to subclasses Also handles pageSize parameter
   * and times how long is spent in an action
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    GrouperSession grouperSession =
        (GrouperSession)
            request.getSession().getAttribute("edu.intenet2.middleware.grouper.ui.GrouperSession");
    // if(grouperSession == null && !"/populateIndex.do".equals(request.getServletPath())) return
    // mapping.findForward("Index");

    ModuleConfig modConfig = (ModuleConfig) request.getAttribute("org.apache.struts.action.MODULE");
    String modulePrefix = modConfig.getPrefix();
    if (modulePrefix == null) modulePrefix = "";
    request.setAttribute("modulePrefix", modulePrefix);
    HttpSession session = request.getSession();
    String pageSize = request.getParameter("pageSize");
    if (pageSize != null && pageSize.length() > 0) {
      session.setAttribute("default.pagesize", pageSize);
    }

    DynaActionForm dummyForm = (DynaActionForm) form;
    if (dummyForm != null) {
      try {
        dummyForm.set("pageSize", "" + getPageSize(session));
      } catch (Exception e) {
        // Ok so form doesn't care about pageSize
        // let's just ignore it
      }
    }
    isWheelGroupMember(session);
    String wheelGroupAction = request.getParameter("wheelGroupAction");
    if (!isEmpty(wheelGroupAction)) doWheelGroupStuff(wheelGroupAction, session);
    UIThreadLocal.replace(
        "isActiveWheelGroupMember", new Boolean(isActiveWheelGroupMember(session)));

    if (grouperSession != null) {
      if (isWheelGroupMember(session)) {
        grouperSession.setConsiderIfWheelMember(isActiveWheelGroupMember(session));
      } else {
        // we'll set this back to the default
        grouperSession.setConsiderIfWheelMember(true);
      }
    }

    if (form != null) request.setAttribute("grouperForm", form);
    Object sessionMessage = session.getAttribute("sessionMessage");
    if (isEmpty(request.getAttribute("message")) && !isEmpty(sessionMessage)) {
      request.setAttribute("message", sessionMessage);
      session.removeAttribute("sessionMessage");
    }
    request.setAttribute("linkBrowseMode", getLinkBrowseMode(session));
    Date before = new Date();
    ActionForward forward = null;
    try {
      if (isEmpty(wheelGroupAction)) {

        forward =
            grouperTransactionExecute(mapping, form, request, response, session, grouperSession);

      } else
        forward =
            new ActionForward(
                GrouperUiFilter.retrieveSessionMediaResourceBundle().getString("admin.browse.path"),
                true);
    } catch (GrouperDAOException e) {
      Throwable cause = e.getCause();

      Throwable causeCause = cause == null ? null : cause.getCause();

      Throwable causeCauseCause = causeCause == null ? null : causeCause.getCause();

      HookVeto hookVeto = (cause instanceof HookVeto) ? (HookVeto) cause : null;

      hookVeto =
          ((hookVeto == null) && (causeCause instanceof HookVeto))
              ? (HookVeto) causeCause
              : hookVeto;

      hookVeto =
          ((hookVeto == null) && (causeCauseCause instanceof HookVeto))
              ? (HookVeto) causeCauseCause
              : hookVeto;

      if (hookVeto != null) {
        Message.addVetoMessageToScreen(request, hookVeto);
      } else if (!(cause instanceof UnrecoverableErrorException)) {
        LOG.error(NavExceptionHelper.toLog(cause));
        cause = new UnrecoverableErrorException(cause);
      }
      if (cause instanceof UnrecoverableErrorException) {
        NavExceptionHelper neh = getExceptionHelper(session);
        String msg = neh.getMessage((UnrecoverableErrorException) cause);
        request.setAttribute("seriousError", msg);
      }
      forward = mapping.findForward("ErrorPage");
    }
    Date after = new Date();
    long diff = after.getTime() - before.getTime();
    String url = request.getServletPath();
    Long ms = (Long) request.getAttribute("timingsMS");
    long mss = 0;
    if (ms != null) mss = ms.longValue();
    if (diff > 25) {
      request.setAttribute("timingsClass", this.getClass().getName());
      request.setAttribute("timingsMS", new Long(diff + mss));
    }
    if (forward != null && forward.getRedirect() && !isEmpty(request.getAttribute("message"))) {
      try {
        session.setAttribute("sessionMessage", request.getAttribute("message"));
      } catch (IllegalStateException e) {
      }
    }

    if (Boolean.TRUE.equals(request.getAttribute("loggedOut"))) {
      return forward;
    }
    try {
      GrouperHelper.fixSessionFields((Map) session.getAttribute("fieldList"));
    } catch (SchemaException e) {
      LOG.error(e);
    }
    String advSearch = request.getParameter("advancedSearch");
    try {
      session.getAttribute("");
    } catch (Exception e) {
      return forward;
    }
    if (!isEmpty(advSearch)) {
      setAdvancedSearchMode("true".equals(advSearch), session);
    }
    request.setAttribute("isAdvancedSearch", getAdvancedSearchMode(session));
    return forward;
  }
  /**
   * Get definition factory for the module attached to specified moduleConfig.
   *
   * @param servletContext Current servlet context.
   * @param moduleConfig Module config of the module for which the factory is requested.
   * @return Definitions factory or null if not found.
   */
  public DefinitionsFactory getDefinitionsFactory(
      ServletContext servletContext, ModuleConfig moduleConfig) {

    return (DefinitionsFactory)
        servletContext.getAttribute(DEFINITIONS_FACTORY + moduleConfig.getPrefix());
  }