Package org.apache.commons.chain

Examples of org.apache.commons.chain.Command


   }

   public void testGetNodes() throws Exception
   {

      Command c = cservice.getCatalog().getCommand("getNodes");
      ctx.put("currentNode", "/");
      c.execute(ctx);

      assertTrue(ctx.get("result") instanceof NodeIterator);
      NodeIterator nodes = (NodeIterator)ctx.get("result");

      assertTrue(nodes.getSize() > 0);
View Full Code Here


   }

   public void testAddResourceFile() throws Exception
   {

      Command c = cservice.getCatalog().getCommand("addResourceFile");
      ctx.put("currentNode", "/");
      ctx.put("path", "resource");
      ctx.put("data", "Node data");
      ctx.put("mimeType", "text/html");

      c.execute(ctx);

      Command save = cservice.getCatalog().getCommand("save");
      ctx.put("path", "/");
      save.execute(ctx);

   }
View Full Code Here

   }

   public void testGetNodeChain() throws Exception
   {
      Command cmd = cservice.getCatalog().getCommand("retrieveNodeCommand");
      ctx.put("currentNode", "/");
      ctx.put("path", "foo");
      cmd.execute(ctx);
   }
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(); //NOSONAR
         throw new ServletException(e);
View Full Code Here

        // init context
        MgnlContext.setInstance(new SimpleContext(MgnlContext.getSystemContext()));
        String catalogName = (String) jobData.get(SchedulerConsts.CONFIG_JOB_COMMAND_CATALOG);
        String cmdName = (String) jobData.get(SchedulerConsts.CONFIG_JOB_COMMAND);

        Command cmd = CommandsManager.getInstance().getCommand(catalogName, cmdName);
        if (cmd == null)
        {
            log.error("can't find command {} for job in catalog {}", cmdName, catalogName);
            return;
        }

        Context ctx = new SimpleContext();
        // copy data, else the jobs context could get manipluated by the commands
        ctx.putAll((Map) jobData.get(SchedulerConsts.CONFIG_JOB_PARAMS));

        JobDefinition jd = null;
        try
        {
            jd = jobDefinitionManager.getJobDefinitionByName(jobName);
            if (jd != null)
            {
                jd.setTerminatedWithError(false);
            }
            cmd.execute(ctx);
            log.info("job executed successfully [{}]", jobName);

        }
        catch (Exception e)
        {
View Full Code Here

    final String[] catalogNames = commandService.getCommandCatalogNames();
    for (final String catalogName : catalogNames) {
      final CommandCatalog catalog = commandService.getCommandCatalog(catalogName);
      final String[] commandNames = catalog.getCommandNames();
      for (final String command : commandNames) {
        final Command cmd = catalog.getCommand(command);
        if (cmd instanceof WebRequestCommand) {
          final String uri = String.format("/command-service/%s/%s", catalogName, command);
          final CommandKey key = new CommandKey(catalogName, command);
          map.put(uri, key);
          log.info("WebRequestCommand uri: {}", uri);
View Full Code Here

            return;
        }

        // Identify the Commons Chain chain or command we will be executing
        String commandName = mapCommand(context, resourceId);
        Command command = catalog.getCommand(commandName);
        if (command == null) {
            if (log().isErrorEnabled()) {
                log().error("Cannot find command '" + commandName + "' in catalog '"
                            + catalogName + "' for resource '" + resourceId + "'");
            }
            sendNotFound(context, resourceId);
            context.responseComplete();
            return;
        }

        // Create a new context and pass it to the specified command
        try {
            command.execute(createContext(context, resourceId));
        } catch (Exception e) {
            if (log().isErrorEnabled()) {
                log().error("Exception executing command '" + commandName
                            + "' from catalog '" + catalogName + "' for resource '"
                            + resourceId + "'", e);
View Full Code Here

            FacesContext facesContext = FacesContext.getCurrentInstance();
            ValueBinding vb = facesContext.getApplication().createValueBinding(getName());
            String targetCommand = (String) vb.getValue(facesContext);

            if (targetCommand != null) {
               Command command = getCatalog().getCommand(targetCommand);
               if (command != null) {
                   return command.execute(context);
               }
            }
        }
        return super.execute(context);
    }
View Full Code Here

        try {
            catalog = getCatalog();
        } catch (Exception e) {
            log.error(e);
        }
        Command command = catalog
                 .getCommand(Globals.ADD_COMPONENT_COMMAND_NAME);

        try {
            command.execute(clayContext);
        } catch (Exception e) {
            log.error(e);
            throw new RuntimeException(e);
        }
View Full Code Here

        BuilderRuleContext context = new BuilderRuleContext();
        context.setNode(node);
        try {
            Catalog catalog = getCatalog();

            Command command = null;
            if (node.getQname() == null) {
                command = catalog.getCommand(Globals.FIND_DEFAULT_BUILDER_COMMAND_NAME);
            } else {
                String prefix = node.getQname();
                String uri = node.getNamespaceURI(prefix);
                if (uri != null) {
                    command = catalog.getCommand(uri);
                    if (command == null) {
                        FacesContext facesContext = FacesContext.getCurrentInstance();
                        if (facesContext != null) {
                            facesContext.getExternalContext().getRequestMap()
                            .put(Globals.CLAY_CUSTOM_BUILDER_XMLNS, uri);
                        }

                        command = catalog.getCommand(Globals.FIND_UNKNOWN_BUILDER_COMMAND_NAME);
                    }
                } else {
                    command = catalog.getCommand(Globals.FIND_UNKNOWN_BUILDER_COMMAND_NAME);
                }

            }

            command.execute(context);

        } catch (Exception e) {
            log.error(e);
            throw new RuntimeException(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.