use of javax.servlet.UnavailableException 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 javax.servlet.UnavailableException in project sonarqube by SonarSource.
the class ComposableRequestProcessor method setActionContextClassName.
/**
* <p>Make sure that the specified <code>className</code> identfies a
* class which can be found and which implements the
* <code>ActionContext</code> interface.</p>
*
* @param className Fully qualified name of
* @throws ServletException If an error occurs during initialization
* @throws UnavailableException if class does not implement ActionContext
* or is not found
*/
private void setActionContextClassName(String className) throws ServletException {
if ((className != null) && (className.trim().length() > 0)) {
if (LOG.isDebugEnabled()) {
LOG.debug("setActionContextClassName: requested context class: " + className);
}
try {
Class actionContextClass = RequestUtils.applicationClass(className);
if (!ActionContext.class.isAssignableFrom(actionContextClass)) {
throw new UnavailableException("ActionContextClass " + "[" + className + "]" + " must implement ActionContext interface.");
}
this.setActionContextClass(actionContextClass);
} catch (ClassNotFoundException e) {
throw new UnavailableException("ActionContextClass " + className + " not found.");
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("setActionContextClassName: no className specified");
}
this.setActionContextClass(null);
}
}
use of javax.servlet.UnavailableException in project sonarqube by SonarSource.
the class ValidatorPlugIn method init.
/**
* Initialize and load our resources.
*
* @param servlet The ActionServlet for our application
* @param config The ModuleConfig for our owning module
* @throws ServletException if we cannot configure ourselves correctly
*/
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
// Remember our associated configuration and servlet
this.config = config;
this.servlet = servlet;
// Load our database from persistent storage
try {
this.initResources();
servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(), resources);
servlet.getServletContext().setAttribute(STOP_ON_ERROR_KEY + '.' + config.getPrefix(), (this.stopOnFirstError ? Boolean.TRUE : Boolean.FALSE));
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new UnavailableException("Cannot load a validator resource from '" + pathnames + "'");
}
}
use of javax.servlet.UnavailableException 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);
}
use of javax.servlet.UnavailableException in project sonarqube by SonarSource.
the class TestActionServlet method notestProcessFormBeanConfigClassError.
/**
* Make sure the code throws the correct exception when it can't create an
* instance of the base config's custom class.
*/
public void notestProcessFormBeanConfigClassError() throws Exception {
CustomFormBeanConfigArg customBase = new CustomFormBeanConfigArg("customBase");
moduleConfig.addFormBeanConfig(customBase);
FormBeanConfig customSub = new FormBeanConfig();
customSub.setName("customSub");
customSub.setExtends("customBase");
moduleConfig.addFormBeanConfig(customSub);
try {
actionServlet.processFormBeanConfigClass(customSub, moduleConfig);
fail("Exception should be thrown");
} catch (UnavailableException e) {
// success
} catch (Exception e) {
fail("Unexpected exception thrown.");
}
}
Aggregations