Search in sources :

Example 41 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.

the class TestAuthorizeAction method testAuthorizeOneOfManyRoles.

public void testAuthorizeOneOfManyRoles() throws Exception {
    ActionConfig config = new ActionConfig();
    config.setPath("/testAuthorizeOneOfManyRoles");
    config.setRoles("administrator,roustabout,memory");
    this.saContext.setActionConfig(config);
    boolean result = command.execute(saContext);
    assertFalse(result);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 42 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class SelectInclude method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Select and cache the include uri for this <code>ActionConfig</code>
     * if specified.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> so that processing continues
     * @throws Exception on any error
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Acquire configuration objects that we need
    ActionConfig actionConfig = actionCtx.getActionConfig();
    // Cache an include uri if found
    String include = actionConfig.getInclude();
    if (include != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Including " + include);
        }
        actionCtx.setInclude(include);
    }
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 43 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class CopyFormToContext method findOrCreateForm.

/**
     * <p>Based on the properties of this command and the given
     * <code>ActionContext</code>, find or create an ActionForm instance for
     * preparation.</p>
     *
     * @param context ActionContextBase class that we are processing
     * @return ActionForm instance
     * @throws IllegalArgumentException On ActionConfig not found
     * @throws IllegalStateException    On undefined scope and formbean
     * @throws IllegalAccessException   On failed instantiation
     * @throws InstantiationException   If ActionContext is not subsclass of
     *                                  ActionContextBase
     */
protected ActionForm findOrCreateForm(ActionContext context) throws IllegalAccessException, InstantiationException {
    String effectiveFormName;
    String effectiveScope;
    if (!(isEmpty(this.getActionPath()))) {
        ActionConfig actionConfig = context.getModuleConfig().findActionConfig(this.getActionPath());
        if (actionConfig == null) {
            throw new IllegalArgumentException("No ActionConfig found for path " + this.getActionPath());
        }
        effectiveFormName = actionConfig.getName();
        effectiveScope = actionConfig.getScope();
    } else {
        effectiveFormName = this.getFormName();
        effectiveScope = this.getScope();
    }
    if (isEmpty(effectiveScope) || isEmpty(effectiveFormName)) {
        throw new IllegalStateException("Both scope [" + effectiveScope + "] and formName [" + effectiveFormName + "] must be defined.");
    }
    return findOrCreateForm(context, effectiveFormName, effectiveScope);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 44 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class AbstractSelectInput method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Select and cache a <code>ForwardConfig</code> for the input page for
     * the current request.</p>
     *
     * @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 {
    // Skip processing if the current request is valid
    Boolean valid = actionCtx.getFormValid();
    if ((valid != null) && valid.booleanValue()) {
        return (false);
    }
    // Acquire configuration objects that we need
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ModuleConfig moduleConfig = actionConfig.getModuleConfig();
    // Cache an ForwardConfig back to our input page
    ForwardConfig forwardConfig;
    String input = actionConfig.getInput();
    if (moduleConfig.getControllerConfig().getInputForward()) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Finding ForwardConfig for '" + input + "'");
        }
        forwardConfig = actionConfig.findForwardConfig(input);
        if (forwardConfig == null) {
            forwardConfig = moduleConfig.findForwardConfig(input);
        }
    } else {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Delegating to forward() for '" + input + "'");
        }
        forwardConfig = forward(actionCtx, moduleConfig, input);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Forwarding back to " + forwardConfig);
    }
    actionCtx.setForwardConfig(forwardConfig);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ModuleConfig(org.apache.struts.config.ModuleConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 45 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class AbstractExceptionHandler method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Invoke the appropriate <code>Action</code> for this request, and
     * cache the returned <code>ActionForward</code>.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> if a <code>ForwardConfig</code> is returned,
     *         else <code>true</code> to complete processing
     * @throws Exception if thrown by the Action class and not declared by an
     *                   Exception Handler
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Look up the exception that was thrown
    Exception exception = actionCtx.getException();
    if (exception == null) {
        LOG.warn("No Exception found in ActionContext");
        return (true);
    }
    // Look up the local or global exception handler configuration
    ExceptionConfig exceptionConfig = null;
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ModuleConfig moduleConfig = actionCtx.getModuleConfig();
    if (actionConfig != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("See if actionConfig " + actionConfig + " has an exceptionConfig for " + exception.getClass().getName());
        }
        exceptionConfig = actionConfig.findException(exception.getClass());
    } else if (moduleConfig != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No action yet, see if moduleConfig " + moduleConfig + " has an exceptionConfig " + exception.getClass().getName());
        }
        exceptionConfig = moduleConfig.findException(exception.getClass());
    }
    // Handle the exception in the configured manner
    if (exceptionConfig == null) {
        LOG.warn("Unhandled exception", exception);
        throw exception;
    }
    ForwardConfig forwardConfig = handle(actionCtx, exception, exceptionConfig, actionConfig, moduleConfig);
    if (forwardConfig != null) {
        actionCtx.setForwardConfig(forwardConfig);
        return (false);
    } else {
        return (true);
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) ModuleConfig(org.apache.struts.config.ModuleConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Aggregations

ActionConfig (org.apache.struts.config.ActionConfig)76 ForwardConfig (org.apache.struts.config.ForwardConfig)14 UnavailableException (javax.servlet.UnavailableException)8 ActionForm (org.apache.struts.action.ActionForm)8 ExceptionConfig (org.apache.struts.config.ExceptionConfig)8 FormBeanConfig (org.apache.struts.config.FormBeanConfig)8 ModuleConfig (org.apache.struts.config.ModuleConfig)8 ServletException (javax.servlet.ServletException)6 MalformedURLException (java.net.MalformedURLException)4 Map (java.util.Map)4 Action (org.apache.struts.action.Action)4 UnauthorizedActionException (org.apache.struts.chain.commands.UnauthorizedActionException)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 MissingResourceException (java.util.MissingResourceException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JspException (javax.servlet.jsp.JspException)2 ActionErrors (org.apache.struts.action.ActionErrors)2 MockActionContext (org.apache.struts.chain.contexts.MockActionContext)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2