Search in sources :

Example 61 with TimeoutException

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

the class SapSender method sendMessage.

@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
    String tid = null;
    try {
        ParameterValueList pvl = null;
        if (paramList != null) {
            pvl = paramList.getValues(message, session);
        }
        SapSystem sapSystem = getSystem(pvl);
        JCoFunction function = getFunction(sapSystem, pvl);
        if (StringUtils.isEmpty(getSapSystemName())) {
            pvl.remove(getSapSystemNameParam());
        }
        if (StringUtils.isEmpty(getFunctionName())) {
            pvl.remove(getFunctionNameParam());
        }
        String correlationID = session == null ? null : session.getMessageId();
        message2FunctionCall(function, message.asString(), correlationID, pvl);
        if (log.isDebugEnabled())
            log.debug(getLogPrefix() + " function call [" + functionCall2message(function) + "]");
        JCoDestination destination = getDestination(session, sapSystem);
        tid = getTid(destination, sapSystem);
        if (StringUtils.isEmpty(tid)) {
            function.execute(destination);
        } else {
            function.execute(destination, tid);
        }
        if (isSynchronous()) {
            return functionResult2message(function);
        }
        return new Message(tid);
    } catch (Exception e) {
        throw new SenderException(e);
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) JCoFunction(com.sap.conn.jco.JCoFunction) Message(nl.nn.adapterframework.stream.Message) JCoDestination(com.sap.conn.jco.JCoDestination) SenderException(nl.nn.adapterframework.core.SenderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) SapException(nl.nn.adapterframework.extensions.sap.SapException)

Example 62 with TimeoutException

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

the class IdocSender method sendMessage.

@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
    String tid = null;
    try {
        ParameterValueList pvl = null;
        if (paramList != null) {
            pvl = paramList.getValues(message, session);
        }
        SapSystem sapSystem = getSystem(pvl);
        IDocDocument idoc = parseIdoc(sapSystem, message);
        try {
            log.trace(getLogPrefix() + "checking syntax");
            idoc.checkSyntax();
        } catch (IDocException e) {
            throw new SenderException("Syntax error in idoc", e);
        }
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix() + "parsed idoc [" + JCoIDoc.getIDocFactory().getIDocXMLProcessor().render(idoc) + "]");
        }
        JCoDestination destination = getDestination(session, sapSystem);
        tid = getTid(destination, sapSystem);
        if (tid == null) {
            throw new SenderException("could not obtain TID to send Idoc");
        }
        JCoIDoc.send(idoc, IDocFactory.IDOC_VERSION_DEFAULT, destination, tid);
        return new Message(tid);
    } catch (Exception e) {
        throw new SenderException(e);
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Message(nl.nn.adapterframework.stream.Message) JCoDestination(com.sap.conn.jco.JCoDestination) IDocDocument(com.sap.conn.idoc.IDocDocument) SenderException(nl.nn.adapterframework.core.SenderException) IDocException(com.sap.conn.idoc.IDocException) IDocException(com.sap.conn.idoc.IDocException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Example 63 with TimeoutException

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

the class FileSystemSenderWithAttachments method sendMessage.

@Override
public PipeRunResult sendMessage(Message message, PipeLineSession session, IForwardTarget next) throws SenderException, TimeoutException {
    if (getAction() != FileSystemAction.LISTATTACHMENTS) {
        return super.sendMessage(message, session, next);
    } else {
        IBasicFileSystem<F> ifs = getFileSystem();
        F file;
        try {
            file = ifs.toFile(message.asString());
        } catch (Exception e) {
            throw new SenderException(getLogPrefix() + "unable to get file", e);
        }
        XmlBuilder attachments = new XmlBuilder("attachments");
        IWithAttachments<F, A> withAttachments = getFileSystem();
        try {
            Iterator<A> it = withAttachments.listAttachments(file);
            if (it != null) {
                while (it.hasNext()) {
                    A attachment = it.next();
                    XmlBuilder attachmentXml = new XmlBuilder("attachment");
                    attachmentXml.addAttribute("name", withAttachments.getAttachmentName(attachment));
                    attachmentXml.addAttribute("contentType", withAttachments.getAttachmentContentType(attachment));
                    attachmentXml.addAttribute("size", withAttachments.getAttachmentSize(attachment));
                    attachmentXml.addAttribute("filename", withAttachments.getAttachmentFileName(attachment));
                    FileAttachment fileAttachment = (FileAttachment) attachment;
                    fileAttachment.load();
                    if (!attachmentsAsSessionKeys) {
                        InputStream binaryInputStream = new ByteArrayInputStream(fileAttachment.getContent());
                        InputStream base64 = new Base64InputStream(binaryInputStream, true);
                        attachmentXml.setCdataValue(Misc.streamToString(base64, StreamUtil.DEFAULT_INPUT_STREAM_ENCODING));
                    } else {
                        attachmentXml.setValue(fileAttachment.getName());
                        session.put(fileAttachment.getName(), fileAttachment.getContent());
                    }
                    attachments.addSubElement(attachmentXml);
                }
            }
        } catch (Exception e) {
            log.error("unable to list all attachments", e);
            throw new SenderException(e);
        }
        return new PipeRunResult(null, attachments.toString());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) InputStream(java.io.InputStream) FileAttachment(microsoft.exchange.webservices.data.property.complex.FileAttachment) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) SenderException(nl.nn.adapterframework.core.SenderException) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream)

Example 64 with TimeoutException

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

the class JdbcQuerySenderBase method provideOutputStream.

@Override
public MessageOutputStream provideOutputStream(PipeLineSession session, IForwardTarget next) throws StreamingException {
    if (!canProvideOutputStream()) {
        return null;
    }
    return TransactionConnectorCoordinator.doInUnsuspendedTransationContext(() -> {
        final Connection connection;
        QueryExecutionContext queryExecutionContext;
        try {
            connection = getConnectionWithTimeout(getTimeout());
            queryExecutionContext = getQueryExecutionContext(connection, null, session);
        } catch (JdbcException | ParameterException | SQLException | SenderException | TimeoutException e) {
            throw new StreamingException(getLogPrefix() + "cannot getQueryExecutionContext", e);
        }
        try {
            PreparedStatement statement = queryExecutionContext.getStatement();
            if (queryExecutionContext.getParameterList() != null) {
                JdbcUtil.applyParameters(getDbmsSupport(), statement, queryExecutionContext.getParameterList().getValues(new Message(""), session));
            }
            if (queryExecutionContext.getQueryType() == QueryType.UPDATEBLOB) {
                BlobOutputStream blobOutputStream = getBlobOutputStream(statement, blobColumn, isBlobsCompressed());
                TransactionConnectorCoordinator.onEndChildThread(() -> {
                    blobOutputStream.close();
                    connection.close();
                    log.warn(getLogPrefix() + "warnings: " + blobOutputStream.getWarnings().toXML());
                });
                return new MessageOutputStream(this, blobOutputStream, next) {

                    // perform close() on MessageOutputStream.close(), necessary when no TransactionConnector available for onEndThread()
                    @Override
                    public void afterClose() throws SQLException {
                        if (!connection.isClosed()) {
                            connection.close();
                        }
                        log.warn(getLogPrefix() + "warnings: " + blobOutputStream.getWarnings().toXML());
                    }
                };
            }
            if (queryExecutionContext.getQueryType() == QueryType.UPDATECLOB) {
                ClobWriter clobWriter = getClobWriter(statement, getClobColumn());
                TransactionConnectorCoordinator.onEndChildThread(() -> {
                    clobWriter.close();
                    connection.close();
                    log.warn(getLogPrefix() + "warnings: " + clobWriter.getWarnings().toXML());
                });
                return new MessageOutputStream(this, clobWriter, next) {

                    // perform close() on MessageOutputStream.close(), necessary when no TransactionConnector available for onEndThread()
                    @Override
                    public void afterClose() throws SQLException {
                        if (!connection.isClosed()) {
                            connection.close();
                        }
                        log.warn(getLogPrefix() + "warnings: " + clobWriter.getWarnings().toXML());
                    }
                };
            }
            throw new IllegalArgumentException(getLogPrefix() + "illegal queryType [" + queryExecutionContext.getQueryType() + "], must be 'updateBlob' or 'updateClob'");
        } catch (JdbcException | SQLException | IOException | ParameterException e) {
            throw new StreamingException(getLogPrefix() + "cannot update CLOB or BLOB", e);
        }
    });
}
Also used : StreamingException(nl.nn.adapterframework.stream.StreamingException) Message(nl.nn.adapterframework.stream.Message) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) MessageOutputStream(nl.nn.adapterframework.stream.MessageOutputStream) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Example 65 with TimeoutException

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

