Search in sources :

Example 6 with IExtendedPipe

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

the class InputOutputPipeProcessor method processPipe.

public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
    Object preservedObject = message;
    PipeRunResult pipeRunResult = null;
    INamedObject owner = pipeLine.getOwner();
    IExtendedPipe pe = null;
    if (pipe instanceof IExtendedPipe) {
        pe = (IExtendedPipe) pipe;
    }
    if (pe != null) {
        if (StringUtils.isNotEmpty(pe.getGetInputFromSessionKey())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] replacing input for pipe [" + pe.getName() + "] with contents of sessionKey [" + pe.getGetInputFromSessionKey() + "]");
            message = pipeLineSession.get(pe.getGetInputFromSessionKey());
        }
        if (StringUtils.isNotEmpty(pe.getGetInputFromFixedValue())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] replacing input for pipe [" + pe.getName() + "] with fixed value [" + pe.getGetInputFromFixedValue() + "]");
            message = pe.getGetInputFromFixedValue();
        }
        if ((message == null || StringUtils.isEmpty(message.toString())) && StringUtils.isNotEmpty(pe.getEmptyInputReplacement())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] replacing empty input for pipe [" + pe.getName() + "] with fixed value [" + pe.getEmptyInputReplacement() + "]");
            message = pe.getEmptyInputReplacement();
        }
    }
    if (pipe instanceof FixedForwardPipe) {
        FixedForwardPipe ffPipe = (FixedForwardPipe) pipe;
        pipeRunResult = ffPipe.doInitialPipe(message, pipeLineSession);
    }
    if (pipeRunResult == null) {
        pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
    }
    if (pipeRunResult == null) {
        throw new PipeRunException(pipe, "Pipeline of [" + pipeLine.getOwner().getName() + "] received null result from pipe [" + pipe.getName() + "]d");
    }
    if (pe != null) {
        if (pe.isRestoreMovedElements()) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] restoring from compacted result for pipe [" + pe.getName() + "]");
            Object result = pipeRunResult.getResult();
            if (result != null) {
                String resultString = (String) result;
                pipeRunResult.setResult(restoreMovedElements(resultString, pipeLineSession));
            }
        }
        if (pe.getChompCharSize() != null || pe.getElementToMove() != null || pe.getElementToMoveChain() != null) {
            log.debug("Pipeline of adapter [" + owner.getName() + "] compact received message");
            Object result = pipeRunResult.getResult();
            if (result != null) {
                String resultString = (String) result;
                try {
                    InputStream xmlInput = IOUtils.toInputStream(resultString, "UTF-8");
                    CompactSaxHandler handler = new CompactSaxHandler();
                    handler.setChompCharSize(pe.getChompCharSize());
                    handler.setElementToMove(pe.getElementToMove());
                    handler.setElementToMoveChain(pe.getElementToMoveChain());
                    handler.setElementToMoveSessionKey(pe.getElementToMoveSessionKey());
                    handler.setRemoveCompactMsgNamespaces(pe.isRemoveCompactMsgNamespaces());
                    handler.setContext(pipeLineSession);
                    SAXParserFactory parserFactory = XmlUtils.getSAXParserFactory();
                    parserFactory.setNamespaceAware(true);
                    SAXParser saxParser = parserFactory.newSAXParser();
                    try {
                        saxParser.parse(xmlInput, handler);
                        resultString = handler.getXmlString();
                    } catch (Exception e) {
                        log.warn("Pipeline of adapter [" + owner.getName() + "] could not compact received message: " + e.getMessage());
                    }
                    handler = null;
                } catch (Exception e) {
                    throw new PipeRunException(pipe, "Pipeline of [" + pipeLine.getOwner().getName() + "] got error during compacting received message to more compact format: " + e.getMessage());
                }
                pipeRunResult.setResult(resultString);
            }
        }
        if (StringUtils.isNotEmpty(pe.getStoreResultInSessionKey())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] storing result for pipe [" + pe.getName() + "] under sessionKey [" + pe.getStoreResultInSessionKey() + "]");
            Object result = pipeRunResult.getResult();
            pipeLineSession.put(pe.getStoreResultInSessionKey(), result);
        }
        if (pe.isPreserveInput()) {
            pipeRunResult.setResult(preservedObject);
        }
    }
    if (pe != null) {
        if (pe.isWriteToSecLog()) {
            String secLogMsg = "adapter [" + owner.getName() + "] pipe [" + pe.getName() + "]";
            if (pe.getSecLogSessionKeys() != null) {
                String sk = "";
                StringTokenizer st = new StringTokenizer(pe.getSecLogSessionKeys(), " ,;");
                while (st.hasMoreTokens()) {
                    if (sk.length() > 0) {
                        sk = sk + ",";
                    }
                    String key = st.nextToken();
                    Object value = pipeLineSession.get(key);
                    sk = sk + key + "=" + value;
                }
                secLogMsg = secLogMsg + " sessionKeys [" + sk + "]";
            }
            secLog.info(secLogMsg);
        }
    }
    return pipeRunResult;
}
Also used : InputStream(java.io.InputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) StringTokenizer(java.util.StringTokenizer) CompactSaxHandler(nl.nn.adapterframework.util.CompactSaxHandler) INamedObject(nl.nn.adapterframework.core.INamedObject) PipeRunException(nl.nn.adapterframework.core.PipeRunException) SAXParser(javax.xml.parsers.SAXParser) INamedObject(nl.nn.adapterframework.core.INamedObject) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe) FixedForwardPipe(nl.nn.adapterframework.pipes.FixedForwardPipe) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 7 with IExtendedPipe

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

