Search in sources :

Example 1 with SenderException

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

the class SenderMonitorAdapter method configure.

public void configure() throws ConfigurationException {
    if (getSender() == null) {
        throw new ConfigurationException("must have sender configured");
    }
    if (StringUtils.isEmpty(getSender().getName())) {
        getSender().setName("sender of " + getName());
    }
    super.configure();
    if (!senderConfigured) {
        getSender().configure();
        senderConfigured = true;
    } else {
        try {
            getSender().close();
        } catch (SenderException e) {
            log.error("cannot close sender", e);
        }
    }
    try {
        getSender().open();
    } catch (SenderException e) {
        throw new ConfigurationException("cannot open sender", e);
    }
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 2 with SenderException

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

the class JdbcQuerySenderBase method executePackageQuery.

protected String executePackageQuery(Connection connection, PreparedStatement statement, String message) throws SenderException, JdbcException, IOException, JMSException {
    Object[] paramArray = new Object[10];
    String callMessage = fillParamArray(paramArray, message);
    ResultSet resultset = null;
    try {
        CallableStatement pstmt = connection.prepareCall(callMessage);
        if (getMaxRows() > 0) {
            pstmt.setMaxRows(getMaxRows() + (getStartRow() > 1 ? getStartRow() - 1 : 0));
        }
        int var = 1;
        for (int i = 0; i < paramArray.length; i++) {
            if (paramArray[i] instanceof Timestamp) {
                pstmt.setTimestamp(var, (Timestamp) paramArray[i]);
                var++;
            }
            if (paramArray[i] instanceof java.sql.Date) {
                pstmt.setDate(var, (java.sql.Date) paramArray[i]);
                var++;
            }
            if (paramArray[i] instanceof String) {
                pstmt.setString(var, (String) paramArray[i]);
                var++;
            }
            if (paramArray[i] instanceof Integer) {
                int x = Integer.parseInt(paramArray[i].toString());
                pstmt.setInt(var, x);
                var++;
            }
            if (paramArray[i] instanceof Float) {
                float x = Float.parseFloat(paramArray[i].toString());
                pstmt.setFloat(var, x);
                var++;
            }
        }
        if (message.indexOf('?') != -1) {
            // make sure enough space is available for result...
            pstmt.registerOutParameter(var, Types.CLOB);
        }
        if ("xml".equalsIgnoreCase(getPackageContent())) {
            log.debug(getLogPrefix() + "executing a package SQL command");
            pstmt.executeUpdate();
            String pUitvoer = pstmt.getString(var);
            return pUitvoer;
        }
        log.debug(getLogPrefix() + "executing a package SQL command");
        int numRowsAffected = pstmt.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 package SQL command", sqle);
    } finally {
        try {
            if (resultset != null) {
                resultset.close();
            }
        } catch (SQLException e) {
            log.warn(new SenderException(getLogPrefix() + "got exception closing resultset", e));
        }
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Timestamp(java.sql.Timestamp) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) SenderException(nl.nn.adapterframework.core.SenderException)

Example 3 with SenderException

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

the class JdbcQuerySenderBase method sendMessage.

@Override
protected String sendMessage(Connection connection, String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    PreparedStatement statement = null;
    ParameterList newParamList = new ParameterList();
    if (paramList != null) {
        newParamList = (ParameterList) paramList.clone();
    }
    if (isUseNamedParams()) {
        message = adjustParamList(newParamList, message);
    }
    try {
        boolean updateBlob = "updateBlob".equalsIgnoreCase(getQueryType());
        boolean updateClob = "updateClob".equalsIgnoreCase(getQueryType());
        log.debug(getLogPrefix() + "obtaining prepared statement to execute");
        statement = getStatement(connection, correlationID, message, updateBlob || updateClob);
        log.debug(getLogPrefix() + "obtained prepared statement to execute");
        statement.setQueryTimeout(getTimeout());
        if (prc != null && paramList != null) {
            applyParameters(statement, prc.getValues(newParamList));
        }
        if ("select".equalsIgnoreCase(getQueryType())) {
            Object blobSessionVar = null;
            Object clobSessionVar = null;
            if (prc != null && StringUtils.isNotEmpty(getBlobSessionKey())) {
                blobSessionVar = prc.getSession().get(getBlobSessionKey());
            }
            if (prc != null && StringUtils.isNotEmpty(getClobSessionKey())) {
                clobSessionVar = prc.getSession().get(getClobSessionKey());
            }
            if (isStreamResultToServlet()) {
                HttpServletResponse response = (HttpServletResponse) prc.getSession().get(IPipeLineSession.HTTP_RESPONSE_KEY);
                String contentType = (String) prc.getSession().get("contentType");
                String contentDisposition = (String) prc.getSession().get("contentDisposition");
                return executeSelectQuery(statement, blobSessionVar, clobSessionVar, response, contentType, contentDisposition);
            } else {
                return executeSelectQuery(statement, blobSessionVar, clobSessionVar);
            }
        }
        if (updateBlob) {
            if (StringUtils.isEmpty(getBlobSessionKey())) {
                return executeUpdateBlobQuery(statement, message);
            }
            return executeUpdateBlobQuery(statement, prc == null ? null : prc.getSession().get(getBlobSessionKey()));
        }
        if (updateClob) {
            if (StringUtils.isEmpty(getClobSessionKey())) {
                return executeUpdateClobQuery(statement, message);
            }
            return executeUpdateClobQuery(statement, prc == null ? null : prc.getSession().get(getClobSessionKey()));
        }
        if ("package".equalsIgnoreCase(getQueryType())) {
            return executePackageQuery(connection, statement, message);
        }
        return executeOtherQuery(connection, correlationID, statement, message, prc, newParamList);
    } catch (SenderException e) {
        if (e.getCause() instanceof SQLException) {
            SQLException sqle = (SQLException) e.getCause();
            if (sqle.getErrorCode() == 1013) {
                throw new TimeOutException("Timeout of [" + getTimeout() + "] sec expired");
            }
        }
        throw new SenderException(e);
    } catch (Throwable t) {
        throw new SenderException(getLogPrefix() + "got exception sending message", t);
    } finally {
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (SQLException e) {
            log.warn(new SenderException(getLogPrefix() + "got exception closing SQL statement", e));
        }
        if (isCloseInputstreamOnExit()) {
            if (paramList != null) {
                for (int i = 0; i < paramList.size(); i++) {
                    if (Parameter.TYPE_INPUTSTREAM.equals(paramList.getParameter(i).getType())) {
                        log.debug(getLogPrefix() + "Closing inputstream for parameter [" + paramList.getParameter(i).getName() + "]");
                        try {
                            InputStream inputStream = (InputStream) paramList.getParameter(i).getValue(null, prc);
                            inputStream.close();
                        } catch (Exception e) {
                            log.warn(new SenderException(getLogPrefix() + "got exception closing inputstream", e));
                        }
                    }
                }
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) InputStream(java.io.InputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) SenderException(nl.nn.adapterframework.core.SenderException)

Example 4 with SenderException

use of nl.nn.adapterframework.core.SenderException 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 5 with SenderException

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

the class JdbcTransactionalStorage method initialize.

/**
 *	Checks if table exists, and creates when necessary.
 */
public void initialize(IDbmsSupport dbmsSupport) throws JdbcException, SQLException, SenderException {
    Connection conn = getConnection();
    try {
        boolean tableMustBeCreated;
        if (checkIfTableExists) {
            try {
                tableMustBeCreated = !JdbcUtil.tableExists(conn, getPrefix() + getTableName());
                if (!isCreateTable() && tableMustBeCreated) {
                    throw new SenderException("table [" + getPrefix() + getTableName() + "] does not exist");
                }
                log.info("table [" + getPrefix() + getTableName() + "] does " + (tableMustBeCreated ? "NOT " : "") + "exist");
            } catch (SQLException e) {
                log.warn(getLogPrefix() + "exception determining existence of table [" + getPrefix() + getTableName() + "] for transactional storage, trying to create anyway." + e.getMessage());
                tableMustBeCreated = true;
            }
        } else {
            log.info("did not check for existence of table [" + getPrefix() + getTableName() + "]");
            tableMustBeCreated = false;
        }
        if (isCreateTable() && tableMustBeCreated || forceCreateTable) {
            log.info(getLogPrefix() + "creating table [" + getPrefix() + getTableName() + "] for transactional storage");
            Statement stmt = conn.createStatement();
            try {
                createStorage(conn, stmt, dbmsSupport);
            } finally {
                stmt.close();
                conn.commit();
            }
        }
    } finally {
        conn.close();
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)130 TimeOutException (nl.nn.adapterframework.core.TimeOutException)41 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)36 SQLException (java.sql.SQLException)25 HashMap (java.util.HashMap)21 ParameterException (nl.nn.adapterframework.core.ParameterException)21 PreparedStatement (java.sql.PreparedStatement)20 Map (java.util.Map)20 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 Iterator (java.util.Iterator)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 InputStream (java.io.InputStream)15 ResultSet (java.sql.ResultSet)13 Element (org.w3c.dom.Element)13 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)12 Date (java.util.Date)10 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)10 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9