Search in sources :

Example 1 with ParameterValueList

use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.

the class JdbcQuerySenderBase method executeOtherQuery.

protected String executeOtherQuery(Connection connection, String correlationID, PreparedStatement statement, String message, ParameterResolutionContext prc, ParameterList newParamList) throws SenderException {
    ResultSet resultset = null;
    try {
        int numRowsAffected = 0;
        if (StringUtils.isNotEmpty(getRowIdSessionKey())) {
            CallableStatement cstmt = getCallWithRowIdReturned(connection, correlationID, message);
            int ri = 1;
            if (prc != null && paramList != null) {
                ParameterValueList parameters = prc.getValues(newParamList);
                applyParameters(cstmt, parameters);
                ri = parameters.size() + 1;
            }
            cstmt.registerOutParameter(ri, Types.VARCHAR);
            log.debug(getLogPrefix() + "executing a SQL command");
            numRowsAffected = cstmt.executeUpdate();
            String rowId = cstmt.getString(ri);
            if (prc != null)
                prc.getSession().put(getRowIdSessionKey(), rowId);
        } else {
            log.debug(getLogPrefix() + "executing a SQL command");
            numRowsAffected = statement.executeUpdate();
        }
        if (StringUtils.isNotEmpty(getResultQuery())) {
            Statement resStmt = null;
            try {
                resStmt = connection.createStatement();
                log.debug("obtaining result from [" + getResultQuery() + "]");
                ResultSet rs = resStmt.executeQuery(getResultQuery());
                return getResult(rs);
            } finally {
                if (resStmt != null) {
                    resStmt.close();
                }
            }
        }
        if (getColumnsReturnedList() != null) {
            return getResult(getReturnedColumns(getColumnsReturnedList(), statement));
        }
        if (isScalar()) {
            return numRowsAffected + "";
        }
        return "<result><rowsupdated>" + numRowsAffected + "</rowsupdated></result>";
    } catch (SQLException sqle) {
        throw new SenderException(getLogPrefix() + "got exception executing a SQL command", sqle);
    } catch (JdbcException e) {
        throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
    } catch (IOException e) {
        throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
    } catch (JMSException e) {
        throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + "got exception evaluating parameters", e);
    } finally {
        try {
            if (resultset != null) {
                resultset.close();
            }
        } catch (SQLException e) {
            log.warn(new SenderException(getLogPrefix() + "got exception closing resultset", e));
        }
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) JMSException(javax.jms.JMSException) ParameterException(nl.nn.adapterframework.core.ParameterException) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 2 with ParameterValueList

use of nl.nn.adapterframework.parameters.ParameterValueList 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 3 with ParameterValueList

use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.

the class CmisSender method getSession.

public Session getSession(ParameterResolutionContext prc) throws SenderException {
    if (session == null || !isKeepSession()) {
        String authAlias_work = null;
        String userName_work = null;
        String password_work = null;
        ParameterValueList pvl = null;
        try {
            if (prc != null && paramList != null) {
                pvl = prc.getValues(paramList);
                if (pvl != null) {
                    ParameterValue pv = pvl.getParameterValue("authAlias");
                    if (pv != null) {
                        authAlias_work = (String) pv.getValue();
                    }
                    pv = pvl.getParameterValue("userName");
                    if (pv != null) {
                        userName_work = (String) pv.getValue();
                    }
                    pv = pvl.getParameterValue("password");
                    if (pv != null) {
                        password_work = (String) pv.getValue();
                    }
                }
            }
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
        }
        if (authAlias_work == null) {
            authAlias_work = getAuthAlias();
        }
        if (userName_work == null) {
            userName_work = getUserName();
        }
        if (password_work == null) {
            password_work = getPassword();
        }
        CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work);
        session = connect(cf.getUsername(), cf.getPassword());
    }
    return session;
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 4 with ParameterValueList

use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.

the class CompareStringPipe method doPipe.

