package org.lapanen.stealth.si.process;

import org.springframework.messaging.MessagingException;

public class OnNokExitValueExceptionThrowingExitValueHandler implements ExitValueResultHandler {

    private int okExitValue = 0;

    @Override
    public ProcessRunResult handleResult(final ProcessRunResult result) {
        if (result.getExitCode().isPresent()) {
            final int exit = result.getExitCode().get();
            if (exit != okExitValue) {
                final StringBuilder exceptionMessageBuilder = new StringBuilder(String.format("Non-OK exit value (%s)", exit));
                if (result.getError().isPresent()) {
                    exceptionMessageBuilder.append(new String(result.getError().get()));
                }
                throw new MessagingException(exceptionMessageBuilder.toString());
            }
        } else {
            if (result.getThrowable().isPresent()) {
                throw new MessagingException("No exit value", result.getThrowable().get());
            } else {
                throw new MessagingException("No exit value and no Throwable attached");
            }
        }
        return result;
    }

    public void setOkExitValue(final int okExitValue) {
        this.okExitValue = okExitValue;
    }
}

@@ -224,16 +224,324 @@
 e = 0;%0A%0A
+    /**%0A     * @param result%0A     *%0A     * @return the original result%0A     *%0A     * @throws org.springframework.messaging.MessagingException%0A     *         if the %7B@code result%7D's %7B@link ProcessRunResult#getExitCode()%7D is not present, or not the same%0A     *         as %7B@link #setOkExitValue(int)%7D.%0A     */%0A
     @Ove

Add javadoc.