Package org.apache.commons.chain

Examples of org.apache.commons.chain.Command


        if (log().isInfoEnabled()) {
            log().info(messages.getMessage("filter.finalizing"));
        }

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


     */
    public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException {

      // Define local variables we will need
      Command command = null;
      boolean result = false;

      // Construct and store a new Context for this request
      ShaleWebContext context =
        new ShaleWebContext(this.context,
          (HttpServletRequest) request,
          (HttpServletResponse) response);
      request.setAttribute(CONTEXT_ATTR, context);

      // Invoke the "preprocess" command (if any is defined).  If this
      // command returns true, the response has been completed already
      // so we do NOT invoke the actual application.
      command = catalog.getCommand(COMMAND_PREPROCESS);
      if (command != null) {
          try {
              result = command.execute(context);
          } catch (IOException e) {
              throw e;
          } catch (ServletException e) {
              throw e;
          } catch (Exception e) {
              throw new ServletException(e);
          }
          if (result) {
              // Clean up the stored request attribute
              request.removeAttribute(CONTEXT_ATTR);
              // Bypass calling the remainder of the application
              return;
          }
      }

      // Invoke the remainder of the processing for this request
      // (which will typically be the JSF controller servlet)
      chain.doFilter(request, response);

      // Invoke the "postprocess" command (if any is defined).
      command = catalog.getCommand(COMMAND_POSTPROCESS);
      if (command != null) {
          try {
              command.execute(context);
          } catch (IOException e) {
              throw e;
          } catch (ServletException e) {
              throw e;
          } catch (Exception e) {
View Full Code Here

        } catch (Exception e) {
            throw new ServletException(e);
        }

        // 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);
                }
                throw new ServletException(e);
View Full Code Here

     * @throws Exception on any error
     */
    public boolean execute(ActionContext actionCtx)
        throws Exception {
        if (shouldProcess(actionCtx)) {
            Command command = getCommand(actionCtx);

            if (command != null) {
                return (command.execute(actionCtx));
            }
        }

        return (false);
    }
View Full Code Here

        throws Exception {
        if (LOG.isTraceEnabled()) {
            LOG.trace("execute [" + this + "]");
        }

        Command command = getCommand(context);

        if (command != null) {
            return command.execute(getContext(context));
        } else {
            return false;
        }
    }
View Full Code Here

     * @param context   Our ActionContext
     * @param exception The Exception thrown by another Comamnd in a Chain
     * @return TRUE if there is a Filter to process
     */
    public boolean postprocess(Context context, Exception exception) {
        Command command = getCommand(context);

        if ((command != null) && (command instanceof Filter)) {
            try {
                return ((Filter) command).postprocess(getContext(context),
                    exception);
View Full Code Here

        if (catalog == null) {
            throw new IllegalArgumentException("Cannot find catalog '"
                + catalogName + "'");
        }

        Command command;
        String name = getName();

        if (name == null) {
            name = (String) context.get(getNameKey());
        }
View Full Code Here

        actionCtx.setException(exception);

        // Execute the specified command
        try {
            Command command = lookupExceptionCommand();

            if (command == null) {
                LOG.error("Cannot find exceptionCommand '" + exceptionCommand
                    + "'");
                throw new IllegalStateException(
                    "Cannot find exceptionCommand '" + exceptionCommand + "'");
            }

            if (LOG.isTraceEnabled()) {
                LOG.trace("Calling exceptionCommand '" + exceptionCommand + "'");
            }

            command.execute(context);
        } catch (Exception e) {
            LOG.warn("Exception from exceptionCommand '" + exceptionCommand
                + "'", e);
            throw new IllegalStateException("Exception chain threw exception");
        }
View Full Code Here

        throw new IllegalArgumentException("Duplicate Catalog name found: " + catalog.getName());
      }
      catMap.put(catalog.getName(), catalog);

      for (String commandName : catalog.getCommandNames()) {
        final Command command = catalog.getCommand(commandName);
        Assert.notNull(command);
        cmdMap.put(new CommandKey(catalog.getName(), commandName), command);
      }
    }
    catalogs = null; // no longer needed
View Full Code Here

         throw new ServletException("Path undefined " + request.getParameter("path") + " Request: "
            + request.getRequestURI());

      try
      {
         Command cmd;
         if (catalogName == null)
            cmd = commandService.getCatalog().getCommand("displayResource");
         else
            cmd = commandService.getCatalog(catalogName).getCommand("displayResource");

         if (cmd == null)
            throw new Exception("No 'displayResource' command found");
         ctx.put("path", currentPath);
         ctx.put("cache-control-max-age", getServletConfig().getInitParameter("cache-control-max-age"));
         cmd.execute(ctx);
      }
      catch (Exception e)
      {
         e.printStackTrace();
         throw new ServletException(e);
View Full Code Here

TOP

Related Classes of org.apache.commons.chain.Command

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.