Search in sources :

Example 31 with PipeForward

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

the class WsdlGeneratorPipe method createValidator.

private EsbSoapValidator createValidator(File xsdFile, String namespace, String root, int rootPosition, int cmhVersion) throws ConfigurationException {
    if (xsdFile != null) {
        EsbSoapValidator esbSoapValidator = new EsbSoapValidator();
        esbSoapValidator.setWarn(false);
        esbSoapValidator.setCmhVersion(cmhVersion);
        if (StringUtils.isEmpty(namespace)) {
            String xsdTargetNamespace = null;
            try {
                TransformerPool tp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource("*/@targetNamespace", "text"));
                xsdTargetNamespace = tp.transform(Misc.fileToString(xsdFile.getPath()), null);
                if (StringUtils.isNotEmpty(xsdTargetNamespace)) {
                    log.debug("found target namespace [" + xsdTargetNamespace + "] in xsd file [" + xsdFile.getName() + "]");
                } else {
                    // default namespace to prevent
                    // "(IllegalArgumentException) The schema attribute isn't supported"
                    xsdTargetNamespace = "urn:wsdlGenerator";
                    log.warn("could not find target namespace in xsd file [" + xsdFile.getName() + "], assuming namespace [" + xsdTargetNamespace + "]");
                }
            } catch (Exception e) {
                throw new ConfigurationException(e);
            }
            if (StringUtils.isEmpty(xsdTargetNamespace)) {
                esbSoapValidator.setSchema(xsdFile.getName());
            } else {
                esbSoapValidator.setSchemaLocation(xsdTargetNamespace + "\t" + xsdFile.getName());
                esbSoapValidator.setAddNamespaceToSchema(true);
            }
        } else {
            esbSoapValidator.setSchemaLocation(namespace + "\t" + xsdFile.getName());
            esbSoapValidator.setAddNamespaceToSchema(true);
        }
        if (StringUtils.isEmpty(root)) {
            String xsdRoot = null;
            try {
                String rootXPath = "*/*[local-name()='element'][" + rootPosition + "]/@name";
                TransformerPool tp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(rootXPath, "text"));
                xsdRoot = tp.transform(Misc.fileToString(xsdFile.getPath()), null);
                if (StringUtils.isNotEmpty(xsdRoot)) {
                    log.debug("found root element [" + xsdRoot + "] in xsd file [" + xsdFile.getName() + "]");
                    esbSoapValidator.setSoapBody(xsdRoot);
                }
            } catch (Exception e) {
                throw new ConfigurationException(e);
            }
        } else {
            esbSoapValidator.setSoapBody(root);
        }
        esbSoapValidator.setForwardFailureToSuccess(true);
        PipeForward pf = new PipeForward();
        pf.setName("success");
        esbSoapValidator.registerForward(pf);
        esbSoapValidator.configure();
        return esbSoapValidator;
    }
    return null;
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeForward(nl.nn.adapterframework.core.PipeForward) TransformerPool(nl.nn.adapterframework.util.TransformerPool) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 32 with PipeForward

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

the class DirectWrapperPipe method doPipeWithTimeoutGuarded.

public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
    String result;
    ParameterValueList pvl = null;
    if (getParameterList() != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        try {
            pvl = prc.getValues(getParameterList());
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
    }
    String destination = getParameterValue(pvl, DESTINATION);
    String cmhVersion = getParameterValue(pvl, CMHVERSION);
    String addOutputNamespace = getParameterValue(pvl, ADDOUTPUTNAMESPACE);
    EsbSoapWrapperPipe eswPipe = new EsbSoapWrapperPipe();
    if (addOutputNamespace != null) {
        if ("on".equalsIgnoreCase(addOutputNamespace)) {
            eswPipe.setAddOutputNamespace(true);
        }
    }
    if (destination != null) {
        Parameter p = new Parameter();
        p.setName(DESTINATION);
        p.setValue(destination);
        eswPipe.addParameter(p);
    }
    if (cmhVersion != null) {
        if (StringUtils.isNumeric(cmhVersion)) {
            eswPipe.setCmhVersion(Integer.parseInt(cmhVersion));
        }
    }
    PipeForward pf = new PipeForward();
    pf.setName("success");
    eswPipe.registerForward(pf);
    try {
        eswPipe.configure();
        PipeRunResult prr = eswPipe.doPipe(input, session);
        result = (String) prr.getResult();
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "Exception on wrapping input", e);
    }
    return result;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 33 with PipeForward

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

Example 34 with PipeForward

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

