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