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

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


     */
    protected ActionErrors validate(Context context,
                                    ActionConfig actionConfig,
                                    ActionForm actionForm) {

        ServletWebContext swcontext = (ServletWebContext) context;
        ActionErrors errors = (actionForm.validate((ActionMapping) actionConfig,
                                    swcontext.getRequest()));

        // Special handling for multipart request
        if (errors != null && !errors.isEmpty()) {
            if (actionForm.getMultipartRequestHandler() != null) {
                if (log.isTraceEnabled()) {
                    log.trace("  Rolling back multipart request");
                }
                actionForm.getMultipartRequestHandler().rollback();
            }
        }

        // Saving the errors is not part of the contract for this method,
        // but the idea of the HttpServletRequest is not present in the
        // abstract parent of this class.  Put this in now so that it
        // at least gets done -- and then see if other developers have
        // opinions about whether this is good, bad, or at least acceptable.
        swcontext.getRequest().setAttribute(Globals.ERROR_KEY, errors);

        return errors;

    }
View Full Code Here


     * @param uri The uri to be included
     */
    protected void perform(Context context, String uri)
        throws Exception {

        ServletWebContext swcontext = (ServletWebContext) context;
       
        // Get the underlying request in the case of a multipart wrapper
        HttpServletRequest request = swcontext.getRequest();
        if (request instanceof MultipartRequestWrapper) {
            request = ((MultipartRequestWrapper) request).getRequest();
        }
       
        RequestDispatcher rd =
                swcontext.getContext().getRequestDispatcher(uri);
        rd.forward(request, swcontext.getResponse());
    }
View Full Code Here

    protected boolean isAuthorized(Context context, String[] roles,
                                   ActionConfig mapping) throws Exception {
       
        // Identify the HTTP request object
        ServletWebContext swcontext = (ServletWebContext) context;
        HttpServletRequest request = swcontext.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

     * @param forwardConfig The forward to be performed
     */
    protected void perform(Context context,ForwardConfig forwardConfig)
        throws Exception {

        ServletWebContext swcontext = (ServletWebContext) context;
        String forwardPath = forwardConfig.getPath();
        String uri = null;

        ModuleConfig moduleConfig  = (ModuleConfig) context.get(getModuleConfigKey());
        // Resolve module-relative paths
        if (forwardPath.startsWith("/")) {
            uri = RequestUtils.forwardURL(swcontext.getRequest(),
                                          forwardConfig,
                                          moduleConfig);
        } else {
            uri = forwardPath;
        }

        // Get the underlying request in the case of a multipart wrapper
        HttpServletRequest request = swcontext.getRequest();
        if (request instanceof MultipartRequestWrapper) {
            request = ((MultipartRequestWrapper) request).getRequest();
        }

        // Perform redirect or forward
        if (forwardConfig.getRedirect()) {
            if (uri.startsWith("/")) {
                uri = request.getContextPath() + uri;
            }
            swcontext.getResponse().sendRedirect
                (swcontext.getResponse().encodeRedirectURL(uri));
        } else {
            RequestDispatcher rd =
                swcontext.getContext().getRequestDispatcher(uri);
            rd.forward(request, swcontext.getResponse());
        }

    }
View Full Code Here

        // Wrap the request in the case of a multipart request
        request = processMultipart(request);
       
        // Create and populate a Context for this request
        ServletWebContext context = new ServletWebContext();
        context.initialize(getServletContext(), request, response);
        context.put(Constants.CATALOG_KEY,
                    this.catalog);
        context.put(Constants.ACTION_SERVLET_KEY,
                    this.servlet);
        context.put(Constants.MODULE_CONFIG_KEY,
                    this.moduleConfig);

        // Create and execute the command.
        Command command = this.catalog.getCommand("servlet-standard");
        try {
            if (log.isDebugEnabled()) {
                log.debug("Using processing chain for this request");
            }
            command.execute(context);
        } catch (Exception e) {
            // Execute the exception processing chain??
            throw new ServletException(e);
        }

        // Release the context.
        context.release();
    }
View Full Code Here

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


    protected void setContentType(Context context, String contentType) {

        ServletWebContext swcontext = (ServletWebContext) context;
        HttpServletResponse response = swcontext.getResponse();
       
        response.setContentType(contentType);

    }
View Full Code Here

    protected void populate(Context context,
                         ActionConfig actionConfig,
                         ActionForm actionForm) throws Exception
    {
        ServletWebContext swcontext = (ServletWebContext) context;
        RequestUtils.populate(actionForm, actionConfig.getPrefix(), actionConfig.getSuffix(), swcontext.getRequest());
    }
View Full Code Here

    protected void reset(Context context,
                         ActionConfig actionConfig,
                         ActionForm actionForm) {

        ServletWebContext swcontext = (ServletWebContext) context;
        actionForm.reset((ActionMapping) actionConfig, swcontext.getRequest());

        // Set the multipart class
        if (actionConfig.getMultipartClass() != null) {
            swcontext.getRequestScope().put(Globals.MULTIPART_KEY,
                                 actionConfig.getMultipartClass());
        }

    }
View Full Code Here

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


    protected String getPath(Context context) {

        ServletWebContext swcontext = (ServletWebContext) context;
        HttpServletRequest request = swcontext.getRequest();
        String path = null;
        boolean extension = false;

        // For prefix matching, match on the path info
        path = (String) request.getAttribute(Constants.INCLUDE_PATH_INFO);
        if (path == null) {
            path = request.getPathInfo();
        }

        // For extension matching, match on the servlet path
        if (path == null) {
            path =
                (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
            if (path == null) {
                path = request.getServletPath();
            }
            if (path == null) {
                throw new IllegalArgumentException
                    ("No path information in request");
            }
            extension = true;
        }

        // Strip the module prefix and extension (if any)
        ModuleConfig moduleConfig = (ModuleConfig)
            swcontext.get(getModuleConfigKey());
        String prefix = moduleConfig.getPrefix();
        if (!path.startsWith(prefix)) {
            throw new IllegalArgumentException("Path does not start with '" +
                                               prefix + "'");
        }
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

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.