Search in sources :

Example 46 with PipeRunResult

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

the class StreamTransformerPipe 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 {
    String streamId = getStreamId(input, session);
    BufferedReader reader = getReader(streamId, input, session);
    if (reader == null) {
        throw new PipeRunException(this, "could not obtain reader for [" + streamId + "]");
    }
    Object transformationResult = null;
    ParameterResolutionContext prc = new ParameterResolutionContext("", session);
    try {
        transformationResult = transform(streamId, reader, session, prc);
    } finally {
        if (isCloseInputstreamOnExit()) {
            try {
                reader.close();
            } catch (IOException e) {
                log.warn(getLogPrefix(session) + "Exception closing reader", e);
            }
        }
    }
    return new PipeRunResult(getForward(), transformationResult);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) BufferedReader(java.io.BufferedReader) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 47 with PipeRunResult

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

the class SoapWrapperPipe method doPipe.

@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String result;
    try {
        if ("wrap".equalsIgnoreCase(getDirection())) {
            String payload = input.toString();
            if (rootTp != null) {
                payload = rootTp.transform(payload, null, true);
            }
            if (outputNamespaceTp != null) {
                payload = outputNamespaceTp.transform(payload, null, true);
            }
            ParameterResolutionContext prc = null;
            Map parameterValues = null;
            if (getParameterList() != null && (soapHeaderTp != null || soapBodyTp != null)) {
                prc = new ParameterResolutionContext(payload, session);
                parameterValues = prc.getValueMap(getParameterList());
            }
            String soapHeader = null;
            if (soapHeaderTp != null) {
                soapHeader = soapHeaderTp.transform(prc.getInputSource(), parameterValues);
            } else {
                if (StringUtils.isNotEmpty(getSoapHeaderSessionKey())) {
                    soapHeader = (String) session.get(getSoapHeaderSessionKey());
                }
            }
            if (soapBodyTp != null) {
                payload = soapBodyTp.transform(prc.getInputSource(), parameterValues);
            }
            result = wrapMessage(payload, soapHeader);
        } else {
            result = unwrapMessage(input.toString());
            if (StringUtils.isEmpty(result)) {
                throw new PipeRunException(this, getLogPrefix(session) + "SOAP Body is empty or message is not a SOAP Message");
            }
            if (!isIgnoreSoapFault() && soapWrapper.getFaultCount(input.toString()) > 0) {
                throw new PipeRunException(this, getLogPrefix(session) + "SOAP Body contains SOAP Fault");
            }
            if (StringUtils.isNotEmpty(getSoapHeaderSessionKey())) {
                String soapHeader = soapWrapper.getHeader(input.toString());
                session.put(getSoapHeaderSessionKey(), soapHeader);
            }
            if (removeOutputNamespacesTp != null) {
                result = removeOutputNamespacesTp.transform(result, null, true);
            }
            if (removeUnusedOutputNamespacesTp != null) {
                result = removeUnusedOutputNamespacesTp.transform(result, null, true);
            }
            if (rootTp != null) {
                result = rootTp.transform(result, null, true);
            }
        }
    } catch (Exception t) {
        throw new PipeRunException(this, getLogPrefix(session) + " Unexpected exception during (un)wrapping ", t);
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) 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) SOAPException(javax.xml.soap.SOAPException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 48 with PipeRunResult

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

the class MonitoringPipeProcessor method processPipe.

public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) 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();
        sb.append("Pipeline of adapter [" + ownerName + "] messageId [" + messageId + "] is about to call pipe [" + pipeName + "]");
        boolean lir = false;
        if (AppConstants.getInstance().getProperty("log.logIntermediaryResults") != null) {
            if (AppConstants.getInstance().getProperty("log.logIntermediaryResults").equalsIgnoreCase("true")) {
                lir = true;
            }
        }
        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 + "] ");
        }
        log.debug(sb.toString());
    }
    // start it
    long pipeDuration = -1;
    try {
        pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
    } 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) {
            if (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 49 with PipeRunResult

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

the class LdapChallengePipe method doPipe.

/**
 * Checks to see if the supplied parameteres of the pipe can login to LDAP
 * @see nl.nn.adapterframework.core.IPipe#doPipe(java.lang.Object, nl.nn.adapterframework.core.PipeLineSession)
 */
public PipeRunResult doPipe(Object msg, IPipeLineSession pls) throws PipeRunException {
    LdapSender ldapSender = new LdapSender();
    String ldapProviderURL;
    String credentials;
    String principal;
    ParameterResolutionContext prc;
    try {
        prc = new ParameterResolutionContext((String) msg, pls);
        Map paramMap = prc.getValueMap(getParameterList());
        if (StringUtils.isNotEmpty(getLdapProviderURL())) {
            ldapProviderURL = getLdapProviderURL();
        } else {
            ldapProviderURL = (String) paramMap.get("ldapProviderURL");
        }
        credentials = (String) paramMap.get("credentials");
        principal = (String) paramMap.get("principal");
    } catch (ParameterException e) {
        throw new PipeRunException(this, "Invalid parameter", e);
    }
    ldapSender.setErrorSessionKey(getErrorSessionKey());
    if (StringUtils.isEmpty(ldapProviderURL)) {
        throw new PipeRunException(this, "ldapProviderURL is empty");
    }
    if (StringUtils.isEmpty(principal)) {
        // throw new PipeRunException(this, "principal is empty");
        handleError(ldapSender, prc, 34, "Principal is Empty");
        return new PipeRunResult(findForward("invalid"), msg);
    }
    if (StringUtils.isEmpty(credentials)) {
        // throw new PipeRunException(this, "credentials are empty");
        handleError(ldapSender, prc, 49, "Credentials are Empty");
        return new PipeRunResult(findForward("invalid"), msg);
    }
    Parameter dummyEntryName = new Parameter();
    dummyEntryName.setName("entryName");
    dummyEntryName.setValue(principal);
    ldapSender.addParameter(dummyEntryName);
    ldapSender.setUsePooling(false);
    ldapSender.setLdapProviderURL(ldapProviderURL);
    if (StringUtils.isNotEmpty(getInitialContextFactoryName())) {
        ldapSender.setInitialContextFactoryName(getInitialContextFactoryName());
    }
    ldapSender.setPrincipal(principal);
    ldapSender.setCredentials(credentials);
    ldapSender.setOperation(LdapSender.OPERATION_READ);
    try {
        log.debug("Looking up context for principal [" + principal + "]");
        ldapSender.configure();
        log.debug("Succesfully looked up context for principal [" + principal + "]");
    } catch (Exception e) {
        if (StringUtils.isNotEmpty(getErrorSessionKey())) {
            ldapSender.storeLdapException(e, prc);
        } else {
            log.warn("LDAP error looking up context for principal [" + principal + "]", e);
        }
        return new PipeRunResult(findForward("invalid"), msg);
    }
    return new PipeRunResult(findForward("success"), msg);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 50 with PipeRunResult

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

the class CounterSwitchPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String forward = "";
    PipeForward pipeForward = null;
    StatisticsKeeper sk = getPipeLine().getPipeStatistics(this);
    if (sk != null) {
        long count = sk.getCount();
        forward = "" + (getDivisor() - (count % getDivisor()));
    }
    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) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) PipeForward(nl.nn.adapterframework.core.PipeForward)

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