use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.
the class ActionServlet method initModuleExceptionConfigs.
/**
* <p>Initialize the exception handlers for the specified module.</p>
*
* @param config ModuleConfig information for this module
* @throws ServletException if initialization cannot be performed
* @since Struts 1.3
*/
protected void initModuleExceptionConfigs(ModuleConfig config) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + config.getPrefix() + "' forwards");
}
// Process exception config extensions.
ExceptionConfig[] exceptions = config.findExceptionConfigs();
for (int i = 0; i < exceptions.length; i++) {
ExceptionConfig exception = exceptions[i];
processExceptionExtension(exception, config, null);
}
for (int i = 0; i < exceptions.length; i++) {
ExceptionConfig exception = exceptions[i];
// Verify that required fields are all present for the config
if (exception.getKey() == null) {
handleValueRequiredException("key", exception.getType(), "global exception config");
}
}
}
use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.
the class ActionServlet method initModuleActions.
/**
* <p>Initialize the action configs for the specified module.</p>
*
* @param config ModuleConfig information for this module
* @throws ServletException if initialization cannot be performed
* @since Struts 1.3
*/
protected void initModuleActions(ModuleConfig config) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + config.getPrefix() + "' action configs");
}
// Process ActionConfig extensions.
ActionConfig[] actionConfigs = config.findActionConfigs();
for (int i = 0; i < actionConfigs.length; i++) {
ActionConfig actionConfig = actionConfigs[i];
processActionConfigExtension(actionConfig, config);
}
for (int i = 0; i < actionConfigs.length; i++) {
ActionConfig actionConfig = actionConfigs[i];
// Verify that required fields are all present for the forward
// configs
ForwardConfig[] forwards = actionConfig.findForwardConfigs();
for (int j = 0; j < forwards.length; j++) {
ForwardConfig forward = forwards[j];
if (forward.getPath() == null) {
handleValueRequiredException("path", forward.getName(), "action forward");
}
}
// ... and the exception configs
ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
for (int j = 0; j < exceptions.length; j++) {
ExceptionConfig exception = exceptions[j];
if (exception.getKey() == null) {
handleValueRequiredException("key", exception.getType(), "action exception config");
}
}
}
}
use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.
the class ActionServlet method processActionConfigClass.
/**
* <p>Checks if the current actionConfig is using the correct class based
* on the class of its ancestor ActionConfig.</p>
*
* @param actionConfig The action config to check.
* @param moduleConfig The config for the current module.
* @return The config object using the correct class as determined by the
* config's ancestor and its own overridden value.
* @throws ServletException if an instance of the action config class
* cannot be created.
*/
protected ActionConfig processActionConfigClass(ActionConfig actionConfig, ModuleConfig moduleConfig) throws ServletException {
String ancestor = actionConfig.getExtends();
if (ancestor == null) {
// Nothing to do, then
return actionConfig;
}
// Make sure that this config is of the right class
ActionConfig baseConfig = moduleConfig.findActionConfig(ancestor);
if (baseConfig == null) {
throw new UnavailableException("Unable to find " + "action config for '" + ancestor + "' to extend.");
}
// Was our actionConfig's class overridden already?
if (actionConfig.getClass().equals(ActionMapping.class)) {
// Ensure that our config is using the correct class
if (!baseConfig.getClass().equals(actionConfig.getClass())) {
// Replace the config with an instance of the correct class
ActionConfig newActionConfig = null;
String baseConfigClassName = baseConfig.getClass().getName();
try {
newActionConfig = (ActionConfig) RequestUtils.applicationInstance(baseConfigClassName);
// copy the values
BeanUtils.copyProperties(newActionConfig, actionConfig);
// copy the forward and exception configs, too
ForwardConfig[] forwards = actionConfig.findForwardConfigs();
for (int i = 0; i < forwards.length; i++) {
newActionConfig.addForwardConfig(forwards[i]);
}
ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
for (int i = 0; i < exceptions.length; i++) {
newActionConfig.addExceptionConfig(exceptions[i]);
}
} catch (Exception e) {
handleCreationException(baseConfigClassName, e);
}
// replace actionConfig with newActionConfig
moduleConfig.removeActionConfig(actionConfig);
moduleConfig.addActionConfig(newActionConfig);
actionConfig = newActionConfig;
}
}
return actionConfig;
}
use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.
the class ModuleConfigImpl method findException.
/**
* <p>Find and return the <code>ExceptionConfig</code> instance defining
* how <code>Exceptions</code> of the specified type should be handled.
*
* <p>In original Struts usage, this was only available in
* <code>ActionConfig</code>, but there are cases when an exception could
* be thrown before an <code>ActionConfig</code> has been identified,
* where global exception handlers may still be pertinent.</p>
*
* <p>TODO: Look for a way to share this logic with
* <code>ActionConfig</code>, although there are subtle differences, and
* it certainly doesn't seem like it should be done with inheritance.</p>
*
* @param type Exception class for which to find a handler
* @since Struts 1.3.0
*/
public ExceptionConfig findException(Class type) {
// Check through the entire superclass hierarchy as needed
ExceptionConfig config = null;
while (true) {
// Check for a locally defined handler
String name = type.getName();
log.debug("findException: look locally for " + name);
config = findExceptionConfig(name);
if (config != null) {
return (config);
}
// Loop again for our superclass (if any)
type = type.getSuperclass();
if (type == null) {
break;
}
}
// No handler has been configured
return (null);
}
use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.
the class TestActionServlet method testProcessExceptionConfigClassNoExtends.
/**
* Make sure processExceptionConfigClass() returns what it was given if
* the handler passed to it doesn't extend anything.
*/
public void testProcessExceptionConfigClassNoExtends() throws Exception {
moduleConfig.addExceptionConfig(baseException);
ExceptionConfig result = null;
try {
result = actionServlet.processExceptionConfigClass(baseException, moduleConfig, null);
} catch (UnavailableException e) {
fail("An exception should not be thrown when there's nothing to do");
}
assertSame("Result should be the same as the input.", baseException, result);
}
Aggregations