Search in sources :

Example 1 with ServletActionContext

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

the class CreateActionForm method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Create (if necessary) and cache a form bean for this request.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> so that processing continues
     * @throws Exception on any error
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Is there a form bean associated with this ActionConfig?
    ActionConfig actionConfig = actionCtx.getActionConfig();
    String name = actionConfig.getName();
    if (name == null) {
        actionCtx.setActionForm(null);
        return (false);
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Look up form-bean " + name);
    }
    // Look up the corresponding FormBeanConfig (if any)
    FormBeanConfig formBeanConfig = actionConfig.getModuleConfig().findFormBeanConfig(name);
    if (formBeanConfig == null) {
        LOG.warn("No FormBeanConfig found in module " + actionConfig.getModuleConfig().getPrefix() + " under name " + name);
        actionCtx.setActionForm(null);
        return (false);
    }
    Map scope = actionCtx.getScope(actionConfig.getScope());
    ActionForm instance;
    instance = (ActionForm) scope.get(actionConfig.getAttribute());
    // Can we recycle the existing instance (if any)?
    if (!formBeanConfig.canReuse(instance)) {
        instance = formBeanConfig.createActionForm(actionCtx);
    }
    //  directly depends on ActionServlet
    if (actionCtx instanceof ServletActionContext) {
        // The servlet property of ActionForm is transient, so
        // ActionForms which are restored from a serialized state
        // need to have their servlet restored.
        ServletActionContext sac = (ServletActionContext) actionCtx;
        instance.setServlet(sac.getActionServlet());
    }
    actionCtx.setActionForm(instance);
    scope.put(actionConfig.getAttribute(), instance);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) FormBeanConfig(org.apache.struts.config.FormBeanConfig) ActionForm(org.apache.struts.action.ActionForm) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) Map(java.util.Map)

Example 2 with ServletActionContext

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

the class PerformInclude method includePath.

protected String includePath(ActionContext actionContext, String include) {
    ServletActionContext swcontext = (ServletActionContext) actionContext;
    String actionIdPath = RequestUtils.actionIdURL(include, swcontext.getModuleConfig(), swcontext.getActionServlet());
    if (actionIdPath != null) {
        return super.includePath(actionContext, actionIdPath);
    } else {
        return super.includePath(actionContext, include);
    }
}
Also used : ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext)

Example 3 with ServletActionContext

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

the class PerformInclude method perform.

// ------------------------------------------------------- Protected Methods
/**
     * <p>Perform the appropriate processing on the specified include
     * uri.</p>
     *
     * @param context The context for this request
     * @param uri     The uri to be included
     */
protected void perform(ActionContext context, String uri) throws Exception {
    ServletActionContext swcontext = (ServletActionContext) context;
    HttpServletRequest request = swcontext.getRequest();
    RequestDispatcher rd = swcontext.getContext().getRequestDispatcher(uri);
    rd.forward(request, swcontext.getResponse());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 4 with ServletActionContext

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

the class RequestNoCache method requestNoCache.

// ------------------------------------------------------- Protected Methods
protected void requestNoCache(ActionContext context) {
    ServletActionContext sacontext = (ServletActionContext) context;
    HttpServletResponse response = sacontext.getResponse();
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
    response.setDateHeader("Expires", 1);
}
Also used : ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 5 with ServletActionContext

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

the class SetContentType method setContentType.

// ------------------------------------------------------- Protected Methods
protected void setContentType(ActionContext context, String contentType) {
    ServletActionContext swcontext = (ServletActionContext) context;
    HttpServletResponse response = swcontext.getResponse();
    response.setContentType(contentType);
}
Also used : ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) HttpServletResponse(javax.servlet.http.HttpServletResponse)

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