Search in sources :

Example 1 with DB2XMLWriter

use of nl.nn.adapterframework.util.DB2XMLWriter in project iaf by ibissource.

the class JdbcQuerySenderBase method getResult.

protected String getResult(ResultSet resultset, Object blobSessionVar, Object clobSessionVar, HttpServletResponse response, String contentType, String contentDisposition) throws JdbcException, SQLException, IOException, JMSException {
    String result = null;
    if (isScalar()) {
        if (resultset.next()) {
            // result = resultset.getString(1);
            ResultSetMetaData rsmeta = resultset.getMetaData();
            if (JdbcUtil.isBlobType(resultset, 1, rsmeta)) {
                if (response == null) {
                    if (blobSessionVar != null) {
                        JdbcUtil.streamBlob(resultset, 1, getBlobCharset(), isBlobsCompressed(), getBlobBase64Direction(), blobSessionVar, isCloseOutputstreamOnExit());
                        return "";
                    }
                } else {
                    InputStream inputStream = JdbcUtil.getBlobInputStream(resultset, 1, isBlobsCompressed());
                    if (StringUtils.isNotEmpty(contentType)) {
                        response.setHeader("Content-Type", contentType);
                    }
                    if (StringUtils.isNotEmpty(contentDisposition)) {
                        response.setHeader("Content-Disposition", contentDisposition);
                    }
                    if (getBlobBase64Direction() != null) {
                        if ("decode".equalsIgnoreCase(getBlobBase64Direction())) {
                            inputStream = new Base64InputStream(inputStream);
                        } else if ("encode".equalsIgnoreCase(getBlobBase64Direction())) {
                            inputStream = new Base64InputStream(inputStream, true);
                        }
                    }
                    OutputStream outputStream = response.getOutputStream();
                    Misc.streamToStream(inputStream, outputStream);
                    log.debug(getLogPrefix() + "copied blob input stream [" + inputStream + "] to output stream [" + outputStream + "]");
                    return "";
                }
            }
            if (clobSessionVar != null && JdbcUtil.isClobType(resultset, 1, rsmeta)) {
                JdbcUtil.streamClob(resultset, 1, clobSessionVar, isCloseOutputstreamOnExit());
                return "";
            }
            result = JdbcUtil.getValue(resultset, 1, rsmeta, getBlobCharset(), isBlobsCompressed(), getNullValue(), isTrimSpaces(), isBlobSmartGet(), StringUtils.isEmpty(getBlobCharset()));
            if (resultset.wasNull()) {
                if (isScalarExtended()) {
                    result = "[null]";
                } else {
                    result = null;
                }
            } else {
                if (result.length() == 0) {
                    if (isScalarExtended()) {
                        result = "[empty]";
                    }
                }
            }
        } else {
            if (isScalarExtended()) {
                result = "[absent]";
            }
        }
    } else {
        // Create XML and give the maxlength as a parameter
        DB2XMLWriter db2xml = new DB2XMLWriter();
        db2xml.setNullValue(getNullValue());
        db2xml.setTrimSpaces(isTrimSpaces());
        db2xml.setBlobCharset(getBlobCharset());
        db2xml.setDecompressBlobs(isBlobsCompressed());
        db2xml.setGetBlobSmart(isBlobSmartGet());
        result = db2xml.getXML(resultset, getMaxRows(), isIncludeFieldDefinition());
    }
    return result;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DB2XMLWriter(nl.nn.adapterframework.util.DB2XMLWriter) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream)

Aggregations

InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 DB2XMLWriter (nl.nn.adapterframework.util.DB2XMLWriter)1 Base64InputStream (org.apache.commons.codec.binary.Base64InputStream)1