Search in sources :

Example 56 with PipeRunResult

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

the class FixedForwardPipe method doInitialPipe.

public PipeRunResult doInitialPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if ((input == null || StringUtils.isEmpty(input.toString())) && isSkipOnEmptyInput()) {
        return new PipeRunResult(getForward(), input);
    }
    if (getIfParam() != null) {
        boolean skipPipe = true;
        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 on extracting parameters", e);
            }
        }
        String ip = getParameterValue(pvl, getIfParam());
        if (ip == null) {
            if (getIfValue() == null) {
                skipPipe = false;
            }
        } else {
            if (getIfValue() != null && getIfValue().equalsIgnoreCase(ip)) {
                skipPipe = false;
            }
        }
        if (skipPipe) {
            return new PipeRunResult(getForward(), input);
        }
    }
    return null;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 57 with PipeRunResult

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

Example 58 with PipeRunResult

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

the class HashPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String message = (String) input;
    String authAlias = getAuthAlias();
    String secret = getSecret();
    try {
        ParameterList parameterList = getParameterList();
        ParameterResolutionContext prc = new ParameterResolutionContext(message, session);
        ParameterValueList pvl = prc.getValues(parameterList);
        if (pvl != null) {
            Parameter authAliasParam = parameterList.findParameter("authAlias");
            if (authAliasParam != null)
                authAlias = (String) authAliasParam.getValue(pvl, prc);
            Parameter secretParam = parameterList.findParameter("secret");
            if (secretParam != null)
                secret = (String) secretParam.getValue(pvl, prc);
        }
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "exception extracting authAlias", e);
    }
    CredentialFactory accessTokenCf = new CredentialFactory(authAlias, "", secret);
    String cfSecret = accessTokenCf.getPassword();
    if (cfSecret == null || cfSecret.isEmpty())
        throw new PipeRunException(this, getLogPrefix(session) + "empty secret, unable to hash");
    try {
        Mac mac = Mac.getInstance(getAlgorithm());
        SecretKeySpec secretkey = new SecretKeySpec(cfSecret.getBytes(getEncoding()), "algorithm");
        mac.init(secretkey);
        String hash = Base64.encodeBase64String(mac.doFinal(message.getBytes()));
        return new PipeRunResult(getForward(), hash);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "error creating hash", e);
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) SecretKeySpec(javax.crypto.spec.SecretKeySpec) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Mac(javax.crypto.Mac)

Example 59 with PipeRunResult

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

the class IfMultipart method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String forward;
    PipeForward pipeForward = null;
    if (input == null) {
        forward = elseForwardName;
    } else {
        if (!(input instanceof HttpServletRequest)) {
            throw new PipeRunException(this, getLogPrefix(null) + "expected HttpServletRequest as input, got [" + ClassUtils.nameOf(input) + "]");
        }
        HttpServletRequest request = (HttpServletRequest) input;
        String contentType = request.getContentType();
        if (StringUtils.isNotEmpty(contentType) && contentType.startsWith("multipart")) {
            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 : HttpServletRequest(javax.servlet.http.HttpServletRequest) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeForward(nl.nn.adapterframework.core.PipeForward)

Example 60 with PipeRunResult

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

the class IsUserInRolePipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    try {
        if (StringUtils.isEmpty(getRole())) {
            String inputString = (String) input;
            if (StringUtils.isEmpty(inputString)) {
                throw new PipeRunException(this, "role cannot be empty");
            }
            assertUserIsInRole(session, inputString);
        } else {
            assertUserIsInRole(session, getRole());
        }
    } catch (SecurityException e) {
        if (notInRoleForward != null) {
            return new PipeRunResult(notInRoleForward, input);
        } else {
            throw new PipeRunException(this, "", e);
        }
    }
    return new PipeRunResult(getForward(), input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException)

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