use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class JmsTransactionalStorage method storeMessage.
public String storeMessage(String messageId, String correlationId, Date receivedDate, String comments, String label, Serializable message) throws SenderException {
Session session = null;
try {
session = createSession();
ObjectMessage msg = session.createObjectMessage(message);
msg.setStringProperty(FIELD_TYPE, getType());
msg.setStringProperty(FIELD_ORIGINAL_ID, messageId);
msg.setJMSCorrelationID(correlationId);
msg.setLongProperty(FIELD_RECEIVED_DATE, receivedDate.getTime());
msg.setStringProperty(FIELD_COMMENTS, comments);
if (StringUtils.isNotEmpty(getSlotId())) {
msg.setStringProperty(FIELD_SLOTID, getSlotId());
}
msg.setStringProperty(FIELD_LABEL, label);
return send(session, getDestination(), msg);
} catch (Exception e) {
throw new SenderException(e);
} finally {
closeSession(session);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class JMSFacade method send.
public String send(Session session, Destination dest, String correlationId, String message, String messageType, long timeToLive, int deliveryMode, int priority, boolean ignoreInvalidDestinationException, Map properties) throws NamingException, JMSException, SenderException {
TextMessage msg = createTextMessage(session, correlationId, message);
MessageProducer mp;
try {
if (useJms102()) {
if ((session instanceof TopicSession) && (dest instanceof Topic)) {
mp = getTopicPublisher((TopicSession) session, (Topic) dest);
} else {
if ((session instanceof QueueSession) && (dest instanceof Queue)) {
mp = getQueueSender((QueueSession) session, (Queue) dest);
} else {
throw new SenderException("classes of Session [" + session.getClass().getName() + "] and Destination [" + dest.getClass().getName() + "] do not match (Queue vs Topic)");
}
}
} else {
mp = session.createProducer(dest);
}
} catch (InvalidDestinationException e) {
if (ignoreInvalidDestinationException) {
log.warn("queue [" + dest + "] doesn't exist");
return null;
} else {
throw e;
}
}
if (messageType != null) {
msg.setJMSType(messageType);
}
if (deliveryMode > 0) {
msg.setJMSDeliveryMode(deliveryMode);
mp.setDeliveryMode(deliveryMode);
}
if (priority >= 0) {
msg.setJMSPriority(priority);
mp.setPriority(priority);
}
if (timeToLive > 0) {
mp.setTimeToLive(timeToLive);
}
if (properties != null) {
for (Iterator it = properties.keySet().iterator(); it.hasNext(); ) {
String key = (String) it.next();
Object value = properties.get(key);
log.debug("setting property [" + name + "] to value [" + value + "]");
msg.setObjectProperty(key, value);
}
}
String result = send(mp, msg, ignoreInvalidDestinationException);
mp.close();
return result;
}
use of nl.nn.adapterframework.core.SenderException 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);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class JdbcFacade method applyParameters.
protected void applyParameters(PreparedStatement statement, ParameterValueList parameters) throws SQLException, SenderException {
for (int i = 0; i < parameters.size(); i++) {
ParameterValue pv = parameters.getParameterValue(i);
String paramType = pv.getDefinition().getType();
Object value = pv.getValue();
if (Parameter.TYPE_DATE.equals(paramType)) {
if (value == null) {
statement.setNull(i + 1, Types.DATE);
} else {
statement.setDate(i + 1, new java.sql.Date(((Date) value).getTime()));
}
} else if (Parameter.TYPE_DATETIME.equals(paramType)) {
if (value == null) {
statement.setNull(i + 1, Types.TIMESTAMP);
} else {
statement.setTimestamp(i + 1, new Timestamp(((Date) value).getTime()));
}
} else if (Parameter.TYPE_TIMESTAMP.equals(paramType)) {
if (value == null) {
statement.setNull(i + 1, Types.TIMESTAMP);
} else {
statement.setTimestamp(i + 1, new Timestamp(((Date) value).getTime()));
}
} else if (Parameter.TYPE_TIME.equals(paramType)) {
if (value == null) {
statement.setNull(i + 1, Types.TIME);
} else {
statement.setTime(i + 1, new java.sql.Time(((Date) value).getTime()));
}
} else if (Parameter.TYPE_XMLDATETIME.equals(paramType)) {
if (value == null) {
statement.setNull(i + 1, Types.TIMESTAMP);
} else {
statement.setTimestamp(i + 1, new Timestamp(((Date) value).getTime()));
}
} else if (Parameter.TYPE_NUMBER.equals(paramType)) {
if (value == null) {
statement.setNull(i + 1, Types.NUMERIC);
} else {
statement.setDouble(i + 1, ((Number) value).doubleValue());
}
} else if (Parameter.TYPE_INTEGER.equals(paramType)) {
if (value == null) {
statement.setNull(i + 1, Types.INTEGER);
} else {
statement.setInt(i + 1, (Integer) value);
}
} else if (Parameter.TYPE_INPUTSTREAM.equals(paramType)) {
if (value instanceof FileInputStream) {
FileInputStream fis = (FileInputStream) value;
long len = 0;
try {
len = fis.getChannel().size();
} catch (IOException e) {
log.warn(getLogPrefix() + "could not determine file size", e);
}
statement.setBinaryStream(i + 1, fis, (int) len);
} else if (value instanceof ByteArrayInputStream) {
ByteArrayInputStream bais = (ByteArrayInputStream) value;
long len = bais.available();
statement.setBinaryStream(i + 1, bais, (int) len);
} else if (value instanceof InputStream) {
statement.setBinaryStream(i + 1, (InputStream) value);
} else {
throw new SenderException(getLogPrefix() + "unknown inputstream [" + value.getClass() + "] for parameter [" + pv.getDefinition().getName() + "]");
}
} else if ("string2bytes".equals(paramType)) {
statement.setBytes(i + 1, ((String) value).getBytes());
} else if ("bytes".equals(paramType)) {
statement.setBytes(i + 1, (byte[]) value);
} else {
statement.setString(i + 1, (String) value);
}
}
}
use of nl.nn.adapterframework.core.SenderException 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);
}
}
}
Aggregations