use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class ActionServlet method initModulePlugIns.
/**
* <p>Initialize the plug ins for the specified module.</p>
*
* @param config ModuleConfig information for this module
* @throws ServletException if initialization cannot be performed
* @since Struts 1.1
*/
protected void initModulePlugIns(ModuleConfig config) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + config.getPrefix() + "' plug ins");
}
PlugInConfig[] plugInConfigs = config.findPlugInConfigs();
PlugIn[] plugIns = new PlugIn[plugInConfigs.length];
getServletContext().setAttribute(Globals.PLUG_INS_KEY + config.getPrefix(), plugIns);
for (int i = 0; i < plugIns.length; i++) {
try {
plugIns[i] = (PlugIn) RequestUtils.applicationInstance(plugInConfigs[i].getClassName());
BeanUtils.populate(plugIns[i], plugInConfigs[i].getProperties());
// This plugin config object is needed by Tiles
try {
PropertyUtils.setProperty(plugIns[i], "currentPlugInConfigObject", plugInConfigs[i]);
} catch (Exception e) {
;
// FIXME Whenever we fail silently, we must document a valid
// reason for doing so. Why should we fail silently if a
// property can't be set on the plugin?
/**
* Between version 1.138-1.140 cedric made these changes.
* The exceptions are caught to deal with containers
* applying strict security. This was in response to bug
* #15736
*
* Recommend that we make the currentPlugInConfigObject part
* of the PlugIn Interface if we can, Rob
*/
}
plugIns[i].init(this, config);
} catch (ServletException e) {
throw e;
} catch (Exception e) {
String errMsg = internal.getMessage("plugIn.init", plugInConfigs[i].getClassName());
log(errMsg, e);
throw new UnavailableException(errMsg);
}
}
}
use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class ActionServlet method processFormBeanConfigClass.
/**
* <p>Checks if the current beanConfig is using the correct class based on
* the class of its ancestor form bean config.</p>
*
* @param beanConfig The form bean to check.
* @param moduleConfig The config for the current module.
* @return The form bean config using the correct class as determined by
* the config's ancestor and its own overridden value.
* @throws UnavailableException if an instance of the form bean config
* class cannot be created.
* @throws ServletException on class creation error
*/
protected FormBeanConfig processFormBeanConfigClass(FormBeanConfig beanConfig, ModuleConfig moduleConfig) throws ServletException {
String ancestor = beanConfig.getExtends();
if (ancestor == null) {
// Nothing to do, then
return beanConfig;
}
// Make sure that this bean is of the right class
FormBeanConfig baseConfig = moduleConfig.findFormBeanConfig(ancestor);
if (baseConfig == null) {
throw new UnavailableException("Unable to find " + "form bean '" + ancestor + "' to extend.");
}
// Was our bean's class overridden already?
if (beanConfig.getClass().equals(FormBeanConfig.class)) {
// Ensure that our bean is using the correct class
if (!baseConfig.getClass().equals(beanConfig.getClass())) {
// Replace the bean with an instance of the correct class
FormBeanConfig newBeanConfig = null;
String baseConfigClassName = baseConfig.getClass().getName();
try {
newBeanConfig = (FormBeanConfig) RequestUtils.applicationInstance(baseConfigClassName);
// copy the values
BeanUtils.copyProperties(newBeanConfig, beanConfig);
FormPropertyConfig[] fpc = beanConfig.findFormPropertyConfigs();
for (int i = 0; i < fpc.length; i++) {
newBeanConfig.addFormPropertyConfig(fpc[i]);
}
} catch (Exception e) {
handleCreationException(baseConfigClassName, e);
}
// replace beanConfig with newBeanConfig
moduleConfig.removeFormBeanConfig(beanConfig);
moduleConfig.addFormBeanConfig(newBeanConfig);
beanConfig = newBeanConfig;
}
}
return beanConfig;
}
use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class ActionServlet method processForwardConfigClass.
/**
* <p>Checks if the current forwardConfig is using the correct class based
* on the class of its configuration ancestor. If actionConfig is
* provided, then this method will process the forwardConfig as part
* of that actionConfig. If actionConfig is null, the forwardConfig
* will be processed as a global forward.</p>
*
* @param forwardConfig The forward to check.
* @param moduleConfig The config for the current module.
* @param actionConfig If applicable, the config for the current action.
* @return The forward config using the correct class as determined by the
* config's ancestor and its own overridden value.
* @throws UnavailableException if an instance of the forward config class
* cannot be created.
* @throws ServletException on class creation error
*/
protected ForwardConfig processForwardConfigClass(ForwardConfig forwardConfig, ModuleConfig moduleConfig, ActionConfig actionConfig) throws ServletException {
String ancestor = forwardConfig.getExtends();
if (ancestor == null) {
// Nothing to do, then
return forwardConfig;
}
// Make sure that this config is of the right class
ForwardConfig baseConfig = null;
if (actionConfig != null) {
// Look for this in the actionConfig
baseConfig = actionConfig.findForwardConfig(ancestor);
}
if (baseConfig == null) {
// Either this is a forwardConfig that inherits a global config,
// or actionConfig is null
baseConfig = moduleConfig.findForwardConfig(ancestor);
}
if (baseConfig == null) {
throw new UnavailableException("Unable to find " + "forward '" + ancestor + "' to extend.");
}
// Was our forwards's class overridden already?
if (forwardConfig.getClass().equals(ActionForward.class)) {
// Ensure that our forward is using the correct class
if (!baseConfig.getClass().equals(forwardConfig.getClass())) {
// Replace the config with an instance of the correct class
ForwardConfig newForwardConfig = null;
String baseConfigClassName = baseConfig.getClass().getName();
try {
newForwardConfig = (ForwardConfig) RequestUtils.applicationInstance(baseConfigClassName);
// copy the values
BeanUtils.copyProperties(newForwardConfig, forwardConfig);
} catch (Exception e) {
handleCreationException(baseConfigClassName, e);
}
// replace forwardConfig with newForwardConfig
if (actionConfig != null) {
actionConfig.removeForwardConfig(forwardConfig);
actionConfig.addForwardConfig(newForwardConfig);
} else {
// this is a global forward
moduleConfig.removeForwardConfig(forwardConfig);
moduleConfig.addForwardConfig(newForwardConfig);
}
forwardConfig = newForwardConfig;
}
}
return forwardConfig;
}
use of javax.servlet.UnavailableException in project sonar-java 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.");
}
}
use of javax.servlet.UnavailableException in project sonar-java by SonarSource.
the class TestActionServlet method testProcessFormBeanConfigClassNoExtends.
/**
* Make sure processFormBeanConfigClass() returns what it was given if the
* form passed to it doesn't extend anything.
*/
public void testProcessFormBeanConfigClassNoExtends() throws Exception {
moduleConfig.addFormBeanConfig(baseFormBean);
FormBeanConfig result = null;
try {
result = actionServlet.processFormBeanConfigClass(baseFormBean, moduleConfig);
} 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.", baseFormBean, result);
}
Aggregations