Search in sources :

Example 71 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonar-java 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 72 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonar-java by SonarSource.

the class AbstractSelectForward method execute.

// ---------------------------------------------------------- Public Methods
/**
 * <p>Select and cache the <code>ActionForward</code> for this
 * <code>ActionConfig</code> if specified.</p>
 *
 * @param actionCtx The <code>Context</code> for the current request
 * @return <code>false</code> so that processing continues
 * @throws Exception if thrown by the Action class
 */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Skip processing if the current request is not valid
    Boolean valid = actionCtx.getFormValid();
    if ((valid == null) || !valid.booleanValue()) {
        return (false);
    }
    // Acquire configuration objects that we need
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ModuleConfig moduleConfig = actionConfig.getModuleConfig();
    ForwardConfig forwardConfig = null;
    String forward = actionConfig.getForward();
    if (forward != null) {
        forwardConfig = forward(actionCtx, moduleConfig, forward);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Forwarding to " + forwardConfig);
        }
        actionCtx.setForwardConfig(forwardConfig);
    }
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ModuleConfig(org.apache.struts.config.ModuleConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 73 with ModuleConfig

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

the class RequestUtils method actionIdURL.

/**
 * <p>Returns the true path of the destination action if the specified forward
 * is an action-aliased URL. This method version forms the URL based on
 * the current request; selecting the current module if the forward does not
 * explicitly contain a module path.</p>
 *
 * @param forward the forward config
 * @param request the current request
 * @param servlet the servlet handling the current request
 * @return the context-relative URL of the action if the forward has an action identifier; otherwise <code>null</code>.
 * @since Struts 1.3.6
 */
public static String actionIdURL(ForwardConfig forward, HttpServletRequest request, ActionServlet servlet) {
    ModuleConfig moduleConfig = null;
    if (forward.getModule() != null) {
        String prefix = forward.getModule();
        moduleConfig = ModuleUtils.getInstance().getModuleConfig(prefix, servlet.getServletContext());
    } else {
        moduleConfig = ModuleUtils.getInstance().getModuleConfig(request);
    }
    return actionIdURL(forward.getPath(), moduleConfig, servlet);
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Aggregations

ModuleConfig (org.apache.struts.config.ModuleConfig)73 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 JspException (javax.servlet.jsp.JspException)10 Iterator (java.util.Iterator)8 ActionConfig (org.apache.struts.config.ActionConfig)8 ForwardConfig (org.apache.struts.config.ForwardConfig)8 MessageResources (org.apache.struts.util.MessageResources)8 ArrayList (java.util.ArrayList)6 ServletException (javax.servlet.ServletException)6 Enumeration (java.util.Enumeration)4 List (java.util.List)4 Locale (java.util.Locale)4 ActionServlet (org.apache.struts.action.ActionServlet)4 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)4 UnavailableException (javax.servlet.UnavailableException)3 Digester (org.apache.commons.digester.Digester)3 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)3 MultipartRequestHandler (org.apache.struts.upload.MultipartRequestHandler)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2