@Test public void testExecCommandInvalidParam() throws Exception { TestWorkItemManager manager = new TestWorkItemManager(); WorkItemImpl workItem = new WorkItemImpl(); ExecWorkItemHandler handler = new ExecWorkItemHandler(); handler.setLogThrownException(true); handler.executeWorkItem(workItem, manager); assertNotNull(manager.getResults()); assertEquals(0, manager.getResults().size()); }
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String command = (String) workItem.getParameter("Command"); List<String> arguments = (List<String>) workItem.getParameter("Arguments"); Map<String, Object> results = new HashMap<>(); CommandLine commandLine = CommandLine.parse(command); if (arguments != null && arguments.size() > 0) { commandLine.addArguments(arguments.toArray(new String[0]), true); } parsedCommandStr = commandLine.toString(); DefaultExecutor executor = new DefaultExecutor(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); executor.execute(commandLine); results.put(RESULT, outputStream.toString()); outputStream.close(); manager.completeWorkItem(workItem.getId(), results); } catch (Throwable t) { handleException(t); } }
ExecWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String command = (String) workItem.getParameter("Command"); List<String> arguments = (List<String>) workItem.getParameter("Arguments"); Map<String, Object> results = new HashMap<>(); CommandLine commandLine = CommandLine.parse(command); if (arguments != null && arguments.size() > 0) { commandLine.addArguments(arguments.toArray(new String[0]), true); } parsedCommandStr = commandLine.toString(); DefaultExecutor executor = new DefaultExecutor(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); executor.execute(commandLine); results.put(RESULT, outputStream.toString()); outputStream.close(); manager.completeWorkItem(workItem.getId(), results); } catch (Throwable t) { handleException(t); } } }
ExecWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String command = (String) workItem.getParameter("Command"); List<String> arguments = (List<String>) workItem.getParameter("Arguments"); Map<String, Object> results = new HashMap<>(); CommandLine commandLine = CommandLine.parse(command); if (arguments != null && arguments.size() > 0) { commandLine.addArguments(arguments.toArray(new String[0]), true); } parsedCommandStr = commandLine.toString(); DefaultExecutor executor = new DefaultExecutor(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); executor.execute(commandLine); results.put(RESULT, outputStream.toString()); outputStream.close(); manager.completeWorkItem(workItem.getId(), results); } catch (Throwable t) { handleException(t); } }  }
ExecWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String command = (String) workItem.getParameter("Command"); List<String> arguments = (List<String>) workItem.getParameter("Arguments"); Map<String, Object> results = new HashMap<>(); CommandLine commandLine = CommandLine.parse(command); if (arguments != null && arguments.size() > 0) { commandLine.addArguments(arguments.toArray(new String[0]), true); } parsedCommandStr = commandLine.toString(); DefaultExecutor executor = new DefaultExecutor(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); executor.execute(commandLine); results.put(RESULT, outputStream.toString()); outputStream.close(); manager.completeWorkItem(workItem.getId(), results); } catch (Throwable t) { handleException(t); } }  void executeWorkItem(WorkItem workItem,
                                WorkItemManager manager); void abortWorkItem(WorkItem workItem,
                              WorkItemManager manager); String getParsedCommandStr(); }
ExecWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String command = (String) workItem.getParameter("Command"); List<String> arguments = (List<String>) workItem.getParameter("Arguments"); Map<String, Object> results = new HashMap<>(); CommandLine commandLine = CommandLine.parse(command); if (arguments != null && arguments.size() > 0) { commandLine.addArguments(arguments.toArray(new String[0]), true); } parsedCommandStr = commandLine.toString(); DefaultExecutor executor = new DefaultExecutor(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); executor.execute(commandLine); results.put(RESULT, outputStream.toString()); outputStream.close(); manager.completeWorkItem(workItem.getId(), results); } catch (Throwable t) { handleException(t); } }  void executeWorkItem(WorkItem workItem,
                                WorkItemManager manager); void abortWorkItem(WorkItem workItem,
                              WorkItemManager manager); String getParsedCommandStr(); static final String RESULT; }