Search in sources :

Example 71 with TimeoutException

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

the class FileSender method sendMessage.

/**
 * Send the message to the specified file. After writing the message to
 * file, this method will check if the file is deleted by another party
 * (detect reading of the file).
 *
 * @param message  the message to write to file
 */
public void sendMessage(String message) throws TimeoutException, SenderException {
    if (runAnt) {
        runAntScript();
    } else {
        if (deletePath) {
            File file = new File(filename);
            if (file.exists()) {
                recursiveDelete(filename);
            }
        } else {
            if (createPath) {
                File file = new File(filename);
                if (file.exists()) {
                    throw new SenderException("Path '" + filename + "' already exists.");
                }
                file.mkdirs();
            } else {
                File file = new File(filename);
                if (!overwrite && file.exists()) {
                    throw new SenderException("File '" + filename + "' already exists.");
                }
                String pathname = file.getParent();
                File path = new File(pathname);
                if (!path.exists()) {
                    path.mkdirs();
                }
                try {
                    FileOutputStream fileOutputStream = new FileOutputStream(file);
                    fileOutputStream.write(message.getBytes(encoding));
                    fileOutputStream.close();
                } catch (Exception e) {
                    throw new SenderException("Exception writing file '" + filename + "': " + e.getMessage(), e);
                }
                long startTime = System.currentTimeMillis();
                while (checkDelete && file.exists() && System.currentTimeMillis() < startTime + timeOut) {
                    try {
                        Thread.sleep(interval);
                    } catch (InterruptedException e) {
                        throw new SenderException("Exception waiting for deletion of file '" + filename + "': " + e.getMessage(), e);
                    }
                }
                if (checkDelete && file.exists()) {
                    throw new TimeoutException("Time out waiting for deletion of file '" + filename + "'.");
                }
            }
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) SenderException(nl.nn.adapterframework.core.SenderException) File(java.io.File) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Example 72 with TimeoutException

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

the class ListenerMessageHandler method processRequest.

@Override
public Message processRequest(IListener<M> origin, String correlationId, M rawMessage, Message message, Map<String, Object> context) throws ListenerException {
    try {
        ListenerMessage requestMessage = new ListenerMessage(correlationId, message.asString(), context);
        requestMessages.add(requestMessage);
        ListenerMessage responseMessage = getResponseMessage(defaultTimeout);
        return new Message(responseMessage.getMessage());
    } catch (IOException e) {
        throw new ListenerException("cannot convert message to string", e);
    } catch (TimeoutException e) {
        throw new ListenerException("error processing request", e);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) Message(nl.nn.adapterframework.stream.Message) IOException(java.io.IOException) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Example 73 with TimeoutException

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

the class SenderThread method run.

@Override
public void run() {
    try {
        if (session == null) {
            session = new PipeLineSession();
        }
        session.put(PipeLineSession.businessCorrelationIdKey, TestTool.TESTTOOL_CORRELATIONID);
        response = sender.sendMessage(new Message(request), session).asString();
    } catch (SenderException e) {
        if (convertExceptionToMessage) {
            response = Util.throwableToXml(e);
        } else {
            log.error("SenderException for ISender '" + name + "'", e);
            senderException = e;
        }
    } catch (IOException e) {
        if (convertExceptionToMessage) {
            response = Util.throwableToXml(e);
        } else {
            log.error("IOException for ISender '" + name + "'", e);
            ioException = e;
        }
    } catch (TimeoutException e) {
        if (convertExceptionToMessage) {
            response = Util.throwableToXml(e);
        } else {
            log.error("timeOutException for ISender '" + name + "'", e);
            timeOutException = e;
        }
    }
}
Also used : Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

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