Search in sources :

Example 16 with UnavailableException

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;
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) UnavailableException(javax.servlet.UnavailableException) ForwardConfig(org.apache.struts.config.ForwardConfig) 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 17 with UnavailableException

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);
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ActionContext(org.apache.struts.chain.contexts.ActionContext)

Example 18 with UnavailableException

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 + "'");
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException) SAXException(org.xml.sax.SAXException)

Example 19 with UnavailableException

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);
}
Also used : ExceptionConfig(org.apache.struts.config.ExceptionConfig) UnavailableException(javax.servlet.UnavailableException)

Example 20 with UnavailableException

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.");
    }
}
Also used : FormBeanConfig(org.apache.struts.config.FormBeanConfig) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) 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