Search in sources :

Example 1 with PipeRunResult

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

the class LdapFindMemberPipe method doPipeWithException.

public PipeRunResult doPipeWithException(Object input, IPipeLineSession session) throws PipeRunException {
    String dnSearchIn_work;
    String dnFind_work;
    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);
        }
    }
    dnSearchIn_work = getParameterValue(pvl, "dnSearchIn");
    if (dnSearchIn_work == null) {
        dnSearchIn_work = getDnSearchIn();
    }
    dnFind_work = getParameterValue(pvl, "dnFind");
    if (dnFind_work == null) {
        dnFind_work = getDnFind();
    }
    boolean found = false;
    if (StringUtils.isNotEmpty(dnSearchIn_work) && StringUtils.isNotEmpty(dnFind_work)) {
        try {
            found = findMember(getHost(), getPort(), dnSearchIn_work, isUseSsl(), dnFind_work, isRecursiveSearch());
        } catch (NamingException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on ldap lookup", e);
        }
    }
    if (!found) {
        String msg = getLogPrefix(session) + "dn [" + dnFind_work + "] not found as member in url [" + retrieveUrl(getHost(), getPort(), dnSearchIn_work, isUseSsl()) + "]";
        if (notFoundForward == null) {
            throw new PipeRunException(this, msg);
        } else {
            log.info(msg);
            return new PipeRunResult(notFoundForward, input);
        }
    }
    return new PipeRunResult(getForward(), input);
}
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) NamingException(javax.naming.NamingException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 2 with PipeRunResult

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

the class ApiPrincipalPipe method doPipe.

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());
    }
    if (getAction().equals("get")) {
        ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
        if (userPrincipal == null)
            throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
        return new PipeRunResult(getForward(), userPrincipal.getData());
    }
    if (getAction().equals("set")) {
        ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
        if (userPrincipal == null)
            throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
        userPrincipal.setData((String) input);
        cache.put(userPrincipal.getToken(), userPrincipal, authTTL);
        return new PipeRunResult(getForward(), "");
    }
    if (getAction().equals("create")) {
        // TODO type of token? (jwt, saml)
        String uidString = (new UID()).toString();
        Random random = new Random();
        String token = random.nextInt() + uidString + Integer.toHexString(uidString.hashCode()) + random.nextInt(8);
        ApiPrincipal userPrincipal = new ApiPrincipal(authTTL);
        userPrincipal.setData((String) input);
        userPrincipal.setToken(token);
        if (getAuthenticationMethod().equals("cookie")) {
            Cookie cookie = new Cookie("authenticationToken", token);
            cookie.setPath("/");
            cookie.setMaxAge(authTTL);
            HttpServletResponse response = (HttpServletResponse) session.get(IPipeLineSession.HTTP_RESPONSE_KEY);
            response.addCookie(cookie);
        }
        cache.put(token, userPrincipal, authTTL);
        return new PipeRunResult(getForward(), token);
    }
    if (getAction().equals("remove")) {
        ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
        if (userPrincipal == null)
            throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
        cache.remove(userPrincipal.getToken());
        return new PipeRunResult(getForward(), "");
    }
    return new PipeRunResult(findForward("exception"), "this is not supposed to happen... like ever!");
}
Also used : Cookie(javax.servlet.http.Cookie) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) UID(java.rmi.server.UID) Random(java.util.Random) PipeRunException(nl.nn.adapterframework.core.PipeRunException) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 3 with PipeRunResult

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

the class CoolGenWrapperPipe method doPipe.

