use of javax.servlet.UnavailableException in project head by mifos.
the class InitializerPlugin method init.
/**
* This is the central method which is called by the struts framework. This
* function then delegates the initialization part to different methods of
* the class.
*
*/
@Override
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
try {
initializeConfiguration(servlet);
initializeFieldConfiguration(servlet);
} catch (Exception ane) {
ane.printStackTrace();
UnavailableException ue = new UnavailableException(ane.getMessage(), 0);
ue.initCause(ane);
throw ue;
}
}
use of javax.servlet.UnavailableException in project sonarqube by SonarSource.
the class ActionServlet method parseModuleConfigFile.
/**
* <p>Parses one module config file.</p>
*
* @param digester Digester instance that does the parsing
* @param path The path to the config file to parse.
* @throws UnavailableException if file cannot be read or parsed
* @since Struts 1.2
* @deprecated use parseModuleConfigFile(Digester digester, URL url)
* instead
*/
protected void parseModuleConfigFile(Digester digester, String path) throws UnavailableException {
try {
List paths = splitAndResolvePaths(path);
if (paths.size() > 0) {
// Get first path as was the old behavior
URL url = (URL) paths.get(0);
parseModuleConfigFile(digester, url);
} else {
throw new UnavailableException("Cannot locate path " + path);
}
} catch (UnavailableException ex) {
throw ex;
} catch (ServletException ex) {
handleConfigException(path, ex);
}
}
use of javax.servlet.UnavailableException in project sonarqube 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 sonarqube by SonarSource.
the class ActionServlet method splitAndResolvePaths.
/**
* <p>Takes a comma-delimited string and splits it into paths, then
* resolves those paths using the ServletContext and appropriate
* ClassLoader. When loading from the classloader, multiple resources per
* path are supported to support, for example, multiple jars containing
* the same named config file.</p>
*
* @param paths A comma-delimited string of paths
* @return A list of resolved URL's for all found resources
* @throws ServletException if a servlet exception is thrown
*/
protected List splitAndResolvePaths(String paths) throws ServletException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
loader = this.getClass().getClassLoader();
}
ArrayList resolvedUrls = new ArrayList();
URL resource;
String path = null;
try {
// Process each specified resource path
while (paths.length() > 0) {
resource = null;
int comma = paths.indexOf(',');
if (comma >= 0) {
path = paths.substring(0, comma).trim();
paths = paths.substring(comma + 1);
} else {
path = paths.trim();
paths = "";
}
if (path.length() < 1) {
break;
}
if (path.charAt(0) == '/') {
resource = getServletContext().getResource(path);
}
if (resource == null) {
if (log.isDebugEnabled()) {
log.debug("Unable to locate " + path + " in the servlet context, " + "trying classloader.");
}
Enumeration e = loader.getResources(path);
if (!e.hasMoreElements()) {
String msg = internal.getMessage("configMissing", path);
log.error(msg);
throw new UnavailableException(msg);
} else {
while (e.hasMoreElements()) {
resolvedUrls.add(e.nextElement());
}
}
} else {
resolvedUrls.add(resource);
}
}
} catch (MalformedURLException e) {
handleConfigException(path, e);
} catch (IOException e) {
handleConfigException(path, e);
}
return resolvedUrls;
}
use of javax.servlet.UnavailableException in project sonarqube by SonarSource.
the class ActionServlet method getRequestProcessor.
/**
* <p>Look up and return the {@link RequestProcessor} responsible for the
* specified module, creating a new one if necessary.</p>
*
* @param config The module configuration for which to acquire and return
* a RequestProcessor.
* @return The {@link RequestProcessor} responsible for the specified
* module,
* @throws ServletException If we cannot instantiate a RequestProcessor
* instance a {@link UnavailableException} is
* thrown, meaning your application is not loaded
* and will not be available.
* @since Struts 1.1
*/
protected synchronized RequestProcessor getRequestProcessor(ModuleConfig config) throws ServletException {
RequestProcessor processor = this.getProcessorForModule(config);
if (processor == null) {
try {
processor = (RequestProcessor) RequestUtils.applicationInstance(config.getControllerConfig().getProcessorClass());
} catch (Exception e) {
throw new UnavailableException("Cannot initialize RequestProcessor of class " + config.getControllerConfig().getProcessorClass() + ": " + e);
}
processor.init(this, config);
String key = Globals.REQUEST_PROCESSOR_KEY + config.getPrefix();
getServletContext().setAttribute(key, processor);
}
return (processor);
}
Aggregations