the class LockerPipeProcessor method processPipe.

public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
    PipeRunResult pipeRunResult;
    IExtendedPipe extendedPipe = null;
    Locker locker = null;
    String objectId = null;
    if (pipe instanceof IExtendedPipe) {
        extendedPipe = (IExtendedPipe) pipe;
        locker = extendedPipe.getLocker();
    }
    if (locker != null) {
        try {
            objectId = locker.lock();
        } catch (Exception e) {
            throw new PipeRunException(pipe, "error while setting lock", e);
        }
    }
    if (objectId != null) {
        try {
            pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
        } finally {
            try {
                locker.unlock(objectId);
            } catch (Exception e) {
                throw new PipeRunException(pipe, "error while removing lock", e);
            }
        }
    } else {
        pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
    }
    return pipeRunResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Locker(nl.nn.adapterframework.util.Locker) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe) PipeRunException(nl.nn.adapterframework.core.PipeRunException)

Example 8 with IExtendedPipe

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

the class CheckMessageSizePipeProcessor method checkMessageSize.

private void checkMessageSize(long messageLength, PipeLine pipeLine, IPipe pipe, boolean input) {
    if (messageLength > -1) {
        if (pipe instanceof AbstractPipe) {
            AbstractPipe aPipe = (AbstractPipe) pipe;
            StatisticsKeeper sizeStat = null;
            if (input) {
                if (aPipe.getInSizeStatDummyObject() != null) {
                    sizeStat = pipeLine.getPipeSizeStatistics(aPipe.getInSizeStatDummyObject());
                }
            } else {
                if (aPipe.getOutSizeStatDummyObject() != null) {
                    sizeStat = pipeLine.getPipeSizeStatistics(aPipe.getOutSizeStatDummyObject());
                }
            }
            if (sizeStat != null) {
                sizeStat.addValue(messageLength);
            }
        }
        if (pipeLine.getMessageSizeWarnNum() >= 0 && messageLength >= pipeLine.getMessageSizeWarnNum()) {
            log.warn(String.format("pipe [%s] of adapter [%s], " + (input ? "input" : "result") + " message size [%s] exceeds [%s]", pipe.getName(), pipeLine.getOwner().getName(), Misc.toFileSize(messageLength), Misc.toFileSize(pipeLine.getMessageSizeWarnNum())));
            if (pipe instanceof IExtendedPipe) {
                IExtendedPipe pe = (IExtendedPipe) pipe;
                pe.throwEvent(IExtendedPipe.MESSAGE_SIZE_MONITORING_EVENT);
            }
        }
    }
}
Also used : AbstractPipe(nl.nn.adapterframework.pipes.AbstractPipe) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe)

Example 9 with IExtendedPipe

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

the class MonitoringPipeProcessor method processPipe.

