Search in sources :

Example 61 with ListenerException

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

the class SimpleJdbcListener method getRawMessage.

protected Object getRawMessage(Connection conn, Map threadContext) throws ListenerException {
    String query = getSelectQuery();
    try {
        Statement stmt = null;
        try {
            stmt = conn.createStatement();
            stmt.setFetchSize(1);
            ResultSet rs = null;
            try {
                if (trace && log.isDebugEnabled())
                    log.debug("executing query for [" + query + "]");
                rs = stmt.executeQuery(query);
                if (!rs.next()) {
                    return null;
                }
                int count = rs.getInt(1);
                if (count == 0) {
                    return null;
                }
                return "<count>" + count + "</count>";
            } finally {
                if (rs != null) {
                    rs.close();
                }
            }
        } finally {
            if (stmt != null) {
                stmt.close();
            }
        }
    } catch (Exception e) {
        throw new ListenerException(getLogPrefix() + "caught exception retrieving message using query [" + query + "]", e);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 62 with ListenerException

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

the class DirectoryListener method archiveFile.

/**
 * Moves a file to another directory and places a UUID in the name.
 * @return String with the name of the (renamed and moved) file
 */
protected String archiveFile(IPipeLineSession session, File file) throws ListenerException {
    // Move file to new directory
    String newFilename = null;
    try {
        File rename2 = new File(getOutputDirectory(), FileUtils.getFilename(null, session, file, getOutputFilenamePattern()));
        newFilename = FileUtils.moveFile(file, rename2, isOverwrite(), getNumberOfBackups(), getNumberOfAttempts(), getWaitBeforeRetry());
        if (newFilename == null) {
            throw new ListenerException(getName() + " was unable to rename file [" + file.getAbsolutePath() + "] to [" + getOutputDirectory() + "]");
        }
        if (passWithoutDirectory) {
            File newFile = new File(newFilename);
            newFilename = newFile.getName();
        }
        return newFilename;
    } catch (Exception e) {
        throw new ListenerException(getName() + " was unable to rename file [" + file.getAbsolutePath() + "] to [" + getOutputDirectory() + "]", e);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) File(java.io.File) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SAXException(org.xml.sax.SAXException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 63 with ListenerException

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

the class DirectoryListener method afterMessageProcessed.

public void afterMessageProcessed(PipeLineResult processResult, Object rawMessage, Map context) throws ListenerException {
    if (isDelete() || StringUtils.isNotEmpty(getProcessedDirectory())) {
        if (getFileList() != null) {
            try {
                XmlUtils.parseXml(new AfterMessageProcessedHandler(), (String) rawMessage);
            } catch (Exception e) {
                throw new ListenerException("Could not move files [" + rawMessage + "]", e);
            }
        } else {
            String filename = getStringFromRawMessage(rawMessage, context);
            moveFileAfterProcessing(filename);
        }
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SAXException(org.xml.sax.SAXException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 64 with ListenerException

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

the class ExchangeMailListener method getStringFromRawMessage.

public String getStringFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {
    Item item = (Item) rawMessage;
    try {
        XmlBuilder emailXml = new XmlBuilder("email");
        EmailMessage emailMessage;
        PropertySet ps;
        if (isSimple()) {
            ps = new PropertySet(EmailMessageSchema.Subject);
            emailMessage = EmailMessage.bind(exchangeService, item.getId(), ps);
            addEmailInfoSimple(emailMessage, emailXml);
        } else {
            ps = new PropertySet(EmailMessageSchema.DateTimeReceived, EmailMessageSchema.From, EmailMessageSchema.Subject, EmailMessageSchema.Body, EmailMessageSchema.DateTimeSent);
            emailMessage = EmailMessage.bind(exchangeService, item.getId(), ps);
            addEmailInfo(emailMessage, emailXml);
        }
        if (StringUtils.isNotEmpty(getStoreEmailAsStreamInSessionKey())) {
            emailMessage.load(new PropertySet(ItemSchema.MimeContent));
            MimeContent mc = emailMessage.getMimeContent();
            ByteArrayInputStream bis = new ByteArrayInputStream(mc.getContent());
            threadContext.put(getStoreEmailAsStreamInSessionKey(), bis);
        }
        return emailXml.toXML();
    } catch (Exception e) {
        throw new ListenerException(e);
    }
}
Also used : Item(microsoft.exchange.webservices.data.core.service.item.Item) EmailMessage(microsoft.exchange.webservices.data.core.service.item.EmailMessage) ListenerException(nl.nn.adapterframework.core.ListenerException) ByteArrayInputStream(java.io.ByteArrayInputStream) MimeContent(microsoft.exchange.webservices.data.property.complex.MimeContent) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) PropertySet(microsoft.exchange.webservices.data.core.PropertySet) ServiceLocalException(microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 65 with ListenerException

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

the class ExchangeMailListener method getRawMessage.

public Object getRawMessage(Map threadContext) throws ListenerException {
    try {
        ItemView view = new ItemView(1);
        view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
        FindItemsResults<Item> findResults;
        if ("NDR".equalsIgnoreCase(getFilter())) {
            SearchFilter searchFilterBounce = new SearchFilter.IsEqualTo(ItemSchema.ItemClass, "REPORT.IPM.Note.NDR");
            findResults = exchangeService.findItems(folderIn.getId(), searchFilterBounce, view);
        } else {
            findResults = exchangeService.findItems(folderIn.getId(), view);
        }
        if (findResults.getTotalCount() == 0) {
            return null;
        } else {
            return findResults.getItems().get(0);
        }
    } catch (Exception e) {
        throw new ListenerException(e);
    }
}
Also used : Item(microsoft.exchange.webservices.data.core.service.item.Item) ItemView(microsoft.exchange.webservices.data.search.ItemView) ListenerException(nl.nn.adapterframework.core.ListenerException) SearchFilter(microsoft.exchange.webservices.data.search.filter.SearchFilter) ServiceLocalException(microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Aggregations

ListenerException (nl.nn.adapterframework.core.ListenerException)84 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)19 HashMap (java.util.HashMap)18 Map (java.util.Map)18 JMSException (javax.jms.JMSException)16 SenderException (nl.nn.adapterframework.core.SenderException)14 SQLException (java.sql.SQLException)13 PreparedStatement (java.sql.PreparedStatement)11 Session (javax.jms.Session)10 LinkedHashMap (java.util.LinkedHashMap)9 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)9 TimeOutException (nl.nn.adapterframework.core.TimeOutException)9 IfsaException (nl.nn.adapterframework.extensions.ifsa.IfsaException)9 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 QueueSession (javax.jms.QueueSession)8 File (java.io.File)7 MessageConsumer (javax.jms.MessageConsumer)7 Message (javax.jms.Message)6