Search in sources :

Example 1 with FixedForwardPipe

use of nl.nn.adapterframework.pipes.FixedForwardPipe in project iaf by ibissource.

the class PipeLine method configure.

/**
 * Configures the pipes of this Pipeline and does some basic checks. It also
 * registers the <code>PipeLineSession</code> object at the pipes.
 * @see IPipe
 */
public void configure() throws ConfigurationException {
    INamedObject owner = getOwner();
    IAdapter adapter = null;
    if (owner instanceof IAdapter) {
        adapter = (IAdapter) owner;
    }
    if (cache != null) {
        cache.configure(owner.getName() + "-Pipeline");
    }
    for (int i = 0; i < pipes.size(); i++) {
        IPipe pipe = getPipe(i);
        log.debug("Pipeline of [" + owner.getName() + "] configuring Pipe [" + pipe.getName() + "]");
        // forward is defined, it is not overwritten by the globals
        for (String gfName : globalForwards.keySet()) {
            PipeForward pipeForward = globalForwards.get(gfName);
            pipe.registerForward(pipeForward);
        }
        if (pipe instanceof FixedForwardPipe) {
            FixedForwardPipe ffpipe = (FixedForwardPipe) pipe;
            if (ffpipe.findForward("success") == null) {
                int i2 = i + 1;
                if (i2 < pipes.size()) {
                    String nextPipeName = getPipe(i2).getName();
                    PipeForward pf = new PipeForward();
                    pf.setName("success");
                    pf.setPath(nextPipeName);
                    pipe.registerForward(pf);
                } else {
                    PipeLineExit plexit = findExitByState("success");
                    if (plexit != null) {
                        PipeForward pf = new PipeForward();
                        pf.setName("success");
                        pf.setPath(plexit.getPath());
                        pipe.registerForward(pf);
                    }
                }
            }
        }
        configure(pipe);
    }
    if (pipeLineExits.size() < 1) {
        throw new ConfigurationException("no PipeLine Exits specified");
    }
    if (this.firstPipe == null) {
        throw new ConfigurationException("no firstPipe defined");
    }
    if (getPipe(firstPipe) == null) {
        throw new ConfigurationException("no pipe found for firstPipe [" + firstPipe + "]");
    }
    IPipe inputValidator = getInputValidator();
    IPipe outputValidator = getOutputValidator();
    if (inputValidator != null && outputValidator == null && inputValidator instanceof IDualModeValidator) {
        outputValidator = ((IDualModeValidator) inputValidator).getResponseValidator();
        setOutputValidator(outputValidator);
    }
    if (inputValidator != null) {
        log.debug("Pipeline of [" + owner.getName() + "] configuring InputValidator");
        PipeForward pf = new PipeForward();
        pf.setName("success");
        inputValidator.registerForward(pf);
        inputValidator.setName(INPUT_VALIDATOR_NAME);
        configure(inputValidator);
    }
    if (outputValidator != null) {
        log.debug("Pipeline of [" + owner.getName() + "] configuring OutputValidator");
        PipeForward pf = new PipeForward();
        pf.setName("success");
        outputValidator.registerForward(pf);
        outputValidator.setName(OUTPUT_VALIDATOR_NAME);
        configure(outputValidator);
    }
    if (getInputWrapper() != null) {
        log.debug("Pipeline of [" + owner.getName() + "] configuring InputWrapper");
        PipeForward pf = new PipeForward();
        pf.setName("success");
        getInputWrapper().registerForward(pf);
        getInputWrapper().setName(INPUT_WRAPPER_NAME);
        configure(getInputWrapper());
    }
    if (getOutputWrapper() != null) {
        log.debug("Pipeline of [" + owner.getName() + "] configuring OutputWrapper");
        PipeForward pf = new PipeForward();
        pf.setName("success");
        if (getOutputWrapper() instanceof AbstractPipe && adapter instanceof Adapter) {
            ((AbstractPipe) getOutputWrapper()).setRecoverAdapter(((Adapter) adapter).isRecover());
        }
        getOutputWrapper().registerForward(pf);
        getOutputWrapper().setName(OUTPUT_WRAPPER_NAME);
        if (getOutputWrapper() instanceof EsbSoapWrapperPipe) {
            EsbSoapWrapperPipe eswPipe = (EsbSoapWrapperPipe) getOutputWrapper();
            boolean stop = false;
            Iterator<IReceiver> recIt = adapter.getReceiverIterator();
            if (recIt.hasNext()) {
                while (recIt.hasNext() && !stop) {
                    IReceiver receiver = recIt.next();
                    if (receiver instanceof ReceiverBase) {
                        ReceiverBase rb = (ReceiverBase) receiver;
                        IListener listener = rb.getListener();
                        try {
                            if (eswPipe.retrievePhysicalDestinationFromListener(listener)) {
                                stop = true;
                            }
                        } catch (JmsException e) {
                            throw new ConfigurationException(e);
                        }
                    }
                }
            }
        }
        configure(getOutputWrapper());
    }
    requestSizeStats = new SizeStatisticsKeeper("- pipeline in");
    if (isTransacted() && getTransactionTimeout() > 0) {
        String systemTransactionTimeout = Misc.getSystemTransactionTimeout();
        if (systemTransactionTimeout != null && StringUtils.isNumeric(systemTransactionTimeout)) {
            int stt = Integer.parseInt(systemTransactionTimeout);
            if (getTransactionTimeout() > stt) {
                ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                String msg = "Pipeline of [" + owner.getName() + "] has a transaction timeout [" + getTransactionTimeout() + "] which exceeds the system transaction timeout [" + stt + "]";
                configWarnings.add(log, msg);
            }
        }
    }
    int txOption = this.getTransactionAttributeNum();
    if (log.isDebugEnabled())
        log.debug("creating TransactionDefinition for transactionAttribute [" + getTransactionAttribute() + "], timeout [" + getTransactionTimeout() + "]");
    txDef = SpringTxManagerProxy.getTransactionDefinition(txOption, getTransactionTimeout());
    log.debug("Pipeline of [" + owner.getName() + "] successfully configured");
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) EsbSoapWrapperPipe(nl.nn.adapterframework.extensions.esb.EsbSoapWrapperPipe) ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) JmsException(nl.nn.adapterframework.jms.JmsException) SizeStatisticsKeeper(nl.nn.adapterframework.statistics.SizeStatisticsKeeper) ICacheAdapter(nl.nn.adapterframework.cache.ICacheAdapter) AbstractPipe(nl.nn.adapterframework.pipes.AbstractPipe) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) FixedForwardPipe(nl.nn.adapterframework.pipes.FixedForwardPipe)

Example 2 with FixedForwardPipe

use of nl.nn.adapterframework.pipes.FixedForwardPipe 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)

Aggregations

FixedForwardPipe (nl.nn.adapterframework.pipes.FixedForwardPipe)2 InputStream (java.io.InputStream)1 StringTokenizer (java.util.StringTokenizer)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 ICacheAdapter (nl.nn.adapterframework.cache.ICacheAdapter)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 ConfigurationWarnings (nl.nn.adapterframework.configuration.ConfigurationWarnings)1 IExtendedPipe (nl.nn.adapterframework.core.IExtendedPipe)1 INamedObject (nl.nn.adapterframework.core.INamedObject)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 EsbSoapWrapperPipe (nl.nn.adapterframework.extensions.esb.EsbSoapWrapperPipe)1 JmsException (nl.nn.adapterframework.jms.JmsException)1 AbstractPipe (nl.nn.adapterframework.pipes.AbstractPipe)1 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)1 SizeStatisticsKeeper (nl.nn.adapterframework.statistics.SizeStatisticsKeeper)1 CompactSaxHandler (nl.nn.adapterframework.util.CompactSaxHandler)1