Search in sources :

Example 51 with PipeRunResult

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

the class CreateRestViewPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    HttpServletRequest httpServletRequest = (HttpServletRequest) session.get(IPipeLineSession.HTTP_REQUEST_KEY);
    String requestURL = httpServletRequest.getRequestURL().toString();
    String servletPath = httpServletRequest.getServletPath();
    String uri = StringUtils.substringAfter(requestURL, servletPath);
    int countSrcPrefix = StringUtils.countMatches(uri, "/");
    String srcPrefix = StringUtils.repeat("../", countSrcPrefix);
    session.put(SRCPREFIX, srcPrefix);
    log.debug(getLogPrefix(session) + "stored [" + srcPrefix + "] in pipeLineSession under key [" + SRCPREFIX + "]");
    PipeRunResult prr = super.doPipe(input, session);
    String result = (String) prr.getResult();
    log.debug("transforming page [" + result + "] to view");
    String newResult = null;
    ServletContext servletContext = (ServletContext) session.get(IPipeLineSession.SERVLET_CONTEXT_KEY);
    try {
        Map parameters = retrieveParameters(httpServletRequest, servletContext, srcPrefix);
        newResult = XmlUtils.getAdapterSite(result, parameters);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on transforming page to view", e);
    }
    session.put(CONTENTTYPE, getContentType());
    log.debug(getLogPrefix(session) + "stored [" + getContentType() + "] in pipeLineSession under key [" + CONTENTTYPE + "]");
    return new PipeRunResult(getForward(), newResult);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ServletContext(javax.servlet.ServletContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 52 with PipeRunResult

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

the class CredentialCheckingPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    CredentialFactory cf = new CredentialFactory(getAuthAlias(), getDefaultUserid(), getDefaultPassword());
    String result = "";
    if (!getTargetUserid().equals(cf.getUsername())) {
        result += "username does not match target";
    }
    if (!getTargetPassword().equals(cf.getPassword())) {
        result += "password does not match target";
    }
    if (StringUtils.isEmpty(result)) {
        result = "OK";
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory)

Example 53 with PipeRunResult

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

the class CrlPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    X509CRL crl;
    InputStream inputStream = (InputStream) input;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        crl = (X509CRL) cf.generateCRL(inputStream);
    } catch (CertificateException e) {
        throw new PipeRunException(this, "Could not read CRL", e);
    } catch (CRLException e) {
        throw new PipeRunException(this, "Could not read CRL", e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                log.warn("Could not close CRL input stream", e);
            }
        }
    }
    String result = null;
    if (isCRLOK(crl, (InputStream) session.get(getIssuerSessionKey()))) {
        XmlBuilder root = new XmlBuilder("SerialNumbers");
        Iterator<? extends X509CRLEntry> it = crl.getRevokedCertificates().iterator();
        while (it.hasNext()) {
            X509CRLEntry e = (X509CRLEntry) it.next();
            XmlBuilder serialNumber = new XmlBuilder("SerialNumber");
            serialNumber.setValue(e.getSerialNumber().toString(16));
            root.addSubElement(serialNumber);
        }
        result = root.toXML();
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) X509CRLEntry(java.security.cert.X509CRLEntry) X509CRL(java.security.cert.X509CRL) InputStream(java.io.InputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) CRLException(java.security.cert.CRLException)

Example 54 with PipeRunResult

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

the class DomainTransformerPipe method doPipe.

public PipeRunResult doPipe(Object invoer, IPipeLineSession session) throws PipeRunException {
    Connection conn = null;
    PreparedStatement stmt = null;
    StringBuffer buffer = new StringBuffer();
    try {
        conn = qs.getConnection();
        stmt = conn.prepareStatement(query);
        String invoerString = invoer.toString();
        int startPos = invoerString.indexOf(DT_START);
        if (startPos == -1)
            return new PipeRunResult(getForward(), invoerString);
        char[] invoerChars = invoerString.toCharArray();
        int copyFrom = 0;
        while (startPos != -1) {
            buffer.append(invoerChars, copyFrom, startPos - copyFrom);
            int nextStartPos = invoerString.indexOf(DT_START, startPos + DT_START.length());
            if (nextStartPos == -1) {
                nextStartPos = invoerString.length();
            }
            int endPos = invoerString.indexOf(DT_END, startPos + DT_START.length());
            if (endPos == -1 || endPos > nextStartPos) {
                log.warn(getLogPrefix(session) + "Found a start delimiter without an end delimiter at position [" + startPos + "] in [" + invoerString + "]");
                buffer.append(invoerChars, startPos, nextStartPos - startPos);
                copyFrom = nextStartPos;
            } else {
                String invoerSubstring = invoerString.substring(startPos + DT_START.length(), endPos);
                StringTokenizer st = new StringTokenizer(invoerSubstring, DT_SEPARATOR);
                int aantalTokens = st.countTokens();
                if (aantalTokens < 2 || aantalTokens > 3) {
                    log.warn(getLogPrefix(session) + "Only 2 or 3 tokens are allowed in [" + invoerSubstring + "]");
                    buffer.append(invoerChars, startPos, endPos - startPos + DT_END.length());
                    copyFrom = endPos + DT_END.length();
                } else {
                    String label = st.nextToken();
                    String valueIn = st.nextToken();
                    String type = TYPE_STRING;
                    if (st.hasMoreTokens()) {
                        type = st.nextToken();
                    }
                    if (!type.equals(TYPE_STRING) && !type.equals(TYPE_NUMBER)) {
                        log.warn(getLogPrefix(session) + "Only types [" + TYPE_STRING + "," + TYPE_NUMBER + "] are allowed in [" + invoerSubstring + "]");
                        buffer.append(invoerChars, startPos, endPos - startPos + DT_END.length());
                        copyFrom = endPos + DT_END.length();
                    } else {
                        String valueOut = null;
                        valueOut = getValueOut(label, valueIn, type, stmt);
                        if (valueOut != null) {
                            buffer.append(valueOut);
                        }
                        copyFrom = endPos + DT_END.length();
                    }
                }
            }
            startPos = invoerString.indexOf(DT_START, copyFrom);
        }
        buffer.append(invoerChars, copyFrom, invoerChars.length - copyFrom);
    } catch (Throwable t) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on transforming domain", t);
    } finally {
        JdbcUtil.fullClose(conn, stmt);
    }
    return new PipeRunResult(getForward(), buffer.toString());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) StringTokenizer(java.util.StringTokenizer) Connection(java.sql.Connection) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PreparedStatement(java.sql.PreparedStatement)

Example 55 with PipeRunResult

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

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