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

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


                                 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
        Command command = getCatalog().getCommand(mapping.getParameter());
        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


    // ------------------------------------------------------- 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

   *            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

     */
    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()) {
View Full Code Here

        }

        // Execute the "destroy" command in the "shale" catalog (if any)
        Command command = catalog.getCommand(COMMAND_DESTROY);
        if (command != null) {
            WebContext webContext = new ServletWebContext(context, null, null);
            try {
                command.execute(webContext);
            } catch (Exception e) {
                if (log().isErrorEnabled()) {
                    log().error(messages.getMessage("filter.destroyException"), e);
View Full Code Here

        }

        // Execute the "init" command in the "shale" catalog (if any)
        Command command = catalog.getCommand(COMMAND_INIT);
        if (command != null) {
            WebContext webContext = new ServletWebContext(context, null, null);
            try {
                command.execute(webContext);
            } catch (Exception e) {
                if (log().isErrorEnabled()) {
                    log().error(messages.getMessage("filter.initException"), e);
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

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.