Search in sources :

Example 56 with ActionConfig

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

the class RequestUtils method actionIdURL.

/**
     * <p>Returns the true path of the destination action if the specified forward
     * is an action-aliased URL. This method version forms the URL based on
     * the specified module.
     *
     * @param originalPath the action-aliased path
     * @param moduleConfig the module config for this request
     * @param servlet the servlet handling the current request
     * @return the context-relative URL of the action if the path has an action identifier; otherwise <code>null</code>.
     * @since Struts 1.3.6
     */
public static String actionIdURL(String originalPath, ModuleConfig moduleConfig, ActionServlet servlet) {
    if (originalPath.startsWith("http") || originalPath.startsWith("/")) {
        return null;
    }
    // Split the forward path into the resource and query string;
    // it is possible a forward (or redirect) has added parameters.
    String actionId = null;
    String qs = null;
    int qpos = originalPath.indexOf("?");
    if (qpos == -1) {
        actionId = originalPath;
    } else {
        actionId = originalPath.substring(0, qpos);
        qs = originalPath.substring(qpos);
    }
    // Find the action of the given actionId
    ActionConfig actionConfig = moduleConfig.findActionConfigId(actionId);
    if (actionConfig == null) {
        if (log.isDebugEnabled()) {
            log.debug("No actionId found for " + actionId);
        }
        return null;
    }
    String path = actionConfig.getPath();
    String mapping = RequestUtils.getServletMapping(servlet);
    StringBuffer actionIdPath = new StringBuffer();
    // Form the path based on the servlet mapping pattern
    if (mapping.startsWith("*")) {
        actionIdPath.append(path);
        actionIdPath.append(mapping.substring(1));
    } else if (mapping.startsWith("/")) {
        // implied ends with a *
        mapping = mapping.substring(0, mapping.length() - 1);
        if (mapping.endsWith("/") && path.startsWith("/")) {
            actionIdPath.append(mapping);
            actionIdPath.append(path.substring(1));
        } else {
            actionIdPath.append(mapping);
            actionIdPath.append(path);
        }
    } else {
        log.warn("Unknown servlet mapping pattern");
        actionIdPath.append(path);
    }
    // Lastly add any query parameters (the ? is part of the query string)
    if (qs != null) {
        actionIdPath.append(qs);
    }
    // Return the path
    if (log.isDebugEnabled()) {
        log.debug(originalPath + " unaliased to " + actionIdPath.toString());
    }
    return actionIdPath.toString();
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 57 with ActionConfig

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

the class TestActionServlet method testProcessActionConfigClassNoExtends.

/**
 * Make sure processActionConfigClass() returns what it was given if the
 * action passed to it doesn't extend anything.
 */
public void testProcessActionConfigClassNoExtends() throws Exception {
    moduleConfig.addActionConfig(baseAction);
    ActionConfig result = null;
    try {
        result = actionServlet.processActionConfigClass(baseAction, moduleConfig);
    } catch (UnavailableException e) {
        fail("An exception should not be thrown here");
    }
    assertSame("Result should be the same as the input.", baseAction, result);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) UnavailableException(javax.servlet.UnavailableException)

Example 58 with ActionConfig

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

the class TestActionServlet method testProcessActionConfigClassSubConfigCustomClass.

/**
 * Make sure processActionConfigClass() returns the same class instance if
 * the base config isn't using a custom class.
 */
public void testProcessActionConfigClassSubConfigCustomClass() throws Exception {
    moduleConfig.addActionConfig(baseAction);
    ActionConfig customSub = new ActionMapping();
    customSub.setPath("/sub");
    customSub.setExtends("/index");
    moduleConfig.addActionConfig(customSub);
    ActionConfig result = actionServlet.processActionConfigClass(customSub, moduleConfig);
    assertSame("The instance returned should be the param given it.", customSub, result);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 59 with ActionConfig

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

the class TestCopyFormToContext method setUp.

/*
     * @see TestCase#setUp()
     */
protected void setUp() throws Exception {
    context = new MockActionContext();
    ModuleConfigImpl moduleConfig = new ModuleConfigImpl("/");
    context.setModuleConfig(moduleConfig);
    FormBeanConfig fooFBC = new FormBeanConfig();
    fooFBC.setName("foo");
    fooFBC.setType("org.apache.struts.mock.MockFormBean");
    moduleConfig.addFormBeanConfig(fooFBC);
    FormBeanConfig barFBC = new FormBeanConfig();
    barFBC.setName("bar");
    // use a different type so we can verify lookups better
    barFBC.setType("org.apache.struts.action.DynaActionForm");
    FormPropertyConfig fpc = new FormPropertyConfig();
    fpc.setName("property");
    fpc.setType("java.lang.String");
    fpc.setInitial("test");
    barFBC.addFormPropertyConfig(fpc);
    moduleConfig.addFormBeanConfig(barFBC);
    ActionConfig testActionConfig = new ActionConfig();
    testActionConfig.setPath("/Test");
    testActionConfig.setName("foo");
    testActionConfig.setScope("request");
    moduleConfig.addActionConfig(testActionConfig);
    // otherwise, ActionConfigMatcher will be null and we'll get an NPE...
    moduleConfig.freeze();
}
Also used : FormPropertyConfig(org.apache.struts.config.FormPropertyConfig) ActionConfig(org.apache.struts.config.ActionConfig) FormBeanConfig(org.apache.struts.config.FormBeanConfig) MockActionContext(org.apache.struts.chain.contexts.MockActionContext) ModuleConfigImpl(org.apache.struts.config.impl.ModuleConfigImpl)

Example 60 with ActionConfig

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

the class TestAuthorizeAction method testAuthorizeNoRoles.

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

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