Search in sources :

Example 11 with ExceptionConfig

use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.

the class AbstractExceptionHandler method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Invoke the appropriate <code>Action</code> for this request, and
     * cache the returned <code>ActionForward</code>.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> if a <code>ForwardConfig</code> is returned,
     *         else <code>true</code> to complete processing
     * @throws Exception if thrown by the Action class and not declared by an
     *                   Exception Handler
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Look up the exception that was thrown
    Exception exception = actionCtx.getException();
    if (exception == null) {
        LOG.warn("No Exception found in ActionContext");
        return (true);
    }
    // Look up the local or global exception handler configuration
    ExceptionConfig exceptionConfig = null;
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ModuleConfig moduleConfig = actionCtx.getModuleConfig();
    if (actionConfig != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("See if actionConfig " + actionConfig + " has an exceptionConfig for " + exception.getClass().getName());
        }
        exceptionConfig = actionConfig.findException(exception.getClass());
    } else if (moduleConfig != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No action yet, see if moduleConfig " + moduleConfig + " has an exceptionConfig " + exception.getClass().getName());
        }
        exceptionConfig = moduleConfig.findException(exception.getClass());
    }
    // Handle the exception in the configured manner
    if (exceptionConfig == null) {
        LOG.warn("Unhandled exception", exception);
        throw exception;
    }
    ForwardConfig forwardConfig = handle(actionCtx, exception, exceptionConfig, actionConfig, moduleConfig);
    if (forwardConfig != null) {
        actionCtx.setForwardConfig(forwardConfig);
        return (false);
    } else {
        return (true);
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) ModuleConfig(org.apache.struts.config.ModuleConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 12 with ExceptionConfig

use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.

the class ModuleConfigImpl method freeze.

/**
     * <p> Freeze the configuration of this module.  After this method
     * returns, any attempt to modify the configuration will return an
     * IllegalStateException. </p>
     */
public void freeze() {
    super.freeze();
    ActionConfig[] aconfigs = findActionConfigs();
    for (int i = 0; i < aconfigs.length; i++) {
        aconfigs[i].freeze();
    }
    matcher = new ActionConfigMatcher(aconfigs);
    getControllerConfig().freeze();
    ExceptionConfig[] econfigs = findExceptionConfigs();
    for (int i = 0; i < econfigs.length; i++) {
        econfigs[i].freeze();
    }
    FormBeanConfig[] fbconfigs = findFormBeanConfigs();
    for (int i = 0; i < fbconfigs.length; i++) {
        fbconfigs[i].freeze();
    }
    ForwardConfig[] fconfigs = findForwardConfigs();
    for (int i = 0; i < fconfigs.length; i++) {
        fconfigs[i].freeze();
    }
    MessageResourcesConfig[] mrconfigs = findMessageResourcesConfigs();
    for (int i = 0; i < mrconfigs.length; i++) {
        mrconfigs[i].freeze();
    }
    PlugInConfig[] piconfigs = findPlugInConfigs();
    for (int i = 0; i < piconfigs.length; i++) {
        piconfigs[i].freeze();
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) FormBeanConfig(org.apache.struts.config.FormBeanConfig) PlugInConfig(org.apache.struts.config.PlugInConfig) ForwardConfig(org.apache.struts.config.ForwardConfig) ActionConfigMatcher(org.apache.struts.config.ActionConfigMatcher) MessageResourcesConfig(org.apache.struts.config.MessageResourcesConfig)

Example 13 with ExceptionConfig

use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.

the class TestActionServlet method testInitModuleExceptionConfigsNullFormType.

/**
     * Test that initModuleExceptionConfigs throws an exception when a handler
     * with a null key is present.
     */
public void testInitModuleExceptionConfigsNullFormType() throws ServletException {
    ExceptionConfig handler = new ExceptionConfig();
    handler.setType("java.lang.NullPointerException");
    moduleConfig.addExceptionConfig(handler);
    try {
        actionServlet.initModuleExceptionConfigs(moduleConfig);
        fail("An exception should've been thrown here.");
    } catch (UnavailableException e) {
    // success
    } catch (Exception e) {
        fail("Unrecognized exception thrown: " + e);
    }
}
Also used : ExceptionConfig(org.apache.struts.config.ExceptionConfig) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 14 with ExceptionConfig

use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.

the class TestActionServlet method testProcessActionExtensionWithExceptionConfig.

/**
     * Test that an ActionConfig's ExceptionConfig can inherit from a
     * global ExceptionConfig.
     */
public void testProcessActionExtensionWithExceptionConfig() throws ServletException {
    ExceptionConfig exceptionConfig = new ExceptionConfig();
    exceptionConfig.setType("SomeException");
    exceptionConfig.setExtends("java.lang.NullPointerException");
    baseAction.addExceptionConfig(exceptionConfig);
    moduleConfig.addActionConfig(baseAction);
    moduleConfig.addExceptionConfig(baseException);
    actionServlet.processActionConfigExtension(baseAction, moduleConfig);
    exceptionConfig = baseAction.findExceptionConfig("SomeException");
    assertEquals("SomeException's inheritance was not processed.", baseException.getKey(), exceptionConfig.getKey());
}
Also used : ExceptionConfig(org.apache.struts.config.ExceptionConfig)

Example 15 with ExceptionConfig

use of org.apache.struts.config.ExceptionConfig in project sonarqube by SonarSource.

the class TestActionServlet method testProcessExceptionConfigClassOverriddenSubFormClass.

/**
     * Test the case where the subconfig has already specified its own config
     * class.  If the code still attempts to create a new instance, an error
     * will be thrown.
     */
public void testProcessExceptionConfigClassOverriddenSubFormClass() throws Exception {
    moduleConfig.addExceptionConfig(baseException);
    ExceptionConfig customSub = new CustomExceptionConfigArg("java.lang.IllegalStateException");
    customSub.setExtends("java.lang.NullPointerException");
    moduleConfig.addExceptionConfig(customSub);
    try {
        actionServlet.processExceptionConfigClass(customSub, moduleConfig, null);
    } catch (Exception e) {
        fail("Exception should not be thrown");
    }
}
Also used : ExceptionConfig(org.apache.struts.config.ExceptionConfig) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Aggregations

ExceptionConfig (org.apache.struts.config.ExceptionConfig)16 UnavailableException (javax.servlet.UnavailableException)7 ServletException (javax.servlet.ServletException)6 ForwardConfig (org.apache.struts.config.ForwardConfig)5 ActionConfig (org.apache.struts.config.ActionConfig)4 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 MissingResourceException (java.util.MissingResourceException)3 SAXException (org.xml.sax.SAXException)3 FormBeanConfig (org.apache.struts.config.FormBeanConfig)2 ActionConfigMatcher (org.apache.struts.config.ActionConfigMatcher)1 FormPropertyConfig (org.apache.struts.config.FormPropertyConfig)1 MessageResourcesConfig (org.apache.struts.config.MessageResourcesConfig)1 ModuleConfig (org.apache.struts.config.ModuleConfig)1 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)1 PlugInConfig (org.apache.struts.config.PlugInConfig)1