/**
 * Transform the input (optionally), check the conformance to the schema (optionally),
 * call the required proxy, transform the output (optionally)
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    Writer proxyResult;
    String proxypreProc = null;
    Variant inputVar;
    String wrapperResult = "";
    CoolGenXMLProxy proxy;
    ActionListener actionListener = new ActionListener() {

        /**
         * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
         */
        public String errorMessage;

        public void actionPerformed(ActionEvent e) {
            errorMessage = e.toString();
        }

        public String toString() {
            return errorMessage;
        }
    };
    Source in;
    try {
        log.info(getLogPrefix(session) + "instantiating proxy [" + proxyClassName + "] as a temporary fix for broken comm-bridge connections");
        proxy = createProxy(proxyClassName);
    } catch (ConfigurationException ce) {
        String msg = getLogPrefix(session) + "cannot recreate proxy after exception";
        log.error(msg, ce);
        throw new PipeRunException(this, msg, ce);
    }
    proxy.addExceptionListener(actionListener);
    try {
        inputVar = new Variant(input);
        in = inputVar.asXmlSource();
        if (preProcTransformer != null) {
            proxypreProc = XmlUtils.transformXml(preProcTransformer, in);
            log.debug(getLogPrefix(session) + "] preprocessing transformed message into [" + proxypreProc + "]");
        } else
            proxypreProc = inputVar.asString();
        if (proxyInputFixTransformer != null)
            proxypreProc = XmlUtils.transformXml(proxyInputFixTransformer, proxypreProc);
        proxyResult = new StringWriter(10 * 1024);
        try {
            proxy.clear();
        } catch (PropertyVetoException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "cannot clear CoolGen proxy", e);
        }
        try {
            proxy.executeXML(new StringReader(proxypreProc), proxyResult);
            proxy.removeExceptionListener(actionListener);
            String err = actionListener.toString();
            if (err != null) {
                // if an error occurs, recreate the proxy and throw an exception
                log.debug(getLogPrefix(session) + "got error, recreating proxy with class [" + proxyClassName + "]");
                try {
                    proxy = createProxy(proxyClassName);
                } catch (ConfigurationException e) {
                    throw new PipeRunException(this, getLogPrefix(session) + "cannot recreate proxy [" + proxyClassName + "]", e);
                }
                throw new PipeRunException(this, getLogPrefix(session) + "error excuting proxy [" + proxyClassName + "]:" + err);
            }
        } catch (XmlProxyException xpe) {
            try {
                proxy = createProxy(proxyClassName);
            } catch (ConfigurationException ce) {
                log.error(getLogPrefix(session) + "cannot recreate proxy", xpe);
            }
            throw new PipeRunException(this, getLogPrefix(session) + "error excecuting proxy", xpe);
        }
        if (postProcTransformer != null) {
            log.debug(getLogPrefix(session) + " CoolGen proxy returned: [" + proxyResult.toString() + "]");
            wrapperResult = XmlUtils.transformXml(postProcTransformer, proxyResult.toString());
        } else
            wrapperResult = proxyResult.toString();
    } catch (DomBuilderException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "DomBuilderException excecuting proxy", e);
    } catch (IOException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "IOException excecuting proxy", e);
    } catch (TransformerException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "TransformerException excecuting proxy", e);
    }
    return new PipeRunResult(getForward(), wrapperResult);
}
Also used : CoolGenXMLProxy(nl.nn.coolgen.proxy.CoolGenXMLProxy) ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) Source(javax.xml.transform.Source) Variant(nl.nn.adapterframework.util.Variant) PropertyVetoException(java.beans.PropertyVetoException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) XmlProxyException(nl.nn.coolgen.proxy.XmlProxyException) ActionListener(java.awt.event.ActionListener) StringWriter(java.io.StringWriter) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StringReader(java.io.StringReader) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) StringWriter(java.io.StringWriter) Writer(java.io.Writer) TransformerException(javax.xml.transform.TransformerException)

Example 4 with PipeRunResult

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

the class WsdlGeneratorPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String result = null;
    IAdapter adapter;
    if ("input".equals(getFrom())) {
        adapter = ((Adapter) getAdapter()).getConfiguration().getIbisManager().getRegisteredAdapter((String) input);
        if (adapter == null) {
            throw new PipeRunException(this, "Could not find adapter: " + input);
        }
    } else {
        adapter = getPipeLine().getAdapter();
    }
    try {
        Wsdl wsdl = new Wsdl(((Adapter) adapter).getPipeLine());
        wsdl.setDocumentation("Generated at " + AppConstants.getInstance().getResolvedProperty("otap.stage") + "-" + AppConstants.getInstance().getResolvedProperty("otap.side") + " on " + DateUtils.getIsoTimeStamp() + ".");
        wsdl.init();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        wsdl.wsdl(outputStream, null);
        result = outputStream.toString("UTF-8");
    } catch (Exception e) {
        throw new PipeRunException(this, "Could not generate WSDL for adapter '" + adapter.getName() + "'", e);
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAdapter(nl.nn.adapterframework.core.IAdapter) Wsdl(nl.nn.adapterframework.soap.Wsdl) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 5 with PipeRunResult

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

the class XQueryPipe method doPipe.

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());
    }
    try {
        String stringResult = (String) input;
        // We already specifically use Saxon in this pipe, hence set xslt2
        // to true to make XmlUtils use the Saxon
        // DocumentBuilderFactoryImpl.
        ParameterResolutionContext prc = new ParameterResolutionContext(stringResult, session, isNamespaceAware(), true);
        Map parametervalues = null;
        if (getParameterList() != null) {
            parametervalues = prc.getValueMap(getParameterList());
        }
        preparedExpression.bindDocument(XQConstants.CONTEXT_ITEM, stringResult, null, null);
        Iterator iterator = getParameterList().iterator();
        while (iterator.hasNext()) {
            Parameter parameter = (Parameter) iterator.next();
            preparedExpression.bindObject(new QName(parameter.getName()), parametervalues.get(parameter.getName()), null);
        }
        XQResultSequence resultSequence = preparedExpression.executeQuery();
        stringResult = resultSequence.getSequenceAsString(null);
        return new PipeRunResult(getForward(), stringResult);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on running xquery", e);
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) QName(javax.xml.namespace.QName) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Iterator(java.util.Iterator) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XQException(javax.xml.xquery.XQException) XQResultSequence(javax.xml.xquery.XQResultSequence)

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