use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.
the class AbstractExceptionHandler method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Invoke the appropriate <code>Action</code> for this request, and
* cache the returned <code>ActionForward</code>.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> if a <code>ForwardConfig</code> is returned,
* else <code>true</code> to complete processing
* @throws Exception if thrown by the Action class and not declared by an
* Exception Handler
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Look up the exception that was thrown
Exception exception = actionCtx.getException();
if (exception == null) {
LOG.warn("No Exception found in ActionContext");
return (true);
}
// Look up the local or global exception handler configuration
ExceptionConfig exceptionConfig = null;
ActionConfig actionConfig = actionCtx.getActionConfig();
ModuleConfig moduleConfig = actionCtx.getModuleConfig();
if (actionConfig != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("See if actionConfig " + actionConfig + " has an exceptionConfig for " + exception.getClass().getName());
}
exceptionConfig = actionConfig.findException(exception.getClass());
} else if (moduleConfig != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No action yet, see if moduleConfig " + moduleConfig + " has an exceptionConfig " + exception.getClass().getName());
}
exceptionConfig = moduleConfig.findException(exception.getClass());
}
// Handle the exception in the configured manner
if (exceptionConfig == null) {
LOG.warn("Unhandled exception", exception);
throw exception;
}
ForwardConfig forwardConfig = handle(actionCtx, exception, exceptionConfig, actionConfig, moduleConfig);
if (forwardConfig != null) {
actionCtx.setForwardConfig(forwardConfig);
return (false);
} else {
return (true);
}
}
use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.
the class ModuleConfigImpl method freeze.
/**
* <p> Freeze the configuration of this module. After this method
* returns, any attempt to modify the configuration will return an
* IllegalStateException. </p>
*/
public void freeze() {
super.freeze();
ActionConfig[] aconfigs = findActionConfigs();
for (int i = 0; i < aconfigs.length; i++) {
aconfigs[i].freeze();
}
matcher = new ActionConfigMatcher(aconfigs);
getControllerConfig().freeze();
ExceptionConfig[] econfigs = findExceptionConfigs();
for (int i = 0; i < econfigs.length; i++) {
econfigs[i].freeze();
}
FormBeanConfig[] fbconfigs = findFormBeanConfigs();
for (int i = 0; i < fbconfigs.length; i++) {
fbconfigs[i].freeze();
}
ForwardConfig[] fconfigs = findForwardConfigs();
for (int i = 0; i < fconfigs.length; i++) {
fconfigs[i].freeze();
}
MessageResourcesConfig[] mrconfigs = findMessageResourcesConfigs();
for (int i = 0; i < mrconfigs.length; i++) {
mrconfigs[i].freeze();
}
PlugInConfig[] piconfigs = findPlugInConfigs();
for (int i = 0; i < piconfigs.length; i++) {
piconfigs[i].freeze();
}
}
use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.
the class TestActionServlet method testInitModuleExceptionConfigsNullFormType.
/**
* Test that initModuleExceptionConfigs throws an exception when a handler
* with a null key is present.
*/
public void testInitModuleExceptionConfigsNullFormType() throws ServletException {
ExceptionConfig handler = new ExceptionConfig();
handler.setType("java.lang.NullPointerException");
moduleConfig.addExceptionConfig(handler);
try {
actionServlet.initModuleExceptionConfigs(moduleConfig);
fail("An exception should've been thrown here.");
} catch (UnavailableException e) {
// success
} catch (Exception e) {
fail("Unrecognized exception thrown: " + e);
}
}
use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.
the class TestActionServlet method testProcessActionExtensionWithExceptionConfig.
/**
* Test that an ActionConfig's ExceptionConfig can inherit from a
* global ExceptionConfig.
*/
public void testProcessActionExtensionWithExceptionConfig() throws ServletException {
ExceptionConfig exceptionConfig = new ExceptionConfig();
exceptionConfig.setType("SomeException");
exceptionConfig.setExtends("java.lang.NullPointerException");
baseAction.addExceptionConfig(exceptionConfig);
moduleConfig.addActionConfig(baseAction);
moduleConfig.addExceptionConfig(baseException);
actionServlet.processActionConfigExtension(baseAction, moduleConfig);
exceptionConfig = baseAction.findExceptionConfig("SomeException");
assertEquals("SomeException's inheritance was not processed.", baseException.getKey(), exceptionConfig.getKey());
}
use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.
the class TestActionServlet method testProcessExceptionConfigClassOverriddenSubFormClass.
/**
* Test the case where the subconfig has already specified its own config
* class. If the code still attempts to create a new instance, an error
* will be thrown.
*/
public void testProcessExceptionConfigClassOverriddenSubFormClass() throws Exception {
moduleConfig.addExceptionConfig(baseException);
ExceptionConfig customSub = new CustomExceptionConfigArg("java.lang.IllegalStateException");
customSub.setExtends("java.lang.NullPointerException");
moduleConfig.addExceptionConfig(customSub);
try {
actionServlet.processExceptionConfigClass(customSub, moduleConfig, null);
} catch (Exception e) {
fail("Exception should not be thrown");
}
}
Aggregations