Search in sources :

Example 11 with SenderException

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);
    }
}
Also used : ObjectMessage(javax.jms.ObjectMessage) SenderException(nl.nn.adapterframework.core.SenderException) SenderException(nl.nn.adapterframework.core.SenderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) ListenerException(nl.nn.adapterframework.core.ListenerException) Session(javax.jms.Session)

Example 12 with SenderException

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;
}
Also used : TopicSession(javax.jms.TopicSession) Iterator(java.util.Iterator) InvalidDestinationException(javax.jms.InvalidDestinationException) INamedObject(nl.nn.adapterframework.core.INamedObject) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) SenderException(nl.nn.adapterframework.core.SenderException) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) QueueSession(javax.jms.QueueSession)

Example 13 with SenderException

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);
    }
}
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 14 with SenderException

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);
        }
    }
}
Also used : ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Timestamp(java.sql.Timestamp) Date(java.util.Date) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) INamedObject(nl.nn.adapterframework.core.INamedObject) SenderException(nl.nn.adapterframework.core.SenderException)

Example 15 with SenderException

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

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