Search in sources :

Example 6 with PipeRunResult

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

the class XmlIf method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String forward = "";
    PipeForward pipeForward = null;
    String sInput;
    if (StringUtils.isEmpty(getSessionKey())) {
        if (input == null) {
            sInput = "";
        } else {
            sInput = input.toString();
        }
    } else {
        log.debug(getLogPrefix(session) + "taking input from sessionKey [" + getSessionKey() + "]");
        sInput = (String) session.get(getSessionKey());
    }
    if (tp != null) {
        try {
            forward = tp.transform(sInput, null, isNamespaceAware());
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + "cannot evaluate expression", e);
        }
    } else {
        if (StringUtils.isEmpty(expressionValue)) {
            if (StringUtils.isEmpty(sInput)) {
                forward = elseForwardName;
            } else {
                forward = thenForwardName;
            }
        } else {
            if (sInput.equals(expressionValue)) {
                forward = thenForwardName;
            } else {
                forward = elseForwardName;
            }
        }
    }
    log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
    pipeForward = findForward(forward);
    if (pipeForward == null) {
        throw new PipeRunException(this, getLogPrefix(null) + "cannot find forward or pipe named [" + forward + "]");
    }
    log.debug(getLogPrefix(session) + "resolved forward [" + forward + "] to path [" + pipeForward.getPath() + "]");
    return new PipeRunResult(pipeForward, input);
}
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) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 7 with PipeRunResult

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

the class XmlSwitch method doPipe.

/**
 * This is where the action takes place, the switching is done. Pipes may only throw a PipeRunException,
 * to be handled by the caller of this object.<br/>
 * As WebLogic has the problem that when an non-well formed XML stream is given to
 * weblogic.xerces the transformer gets corrupt, on an exception the configuration is done again, so that the
 * transformer is re-initialized.
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String forward = "";
    String sInput = (String) input;
    PipeForward pipeForward = null;
    if (StringUtils.isNotEmpty(getSessionKey())) {
        sInput = (String) session.get(sessionKey);
    }
    if (transformerPool != null) {
        ParameterList parameterList = null;
        ParameterResolutionContext prc = new ParameterResolutionContext(sInput, session, isNamespaceAware());
        ;
        try {
            Map parametervalues = null;
            if (getParameterList() != null) {
                parameterList = getParameterList();
                parametervalues = prc.getValueMap(parameterList);
            }
            forward = transformerPool.transform(prc.getInputSource(), parametervalues);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception on transformation", e);
        }
    } else {
        forward = sInput;
    }
    log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
    if (StringUtils.isEmpty(forward) && getEmptyForwardName() != null) {
        throwEvent(XML_SWITCH_FORWARD_FOUND_MONITOR_EVENT);
        pipeForward = findForward(getEmptyForwardName());
    } else {
        if (findForward(forward) != null) {
            throwEvent(XML_SWITCH_FORWARD_FOUND_MONITOR_EVENT);
            pipeForward = findForward(forward);
        } else {
            log.info(getLogPrefix(session) + "determined forward [" + forward + "], which is not defined. Will use [" + getNotFoundForwardName() + "] instead");
            throwEvent(XML_SWITCH_FORWARD_NOT_FOUND_MONITOR_EVENT);
            pipeForward = findForward(getNotFoundForwardName());
        }
    }
    if (pipeForward == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "cannot find forward or pipe named [" + forward + "]");
    }
    return new PipeRunResult(pipeForward, input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) PipeForward(nl.nn.adapterframework.core.PipeForward) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map)

Example 8 with PipeRunResult

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

the class XsltPipe method doPipe.

/**
 * Here the actual transforming is done. Under weblogic the transformer object becomes
 * corrupt when a not-well formed xml was handled. The transformer is then re-initialized
 * via the configure() and start() methods.
 */
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (input == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "got null input");
    }
    if (!(input instanceof String)) {
        throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
    }
    String stringResult = (String) input;
    // ParameterResolutionContext prc = new ParameterResolutionContext((String)input, session, isNamespaceAware());
    try {
        ParameterResolutionContext prc = getInput(stringResult, session);
        Map parametervalues = null;
        ParameterList parameterList = getParameterList();
        if (parameterList != null) {
            parametervalues = prc.getValueMap(parameterList);
        }
        // stringResult = transformerPool.transform(prc.getInputSource(), parametervalues);
        stringResult = transform(transformerPool, prc.getInputSource(), parametervalues);
        if (isSkipEmptyTags()) {
            log.debug(getLogPrefix(session) + " skipping empty tags from result [" + stringResult + "]");
            // URL xsltSource = ClassUtils.getResourceURL( this, skipEmptyTags_xslt);
            // Transformer transformer = XmlUtils.createTransformer(xsltSource);
            // stringResult = XmlUtils.transformXml(transformer, stringResult);
            ParameterResolutionContext prc_SkipEmptyTags = new ParameterResolutionContext(stringResult, session, true, true);
            stringResult = transformerPoolSkipEmptyTags.transform(prc_SkipEmptyTags.getInputSource(), null);
        }
        if (StringUtils.isEmpty(getSessionKey())) {
            return new PipeRunResult(getForward(), stringResult);
        }
        session.put(getSessionKey(), stringResult);
        return new PipeRunResult(getForward(), input);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on transforming input", e);
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 9 with PipeRunResult

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

the class CheckMessageSizePipeProcessor method processPipe.

public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
    checkMessageSize(message, pipeLine, pipe, true);
    PipeRunResult pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
    Object result = pipeRunResult.getResult();
    checkMessageSize(result, pipeLine, pipe, false);
    return pipeRunResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult)

Example 10 with PipeRunResult

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

the class CheckSemaphorePipeProcessor method processPipe.

public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
    PipeRunResult pipeRunResult;
    Semaphore s = getSemaphore(pipe);
    if (s != null) {
        long waitingDuration = 0;
        try {
            // keep waiting statistics for thread-limited pipes
            long startWaiting = System.currentTimeMillis();
            s.acquire();
            waitingDuration = System.currentTimeMillis() - startWaiting;
            StatisticsKeeper sk = pipeLine.getPipeWaitingStatistics(pipe);
            sk.addValue(waitingDuration);
            pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
        } catch (InterruptedException e) {
            throw new PipeRunException(pipe, "Interrupted acquiring semaphore", e);
        } finally {
            s.release();
        }
    } else {
        // no restrictions on the maximum number of threads (s==null)
        pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
    }
    return pipeRunResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) Semaphore(nl.nn.adapterframework.util.Semaphore)

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