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);
}
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);
}
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"));
}
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");
}
}
}
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);
}
}
Aggregations