@Override
protected PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, Message message, PipeLineSession pipeLineSession, ThrowingFunction<Message, PipeRunResult, PipeRunException> chain) throws PipeRunException {
    PipeRunResult pipeRunResult = null;
    IExtendedPipe pe = null;
    if (pipe instanceof IExtendedPipe) {
        pe = (IExtendedPipe) pipe;
    }
    long pipeStartTime = System.currentTimeMillis();
    if (log.isDebugEnabled()) {
        // for performance reasons
        StringBuffer sb = new StringBuffer();
        String ownerName = pipeLine.getOwner() == null ? "<null>" : pipeLine.getOwner().getName();
        String pipeName = pipe == null ? "<null>" : pipe.getName();
        String messageId = pipeLineSession == null ? null : pipeLineSession.getMessageId();
        sb.append("Pipeline of adapter [" + ownerName + "] messageId [" + messageId + "] is about to call pipe [" + pipeName + "]");
        boolean lir = AppConstants.getInstance().getBoolean("log.logIntermediaryResults", false);
        if (pipe instanceof AbstractPipe) {
            AbstractPipe ap = (AbstractPipe) pipe;
            if (StringUtils.isNotEmpty(ap.getLogIntermediaryResults())) {
                lir = Boolean.valueOf(ap.getLogIntermediaryResults());
            }
        }
        if (lir) {
            sb.append(" current result " + (message == null ? "<null>" : "(" + message.getClass().getSimpleName() + ") [" + message + "]") + " ");
        }
        log.debug(sb.toString());
    }
    // start it
    long pipeDuration = -1;
    try {
        pipeRunResult = chain.apply(message);
    } catch (PipeRunException pre) {
        if (pe != null) {
            pe.throwEvent(IExtendedPipe.PIPE_EXCEPTION_MONITORING_EVENT);
        }
        throw pre;
    } catch (RuntimeException re) {
        if (pe != null) {
            pe.throwEvent(IExtendedPipe.PIPE_EXCEPTION_MONITORING_EVENT);
        }
        throw new PipeRunException(pipe, "Uncaught runtime exception running pipe '" + (pipe == null ? "null" : pipe.getName()) + "'", re);
    } finally {
        long pipeEndTime = System.currentTimeMillis();
        pipeDuration = pipeEndTime - pipeStartTime;
        StatisticsKeeper sk = pipeLine.getPipeStatistics(pipe);
        if (sk == null) {
            log.warn("Could not get statistics for pipe [+" + pipe.getName() + "]");
        } else {
            sk.addValue(pipeDuration);
        }
        if (pe != null && pe.getDurationThreshold() >= 0 && pipeDuration > pe.getDurationThreshold()) {
            durationLog.info("Pipe [" + pe.getName() + "] of [" + pipeLine.getOwner().getName() + "] duration [" + pipeDuration + "] ms exceeds max [" + pe.getDurationThreshold() + "], message [" + message + "]");
            pe.throwEvent(IExtendedPipe.LONG_DURATION_MONITORING_EVENT);
        }
    }
    return pipeRunResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) AbstractPipe(nl.nn.adapterframework.pipes.AbstractPipe) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe)

Example 10 with IExtendedPipe

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

the class InputOutputPipeProcessor method processPipe.

