Example usage for org.apache.commons.chain.web.servlet ServletWebContext ServletWebContext

List of usage examples for org.apache.commons.chain.web.servlet ServletWebContext ServletWebContext

Introduction

In this page you can find the example usage for org.apache.commons.chain.web.servlet ServletWebContext ServletWebContext.

Prototype

public ServletWebContext(ServletContext context, HttpServletRequest request, HttpServletResponse response) 

Source Link

Document

Construct a ServletWebContext instance that is initialized with the specified Servlet API objects.

Usage

From source file:com.liulangf.pattern.gof.behavioral.chain.jakarta.simple.ExampleServlet.java

/**
 * <p>Configure a {@link ServletWebContext} for the current request, and
 * pass it to the <code>execute()</code> method of the specified
 * {@link Command}, loaded from our configured {@link Catalog}.</p>
 *
 * @param request The request we are processing
 * @param response The response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet exception occurs
 *//* w  w  w  . java  2  s  .  c  o  m*/
public void service(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    CatalogFactory factory = CatalogFactory.getInstance();
    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);
    }

}

From source file:org.apache.struts.chain.contexts.ServletActionContext.java

/**
 * <p> Instantiate this Context for a given ServletContext,
 * HttpServletRequest, and HttpServletResponse. </p>
 *
 * @param context  The instant ServletContext
 * @param request  The instant HttpServletRequest
 * @param response The instant HttpServletResponse
 *///from w ww .  j a va2 s . c  om
public ServletActionContext(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
    this(new ServletWebContext(context, request, response));
}

From source file:org.apache.struts.chain.legacy.ChainAction.java

/**
 * <p>Delegate to the command chain specified in our configuration.</p>
 *
 * @param mapping <code>ActionMapping</code> configuring this action
 * @param form <code>ActionForm</code> for this request (if any)
 * @param request <code>HttpServletRequest</code> we are processing
 * @param response <code>HttpServletResponse</code> we are creating
 */// w  ww  . ja va 2  s.  co m
public ActionForward execute(ActionMapping mapping, ActionForm form, 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;

}

From source file:org.apache.struts.chain.legacy.DispatchAction.java

/**
 * <p>Delegate to the command chain specified in our configuration.</p>
 *
 * @param mapping <code>ActionMapping</code> configuring this action
 * @param form <code>ActionForm</code> for this request (if any)
 * @param request <code>HttpServletRequest</code> we are processing
 * @param response <code>HttpServletResponse</code> we are creating
 *//*from  ww  w. ja  v a2s. com*/
public ActionForward execute(ActionMapping mapping, ActionForm form, 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;

}