/**
   * 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));
  }
Exemplo n.º 2
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;
  }
  /**
   * 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());
  }
 private void createFormBeanConfigIfNecessary(
     ModuleConfig config, Mapping mapping, final String formName) {
   FormBeanConfig formBeanConfig = config.findFormBeanConfig(formName);
   if (formBeanConfig == null) {
     formBeanConfig = new FormBeanConfig();
     formBeanConfig.setType(mapping.formBeanClass().getName());
     formBeanConfig.setName(formName);
     config.addFormBeanConfig(formBeanConfig);
   }
 }
Exemplo n.º 5
0
  /**
   * Check to see if the controller is configured to prevent caching, and if so, request no cache
   * flags to be set.
   *
   * @param actionCtx The <code>Context</code> for the current request
   * @return <code>false</code> so that processing continues
   * @throws Exception if thrown by the Action class
   */
  public boolean execute(ActionContext actionCtx) throws Exception {
    // Retrieve the ModuleConfig instance
    ModuleConfig moduleConfig = actionCtx.getModuleConfig();

    // If the module is configured for no caching, request no caching
    if (moduleConfig.getControllerConfig().getNocache()) {
      requestNoCache(actionCtx);
    }

    return CONTINUE_PROCESSING;
  }
  /**
   * Check to see if the content type is set, and if so, set it for this response.
   *
   * @param actionCtx The <code>Context</code> for the current request
   * @return <code>false</code> so that processing continues
   * @throws Exception if thrown by the Action class
   */
  public boolean execute(ActionContext actionCtx) throws Exception {
    // Retrieve the ModuleConfig instance
    ModuleConfig moduleConfig = actionCtx.getModuleConfig();

    // If the content type is configured, set it for the response
    String contentType = moduleConfig.getControllerConfig().getContentType();

    if (contentType != null) {
      setContentType(actionCtx, contentType);
    }

    return (false);
  }
Exemplo n.º 7
0
  /**
   * Unregister all the registered ActionMappings
   *
   * @throws Exception
   */
  protected void unregisterActionMappings() throws Exception {

    if (actions != null) {

      ModuleConfig moduleConfig = activatorUtil.getModuleConfig();
      // We need to unfreeze this module in order to add new action mappings
      activatorUtil.unfreeze(moduleConfig);

      for (ActionConfig actionConfig : actions) {
        moduleConfig.removeActionConfig(actionConfig);
      }
      moduleConfig.freeze();
    }
  }
  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;
  }
  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()]);
  }
Exemplo n.º 10
0
  /**
   * Register a given ActionMapping
   *
   * @param actionMapping
   * @throws Exception
   */
  protected void registerActionMapping(ActionMapping actionMapping) throws Exception {

    if (actions == null) {
      actions = new ArrayList<ActionConfig>();
    }

    String actionClassType = actionMapping.getType();

    // Will inject the action classes inside the dotCMS context
    injectContext(actionClassType);

    ModuleConfig moduleConfig = activatorUtil.getModuleConfig();
    // We need to unfreeze this module in order to add new action mappings
    activatorUtil.unfreeze(moduleConfig);

    // Adding the ActionConfig to the ForwardConfig
    moduleConfig.addActionConfig(actionMapping);
    // moduleConfig.freeze();

    actions.add(actionMapping);
    Logger.info(this, "Added Struts Action Mapping: " + actionClassType);
  }
Exemplo n.º 11
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;
  }
Exemplo n.º 12
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);
    }
  }
