Search in sources :

Example 91 with SenderException

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

the class HttpSender method createMultiPartEntity.

protected HttpEntity createMultiPartEntity(String message, ParameterValueList parameters, IPipeLineSession session) throws SenderException {
    MultipartEntityBuilder entity = MultipartEntityBuilder.create();
    entity.setCharset(Charset.forName(getCharSet()));
    if (isMtomEnabled())
        entity.setMtomMultipart();
    if (StringUtils.isNotEmpty(getInputMessageParam())) {
        entity.addPart(createMultipartBodypart(getInputMessageParam(), message));
        log.debug(getLogPrefix() + "appended stringpart [" + getInputMessageParam() + "] with value [" + message + "]");
    }
    if (parameters != null) {
        for (int i = 0; i < parameters.size(); i++) {
            ParameterValue pv = parameters.getParameterValue(i);
            String paramType = pv.getDefinition().getType();
            String name = pv.getDefinition().getName();
            if (Parameter.TYPE_INPUTSTREAM.equals(paramType)) {
                Object value = pv.getValue();
                if (value instanceof InputStream) {
                    InputStream fis = (InputStream) value;
                    String fileName = null;
                    String sessionKey = pv.getDefinition().getSessionKey();
                    if (sessionKey != null) {
                        fileName = (String) session.get(sessionKey + "Name");
                    }
                    entity.addPart(createMultipartBodypart(name, fis, fileName));
                    log.debug(getLogPrefix() + "appended filepart [" + name + "] with value [" + value + "] and name [" + fileName + "]");
                } else {
                    throw new SenderException(getLogPrefix() + "unknown inputstream [" + value.getClass() + "] for parameter [" + name + "]");
                }
            } else {
                String value = pv.asStringValue("");
                entity.addPart(createMultipartBodypart(name, value));
                log.debug(getLogPrefix() + "appended stringpart [" + name + "] with value [" + value + "]");
            }
        }
    }
    if (StringUtils.isNotEmpty(getMultipartXmlSessionKey())) {
        String multipartXml = (String) session.get(getMultipartXmlSessionKey());
        if (StringUtils.isEmpty(multipartXml)) {
            log.warn(getLogPrefix() + "sessionKey [" + getMultipartXmlSessionKey() + "] is empty");
        } else {
            Element partsElement;
            try {
                partsElement = XmlUtils.buildElement(multipartXml);
            } catch (DomBuilderException e) {
                throw new SenderException(getLogPrefix() + "error building multipart xml", e);
            }
            Collection<Node> parts = XmlUtils.getChildTags(partsElement, "part");
            if (parts == null || parts.size() == 0) {
                log.warn(getLogPrefix() + "no part(s) in multipart xml [" + multipartXml + "]");
            } else {
                Iterator<Node> iter = parts.iterator();
                while (iter.hasNext()) {
                    Element partElement = (Element) iter.next();
                    // String partType = partElement.getAttribute("type");
                    String partName = partElement.getAttribute("name");
                    String partSessionKey = partElement.getAttribute("sessionKey");
                    String partMimeType = partElement.getAttribute("mimeType");
                    Object partObject = session.get(partSessionKey);
                    if (partObject instanceof InputStream) {
                        InputStream fis = (InputStream) partObject;
                        entity.addPart(createMultipartBodypart(partSessionKey, fis, partName, partMimeType));
                        log.debug(getLogPrefix() + "appended filepart [" + partSessionKey + "] with value [" + partObject + "] and name [" + partName + "]");
                    } else {
                        String partValue = (String) session.get(partSessionKey);
                        entity.addPart(createMultipartBodypart(partName, partValue, partMimeType));
                        log.debug(getLogPrefix() + "appended stringpart [" + partSessionKey + "]  with value [" + partValue + "]");
                    }
                }
            }
        }
    }
    // entity.seContentType(contentTypeMtom);
    return entity.build();
}
Also used : MultipartEntityBuilder(nl.nn.adapterframework.http.mime.MultipartEntityBuilder) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 92 with SenderException

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

the class ResultSet2FileSender method sendMessage.

protected String sendMessage(Connection connection, String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    int counter = 0;
    ResultSet resultset = null;
    String fileName = (String) prc.getSession().get(getFileNameSessionKey());
    int maxRecords = -1;
    if (StringUtils.isNotEmpty(getMaxRecordsSessionKey())) {
        maxRecords = Integer.parseInt((String) prc.getSession().get(getMaxRecordsSessionKey()));
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(fileName, isAppend());
        PreparedStatement statement = getStatement(connection, correlationID, null, true);
        resultset = statement.executeQuery();
        boolean eor = false;
        if (maxRecords == 0) {
            eor = true;
        }
        while (resultset.next() && !eor) {
            counter++;
            processResultSet(resultset, fos, counter);
            if (maxRecords >= 0 && counter >= maxRecords) {
                ResultSetMetaData rsmd = resultset.getMetaData();
                if (rsmd.getColumnCount() >= 3) {
                    String group = resultset.getString(3);
                    while (resultset.next() && !eor) {
                        String groupNext = resultset.getString(3);
                        if (groupNext.equals(group)) {
                            counter++;
                            processResultSet(resultset, fos, counter);
                        } else {
                            eor = true;
                        }
                    }
                } else {
                    eor = true;
                }
            }
        }
    } catch (FileNotFoundException e) {
        throw new SenderException(getLogPrefix() + "could not find file [" + fileName + "]", e);
    } catch (IOException e) {
        throw new SenderException(getLogPrefix() + "got IOException", e);
    } 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);
    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
        } catch (IOException e) {
            log.warn(new SenderException(getLogPrefix() + "got exception closing fileoutputstream", e));
        }
        try {
            if (resultset != null) {
                resultset.close();
            }
        } catch (SQLException e) {
            log.warn(new SenderException(getLogPrefix() + "got exception closing resultset", e));
        }
    }
    return "<result><rowsprocessed>" + counter + "</rowsprocessed></result>";
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SQLException(java.sql.SQLException) FileOutputStream(java.io.FileOutputStream) ResultSet(java.sql.ResultSet) FileNotFoundException(java.io.FileNotFoundException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException)