@Override
protected PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, Message message, PipeLineSession pipeLineSession, ThrowingFunction<Message, PipeRunResult, PipeRunException> chain) throws PipeRunException {
    Object preservedObject = message;
    PipeRunResult pipeRunResult = null;
    INamedObject owner = pipeLine.getOwner();
    IExtendedPipe pe = null;
    if (pipe instanceof IExtendedPipe) {
        pe = (IExtendedPipe) pipe;
    }
    if (pe != null) {
        if (StringUtils.isNotEmpty(pe.getGetInputFromSessionKey())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] replacing input for pipe [" + pe.getName() + "] with contents of sessionKey [" + pe.getGetInputFromSessionKey() + "]");
            message.closeOnCloseOf(pipeLineSession, owner);
            if (!pipeLineSession.containsKey(pe.getGetInputFromSessionKey()) && StringUtils.isEmpty(pe.getEmptyInputReplacement())) {
                throw new PipeRunException(pe, "getInputFromSessionKey [" + pe.getGetInputFromSessionKey() + "] is not present in session");
            }
            message = Message.asMessage(pipeLineSession.get(pe.getGetInputFromSessionKey()));
        }
        if (StringUtils.isNotEmpty(pe.getGetInputFromFixedValue())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] replacing input for pipe [" + pe.getName() + "] with fixed value [" + pe.getGetInputFromFixedValue() + "]");
            message.closeOnCloseOf(pipeLineSession, owner);
            message = new Message(pe.getGetInputFromFixedValue());
        }
        if (Message.isEmpty(message) && StringUtils.isNotEmpty(pe.getEmptyInputReplacement())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] replacing empty input for pipe [" + pe.getName() + "] with fixed value [" + pe.getEmptyInputReplacement() + "]");
            message = new Message(pe.getEmptyInputReplacement());
        }
    }
    if (pipe instanceof FixedForwardPipe) {
        FixedForwardPipe ffPipe = (FixedForwardPipe) pipe;
        pipeRunResult = ffPipe.doInitialPipe(message, pipeLineSession);
    }
    if (pipeRunResult == null) {
        pipeRunResult = chain.apply(message);
    }
    if (pipeRunResult == null) {
        throw new PipeRunException(pipe, "Pipeline of [" + pipeLine.getOwner().getName() + "] received null result from pipe [" + pipe.getName() + "]d");
    }
    if (pe != null) {
        if (pe.isRestoreMovedElements()) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] restoring from compacted result for pipe [" + pe.getName() + "]");
            Message result = pipeRunResult.getResult();
            if (!result.isEmpty()) {
                try {
                    String resultString = result.asString();
                    pipeRunResult.setResult(restoreMovedElements(resultString, pipeLineSession));
                } catch (IOException e) {
                    throw new PipeRunException(pipe, "cannot open stream of result", e);
                }
            }
        }
        if (pe.getChompCharSize() != null || pe.getElementToMove() != null || pe.getElementToMoveChain() != null) {
            log.debug("Pipeline of adapter [" + owner.getName() + "] compact received message");
            Message result = pipeRunResult.getResult();
            if (result != null && !result.isEmpty()) {
                try {
                    String resultString = result.asString();
                    InputStream xmlInput = result.asInputStream();
                    CompactSaxHandler handler = new CompactSaxHandler();
                    handler.setChompCharSize(pe.getChompCharSize());
                    handler.setElementToMove(pe.getElementToMove());
                    handler.setElementToMoveChain(pe.getElementToMoveChain());
                    handler.setElementToMoveSessionKey(pe.getElementToMoveSessionKey());
                    handler.setRemoveCompactMsgNamespaces(pe.isRemoveCompactMsgNamespaces());
                    handler.setContext(pipeLineSession);
                    SAXParserFactory parserFactory = XmlUtils.getSAXParserFactory();
                    parserFactory.setNamespaceAware(true);
                    SAXParser saxParser = parserFactory.newSAXParser();
                    try {
                        saxParser.parse(xmlInput, handler);
                        resultString = handler.getXmlString();
                    } catch (Exception e) {
                        log.warn("Pipeline of adapter [" + owner.getName() + "] could not compact received message: " + e.getMessage());
                    }
                    handler = null;
                    pipeRunResult.setResult(resultString);
                } catch (Exception e) {
                    throw new PipeRunException(pipe, "Pipeline of [" + pipeLine.getOwner().getName() + "] got error during compacting received message to more compact format: " + e.getMessage());
                }
            }
        }
        if (StringUtils.isNotEmpty(pe.getStoreResultInSessionKey())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] storing result for pipe [" + pe.getName() + "] under sessionKey [" + pe.getStoreResultInSessionKey() + "]");
            Message result = pipeRunResult.getResult();
            pipeLineSession.put(pe.getStoreResultInSessionKey(), result);
            if (!pe.isPreserveInput() && !result.isRepeatable()) {
                // when there is a duplicate use of the result (in a sessionKey as well as as the result), then message must be repeatable
                try {
                    result.preserve();
                } catch (IOException e) {
                    throw new PipeRunException(pipe, "Pipeline of [" + pipeLine.getOwner().getName() + "] could not preserve output", e);
                }
            }
        }
        if (pe.isPreserveInput()) {
            pipeRunResult.getResult().closeOnCloseOf(pipeLineSession, owner);
            pipeRunResult.setResult(preservedObject);
        }
    }
    if (pe != null && pe.isWriteToSecLog()) {
        String secLogMsg = "adapter [" + owner.getName() + "] pipe [" + pe.getName() + "]";
        if (pe.getSecLogSessionKeys() != null) {
            String sk = "";
            StringTokenizer st = new StringTokenizer(pe.getSecLogSessionKeys(), " ,;");
            while (st.hasMoreTokens()) {
                if (sk.length() > 0) {
                    sk = sk + ",";
                }
                String key = st.nextToken();
                Object value = pipeLineSession.get(key);
                sk = sk + key + "=" + value;
            }
            secLogMsg = secLogMsg + " sessionKeys [" + sk + "]";
        }
        secLog.info(secLogMsg);
    }
    return pipeRunResult;
}
Also used : Message(nl.nn.adapterframework.stream.Message) InputStream(java.io.InputStream) IOException(java.io.IOException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) StringTokenizer(java.util.StringTokenizer) CompactSaxHandler(nl.nn.adapterframework.util.CompactSaxHandler) INamedObject(nl.nn.adapterframework.core.INamedObject) PipeRunException(nl.nn.adapterframework.core.PipeRunException) SAXParser(javax.xml.parsers.SAXParser) INamedObject(nl.nn.adapterframework.core.INamedObject) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe) FixedForwardPipe(nl.nn.adapterframework.pipes.FixedForwardPipe) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

IExtendedPipe (nl.nn.adapterframework.core.IExtendedPipe)11 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)8 PipeRunException (nl.nn.adapterframework.core.PipeRunException)6 INamedObject (nl.nn.adapterframework.core.INamedObject)4 AbstractPipe (nl.nn.adapterframework.pipes.AbstractPipe)4 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)4 InputStream (java.io.InputStream)2 StringTokenizer (java.util.StringTokenizer)2 SAXParser (javax.xml.parsers.SAXParser)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 FixedForwardPipe (nl.nn.adapterframework.pipes.FixedForwardPipe)2 CompactSaxHandler (nl.nn.adapterframework.util.CompactSaxHandler)2 Locker (nl.nn.adapterframework.util.Locker)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Configuration (nl.nn.adapterframework.configuration.Configuration)1