Search in sources :

Example 36 with ActionConfig

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

the class AbstractPopulateActionForm method execute.

// ---------------------------------------------------------- Public Methods
/**
 * <p>Populate the form bean (if any) for this request.</p>
 *
 * @param actionCtx The <code>Context</code> for the current request
 * @return <code>false</code> so that processing continues
 * @throws Exception On an unexpected error
 */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Is there a form bean for this request?
    ActionForm actionForm = actionCtx.getActionForm();
    if (actionForm == null) {
        return (false);
    }
    // Reset the form bean property values
    ActionConfig actionConfig = actionCtx.getActionConfig();
    reset(actionCtx, actionConfig, actionForm);
    populate(actionCtx, actionConfig, actionForm);
    handleCancel(actionCtx, actionConfig, actionForm);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ActionForm(org.apache.struts.action.ActionForm)

Example 37 with ActionConfig

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

the class TestActionServlet method testProcessActionConfigClassOverriddenSubConfigClass.

/**
 * Test the case where the subconfig has already specified its own config
 * class.  If the code still attempts to create a new instance, an error
 * will be thrown.
 */
public void testProcessActionConfigClassOverriddenSubConfigClass() throws Exception {
    moduleConfig.addActionConfig(baseAction);
    ActionConfig customSub = new CustomActionConfigArg("/sub");
    customSub.setExtends("/index");
    moduleConfig.addActionConfig(customSub);
    try {
        actionServlet.processActionConfigClass(customSub, moduleConfig);
    } catch (Exception e) {
        fail("Exception should not be thrown");
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 38 with ActionConfig

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

the class TestActionServlet method testProcessActionConfigClass.

/**
 * Make sure processActionConfigClass() returns an instance of the correct
 * class if the base config is using a custom class.
 */
public void testProcessActionConfigClass() throws Exception {
    CustomActionConfig customBase = new CustomActionConfig("/base");
    moduleConfig.addActionConfig(customBase);
    ActionMapping customSub = new ActionMapping();
    customSub.setPath("/sub");
    customSub.setExtends("/base");
    moduleConfig.addActionConfig(customSub);
    ActionConfig result = actionServlet.processActionConfigClass(customSub, moduleConfig);
    assertTrue("Incorrect class of action config", result instanceof CustomActionConfig);
    assertEquals("Incorrect path", customSub.getPath(), result.getPath());
    assertEquals("Incorrect extends", customSub.getExtends(), result.getExtends());
    assertSame("Result was not registered in the module config", result, moduleConfig.findActionConfig("/sub"));
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 39 with ActionConfig

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

the class TestActionServlet method notestProcessActionConfigClassError.

/**
 * Make sure the code throws the correct exception when it can't create an
 * instance of the base config's custom class.
 */
public void notestProcessActionConfigClassError() throws Exception {
    ActionConfig customBase = new CustomActionConfigArg("/index");
    moduleConfig.addActionConfig(customBase);
    ActionConfig customSub = new ActionMapping();
    customSub.setPath("/sub");
    customSub.setExtends("/index");
    moduleConfig.addActionConfig(customSub);
    try {
        actionServlet.processActionConfigClass(customSub, moduleConfig);
        fail("Exception should be thrown");
    } catch (UnavailableException e) {
    // success
    } catch (Exception e) {
        fail("Unexpected exception thrown.");
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 40 with ActionConfig

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

the class TestAuthorizeAction method testNotAuthorizedOneRole.

public void testNotAuthorizedOneRole() throws Exception {
    ActionConfig config = new ActionConfig();
    config.setPath("/testNotAuthorizedOneRole");
    config.setRoles("roustabout");
    this.saContext.setActionConfig(config);
    try {
        boolean result = command.execute(saContext);
    } catch (UnauthorizedActionException ex) {
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) UnauthorizedActionException(org.apache.struts.chain.commands.UnauthorizedActionException)

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