the class FilenameSwitch method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String forward = "";
    String sInput = (String) input;
    PipeForward pipeForward = null;
    int slashPos = sInput.lastIndexOf('/');
    if (slashPos > 0) {
        sInput = sInput.substring(slashPos + 1);
    }
    slashPos = sInput.lastIndexOf('\\');
    if (slashPos > 0) {
        sInput = sInput.substring(slashPos + 1);
    }
    forward = sInput;
    if (isToLowercase()) {
        forward = forward.toLowerCase();
    }
    log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
    if (findForward(forward) != null)
        pipeForward = findForward(forward);
    else {
        log.info(getLogPrefix(session) + "determined forward [" + forward + "], which is not defined. Will use [" + getNotFoundForwardName() + "] instead");
        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) PipeForward(nl.nn.adapterframework.core.PipeForward)

Example 35 with PipeForward

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

the class FixedResult method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String result = returnString;
    if ((StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) || StringUtils.isNotEmpty(getFileNameSessionKey())) {
        String fileName = null;
        if (StringUtils.isNotEmpty(getFileNameSessionKey())) {
            fileName = (String) session.get(fileNameSessionKey);
        }
        if (fileName == null) {
            if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) {
                fileName = getFileName();
            }
        }
        URL resource = null;
        try {
            resource = ClassUtils.getResourceURL(classLoader, fileName);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception searching for [" + fileName + "]", e);
        }
        if (resource == null) {
            PipeForward fileNotFoundForward = findForward(FILE_NOT_FOUND_FORWARD);
            if (fileNotFoundForward != null) {
                return new PipeRunResult(fileNotFoundForward, input);
            } else {
                throw new PipeRunException(this, getLogPrefix(session) + "cannot find resource [" + fileName + "]");
            }
        }
        try {
            result = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + fileName + "]", e);
        }
    }
    if (getParameterList() != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        ParameterValueList pvl;
        try {
            pvl = prc.getValues(getParameterList());
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
        for (int i = 0; i < pvl.size(); i++) {
            ParameterValue pv = pvl.getParameterValue(i);
            String replaceFrom;
            if (isReplaceFixedParams()) {
                replaceFrom = pv.getDefinition().getName();
            } else {
                replaceFrom = "${" + pv.getDefinition().getName() + "}";
            }
            result = replace(result, replaceFrom, pv.asStringValue(""));
        }
    }
    if (getSubstituteVars()) {
        result = StringResolver.substVars(returnString, session, appConstants);
    }
    if (StringUtils.isNotEmpty(styleSheetName)) {
        URL xsltSource = ClassUtils.getResourceURL(classLoader, styleSheetName);
        if (xsltSource != null) {
            try {
                String xsltResult = null;
                Transformer transformer = XmlUtils.createTransformer(xsltSource);
                xsltResult = XmlUtils.transformXml(transformer, result);
                result = xsltResult;
            } catch (IOException e) {
                throw new PipeRunException(this, getLogPrefix(session) + "cannot retrieve [" + styleSheetName + "], resource [" + xsltSource.toString() + "]", e);
            } catch (TransformerConfigurationException te) {
                throw new PipeRunException(this, getLogPrefix(session) + "got error creating transformer from file [" + styleSheetName + "]", te);
            } catch (TransformerException te) {
                throw new PipeRunException(this, getLogPrefix(session) + "got error transforming resource [" + xsltSource.toString() + "] from [" + styleSheetName + "]", te);
            } catch (DomBuilderException te) {
                throw new PipeRunException(this, getLogPrefix(session) + "caught DomBuilderException", te);
            }
        }
    }
    log.debug(getLogPrefix(session) + " returning fixed result [" + result + "]");
    return new PipeRunResult(getForward(), result);
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Transformer(javax.xml.transform.Transformer) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) PipeForward(nl.nn.adapterframework.core.PipeForward) URL(java.net.URL) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) TransformerException(javax.xml.transform.TransformerException)

Aggregations

PipeForward (nl.nn.adapterframework.core.PipeForward)49 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)23 PipeRunException (nl.nn.adapterframework.core.PipeRunException)21 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)10 Test (org.junit.Test)8 IOException (java.io.IOException)7 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)7 ParameterException (nl.nn.adapterframework.core.ParameterException)6 ParameterList (nl.nn.adapterframework.parameters.ParameterList)6 IPipe (nl.nn.adapterframework.core.IPipe)4 Map (java.util.Map)3 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 ConfigurationWarnings (nl.nn.adapterframework.configuration.ConfigurationWarnings)3 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)3 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)3 PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)3 ApiWsdlXmlValidator (nl.nn.adapterframework.extensions.api.ApiWsdlXmlValidator)3 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)3 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)3 InputStream (java.io.InputStream)2