protected void executeCommands()

in src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java [203:249]


    protected void executeCommands(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws IOException {
        PrintWriter writer = response.getWriter();
        String currentCommand = null;
        try {
            ResourceResolver resolver = request.getResourceResolver();
            Map<String, Object> bindings = plumber.getBindingsFromRequest(request, true);
            List<String> cmds = getCommandList(request, bindings);
            if (cmds.isEmpty()) {
                writer.println("No command to execute!");
            }
            short idxLine = 0;

            OutputWriter pipeWriter = getWriter(request, response);
            if (pipeWriter == null) {
                pipeWriter = new NopWriter();
            }
            pipeWriter.disableAutoClose();
            pipeWriter.init(request, response);
            for (String command : cmds) {
                if (StringUtils.isNotBlank(command)) {
                    currentCommand = command;
                    PipeBuilder pipeBuilder = parse(resolver, command);
                    Pipe pipe = pipeBuilder.build();
                    bindings.put(CMD_LINE_PREFIX + idxLine++, pipe.getResource().getPath());
                    ModifiableValueMap root = pipe.getResource().adaptTo(ModifiableValueMap.class);
                    if (root != null) {
                        root.put(PN_DESCRIPTION, command);
                    }
                    plumber.execute(resolver, pipe, bindings, pipeWriter, true);
                }
            }
            pipeWriter.ends();
        }  catch (IllegalAccessException | InvocationTargetException e) {
            writer.println("Error executing " + currentCommand);
            e.printStackTrace(writer);
            response.setStatus(SC_INTERNAL_SERVER_ERROR);
            response.sendError(SC_INTERNAL_SERVER_ERROR);
            writer.println(help());
        }
        catch (IllegalArgumentException | JsonException e) {
            writer.println("Error executing " +  currentCommand);
            e.printStackTrace(writer);
            response.setStatus(SC_NOT_ACCEPTABLE);
            response.sendError(SC_NOT_ACCEPTABLE);
            writer.println(help());
        }
    }