Search in sources :

Example 81 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class TransactionAttributePipeProcessor method processPipe.

public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
    PipeRunResult pipeRunResult;
    int txOption;
    int txTimeout = 0;
    if (pipe instanceof HasTransactionAttribute) {
        HasTransactionAttribute taPipe = (HasTransactionAttribute) pipe;
        txOption = taPipe.getTransactionAttributeNum();
        txTimeout = taPipe.getTransactionTimeout();
    } else {
        txOption = TransactionDefinition.PROPAGATION_SUPPORTS;
    }
    // TransactionStatus txStatus = txManager.getTransaction(SpringTxManagerProxy.getTransactionDefinition(txOption,txTimeout));
    IbisTransaction itx = new IbisTransaction(txManager, SpringTxManagerProxy.getTransactionDefinition(txOption, txTimeout), "pipe [" + pipe.getName() + "]");
    TransactionStatus txStatus = itx.getStatus();
    try {
        TimeoutGuard tg = new TimeoutGuard("pipeline of adapter [" + pipeLine.getOwner().getName() + "] running pipe [" + pipe.getName() + "]");
        Throwable tCaught = null;
        try {
            tg.activateGuard(txTimeout);
            pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
        } catch (Throwable t) {
            tCaught = t;
            throw tCaught;
        } finally {
            if (tg.cancel()) {
                if (tCaught == null) {
                    throw new PipeRunException(pipe, tg.getDescription() + " was interrupted");
                } else {
                    log.warn("Thread interrupted, but propagating other caught exception of type [" + ClassUtils.nameOf(tCaught) + "]");
                }
            }
        }
    } catch (Throwable t) {
        log.debug("setting RollBackOnly for pipe [" + pipe.getName() + "] after catching exception");
        txStatus.setRollbackOnly();
        if (t instanceof Error) {
            throw (Error) t;
        } else if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        } else if (t instanceof PipeRunException) {
            throw (PipeRunException) t;
        } else {
            throw new PipeRunException(pipe, "Caught unknown checked exception", t);
        }
    } finally {
        // txManager.commit(txStatus);
        itx.commit();
    }
    return pipeRunResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) IbisTransaction(nl.nn.adapterframework.core.IbisTransaction) HasTransactionAttribute(nl.nn.adapterframework.core.HasTransactionAttribute) PipeRunException(nl.nn.adapterframework.core.PipeRunException) TransactionStatus(org.springframework.transaction.TransactionStatus) TimeoutGuard(nl.nn.adapterframework.task.TimeoutGuard)

Example 82 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class MoveFilePipe method moveFile.