Exemplo n.º 13
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;
  }
  /**
   * Create an appropriate form bean in the appropriate scope, if one does not already exist.
   *
   * @param context FacesContext for the current request
   * @exception IllegalArgumentException if no ActionConfig for the specified action attribute can
   *     be located
   * @exception IllegalArgumentException if no FormBeanConfig for the specified form bean can be
   *     located
   * @exception IllegalArgumentException if no ModuleConfig can be located for this application
   *     module
   */
  public void createActionForm(FacesContext context) {

    // Look up the application module configuration information we need
    ModuleConfig moduleConfig = lookupModuleConfig(context);

    // Look up the ActionConfig we are processing
    String action = getAction();
    ActionConfig actionConfig = moduleConfig.findActionConfig(action);
    if (actionConfig == null) {
      throw new IllegalArgumentException("Cannot find action '" + action + "' configuration");
    }

    // Does this ActionConfig specify a form bean?
    String name = actionConfig.getName();
    if (name == null) {
      return;
    }

    // Look up the FormBeanConfig we are processing
    FormBeanConfig fbConfig = moduleConfig.findFormBeanConfig(name);
    if (fbConfig == null) {
      throw new IllegalArgumentException("Cannot find form bean '" + name + "' configuration");
    }

    // Does a usable form bean attribute already exist?
    String attribute = actionConfig.getAttribute();
    String scope = actionConfig.getScope();
    ActionForm instance = null;
    if ("request".equals(scope)) {
      instance = (ActionForm) context.getExternalContext().getRequestMap().get(attribute);
    } else if ("session".equals(scope)) {
      HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
      instance = (ActionForm) context.getExternalContext().getSessionMap().get(attribute);
    }
    if (instance != null) {
      if (fbConfig.getDynamic()) {
        String className = ((DynaBean) instance).getDynaClass().getName();
        if (className.equals(fbConfig.getName())) {
          if (log.isDebugEnabled()) {
            log.debug(
                " Recycling existing DynaActionForm instance " + "of type '" + className + "'");
          }
          return;
        }
      } else {
        try {
          Class configClass = RequestUtils.applicationClass(fbConfig.getType());
          if (configClass.isAssignableFrom(instance.getClass())) {
            if (log.isDebugEnabled()) {
              log.debug(
                  " Recycling existing ActionForm instance "
                      + "of class '"
                      + instance.getClass().getName()
                      + "'");
            }
            return;
          }
        } catch (Throwable t) {
          throw new IllegalArgumentException(
              "Cannot load form bean class '" + fbConfig.getType() + "'");
        }
      }
    }

    // Create a new form bean instance
    if (fbConfig.getDynamic()) {
      try {
        DynaActionFormClass dynaClass = DynaActionFormClass.createDynaActionFormClass(fbConfig);
        instance = (ActionForm) dynaClass.newInstance();
        if (log.isDebugEnabled()) {
          log.debug(
              " Creating new DynaActionForm instance " + "of type '" + fbConfig.getType() + "'");
          log.trace(" --> " + instance);
        }
      } catch (Throwable t) {
        throw new IllegalArgumentException(
            "Cannot create form bean of type '" + fbConfig.getType() + "'");
      }
    } else {
      try {
        instance = (ActionForm) RequestUtils.applicationInstance(fbConfig.getType());
        if (log.isDebugEnabled()) {
          log.debug(" Creating new ActionForm instance " + "of type '" + fbConfig.getType() + "'");
          log.trace(" --> " + instance);
        }
      } catch (Throwable t) {
        throw new IllegalArgumentException(
            "Cannot create form bean of class '" + fbConfig.getType() + "'");
      }
    }

    // Configure and cache the form bean instance in the correct scope
    ActionServlet servlet =
        (ActionServlet)
            context.getExternalContext().getApplicationMap().get(Globals.ACTION_SERVLET_KEY);
    instance.setServlet(servlet);
    if ("request".equals(scope)) {
      context.getExternalContext().getRequestMap().put(attribute, instance);
    } else if ("session".equals(scope)) {
      context.getExternalContext().getSessionMap().put(attribute, instance);
    }
  }
  @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);
    }
  }
 private static String getDefaultResourcesName(ModuleConfig config) {
   MessageResourcesConfig resourcesConfig =
       config.findMessageResourcesConfig(STRUTS_DEFAULT_RESOURCE_MESSAGE);
   return (resourcesConfig == null) ? null : resourcesConfig.getParameter();
 }
  /**
   * 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());
  }