Search in sources :

Example 1 with ParameterResolutionContext

use of nl.nn.adapterframework.parameters.ParameterResolutionContext 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 ParameterResolutionContext

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

the class BatchTransformerPipeBase method getReader.

protected BufferedReader getReader(String streamId, Object input, IPipeLineSession session) throws PipeRunException {
    Connection connection = null;
    try {
        connection = querySender.getConnection();
        PreparedStatement statement = null;
        String msg = (String) input;
        statement = querySender.getStatement(connection, streamId, msg, false);
        ParameterResolutionContext prc = new ParameterResolutionContext(msg, session);
        if (querySender.paramList != null) {
            querySender.applyParameters(statement, prc.getValues(querySender.paramList));
        }
        ResultSet rs = statement.executeQuery();
        if (rs == null || !rs.next()) {
            throw new SenderException("query has empty resultset");
        }
        return new ResultSetReader(connection, rs, getReader(rs, getCharset(), streamId, session));
    } catch (Exception e) {
        throw new PipeRunException(this, "cannot open reader", e);
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PreparedStatement(java.sql.PreparedStatement) SenderException(nl.nn.adapterframework.core.SenderException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 3 with ParameterResolutionContext

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

the class JdbcIteratingPipeBase method getIterator.

protected IDataIterator getIterator(Object input, IPipeLineSession session, String correlationID, Map threadContext) throws SenderException {
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        connection = querySender.getConnection();
        String msg = (String) input;
        statement = querySender.getStatement(connection, correlationID, msg, false);
        ParameterResolutionContext prc = new ParameterResolutionContext(msg, session);
        if (querySender.paramList != null) {
            querySender.applyParameters(statement, prc.getValues(querySender.paramList));
        }
        rs = statement.executeQuery();
        if (rs == null) {
            throw new SenderException("resultset is null");
        }
        if (!rs.next()) {
            JdbcUtil.fullClose(connection, rs);
            // no results
            return null;
        }
        return getIterator(connection, rs);
    } catch (Throwable t) {
        try {
            if (rs != null) {
                JdbcUtil.fullClose(connection, rs);
            } else {
                if (statement != null) {
                    JdbcUtil.fullClose(connection, statement);
                } else {
                    if (connection != null) {
                        try {
                            connection.close();
                        } catch (SQLException e1) {
                            log.debug(getLogPrefix(session) + "caught exception closing sender after exception", e1);
                        }
                    }
                }
            }
        } finally {
            throw new SenderException(getLogPrefix(session), t);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SenderException(nl.nn.adapterframework.core.SenderException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 4 with ParameterResolutionContext

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

the class ExecuteJdbcProperties method doPost.

private String doPost(IPipeLineSession session) throws PipeRunException {
    String action = (String) session.get("action");
    String name = (String) session.get("name");
    String value = (String) session.get("value");
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    String form_jmsRealm = (String) session.get("jmsRealm");
    if (StringUtils.isEmpty(name)) {
        throw new PipeRunException(this, getLogPrefix(session) + "Name should not be empty");
    }
    String result = null;
    String remoteUser = (String) session.get("principal");
    if ("insert".equalsIgnoreCase(action)) {
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(form_jmsRealm);
            qs.setQueryType("insert");
            if (StringUtils.isEmpty(remoteUser)) {
                qs.setQuery("INSERT INTO IBISPROP (NAME, VALUE, LASTMODDATE) VALUES (?, ?, CURRENT_TIMESTAMP)");
            } else {
                qs.setQuery("INSERT INTO IBISPROP (NAME, VALUE, LASTMODDATE, LASTMODBY) VALUES (?, ?, CURRENT_TIMESTAMP, ?)");
            }
            Parameter param = new Parameter();
            param.setName("name");
            param.setValue(name);
            qs.addParameter(param);
            param = new Parameter();
            param.setName("value");
            param.setValue(value);
            qs.addParameter(param);
            if (StringUtils.isNotEmpty(remoteUser)) {
                param = new Parameter();
                param.setName("lastmodby");
                param.setValue(remoteUser);
                qs.addParameter(param);
            }
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("", session);
            result = qs.sendMessage("", "", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc insert query", t);
        } finally {
            qs.close();
        }
    } else if ("update".equalsIgnoreCase(action)) {
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(form_jmsRealm);
            qs.setQueryType("update");
            qs.setQuery("UPDATE IBISPROP SET VALUE=?, LASTMODDATE=CURRENT_TIMESTAMP, LASTMODBY=? WHERE NAME=?");
            Parameter param = new Parameter();
            param.setName("value");
            param.setValue(value);
            qs.addParameter(param);
            param = new Parameter();
            param.setName("lastmodby");
            if (StringUtils.isNotEmpty(remoteUser)) {
                param.setValue(remoteUser);
            }
            qs.addParameter(param);
            param = new Parameter();
            param.setName("name");
            param.setValue(name);
            qs.addParameter(param);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("", session);
            result = qs.sendMessage("", "", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc update query", t);
        } finally {
            qs.close();
        }
    } else if ("delete".equalsIgnoreCase(action)) {
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(form_jmsRealm);
            qs.setQueryType("delete");
            qs.setQuery("DELETE IBISPROP WHERE NAME=?");
            Parameter param = new Parameter();
            param.setName("name");
            param.setValue(name);
            qs.addParameter(param);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("", session);
            result = qs.sendMessage("", "", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc delete query", t);
        } finally {
            qs.close();
        }
    } else {
        throw new PipeRunException(this, getLogPrefix(session) + "Unknown action [" + action + "]");
    }
    session.put("result", result);
    return "<dummy/>";
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Example 5 with ParameterResolutionContext

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

the class ShowConfig method doGet.

private String doGet(IPipeLineSession session) throws PipeRunException {
    String parm_name = (String) session.get("name");
    if (StringUtils.isEmpty(parm_name)) {
        return retrieveAllConfigs(session);
    } else {
        session.put("contentType", "application/octet-stream");
        String parm_jmsRealm = (String) session.get("jmsRealm");
        if (StringUtils.isEmpty(parm_jmsRealm)) {
            parm_jmsRealm = JmsRealmFactory.getInstance().getFirstDatasourceJmsRealm();
            if (parm_jmsRealm == null) {
                throw new PipeRunException(this, getLogPrefix(session) + "No datasource jmsRealm available");
            }
        }
        FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
        String queryResult;
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(parm_jmsRealm);
            qs.setQueryType("select");
            qs.setQuery("SELECT CONFIG FROM IBISCONFIG WHERE NAME = ? ORDER BY NAME");
            Parameter param = new Parameter();
            param.setName("name");
            param.setSessionKey("name");
            qs.addParameter(param);
            qs.setScalar(true);
            qs.setScalarExtended(true);
            qs.setBlobsCompressed(false);
            qs.setStreamResultToServlet(true);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("dummy", session);
            queryResult = qs.sendMessage("dummy", "dummy", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc query", t);
        } finally {
            qs.close();
        }
        if (queryResult.length() == 0) {
        // means result is found and streamed
        } else {
            throw new PipeRunException(this, getLogPrefix(session) + "Could not retrieve configuration for name [" + parm_name + "]");
        }
        return queryResult;
    }
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Aggregations

ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)47 PipeRunException (nl.nn.adapterframework.core.PipeRunException)32 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)21 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)20 ParameterException (nl.nn.adapterframework.core.ParameterException)18 IOException (java.io.IOException)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 Parameter (nl.nn.adapterframework.parameters.Parameter)15 Map (java.util.Map)10 SenderException (nl.nn.adapterframework.core.SenderException)10 ParameterList (nl.nn.adapterframework.parameters.ParameterList)10 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)8 PipeForward (nl.nn.adapterframework.core.PipeForward)7 HashMap (java.util.HashMap)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)4 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)4 URL (java.net.URL)3 ISender (nl.nn.adapterframework.core.ISender)3 PipeStartException (nl.nn.adapterframework.core.PipeStartException)3