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

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



    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

                                   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

     */
    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.ACTION_SERVLET_KEY,
                    this.servlet);
        context.put(Constants.MODULE_CONFIG_KEY,
                    this.moduleConfig);

        // Create and execute the command.
        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

                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {

        // Set up a context for this request
        Context context = new ServletWebContext
            (getServlet().getServletContext(), request, response);
        context.put("mapping", mapping);
        context.put("form", form);

        // Delegate to the specified command
        String name = mapping.getParameter();
        Command command = getCatalog().getCommand(request.getParameter(name));
        command.execute(context); // Ignore return state

        // Return results as appropriate
        Exception exception = null;
        try {
            exception = (Exception) context.get("exception");
            if (exception != null) {
                throw exception;
            }
        } catch (ClassCastException e) {
            ; // It is not an Exception
        }
        ActionForward forward = null;
        try {
            forward = (ActionForward) context.get("forward");
        } catch (ClassCastException e) {
            forward = null; // It is not an ActionForward
        }
        return forward;
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.