Search in sources :

Example 16 with ForwardConfig

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

the class TestRequestUtils method testForwardURL1.

// ----------------------------------------------------------- forwardURL()
// Default module (default forwardPattern)
public void testForwardURL1() {
    request.setAttribute(Globals.MODULE_KEY, moduleConfig);
    request.setPathElements("/myapp", "/action.do", null, null);
    ForwardConfig forward = null;
    String result = null;
    // redirect=false, module=null
    forward = moduleConfig.findForwardConfig("moduleForward");
    assertNotNull("moduleForward found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("moduleForward computed", result);
    assertEquals("moduleForward value", "/module/forward", result);
    // redirect=true, module=null
    forward = moduleConfig.findForwardConfig("moduleRedirect");
    assertNotNull("moduleRedirect found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("moduleRedirect computed", result);
    assertEquals("moduleRedirect value", "/module/redirect", result);
    // redirect=false, module=/context
    forward = moduleConfig.findForwardConfig("contextForward");
    assertNotNull("contextForward found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("contextForward computed", result);
    assertEquals("contextForward value", "/context/forward", result);
    // redirect=true, module=/context
    forward = moduleConfig.findForwardConfig("contextRedirect");
    assertNotNull("contextRedirect found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("contextRedirect computed", result);
    assertEquals("contextRedirct value", "/context/redirect", result);
    // noslash, module=null
    forward = moduleConfig.findForwardConfig("moduleNoslash");
    assertNotNull("moduleNoslash found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("moduleNoslash computed", result);
    assertEquals("moduleNoslash value", "/module/noslash", result);
    // noslash, module=/
    forward = moduleConfig.findForwardConfig("contextNoslash");
    assertNotNull("contextNoslash found", forward);
    result = RequestUtils.forwardURL(request, forward, null);
    assertNotNull("contextNoslash computed", result);
    assertEquals("contextNoslash value", "/context/noslash", result);
}
Also used : ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 17 with ForwardConfig

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

the class TestRequestUtils method testForwardURLa.

// Cross module forwards
public void testForwardURLa() {
    request.setAttribute(Globals.MODULE_KEY, moduleConfig);
    request.setPathElements("/myapp", "/action.do", null, null);
    ForwardConfig forward = null;
    String result = null;
    // redirect=false, contextRelative=false, link to module 3
    forward = moduleConfig3.findForwardConfig("moduleForward");
    assertNotNull("moduleForward found", forward);
    result = RequestUtils.forwardURL(request, forward, moduleConfig3);
    assertNotNull("moduleForward computed", result);
    assertEquals("moduleForward value", "/forwarding/3/module/forward", result);
    // redirect=true, contextRelative=false, link to module 3
    forward = moduleConfig3.findForwardConfig("moduleRedirect");
    assertNotNull("moduleRedirect found", forward);
    result = RequestUtils.forwardURL(request, forward, moduleConfig3);
    assertNotNull("moduleRedirect computed", result);
    assertEquals("moduleRedirect value", "/forwarding/3/module/redirect", result);
    // redirect=false, module=/context
    forward = moduleConfig3.findForwardConfig("contextForward");
    assertNotNull("contextForward found", forward);
    result = RequestUtils.forwardURL(request, forward, moduleConfig3);
    assertNotNull("contextForward computed", result);
    assertEquals("contextForward value", "/forwarding/context/forward", result);
    // redirect=true, module=/context
    forward = moduleConfig3.findForwardConfig("contextRedirect");
    assertNotNull("contextRedirect found", forward);
    result = RequestUtils.forwardURL(request, forward, moduleConfig3);
    assertNotNull("contextRedirect computed", result);
    assertEquals("contextRedirct value", "/forwarding/context/redirect", result);
    // noslash, contextRelative=false, link to module 3
    forward = moduleConfig3.findForwardConfig("moduleNoslash");
    assertNotNull("moduleNoslash found", forward);
    result = RequestUtils.forwardURL(request, forward, moduleConfig3);
    assertNotNull("moduleNoslash computed", result);
    assertEquals("moduleNoslash value", "/forwarding/3/module/noslash", result);
    // noslash, module=/
    forward = moduleConfig3.findForwardConfig("contextNoslash");
    assertNotNull("contextNoslash found", forward);
    result = RequestUtils.forwardURL(request, forward, moduleConfig3);
    assertNotNull("contextNoslash computed", result);
    assertEquals("contextNoslash value", "/forwarding/context/noslash", result);
}
Also used : ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 18 with ForwardConfig

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

the class TestMockBase method setUpThirdApp.

// Set up third app for testing URL mapping
protected void setUpThirdApp() {
    ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
    moduleConfig3 = factoryObject.createModuleConfig("/3");
    context.setAttribute(Globals.MODULE_KEY + "/3", moduleConfig3);
    // Instantiate the controller configuration for this app
    ControllerConfig controller = new ControllerConfig();
    moduleConfig3.setControllerConfig(controller);
    // Configure the properties we will be testing
    controller.setForwardPattern("/forwarding$M$P");
    controller.setInputForward(true);
    controller.setPagePattern("/paging$M$P");
    // Configure global forward declarations
    moduleConfig3.addForwardConfig(new ForwardConfig("moduleForward", "/module/forward", // No redirect, same module
    false));
    moduleConfig3.addForwardConfig(new ForwardConfig("moduleRedirect", "/module/redirect", // Redirect, same module
    true));
    moduleConfig3.addForwardConfig(new ForwardConfig("contextForward", // No redirect
    "/forward", // No redirect
    false, // Specify module
    "/context"));
    moduleConfig3.addForwardConfig(new ForwardConfig("contextRedirect", // Redirect
    "/redirect", // Redirect
    true, // Specify module
    "/context"));
    moduleConfig3.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", // No redirect, same module
    false));
    moduleConfig3.addForwardConfig(new ForwardConfig("contextNoslash", // No redirect
    "noslash", // No redirect
    false, // specify module
    "/context"));
}
Also used : ModuleConfigFactory(org.apache.struts.config.ModuleConfigFactory) ControllerConfig(org.apache.struts.config.ControllerConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 19 with ForwardConfig

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

the class ActionServlet method initModuleForwards.

/**
 * <p>Initialize the forwards for the specified module.</p>
 *
 * @param config ModuleConfig information for this module
 * @throws ServletException if initialization cannot be performed
 */
protected void initModuleForwards(ModuleConfig config) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Initializing module path '" + config.getPrefix() + "' forwards");
    }
    // Process forwards extensions.
    ForwardConfig[] forwards = config.findForwardConfigs();
    for (int i = 0; i < forwards.length; i++) {
        ForwardConfig forward = forwards[i];
        processForwardExtension(forward, config, null);
    }
    for (int i = 0; i < forwards.length; i++) {
        ForwardConfig forward = forwards[i];
        // Verify that required fields are all present for the forward
        if (forward.getPath() == null) {
            handleValueRequiredException("path", forward.getName(), "global forward");
        }
    }
}
Also used : ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 20 with ForwardConfig

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

the class ActionServlet method processActionConfigExtension.

/**
 * <p>Extend the action's configuration as necessary.</p>
 *
 * @param actionConfig the configuration to process.
 * @param moduleConfig the module configuration for this module.
 * @throws ServletException if initialization cannot be performed.
 */
protected void processActionConfigExtension(ActionConfig actionConfig, ModuleConfig moduleConfig) throws ServletException {
    try {
        if (!actionConfig.isExtensionProcessed()) {
            if (log.isDebugEnabled()) {
                log.debug("Processing extensions for '" + actionConfig.getPath() + "'");
            }
            actionConfig = processActionConfigClass(actionConfig, moduleConfig);
            actionConfig.processExtends(moduleConfig);
        }
        // Process forwards extensions.
        ForwardConfig[] forwards = actionConfig.findForwardConfigs();
        for (int i = 0; i < forwards.length; i++) {
            ForwardConfig forward = forwards[i];
            processForwardExtension(forward, moduleConfig, actionConfig);
        }
        // Process exception extensions.
        ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
        for (int i = 0; i < exceptions.length; i++) {
            ExceptionConfig exception = exceptions[i];
            processExceptionExtension(exception, moduleConfig, actionConfig);
        }
    } catch (ServletException e) {
        throw e;
    } catch (Exception e) {
        handleGeneralExtensionException("Action", actionConfig.getPath(), e);
    }
}
Also used : ServletException(javax.servlet.ServletException) ExceptionConfig(org.apache.struts.config.ExceptionConfig) ForwardConfig(org.apache.struts.config.ForwardConfig) ServletException(javax.servlet.ServletException) MissingResourceException(java.util.MissingResourceException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Aggregations

ForwardConfig (org.apache.struts.config.ForwardConfig)63 ActionConfig (org.apache.struts.config.ActionConfig)14 UnavailableException (javax.servlet.UnavailableException)12 ServletException (javax.servlet.ServletException)10 ExceptionConfig (org.apache.struts.config.ExceptionConfig)10 MalformedURLException (java.net.MalformedURLException)8 ModuleConfig (org.apache.struts.config.ModuleConfig)8 IOException (java.io.IOException)6 MissingResourceException (java.util.MissingResourceException)6 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)6 SAXException (org.xml.sax.SAXException)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ActionFormBean (org.apache.struts.action.ActionFormBean)4 ActionForward (org.apache.struts.action.ActionForward)4 ActionMapping (org.apache.struts.action.ActionMapping)4 ActionServlet (org.apache.struts.action.ActionServlet)4 FormPropertyConfig (org.apache.struts.config.FormPropertyConfig)4 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)3 ArrayList (java.util.ArrayList)2