the class ResultSet2FileSender method executeStatementSet.

@Override
protected PipeRunResult executeStatementSet(QueryExecutionContext queryExecutionContext, Message message, PipeLineSession session, IForwardTarget next) throws SenderException, TimeoutException {
    int counter = 0;
    String fileName = null;
    try {
        fileName = session.getMessage(getFilenameSessionKey()).asString();
    } catch (IOException e) {
        throw new SenderException(getLogPrefix() + "unable to get filename from session key [" + getFilenameSessionKey() + "]", e);
    }
    int maxRecords = -1;
    if (StringUtils.isNotEmpty(getMaxRecordsSessionKey())) {
        try {
            maxRecords = Integer.parseInt(session.getMessage(getMaxRecordsSessionKey()).asString());
        } catch (Exception e) {
            throw new SenderException(getLogPrefix() + "unable to parse " + getMaxRecordsSessionKey() + " to integer", e);
        }
    }
    try (FileOutputStream fos = new FileOutputStream(fileName, isAppend())) {
        PreparedStatement statement = queryExecutionContext.getStatement();
        JdbcUtil.applyParameters(getDbmsSupport(), statement, queryExecutionContext.getParameterList(), message, session);
        try (ResultSet 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 (ParameterException e) {
        throw new SenderException(getLogPrefix() + "got Exception resolving parameter", 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);
    }
    return new PipeRunResult(null, new Message("<result><rowsprocessed>" + counter + "</rowsprocessed></result>"));
}
Also used : Message(nl.nn.adapterframework.stream.Message) SQLException(java.sql.SQLException) FileNotFoundException(java.io.FileNotFoundException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) ParameterException(nl.nn.adapterframework.core.ParameterException) ResultSetMetaData(java.sql.ResultSetMetaData) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) FileOutputStream(java.io.FileOutputStream) ResultSet(java.sql.ResultSet) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)68 TimeoutException (nl.nn.adapterframework.core.TimeoutException)45 IOException (java.io.IOException)40 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)34 TimeOutException (nl.nn.adapterframework.core.TimeOutException)28 Message (nl.nn.adapterframework.stream.Message)26 ParameterException (nl.nn.adapterframework.core.ParameterException)24 HashMap (java.util.HashMap)20 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)18 Map (java.util.Map)16 LinkedHashMap (java.util.LinkedHashMap)12 ListenerException (nl.nn.adapterframework.core.ListenerException)10 PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)9 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)9 JMSException (javax.jms.JMSException)8 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)8 FileNotFoundException (java.io.FileNotFoundException)7 InputStream (java.io.InputStream)7 SAXException (org.xml.sax.SAXException)7 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)6