Search in sources :

Example 11 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class ExceptionHandler method handle.

// ------------------------------------------------------- Protected Methods
protected ForwardConfig handle(ActionContext context, Exception exception, ExceptionConfig exceptionConfig, ActionConfig actionConfig, ModuleConfig moduleConfig) throws Exception {
    // Look up the remaining properties needed for this handler
    ServletActionContext sacontext = (ServletActionContext) context;
    ActionForm actionForm = (ActionForm) sacontext.getActionForm();
    HttpServletRequest request = sacontext.getRequest();
    HttpServletResponse response = sacontext.getResponse();
    // Handle this exception
    org.apache.struts.action.ExceptionHandler handler = (org.apache.struts.action.ExceptionHandler) ClassUtils.getApplicationInstance(exceptionConfig.getHandler());
    return (handler.execute(exception, exceptionConfig, (ActionMapping) actionConfig, actionForm, request, response));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractExceptionHandler(org.apache.struts.chain.commands.AbstractExceptionHandler) ActionMapping(org.apache.struts.action.ActionMapping) ActionForm(org.apache.struts.action.ActionForm) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 12 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class PerformForward method perform.

// ------------------------------------------------------- Protected Methods
/**
     * <p>Perform the appropriate processing on the specified
     * <code>ForwardConfig</code>.</p>
     *
     * @param context       The context for this request
     * @param forwardConfig The forward to be performed
     */
protected void perform(ActionContext context, ForwardConfig forwardConfig) throws Exception {
    ServletActionContext sacontext = (ServletActionContext) context;
    String uri = forwardConfig.getPath();
    if (uri == null) {
        ActionServlet servlet = sacontext.getActionServlet();
        MessageResources resources = servlet.getInternal();
        throw new IllegalArgumentException(resources.getMessage("forwardPathNull"));
    }
    HttpServletRequest request = sacontext.getRequest();
    ServletContext servletContext = sacontext.getContext();
    HttpServletResponse response = sacontext.getResponse();
    // If the forward can be unaliased into an action, then use the path of the action
    String actionIdPath = RequestUtils.actionIdURL(forwardConfig, sacontext.getRequest(), sacontext.getActionServlet());
    if (actionIdPath != null) {
        uri = actionIdPath;
        ForwardConfig actionIdForwardConfig = new ForwardConfig(forwardConfig);
        actionIdForwardConfig.setPath(actionIdPath);
        forwardConfig = actionIdForwardConfig;
    }
    if (uri.startsWith("/")) {
        uri = resolveModuleRelativePath(forwardConfig, servletContext, request);
    }
    if (response.isCommitted() && !forwardConfig.getRedirect()) {
        handleAsInclude(uri, servletContext, request, response);
    } else if (forwardConfig.getRedirect()) {
        handleAsRedirect(uri, request, response);
    } else {
        handleAsForward(uri, servletContext, request, response);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MessageResources(org.apache.struts.util.MessageResources) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) ForwardConfig(org.apache.struts.config.ForwardConfig) ActionServlet(org.apache.struts.action.ActionServlet)

Example 13 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class FormBeanConfig method createActionForm.

/**
     * <p>Create and return an <code>ActionForm</code> instance appropriate to
     * the information in this <code>FormBeanConfig</code>.</p>
     * <p><b>NOTE:</b> If the given <code>ActionContext</code> is not of type
     * <code>ServletActionContext</code> (or a subclass), then the form which
     * is returned will have a null <code>servlet</code> property.  Some of
     * the subclasses of <code>ActionForm</code> included in Struts will later
     * throw a <code>NullPointerException</code> in this case. </p> <p>TODO:
     * Find a way to control this direct dependency on the Servlet API.</p>
     *
     * @param context The ActionContext.
     * @return ActionForm instance
     * @throws IllegalAccessException if the Class or the appropriate
     *                                constructor is not accessible
     * @throws InstantiationException if this Class represents an abstract
     *                                class, an array class, a primitive type,
     *                                or void; or if instantiation fails for
     *                                some other reason
     */
public ActionForm createActionForm(ActionContext context) throws IllegalAccessException, InstantiationException {
    ActionServlet actionServlet = null;
    if (context instanceof ServletActionContext) {
        ServletActionContext saContext = (ServletActionContext) context;
        actionServlet = saContext.getActionServlet();
    }
    return createActionForm(actionServlet);
}
Also used : ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ActionServlet(org.apache.struts.action.ActionServlet)

Example 14 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class PopulateActionForm method populate.

// ------------------------------------------------------- Protected Methods
protected void populate(ActionContext context, ActionConfig actionConfig, ActionForm actionForm) throws Exception {
    ServletActionContext saContext = (ServletActionContext) context;
    RequestUtils.populate(actionForm, actionConfig.getPrefix(), actionConfig.getSuffix(), saContext.getRequest());
}
Also used : ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext)

Example 15 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class PopulateActionForm method reset.

protected void reset(ActionContext context, ActionConfig actionConfig, ActionForm actionForm) {
    ServletActionContext saContext = (ServletActionContext) context;
    actionForm.reset((ActionMapping) actionConfig, saContext.getRequest());
    // Set the multipart class
    if (actionConfig.getMultipartClass() != null) {
        saContext.getRequestScope().put(Globals.MULTIPART_KEY, actionConfig.getMultipartClass());
    }
}
Also used : ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext)

Aggregations

ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ActionServlet (org.apache.struts.action.ActionServlet)4 MockActionServlet (org.apache.struts.mock.MockActionServlet)3 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)3 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)3 MockServletConfig (org.apache.struts.mock.MockServletConfig)3 MockServletContext (org.apache.struts.mock.MockServletContext)3 Map (java.util.Map)2 ActionForm (org.apache.struts.action.ActionForm)2 ActionMapping (org.apache.struts.action.ActionMapping)2 ModuleConfig (org.apache.struts.config.ModuleConfig)2 MockPrincipal (org.apache.struts.mock.MockPrincipal)2 MessageResources (org.apache.struts.util.MessageResources)2 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletContext (javax.servlet.ServletContext)1 HttpSession (javax.servlet.http.HttpSession)1