Search in sources :

Example 36 with ListenerException

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

the class ReceiverBase method moveInProcessToError.

private void moveInProcessToError(String originalMessageId, String correlationId, String message, Date receivedDate, String comments, Object rawMessage, TransactionDefinition txDef) {
    cachePoisonMessageId(originalMessageId);
    ISender errorSender = getErrorSender();
    ITransactionalStorage errorStorage = getErrorStorage();
    if (errorSender == null && errorStorage == null) {
        log.debug(getLogPrefix() + "has no errorSender or errorStorage, will not move message with id [" + originalMessageId + "] correlationId [" + correlationId + "] to errorSender/errorStorage");
        return;
    }
    throwEvent(RCV_MESSAGE_TO_ERRORSTORE_EVENT);
    log.debug(getLogPrefix() + "moves message with id [" + originalMessageId + "] correlationId [" + correlationId + "] to errorSender/errorStorage");
    TransactionStatus txStatus = null;
    try {
        txStatus = txManager.getTransaction(txDef);
    } catch (Exception e) {
        log.error(getLogPrefix() + "Exception preparing to move input message with id [" + originalMessageId + "] to error sender", e);
        // no use trying again to send message on errorSender, will cause same exception!
        return;
    }
    try {
        if (errorSender != null) {
            errorSender.sendMessage(correlationId, message);
        }
        Serializable sobj;
        if (rawMessage instanceof Serializable) {
            sobj = (Serializable) rawMessage;
        } else {
            try {
                sobj = new MessageWrapper(rawMessage, getListener());
            } catch (ListenerException e) {
                log.error(getLogPrefix() + "could not wrap non serializable message for messageId [" + originalMessageId + "]", e);
                sobj = message;
            }
        }
        if (hideRegex != null) {
            if (getHideMethod().equalsIgnoreCase("FIRSTHALF")) {
                message = Misc.hideFirstHalf(message, hideRegex);
            } else {
                message = Misc.hideAll(message, hideRegex);
            }
            sobj = message;
        }
        if (errorStorage != null) {
            errorStorage.storeMessage(originalMessageId, correlationId, receivedDate, comments, null, sobj);
        }
        txManager.commit(txStatus);
    } catch (Exception e) {
        log.error(getLogPrefix() + "Exception moving message with id [" + originalMessageId + "] correlationId [" + correlationId + "] to error sender, original message: [" + message + "]", e);
        try {
            if (!txStatus.isCompleted()) {
                txManager.rollback(txStatus);
            }
        } catch (Exception rbe) {
            log.error(getLogPrefix() + "Exception while rolling back transaction for message  with id [" + originalMessageId + "] correlationId [" + correlationId + "], original message: [" + message + "]", rbe);
        }
    }
}
Also used : Serializable(java.io.Serializable) ListenerException(nl.nn.adapterframework.core.ListenerException) ISender(nl.nn.adapterframework.core.ISender) TransactionStatus(org.springframework.transaction.TransactionStatus) SenderException(nl.nn.adapterframework.core.SenderException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage)

Example 37 with ListenerException

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

the class ReceiverBase method processRequest.

public String processRequest(IListener origin, String correlationId, String message, Map context, long waitingTime) throws ListenerException {
    if (getRunState() != RunStateEnum.STARTED) {
        throw new ListenerException(getLogPrefix() + "is not started");
    }
    Date tsReceived = null;
    Date tsSent = null;
    if (context != null) {
        tsReceived = (Date) context.get(IPipeLineSession.tsReceivedKey);
        tsSent = (Date) context.get(IPipeLineSession.tsSentKey);
    } else {
        context = new HashMap();
    }
    PipeLineSessionBase.setListenerParameters(context, null, correlationId, tsReceived, tsSent);
    return processMessageInAdapter(origin, message, message, null, correlationId, context, waitingTime, false);
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Date(java.util.Date)

Example 38 with ListenerException

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

the class DirectoryListener method getIdFromRawMessage.

/**
 * Returns the name of the file in process (the {@link #archiveFile(IPipeLineSession session, File file) archived} file) concatenated with the
 * record number. As the {@link #archiveFile(IPipeLineSession session, File file) archivedFile} method always renames to a
 * unique file, the combination of this filename and the recordnumber is unique, enabling tracing in case of errors
 * in the processing of the file.
 * Override this method for your specific needs!
 */
public String getIdFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {
    if (getFileList() == null) {
        String filename = rawMessage.toString();
        String correlationId = filename;
        if (isFileTimeSensitive()) {
            try {
                File f = new File(filename);
                correlationId += "-" + DateUtils.format(f.lastModified());
            } catch (Exception e) {
                throw new ListenerException("Could not get filetime from filename [" + filename + "]", e);
            }
        }
        PipeLineSessionBase.setListenerParameters(threadContext, correlationId, correlationId, null, null);
        return correlationId;
    } else {
        return null;
    }
}
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 39 with ListenerException

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

the class ExchangeMailListener method afterMessageProcessed.

public void afterMessageProcessed(PipeLineResult processResult, Object rawMessage, Map context) throws ListenerException {
    Item item = (Item) rawMessage;
    try {
        if (folderOut != null) {
            item.move(folderOut.getId());
            log.debug("moved item [" + item.getId() + "] from folder [" + folderIn.getDisplayName() + "] to folder [" + folderOut.getDisplayName() + "]");
        } else {
            item.delete(DeleteMode.MoveToDeletedItems);
            log.debug("deleted item [" + item.getId() + "] from folder [" + folderIn.getDisplayName() + "]");
        }
    } catch (Exception e) {
        throw new ListenerException(e);
    }
}
Also used : Item(microsoft.exchange.webservices.data.core.service.item.Item) ListenerException(nl.nn.adapterframework.core.ListenerException) ServiceLocalException(microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 40 with ListenerException

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

the class JavaListener method open.

@Override
public synchronized void open() throws ListenerException {
    try {
        // add myself to local list so that IbisLocalSenders can find me
        registerListener();
        // (performed only if serviceName is not empty
        if (StringUtils.isNotEmpty(getServiceName())) {
            DispatcherManagerFactory.getDispatcherManager().register(getServiceName(), this);
        }
        opened = true;
    } catch (Exception e) {
        throw new ListenerException("error occured while starting listener [" + getName() + "]", e);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ListenerException(nl.nn.adapterframework.core.ListenerException)

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