@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    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 operand1 = getParameterValue(pvl, OPERAND1);
    if (operand1 == null) {
        if (StringUtils.isNotEmpty(getSessionKey1())) {
            operand1 = (String) session.get(getSessionKey1());
        }
        if (operand1 == null) {
            operand1 = (String) input;
        }
    }
    String operand2 = getParameterValue(pvl, OPERAND2);
    if (operand2 == null) {
        if (StringUtils.isNotEmpty(getSessionKey2())) {
            operand2 = (String) session.get(getSessionKey2());
        }
        if (operand2 == null) {
            operand2 = (String) input;
        }
    }
    if (isXml()) {
        try {
            operand1 = XmlUtils.canonicalize(operand1);
            operand2 = XmlUtils.canonicalize(operand2);
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + " Exception on pretty printing input", e);
        }
    }
    String ip = getParameterValue(pvl, IGNOREPATTERNS);
    if (ip != null) {
        try {
            Node n = XmlUtils.buildNode(ip);
            if (n.getNodeName().equals("ignores")) {
                NodeList nList = n.getChildNodes();
                for (int i = 0; i <= nList.getLength() - 1; i++) {
                    Node cn = nList.item(i);
                    if (cn.getNodeName().equals("ignore")) {
                        NodeList cnList = cn.getChildNodes();
                        String after = null;
                        String before = null;
                        for (int j = 0; j <= cnList.getLength() - 1; j++) {
                            Node ccn = cnList.item(j);
                            if (ccn.getNodeName().equals("after")) {
                                after = ccn.getFirstChild().getNodeValue();
                            } else {
                                if (ccn.getNodeName().equals("before")) {
                                    before = ccn.getFirstChild().getNodeValue();
                                }
                            }
                        }
                        operand1 = ignoreBetween(operand1, after, before);
                        operand2 = ignoreBetween(operand2, after, before);
                    }
                }
            }
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + " Exception on ignoring parts of input", e);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("operand1 [" + operand1 + "]");
        log.debug("operand2 [" + operand2 + "]");
    }
    int comparison = operand1.compareTo(operand2);
    if (comparison == 0)
        return new PipeRunResult(findForward(EQUALSFORWARD), input);
    else if (comparison < 0)
        return new PipeRunResult(findForward(LESSTHANFORWARD), input);
    else
        return new PipeRunResult(findForward(GREATERTHANFORWARD), input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 5 with ParameterValueList

use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.

the class TimeoutGuardPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    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);
        }
    }
    int timeout_work;
    String timeout_work_str = getParameterValue(pvl, "timeout");
    if (timeout_work_str == null) {
        timeout_work = getTimeout();
    } else {
        timeout_work = Integer.valueOf(timeout_work_str);
    }
    DoPipe doPipe = new DoPipe(input, session, Thread.currentThread().getName(), NDC.peek());
    ExecutorService service = Executors.newSingleThreadExecutor();
    Future future = service.submit(doPipe);
    String result = null;
    try {
        log.debug(getLogPrefix(session) + "setting timeout of [" + timeout_work + "] s");
        result = (String) future.get(timeout_work, TimeUnit.SECONDS);
    } catch (Exception e) {
        String msg;
        if (e instanceof TimeoutException) {
            String errorMsg = getLogPrefix(session) + "exceeds timeout of [" + timeout_work + "] s, interupting";
            future.cancel(true);
            msg = e.getClass().getName() + ": " + errorMsg;
        } else {
            msg = e.getClass().getName();
        }
        if (isThrowException()) {
            throw new PipeRunException(this, msg, e);
        } else {
            String msgString = msg + ": " + e.getMessage();
            log.error(msgString, e);
            String msgCdataString = "<![CDATA[" + msgString + "]]>";
            result = "<error>" + msgCdataString + "</error>";
        }
    } finally {
        service.shutdown();
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeRunException(nl.nn.adapterframework.core.PipeRunException) TimeoutException(java.util.concurrent.TimeoutException) ParameterException(nl.nn.adapterframework.core.ParameterException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)30 ParameterException (nl.nn.adapterframework.core.ParameterException)23 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)16 SenderException (nl.nn.adapterframework.core.SenderException)15 PipeRunException (nl.nn.adapterframework.core.PipeRunException)13 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)11 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)9 TimeOutException (nl.nn.adapterframework.core.TimeOutException)8 IOException (java.io.IOException)7 ParameterValue (nl.nn.adapterframework.parameters.ParameterValue)6 JMSException (javax.jms.JMSException)5 Parameter (nl.nn.adapterframework.parameters.Parameter)5 URL (java.net.URL)4 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)4 HashMap (java.util.HashMap)3 Session (javax.jms.Session)3 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 ParameterList (nl.nn.adapterframework.parameters.ParameterList)3 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)3