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);
}
}
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));
}
}
}
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));
}
}
}
}
}
}
}
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));
}
}
}
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();
}
}
Aggregations