private void moveFile(IPipeLineSession session, File srcFile, File dstFile) throws PipeRunException {
    try {
        if (!dstFile.getParentFile().exists()) {
            if (isCreateDirectory()) {
                if (dstFile.getParentFile().mkdirs()) {
                    log.debug(getLogPrefix(session) + "created directory [" + dstFile.getParent() + "]");
                } else {
                    log.warn(getLogPrefix(session) + "directory [" + dstFile.getParent() + "] could not be created");
                }
            } else {
                log.warn(getLogPrefix(session) + "directory [" + dstFile.getParent() + "] does not exists");
            }
        }
        if (isAppend()) {
            if (FileUtils.appendFile(srcFile, dstFile, getNumberOfAttempts(), getWaitBeforeRetry()) == null) {
                throw new PipeRunException(this, "Could not move file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "]");
            } else {
                srcFile.delete();
                log.info(getLogPrefix(session) + "moved file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "]");
            }
        } else {
            if (!isOverwrite() && getNumberOfBackups() == 0) {
                if (dstFile.exists() && isThrowException()) {
                    throw new PipeRunException(this, "Could not move file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "] because it already exists");
                } else {
                    dstFile = FileUtils.getFreeFile(dstFile);
                }
            }
            if (FileUtils.moveFile(srcFile, dstFile, isOverwrite(), getNumberOfBackups(), getNumberOfAttempts(), getWaitBeforeRetry()) == null) {
                throw new PipeRunException(this, "Could not move file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "]");
            } else {
                log.info(getLogPrefix(session) + "moved file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "]");
            }
        }
    } catch (Exception e) {
        throw new PipeRunException(this, "Error while moving file [" + srcFile.getAbsolutePath() + "] to file [" + dstFile.getAbsolutePath() + "]", e);
    }
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 83 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class PasswordHashPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    Object result;
    PipeForward pipeForward;
    if (StringUtils.isEmpty(getHashSessionKey())) {
        try {
            if (getRoundsSessionKey() == null) {
                result = PasswordHash.createHash(input.toString().toCharArray(), getRounds());
            } else {
                result = PasswordHash.createHash(input.toString().toCharArray(), Integer.valueOf(session.get(getRoundsSessionKey()).toString()));
            }
            pipeForward = getForward();
        } catch (Exception e) {
            throw new PipeRunException(this, "Could not hash password", e);
        }
    } else {
        try {
            result = input;
            if (PasswordHash.validatePassword(input.toString(), (String) session.get(getHashSessionKey()))) {
                pipeForward = getForward();
            } else {
                pipeForward = findForward(FAILURE_FORWARD_NAME);
            }
        } catch (Exception e) {
            throw new PipeRunException(this, "Could not validate password", e);
        }
    }
    return new PipeRunResult(pipeForward, result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 84 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class PutParametersInSession method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    ParameterValueList pvl = null;
    ParameterList parameterList = getParameterList();
    if (parameterList != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        try {
            pvl = prc.getValues(getParameterList());
            if (pvl != null) {
                for (int i = 0; i < parameterList.size(); i++) {
                    Parameter parameter = parameterList.getParameter(i);
                    String pn = parameter.getName();
                    Object pv = parameter.getValue(pvl, prc);
                    session.put(pn, pv);
                    log.debug(getLogPrefix(session) + "stored [" + pv + "] in pipeLineSession under key [" + pn + "]");
                }
            }
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
    }
    return new PipeRunResult(getForward(), input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 85 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class PutSystemDateInSession method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String formattedDate;
    if (isReturnFixedDate()) {
        SimpleDateFormat formatterFrom = new SimpleDateFormat(FORMAT_FIXEDDATETIME);
        String fixedDateTime = (String) session.get(FIXEDDATE_STUB4TESTTOOL_KEY);
        if (StringUtils.isEmpty(fixedDateTime)) {
            fixedDateTime = FIXEDDATETIME;
        }
        Date d;
        try {
            d = formatterFrom.parse(fixedDateTime);
        } catch (ParseException e) {
            throw new PipeRunException(this, "cannot parse fixed date [" + fixedDateTime + "] with format [" + FORMAT_FIXEDDATETIME + "]", e);
        }
        formattedDate = formatter.format(d);
    } else {
        if (sleepWhenEqualToPrevious > -1) {
            // whole virtual machine.
            synchronized (OBJECT) {
                formattedDate = formatter.format(new Date());
                while (formattedDate.equals(previousFormattedDate)) {
                    try {
                        Thread.sleep(sleepWhenEqualToPrevious);
                    } catch (InterruptedException e) {
                    }
                    formattedDate = formatter.format(new Date());
                }
                previousFormattedDate = formattedDate;
            }
        } else {
            formattedDate = formatter.format(new Date());
        }
    }
    session.put(this.getSessionKey(), formattedDate);
    if (log.isDebugEnabled()) {
        log.debug(getLogPrefix(session) + "stored [" + formattedDate + "] in pipeLineSession under key [" + getSessionKey() + "]");
    }
    return new PipeRunResult(getForward(), input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

PipeRunException (nl.nn.adapterframework.core.PipeRunException)101 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)65 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)40 IOException (java.io.IOException)34 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)32 PipeForward (nl.nn.adapterframework.core.PipeForward)20 ParameterException (nl.nn.adapterframework.core.ParameterException)16 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)13 Parameter (nl.nn.adapterframework.parameters.Parameter)12 InputStream (java.io.InputStream)10 File (java.io.File)9 Map (java.util.Map)9 ParameterList (nl.nn.adapterframework.parameters.ParameterList)8 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)7 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)6 PipeStartException (nl.nn.adapterframework.core.PipeStartException)6 ArrayList (java.util.ArrayList)5 ZipInputStream (java.util.zip.ZipInputStream)5 IAdapter (nl.nn.adapterframework.core.IAdapter)5