Search in sources :

Example 11 with UnavailableException

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;
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) AppNotConfiguredException(org.mifos.framework.exceptions.AppNotConfiguredException) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) ApplicationException(org.mifos.framework.exceptions.ApplicationException)

Example 12 with UnavailableException

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException) List(java.util.List) ArrayList(java.util.ArrayList) URL(java.net.URL)

Example 13 with UnavailableException

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;
}
Also used : FormPropertyConfig(org.apache.struts.config.FormPropertyConfig) FormBeanConfig(org.apache.struts.config.FormBeanConfig) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) MissingResourceException(java.util.MissingResourceException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 14 with UnavailableException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) UnavailableException(javax.servlet.UnavailableException) IOException(java.io.IOException) URL(java.net.URL)

Example 15 with UnavailableException

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);
}
Also used : UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) MissingResourceException(java.util.MissingResourceException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Aggregations

UnavailableException (javax.servlet.UnavailableException)95 ServletException (javax.servlet.ServletException)54 IOException (java.io.IOException)33 MalformedURLException (java.net.MalformedURLException)15 SAXException (org.xml.sax.SAXException)14 MissingResourceException (java.util.MissingResourceException)12 ExceptionConfig (org.apache.struts.config.ExceptionConfig)10 URL (java.net.URL)8 Servlet (javax.servlet.Servlet)8 FormBeanConfig (org.apache.struts.config.FormBeanConfig)8 ForwardConfig (org.apache.struts.config.ForwardConfig)8 ServletContext (javax.servlet.ServletContext)6 ActionConfig (org.apache.struts.config.ActionConfig)6 ArrayList (java.util.ArrayList)5 ServletConfig (javax.servlet.ServletConfig)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ClientAbortException (org.apache.catalina.connector.ClientAbortException)4 InvalidConfigException (com.revolsys.ui.web.config.InvalidConfigException)3 XmlConfigLoader (com.revolsys.ui.web.config.XmlConfigLoader)3 BufferedImage (java.awt.image.BufferedImage)3