Package org.apache.struts.chain.contexts

Examples of org.apache.struts.chain.contexts.ServletActionContext


     * @throws Exception if thrown by the <code>Action</code>
     */
    protected ForwardConfig execute(ActionContext context, Action action,
        ActionConfig actionConfig, ActionForm actionForm)
        throws Exception {
        ServletActionContext saContext = (ServletActionContext) context;

        return (action.execute((ActionMapping) actionConfig, actionForm,
            saContext.getRequest(), saContext.getResponse()));
    }
View Full Code Here


     * @param context    The context for this request
     * @param actionForm The form bean for this request
     */
    protected ActionErrors validate(ActionContext context,
        ActionConfig actionConfig, ActionForm actionForm) {
        ServletActionContext saContext = (ServletActionContext) context;
        ActionErrors errors =
            (actionForm.validate((ActionMapping) actionConfig,
                saContext.getRequest()));

        // Special handling for multipart request
        if ((errors != null) && !errors.isEmpty()) {
            if (actionForm.getMultipartRequestHandler() != null) {
                if (log.isTraceEnabled()) {
View Full Code Here

     * @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());
    }
View Full Code Here

        rd.forward(request, swcontext.getResponse());
    }

    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);
        }
View Full Code Here

    // ------------------------------------------------------- Protected Methods
    protected boolean isAuthorized(ActionContext context, String[] roles,
        ActionConfig mapping)
        throws Exception {
        // Identify the HTTP request object
        ServletActionContext servletActionContext =
            (ServletActionContext) context;
        HttpServletRequest request = servletActionContext.getRequest();

        // Check the current user against the list of required roles
        for (int i = 0; i < roles.length; i++) {
            if (request.isUserInRole(roles[i])) {
                return (true);
View Full Code Here

        return (false);
    }

    protected String getErrorMessage(ActionContext context,
        ActionConfig actionConfig) {
        ServletActionContext servletActionContext =
            (ServletActionContext) context;

        // Retrieve internal message resources
        ActionServlet servlet = servletActionContext.getActionServlet();
        MessageResources resources = servlet.getInternal();

        return resources.getMessage("notAuthorized", actionConfig.getPath());
    }
View Full Code Here

     * @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;
View Full Code Here

     * that we're processing in "include" mode.
     */
    public boolean execute(Context context) throws Exception {

        // Is there a Tiles Definition to be processed?
        ServletActionContext sacontext = (ServletActionContext) context;
        ForwardConfig forwardConfig = sacontext.getForwardConfig();
        if (forwardConfig == null || forwardConfig.getPath() == null)
        {
            log.debug("No forwardConfig or no path, so pass to next command.");
            return (false);
        }


        ComponentDefinition definition = null;
        try
        {
            definition = TilesUtil.getDefinition(forwardConfig.getPath(),
                    sacontext.getRequest(),
                    sacontext.getContext());
        }
        catch (FactoryNotFoundException ex)
        {
            // this is not a serious error, so log at low priority
            log.debug("Tiles DefinitionFactory not found, so pass to next command.");
            return false;
        }
        catch (NoSuchDefinitionException ex)
        {
            // ignore not found
            log.debug("NoSuchDefinitionException " + ex.getMessage());
        }

        // Do we do a forward (original behavior) or an include ?
        boolean doInclude = false;
        ComponentContext tileContext = null;

        // Get current tile context if any.
        // If context exists, or if the response has already been committed we will do an include
        tileContext = ComponentContext.getContext(sacontext.getRequest());
        doInclude = (tileContext != null || sacontext.getResponse().isCommitted());

        // Controller associated to a definition, if any
        Controller controller = null;

        // Computed uri to include
        String uri = null;

        if (definition != null)
        {
            // We have a "forward config" definition.
            // We use it to complete missing attribute in context.
            // We also get uri, controller.
            uri = definition.getPath();
            controller = definition.getOrCreateController();

            if (tileContext == null) {
                tileContext =
                        new ComponentContext(definition.getAttributes());
                ComponentContext.setContext(tileContext, sacontext.getRequest());

            } else {
                tileContext.addMissing(definition.getAttributes());
            }
        }

        // Process definition set in Action, if any.  This may override the
        // values for uri or controller found using the ForwardConfig, and
        // may augment the tileContext with additional attributes.
        // :FIXME: the class DefinitionsUtil is deprecated, but I can't find
        // the intended alternative to use.
        definition = DefinitionsUtil.getActionDefinition(sacontext.getRequest());
        if (definition != null) { // We have a definition.
                // We use it to complete missing attribute in context.
                // We also overload uri and controller if set in definition.
                if (definition.getPath() != null) {
                    log.debug("Override forward uri "
                              + uri
                              + " with action uri "
                              + definition.getPath());
                        uri = definition.getPath();
                }

                if (definition.getOrCreateController() != null) {
                    log.debug("Override forward controller with action controller");
                        controller = definition.getOrCreateController();
                }

                if (tileContext == null) {
                        tileContext =
                                new ComponentContext(definition.getAttributes());
                        ComponentContext.setContext(tileContext, sacontext.getRequest());
                } else {
                        tileContext.addMissing(definition.getAttributes());
                }
        }


        if (uri == null) {
            log.debug("no uri computed, so pass to next command");
            return false;
        }

        // Execute controller associated to definition, if any.
        if (controller != null) {
            log.trace("Execute controller: " + controller);
            controller.execute(
                    tileContext,
                    sacontext.getRequest(),
                    sacontext.getResponse(),
                    sacontext.getContext());
        }

        // If request comes from a previous Tile, do an include.
        // This allows to insert an action in a Tile.

        if (doInclude) {
            log.info("Tiles process complete; doInclude with " + uri);
            doInclude(sacontext, uri);
        } else {
            log.info("Tiles process complete; forward to " + uri);
            doForward(sacontext, uri);
        }

        log.debug("Tiles processed, so clearing forward config from context.");
        sacontext.setForwardConfig( null );
        return (false);
    }
View Full Code Here

            new MockActionServlet(servletContext, servletConfig);

        servlet.initInternal();

        this.saContext =
            new ServletActionContext(servletContext, request,
                new MockHttpServletResponse());

        this.saContext.setActionServlet(servlet);
        this.command = new AuthorizeAction();
    }
View Full Code Here

        MockActionServlet servlet =
            new MockActionServlet(servletContext, servletConfig);

        servlet.initInternal();

        ServletActionContext saContext =
            new ServletActionContext(servletContext, request,
                new MockHttpServletResponse());

        saContext.setActionServlet(servlet);

        boolean result = command.execute(saContext);

        assertTrue(!result);
View Full Code Here

TOP

Related Classes of org.apache.struts.chain.contexts.ServletActionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.