Search in sources :

Example 71 with PipeRunResult

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

the class KeyTransformer method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String cacheKey = keyTransformer.transformKey((String) input, session);
    Cache cache = ibisCacheManager.getCache(cacheName);
    if (cache.remove("r" + cacheKey) && cache.remove("s" + cacheKey)) {
        log.debug("removed cache key [" + cacheKey + "] from cache [" + cacheName + "]");
    } else {
        log.warn("could not find cache key [" + cacheKey + "] to remove from cache [" + cacheName + "]");
    }
    return new PipeRunResult(getForward(), input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Cache(net.sf.ehcache.Cache)

Example 72 with PipeRunResult

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

the class BatchFileTransformerPipe method doPipe.

/**
 * Open a reader for the file named according the input messsage and
 * transform it.
 * Move the input file to a done directory when transformation is finished
 * and return the names of the generated files.
 *
 * @see nl.nn.adapterframework.core.IPipe#doPipe(java.lang.Object, nl.nn.adapterframework.core.IPipeLineSession)
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (input == null) {
        throw new PipeRunException(this, "got null input instead of String containing filename");
    }
    if (!(input instanceof String)) {
        throw new PipeRunException(this, "expected String containing filename as input, got [" + ClassUtils.nameOf(input) + "], value [" + input + "]");
    }
    String filename = input.toString();
    File file = new File(filename);
    try {
        PipeRunResult result = super.doPipe(file, session);
        try {
            FileUtils.moveFileAfterProcessing(file, getMove2dirAfterTransform(), isDelete(), isOverwrite(), getNumberOfBackups());
        } catch (Exception e) {
            log.error(getLogPrefix(session), e);
        }
        return result;
    } catch (PipeRunException e) {
        try {
            FileUtils.moveFileAfterProcessing(file, getMove2dirAfterError(), isDelete(), isOverwrite(), getNumberOfBackups());
        } catch (Exception e2) {
            log.error(getLogPrefix(session) + "Could not move file after exception [" + e2 + "]");
        }
        throw e;
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) File(java.io.File) PipeRunException(nl.nn.adapterframework.core.PipeRunException) FileNotFoundException(java.io.FileNotFoundException)

Example 73 with PipeRunResult

use of nl.nn.adapterframework.core.PipeRunResult 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 74 with PipeRunResult

use of nl.nn.adapterframework.core.PipeRunResult 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 75 with PipeRunResult

use of nl.nn.adapterframework.core.PipeRunResult 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)

Aggregations

PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)89 PipeRunException (nl.nn.adapterframework.core.PipeRunException)65 PipeForward (nl.nn.adapterframework.core.PipeForward)23 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)22 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)21 IOException (java.io.IOException)17 ParameterException (nl.nn.adapterframework.core.ParameterException)14 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)11 Test (org.junit.Test)11 File (java.io.File)10 Map (java.util.Map)10 ParameterList (nl.nn.adapterframework.parameters.ParameterList)8 InputStream (java.io.InputStream)7 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)7 Parameter (nl.nn.adapterframework.parameters.Parameter)6 FileInputStream (java.io.FileInputStream)4 StringReader (java.io.StringReader)4 Iterator (java.util.Iterator)4 StringTokenizer (java.util.StringTokenizer)4 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)4