Example 93 with SenderException

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

the class ResultSetIterator method hasNext.

public boolean hasNext() throws SenderException {
    try {
        if (!lineChecked) {
            lineAvailable = rs.next();
            lineChecked = true;
        }
        return lineAvailable;
    } catch (Exception e) {
        throw new SenderException(e);
    }
}
Also used : SenderException(nl.nn.adapterframework.core.SenderException) SQLException(java.sql.SQLException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 94 with SenderException

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

the class XmlQuerySender method selectQuery.

private String selectQuery(Connection connection, String correlationID, String tableName, Vector columns, String where, String order) throws SenderException, JdbcException {
    try {
        String query = "SELECT ";
        if (columns != null) {
            Iterator iter = columns.iterator();
            boolean firstColumn = true;
            while (iter.hasNext()) {
                Column column = (Column) iter.next();
                if (firstColumn) {
                    query = query + column.getName();
                    firstColumn = false;
                } else {
                    query = query + "," + column.getName();
                }
            }
        } else {
            query = query + "*";
        }
        query = query + " FROM " + tableName;
        if (where != null) {
            query = query + " WHERE " + where;
        }
        if (order != null) {
            query = query + " ORDER BY " + order;
        }
        PreparedStatement statement = getStatement(connection, correlationID, query, false);
        statement.setQueryTimeout(getTimeout());
        setBlobSmartGet(true);
        return executeSelectQuery(statement, null, null);
    } catch (SQLException e) {
        throw new SenderException(getLogPrefix() + "got exception executing a SELECT SQL command", e);
    }
}
Also used : SQLException(java.sql.SQLException) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) SenderException(nl.nn.adapterframework.core.SenderException)

Example 95 with SenderException

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

the class XmlQuerySender method sendMessage.

@Override
protected String sendMessage(Connection connection, String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queryElement;
    String tableName = null;
    Vector columns = null;
    String where = null;
    String order = null;
    String result = null;
    try {
        queryElement = XmlUtils.buildElement(message);
        String root = queryElement.getTagName();
        tableName = XmlUtils.getChildTagAsString(queryElement, "tableName");
        Element columnsElement = XmlUtils.getFirstChildTag(queryElement, "columns");
        if (columnsElement != null) {
            columns = getColumns(columnsElement);
        }
        where = XmlUtils.getChildTagAsString(queryElement, "where");
        order = XmlUtils.getChildTagAsString(queryElement, "order");
        if (root.equalsIgnoreCase("select")) {
            result = selectQuery(connection, correlationID, tableName, columns, where, order);
        } else {
            if (root.equalsIgnoreCase("insert")) {
                result = insertQuery(connection, correlationID, prc, tableName, columns);
            } else {
                if (root.equalsIgnoreCase("delete")) {
                    result = deleteQuery(connection, correlationID, tableName, where);
                } else {
                    if (root.equalsIgnoreCase("update")) {
                        result = updateQuery(connection, correlationID, tableName, columns, where);
                    } else {
                        if (root.equalsIgnoreCase("alter")) {
                            String sequenceName = XmlUtils.getChildTagAsString(queryElement, "sequenceName");
                            int startWith = Integer.parseInt(XmlUtils.getChildTagAsString(queryElement, "startWith"));
                            result = alterQuery(connection, sequenceName, startWith);
                        } else {
                            if (root.equalsIgnoreCase("sql")) {
                                String type = XmlUtils.getChildTagAsString(queryElement, "type");
                                String query = XmlUtils.getChildTagAsString(queryElement, "query");
                                result = sql(connection, correlationID, query, type);
                            } else {
                                throw new SenderException(getLogPrefix() + "unknown root element [" + root + "]");
                            }
                        }
                    }
                }
            }
        }
    } catch (DomBuilderException e) {
        throw new SenderException(getLogPrefix() + "got exception parsing [" + message + "]", e);
    } catch (JdbcException e) {
        throw new SenderException(getLogPrefix() + "got exception preparing [" + message + "]", e);
    }
    return result;
}
Also used : Element(org.w3c.dom.Element) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) Vector(java.util.Vector)

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