Search in sources :

Example 1 with ForwardConfig

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

the class ActionServlet method initModuleForwards.

/**
     * <p>Initialize the forwards for the specified module.</p>
     *
     * @param config ModuleConfig information for this module
     * @throws ServletException if initialization cannot be performed
     */
protected void initModuleForwards(ModuleConfig config) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Initializing module path '" + config.getPrefix() + "' forwards");
    }
    // Process forwards extensions.
    ForwardConfig[] forwards = config.findForwardConfigs();
    for (int i = 0; i < forwards.length; i++) {
        ForwardConfig forward = forwards[i];
        processForwardExtension(forward, config, null);
    }
    for (int i = 0; i < forwards.length; i++) {
        ForwardConfig forward = forwards[i];
        // Verify that required fields are all present for the forward
        if (forward.getPath() == null) {
            handleValueRequiredException("path", forward.getName(), "global forward");
        }
    }
}
Also used : ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 2 with ForwardConfig

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

the class ActionServlet method initModuleActions.

/**
     * <p>Initialize the action configs for the specified module.</p>
     *
     * @param config ModuleConfig information for this module
     * @throws ServletException if initialization cannot be performed
     * @since Struts 1.3
     */
protected void initModuleActions(ModuleConfig config) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Initializing module path '" + config.getPrefix() + "' action configs");
    }
    // Process ActionConfig extensions.
    ActionConfig[] actionConfigs = config.findActionConfigs();
    for (int i = 0; i < actionConfigs.length; i++) {
        ActionConfig actionConfig = actionConfigs[i];
        processActionConfigExtension(actionConfig, config);
    }
    for (int i = 0; i < actionConfigs.length; i++) {
        ActionConfig actionConfig = actionConfigs[i];
        // Verify that required fields are all present for the forward
        // configs
        ForwardConfig[] forwards = actionConfig.findForwardConfigs();
        for (int j = 0; j < forwards.length; j++) {
            ForwardConfig forward = forwards[j];
            if (forward.getPath() == null) {
                handleValueRequiredException("path", forward.getName(), "action forward");
            }
        }
        // ... and the exception configs
        ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
        for (int j = 0; j < exceptions.length; j++) {
            ExceptionConfig exception = exceptions[j];
            if (exception.getKey() == null) {
                handleValueRequiredException("key", exception.getType(), "action exception config");
            }
        }
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 3 with ForwardConfig

use of org.apache.struts.config.ForwardConfig 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 4 with ForwardConfig

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

the class RequestProcessor method processForwardConfig.

/**
     * <p>Forward or redirect to the specified destination, by the specified
     * mechanism.  This method uses a <code>ForwardConfig</code> object
     * instead an <code>ActionForward</code>.</p>
     *
     * @param request  The servlet request we are processing
     * @param response The servlet response we are creating
     * @param forward  The ForwardConfig controlling where we go next
     * @throws IOException      if an input/output error occurs
     * @throws ServletException if a servlet exception occurs
     */
protected void processForwardConfig(HttpServletRequest request, HttpServletResponse response, ForwardConfig forward) throws IOException, ServletException {
    if (forward == null) {
        return;
    }
    if (log.isDebugEnabled()) {
        log.debug("processForwardConfig(" + forward + ")");
    }
    String forwardPath = forward.getPath();
    String uri;
    // If the forward can be unaliased into an action, then use the path of the action
    String actionIdPath = RequestUtils.actionIdURL(forward, request, servlet);
    if (actionIdPath != null) {
        forwardPath = actionIdPath;
        ForwardConfig actionIdForward = new ForwardConfig(forward);
        actionIdForward.setPath(actionIdPath);
        forward = actionIdForward;
    }
    // processing (ie. they're absolute)
    if (forwardPath.startsWith("/")) {
        // get module relative uri
        uri = RequestUtils.forwardURL(request, forward, null);
    } else {
        uri = forwardPath;
    }
    if (forward.getRedirect()) {
        // only prepend context path for relative uri
        if (uri.startsWith("/")) {
            uri = request.getContextPath() + uri;
        }
        response.sendRedirect(response.encodeRedirectURL(uri));
    } else {
        doForward(uri, request, response);
    }
}
Also used : ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 5 with ForwardConfig

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

the class AbstractExecuteAction 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> 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 the resources we will need to send to the Action
    Action action = actionCtx.getAction();
    if (action == null) {
        return (false);
    }
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ActionForm actionForm = actionCtx.getActionForm();
    // Execute the Action for this request, caching returned ActionForward
    ForwardConfig forwardConfig = execute(actionCtx, action, actionConfig, actionForm);
    actionCtx.setForwardConfig(forwardConfig);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) Action(org.apache.struts.action.Action) ActionForm(org.apache.struts.action.ActionForm) ForwardConfig(org.apache.struts.config.ForwardConfig)

Aggregations

ForwardConfig (org.apache.struts.config.ForwardConfig)63 ActionConfig (org.apache.struts.config.ActionConfig)14 UnavailableException (javax.servlet.UnavailableException)12 ServletException (javax.servlet.ServletException)10 ExceptionConfig (org.apache.struts.config.ExceptionConfig)10 MalformedURLException (java.net.MalformedURLException)8 ModuleConfig (org.apache.struts.config.ModuleConfig)8 IOException (java.io.IOException)6 MissingResourceException (java.util.MissingResourceException)6 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)6 SAXException (org.xml.sax.SAXException)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ActionFormBean (org.apache.struts.action.ActionFormBean)4 ActionForward (org.apache.struts.action.ActionForward)4 ActionMapping (org.apache.struts.action.ActionMapping)4 ActionServlet (org.apache.struts.action.ActionServlet)4 FormPropertyConfig (org.apache.struts.config.FormPropertyConfig)4 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)3 ArrayList (java.util.ArrayList)2