Package org.apache.commons.chain.web.servlet

Examples of org.apache.commons.chain.web.servlet.ServletWebContext


        throws Exception {
        WrappingLookupCommand command = new WrappingLookupCommand();

        command.setWrapperClassName(ServletActionContext.class.getName());

        Context testContext = new ServletWebContext();

        Context wrapped = command.getContext(testContext);

        assertNotNull(wrapped);
        assertTrue(wrapped instanceof ServletActionContext);
View Full Code Here


     * @param request  The instant HttpServletRequest
     * @param response The instant HttpServletResponse
     */
    public ServletActionContext(ServletContext context,
        HttpServletRequest request, HttpServletResponse response) {
        this(new ServletWebContext(context, request, response));
    }
View Full Code Here

        String uri = getForward(context);
        if (uri != null) {
            if (log.isDebugEnabled()) {
                log.debug("Forwarding to " + uri);
            }
            ServletWebContext swcontext = (ServletWebContext)context;
            RequestDispatcher rd = swcontext.getContext().getRequestDispatcher(uri);
            rd.forward(swcontext.getRequest(), swcontext.getResponse());
            return true;
        } else {
            if (log.isDebugEnabled()) {
                log.debug("No forward found");
            }
View Full Code Here

        Catalog catalog = factory.getCatalog(servletName);
        if (catalog == null) {
            catalog = factory.getCatalog();
        }

        ServletWebContext context =
            new ServletWebContext(getServletContext(), request, response);
        Command command = catalog.getCommand("COMMAND_MAPPER");
        try {
            command.execute(context);
        } catch (Exception e) {
            throw new ServletException(e);
View Full Code Here

     *
     * @param context The <code>Context</code> for this request
     */
    protected Locale getLocale(Context context) {

        ServletWebContext swcontext = (ServletWebContext) context;

        // Has a Locale already been selected?
        HttpSession session = swcontext.getRequest().getSession();
        Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
        if (locale != null) {
            return (locale);
        }

        // Select and cache the Locale to be used
        locale = swcontext.getRequest().getLocale();
        if (locale == null) {
            locale = Locale.getDefault();
        }
        session.setAttribute(Globals.LOCALE_KEY, locale);
        return (locale);
View Full Code Here


    protected String getPrefix(Context context) {

        // Identify the URI from which we will match a module prefix
        ServletWebContext swcontext = (ServletWebContext) context;
        HttpServletRequest request = swcontext.getRequest();
        String uri =
            (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
        if (uri == null) {
            uri = request.getServletPath();
        }
        if (uri == null) {
            throw new IllegalArgumentException
                ("No path information in request");
        }

        // Identify the module prefix for the current module
        String prefix = ""// Initialize to default prefix
        String prefixes[] = (String[])
            swcontext.getApplicationScope().get(Globals.MODULE_PREFIXES_KEY);
        int lastSlash = 0;
        while (prefix.equals("") &&
               ((lastSlash = uri.lastIndexOf("/")) > 0)) {
            uri = uri.substring(0, lastSlash);
            for (int i = 0; i < prefixes.length; i++) {
View Full Code Here

    // ------------------------------------------------------- Protected Methods


    protected void requestNoCache(Context context) {

        ServletWebContext swcontext = (ServletWebContext) context;
        HttpServletResponse response = swcontext.getResponse();
       
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
        response.setDateHeader("Expires", 1);
View Full Code Here

        {
            log.debug("No forwardConfig or no path, so pass to next command.");
            return (false);
        }

        ServletWebContext swcontext = (ServletWebContext) context;

        ComponentDefinition definition = null;
        try
        {
            definition = TilesUtil.getDefinition(forwardConfig.getPath(),
                    swcontext.getRequest(),
                    swcontext.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;
        }

        // 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, we will do an include
        tileContext = ComponentContext.getContext(swcontext.getRequest());
        doInclude = (tileContext != null);

        // 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, swcontext.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(swcontext.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, swcontext.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,
                    swcontext.getRequest(),
                    swcontext.getResponse(),
                    swcontext.getContext());
        }

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

                                   ActionConfig actionConfig,
                                   ModuleConfig moduleConfig)
        throws Exception {

        // Look up the remaining properties needed for this handler
        ServletWebContext swcontext = (ServletWebContext) context;
        ActionForm actionForm = (ActionForm)
            swcontext.get(getActionFormKey());
        HttpServletRequest request = swcontext.getRequest();
        HttpServletResponse response = swcontext.getResponse();

        // Handle this exception
        org.apache.struts.action.ExceptionHandler handler =
            (org.apache.struts.action.ExceptionHandler)
            ClassUtils.getApplicationInstance(exceptionConfig.getHandler());
View Full Code Here

                                    Action action,
                                    ActionConfig actionConfig,
                                    ActionForm actionForm)
        throws Exception {

        ServletWebContext swcontext = (ServletWebContext) context;
        return (action.execute((ActionMapping) actionConfig,
                               actionForm,
                               swcontext.getRequest(),
                               swcontext.getResponse()));

    }
View Full Code Here

TOP

Related Classes of org.apache.commons.chain.web.servlet.ServletWebContext

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.