use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class TestTool method closeQueues.
public static boolean closeQueues(Map<String, Map<String, Object>> queues, Properties properties, Map<String, Object> writers) {
boolean remainingMessagesFound = false;
Iterator<String> iterator;
debugMessage("Close jms senders", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String queueName = (String) iterator.next();
if ("nl.nn.adapterframework.jms.JmsSender".equals(properties.get(queueName + ".className"))) {
JmsSender jmsSender = (JmsSender) ((Map<?, ?>) queues.get(queueName)).get("jmsSender");
jmsSender.close();
debugMessage("Closed jms sender '" + queueName + "'", writers);
}
}
debugMessage("Close jms listeners", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String queueName = (String) iterator.next();
if ("nl.nn.adapterframework.jms.JmsListener".equals(properties.get(queueName + ".className"))) {
PullingJmsListener pullingJmsListener = (PullingJmsListener) ((Map<?, ?>) queues.get(queueName)).get("jmsListener");
if (jmsCleanUp(queueName, pullingJmsListener, writers)) {
remainingMessagesFound = true;
}
pullingJmsListener.close();
debugMessage("Closed jms listener '" + queueName + "'", writers);
}
}
debugMessage("Close jdbc connections", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String name = (String) iterator.next();
if ("nl.nn.adapterframework.jdbc.FixedQuerySender".equals(properties.get(name + ".className"))) {
Map<?, ?> querySendersInfo = (Map<?, ?>) queues.get(name);
FixedQuerySender prePostFixedQuerySender = (FixedQuerySender) querySendersInfo.get("prePostQueryFixedQuerySender");
if (prePostFixedQuerySender != null) {
try {
/* Check if the preResult and postResult are not equal. If so, then there is a
* database change that has not been read in the scenario.
* So set remainingMessagesFound to true and show the entry.
* (see also executeFixedQuerySenderRead() )
*/
String preResult = (String) querySendersInfo.get("prePostQueryResult");
PipeLineSession session = new PipeLineSession();
session.put(PipeLineSession.businessCorrelationIdKey, TestTool.TESTTOOL_CORRELATIONID);
String postResult = prePostFixedQuerySender.sendMessage(TESTTOOL_DUMMY_MESSAGE, session).asString();
if (!preResult.equals(postResult)) {
String message = null;
FixedQuerySender readQueryFixedQuerySender = (FixedQuerySender) querySendersInfo.get("readQueryQueryFixedQuerySender");
try {
message = readQueryFixedQuerySender.sendMessage(TESTTOOL_DUMMY_MESSAGE, session).asString();
} catch (TimeoutException e) {
errorMessage("Time out on execute query for '" + name + "': " + e.getMessage(), e, writers);
} catch (IOException | SenderException e) {
errorMessage("Could not execute query for '" + name + "': " + e.getMessage(), e, writers);
}
if (message != null) {
wrongPipelineMessage("Found remaining message on '" + name + "'", message, writers);
}
remainingMessagesFound = true;
}
prePostFixedQuerySender.close();
} catch (TimeoutException e) {
errorMessage("Time out on close (pre/post) '" + name + "': " + e.getMessage(), e, writers);
} catch (IOException | SenderException e) {
errorMessage("Could not close (pre/post) '" + name + "': " + e.getMessage(), e, writers);
}
}
FixedQuerySender readQueryFixedQuerySender = (FixedQuerySender) querySendersInfo.get("readQueryQueryFixedQuerySender");
readQueryFixedQuerySender.close();
}
}
debugMessage("Close ibis webservice senders", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String queueName = (String) iterator.next();
if ("nl.nn.adapterframework.http.IbisWebServiceSender".equals(properties.get(queueName + ".className"))) {
IbisWebServiceSender ibisWebServiceSender = (IbisWebServiceSender) ((Map<?, ?>) queues.get(queueName)).get("ibisWebServiceSender");
Map<?, ?> ibisWebServiceSenderInfo = (Map<?, ?>) queues.get(queueName);
SenderThread senderThread = (SenderThread) ibisWebServiceSenderInfo.remove("ibisWebServiceSenderThread");
if (senderThread != null) {
debugMessage("Found remaining SenderThread", writers);
SenderException senderException = senderThread.getSenderException();
if (senderException != null) {
errorMessage("Found remaining SenderException: " + senderException.getMessage(), senderException, writers);
}
IOException ioException = senderThread.getIOException();
if (ioException != null) {
errorMessage("Found remaining IOException: " + ioException.getMessage(), ioException, writers);
}
TimeoutException timeOutException = senderThread.getTimeOutException();
if (timeOutException != null) {
errorMessage("Found remaining TimeOutException: " + timeOutException.getMessage(), timeOutException, writers);
}
String message = senderThread.getResponse();
if (message != null) {
wrongPipelineMessage("Found remaining message on '" + queueName + "'", message, writers);
}
}
try {
ibisWebServiceSender.close();
debugMessage("Closed ibis webservice sender '" + queueName + "'", writers);
} catch (SenderException e) {
errorMessage("Could not close '" + queueName + "': " + e.getMessage(), e, writers);
}
}
}
debugMessage("Close web service senders", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String queueName = (String) iterator.next();
if ("nl.nn.adapterframework.http.WebServiceSender".equals(properties.get(queueName + ".className"))) {
WebServiceSender webServiceSender = (WebServiceSender) ((Map<?, ?>) queues.get(queueName)).get("webServiceSender");
Map<?, ?> webServiceSenderInfo = (Map<?, ?>) queues.get(queueName);
SenderThread senderThread = (SenderThread) webServiceSenderInfo.remove("webServiceSenderThread");
if (senderThread != null) {
debugMessage("Found remaining SenderThread", writers);
SenderException senderException = senderThread.getSenderException();
if (senderException != null) {
errorMessage("Found remaining SenderException: " + senderException.getMessage(), senderException, writers);
}
TimeoutException timeOutException = senderThread.getTimeOutException();
if (timeOutException != null) {
errorMessage("Found remaining TimeOutException: " + timeOutException.getMessage(), timeOutException, writers);
}
String message = senderThread.getResponse();
if (message != null) {
wrongPipelineMessage("Found remaining message on '" + queueName + "'", message, writers);
}
}
try {
webServiceSender.close();
} catch (SenderException e) {
// Ignore
}
debugMessage("Closed webservice sender '" + queueName + "'", writers);
}
}
debugMessage("Close web service listeners", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String queueName = (String) iterator.next();
if ("nl.nn.adapterframework.http.WebServiceListener".equals(properties.get(queueName + ".className"))) {
Map<?, ?> webServiceListenerInfo = (Map<?, ?>) queues.get(queueName);
WebServiceListener webServiceListener = (WebServiceListener) webServiceListenerInfo.get("webServiceListener");
webServiceListener.close();
debugMessage("Closed web service listener '" + queueName + "'", writers);
ListenerMessageHandler listenerMessageHandler = (ListenerMessageHandler) webServiceListenerInfo.get("listenerMessageHandler");
if (listenerMessageHandler != null) {
ListenerMessage listenerMessage = listenerMessageHandler.getRequestMessage();
while (listenerMessage != null) {
String message = listenerMessage.getMessage();
wrongPipelineMessage("Found remaining request message on '" + queueName + "'", message, writers);
remainingMessagesFound = true;
listenerMessage = listenerMessageHandler.getRequestMessage();
}
listenerMessage = listenerMessageHandler.getResponseMessage();
while (listenerMessage != null) {
String message = listenerMessage.getMessage();
wrongPipelineMessage("Found remaining response message on '" + queueName + "'", message, writers);
remainingMessagesFound = true;
listenerMessage = listenerMessageHandler.getResponseMessage();
}
}
}
}
debugMessage("Close ibis java senders", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String queueName = (String) iterator.next();
if ("nl.nn.adapterframework.senders.IbisJavaSender".equals(properties.get(queueName + ".className"))) {
IbisJavaSender ibisJavaSender = (IbisJavaSender) ((Map<?, ?>) queues.get(queueName)).get("ibisJavaSender");
Map<?, ?> ibisJavaSenderInfo = (Map<?, ?>) queues.get(queueName);
SenderThread ibisJavaSenderThread = (SenderThread) ibisJavaSenderInfo.remove("ibisJavaSenderThread");
if (ibisJavaSenderThread != null) {
debugMessage("Found remaining SenderThread", writers);
SenderException senderException = ibisJavaSenderThread.getSenderException();
if (senderException != null) {
errorMessage("Found remaining SenderException: " + senderException.getMessage(), senderException, writers);
}
TimeoutException timeOutException = ibisJavaSenderThread.getTimeOutException();
if (timeOutException != null) {
errorMessage("Found remaining TimeOutException: " + timeOutException.getMessage(), timeOutException, writers);
}
String message = ibisJavaSenderThread.getResponse();
if (message != null) {
wrongPipelineMessage("Found remaining message on '" + queueName + "'", message, writers);
}
}
try {
ibisJavaSender.close();
debugMessage("Closed ibis java sender '" + queueName + "'", writers);
} catch (SenderException e) {
errorMessage("Could not close '" + queueName + "': " + e.getMessage(), e, writers);
}
}
}
debugMessage("Close delay senders", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String queueName = (String) iterator.next();
if ("nl.nn.adapterframework.senders.DelaySender".equals(properties.get(queueName + ".className"))) {
DelaySender delaySender = (DelaySender) ((Map<?, ?>) queues.get(queueName)).get("delaySender");
try {
delaySender.close();
debugMessage("Closed delay sender '" + queueName + "'", writers);
} catch (SenderException e) {
errorMessage("Could not close delay sender '" + queueName + "': " + e.getMessage(), e, writers);
}
}
}
debugMessage("Close java listeners", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String queueName = (String) iterator.next();
if ("nl.nn.adapterframework.receivers.JavaListener".equals(properties.get(queueName + ".className"))) {
Map<?, ?> javaListenerInfo = (Map<?, ?>) queues.get(queueName);
JavaListener javaListener = (JavaListener) javaListenerInfo.get("javaListener");
try {
javaListener.close();
debugMessage("Closed java listener '" + queueName + "'", writers);
} catch (ListenerException e) {
errorMessage("Could not close java listener '" + queueName + "': " + e.getMessage(), e, writers);
}
ListenerMessageHandler listenerMessageHandler = (ListenerMessageHandler) javaListenerInfo.get("listenerMessageHandler");
if (listenerMessageHandler != null) {
ListenerMessage listenerMessage = listenerMessageHandler.getRequestMessage();
while (listenerMessage != null) {
String message = listenerMessage.getMessage();
wrongPipelineMessage("Found remaining request message on '" + queueName + "'", message, writers);
remainingMessagesFound = true;
listenerMessage = listenerMessageHandler.getRequestMessage();
}
listenerMessage = listenerMessageHandler.getResponseMessage();
while (listenerMessage != null) {
String message = listenerMessage.getMessage();
wrongPipelineMessage("Found remaining response message on '" + queueName + "'", message, writers);
remainingMessagesFound = true;
listenerMessage = listenerMessageHandler.getResponseMessage();
}
}
}
}
debugMessage("Close file listeners", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String queueName = (String) iterator.next();
if ("nl.nn.adapterframework.testtool.FileListener".equals(properties.get(queueName + ".className"))) {
FileListener fileListener = (FileListener) ((Map<?, ?>) queues.get(queueName)).get("fileListener");
fileListenerCleanUp(queueName, fileListener, writers);
debugMessage("Closed file listener '" + queueName + "'", writers);
}
}
debugMessage("Close xslt provider listeners", writers);
iterator = queues.keySet().iterator();
while (iterator.hasNext()) {
String queueName = (String) iterator.next();
if ("nl.nn.adapterframework.testtool.XsltProviderListener".equals(properties.get(queueName + ".className"))) {
XsltProviderListener xsltProviderListener = (XsltProviderListener) ((Map<?, ?>) queues.get(queueName)).get("xsltProviderListener");
xsltProviderListenerCleanUp(queues, queueName, writers);
debugMessage("Closed xslt provider listener '" + queueName + "'", writers);
}
}
return remainingMessagesFound;
}
use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class FileListener method getMessage.
/**
* Read the message from the specified file. If the file doesn't exist,
* this methods waits a specified time before it attempts to read the file.
*
* @return The message read from the specified file
*/
public String getMessage() throws TimeoutException, ListenerException {
String result = null;
if (waitBeforeRead != -1) {
try {
Thread.sleep(waitBeforeRead);
} catch (InterruptedException e) {
throw new ListenerException("Exception waiting before reading the file: " + e.getMessage(), e);
}
}
File file = null;
if (filename == null) {
File[] files = FileUtils.getFiles(directory, wildcard, null, 0);
if (files.length > 0) {
file = files[0];
}
} else {
file = new File(filename);
}
if (filename2 != null) {
try {
File file2 = new File(filename2);
boolean equal = FileUtils.isFileBinaryEqual(file, file2);
result = Boolean.toString(equal);
} catch (IOException e) {
throw new ListenerException("Exception comparing files '" + filename + "' and '" + filename2 + "': " + e.getMessage(), e);
}
} else {
long startTime = System.currentTimeMillis();
while ((file == null || !file.exists()) && System.currentTimeMillis() < startTime + timeOut) {
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
throw new ListenerException("Exception waiting for file: " + e.getMessage(), e);
}
if (filename == null) {
File[] files = FileUtils.getFiles(directory, wildcard, null, 0);
if (files.length > 0) {
file = files[0];
}
}
}
if (file != null && file.exists()) {
StringBuffer stringBuffer = new StringBuffer();
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(file);
} catch (IOException e) {
throw new ListenerException("Exception opening file '" + file.getAbsolutePath() + "': " + e.getMessage(), e);
}
byte[] buffer = new byte[1024];
try {
int length = fileInputStream.read(buffer);
while (length != -1) {
stringBuffer.append(new String(buffer, 0, length, "UTF-8"));
length = fileInputStream.read(buffer);
}
} catch (IOException e) {
try {
fileInputStream.close();
} catch (Exception e2) {
}
throw new ListenerException("Exception reading file '" + file.getAbsolutePath() + "': " + e.getMessage(), e);
}
try {
fileInputStream.close();
} catch (IOException e) {
throw new ListenerException("Exception closing file '" + file.getAbsolutePath() + "': " + e.getMessage(), e);
}
result = stringBuffer.toString();
if (!file.delete()) {
throw new ListenerException("Could not delete file '" + file.getAbsolutePath() + "'.");
}
} else {
throw new TimeoutException("Time out waiting for file.");
}
}
return result;
}
use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class JmsSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc, String soapHeader) throws SenderException, TimeOutException {
Session s = null;
MessageProducer mp = null;
ParameterValueList pvl = null;
if (prc != null && paramList != null) {
try {
pvl = prc.getValues(paramList);
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "cannot extract parameters", e);
}
}
if (isSoap()) {
if (soapHeader == null) {
if (pvl != null && StringUtils.isNotEmpty(getSoapHeaderParam())) {
ParameterValue soapHeaderParamValue = pvl.getParameterValue(getSoapHeaderParam());
if (soapHeaderParamValue == null) {
log.warn("no SoapHeader found using parameter [" + getSoapHeaderParam() + "]");
} else {
soapHeader = soapHeaderParamValue.asStringValue("");
}
}
}
message = soapWrapper.putInEnvelope(message, getEncodingStyleURI(), getServiceNamespaceURI(), soapHeader);
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "correlationId [" + correlationID + "] soap message [" + message + "]");
}
try {
s = createSession();
mp = getMessageProducer(s, getDestination(prc));
Destination replyQueue = null;
// create message
Message msg = createTextMessage(s, correlationID, message);
if (getMessageType() != null) {
msg.setJMSType(getMessageType());
}
if (getDeliveryModeInt() > 0) {
msg.setJMSDeliveryMode(getDeliveryModeInt());
mp.setDeliveryMode(getDeliveryModeInt());
}
if (getPriority() >= 0) {
msg.setJMSPriority(getPriority());
mp.setPriority(getPriority());
}
// set properties
if (pvl != null) {
setProperties(msg, pvl);
}
if (replyToName != null) {
replyQueue = getDestination(replyToName);
} else {
if (isSynchronous()) {
replyQueue = getMessagingSource().getDynamicReplyQueue(s);
}
}
if (replyQueue != null) {
msg.setJMSReplyTo(replyQueue);
if (log.isDebugEnabled())
log.debug("replyTo set to queue [" + replyQueue.toString() + "]");
}
// send message
send(mp, msg);
if (log.isDebugEnabled()) {
log.debug("[" + getName() + "] " + "sent message [" + message + "] " + "to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : ""));
} else {
if (log.isInfoEnabled()) {
log.info("[" + getName() + "] " + "sent message to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : ""));
}
}
if (isSynchronous()) {
String replyCorrelationId = null;
if (replyToName != null) {
if ("CORRELATIONID".equalsIgnoreCase(getLinkMethod())) {
replyCorrelationId = correlationID;
} else if ("CORRELATIONID_FROM_MESSAGE".equalsIgnoreCase(getLinkMethod())) {
replyCorrelationId = msg.getJMSCorrelationID();
} else {
replyCorrelationId = msg.getJMSMessageID();
}
}
if (log.isDebugEnabled())
log.debug("[" + getName() + "] start waiting for reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] for [" + getReplyTimeout() + "] ms");
MessageConsumer mc = getMessageConsumerForCorrelationId(s, replyQueue, replyCorrelationId);
try {
Message rawReplyMsg = mc.receive(getReplyTimeout());
if (rawReplyMsg == null) {
throw new TimeOutException("did not receive reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] within [" + getReplyTimeout() + "] ms");
}
return getStringFromRawMessage(rawReplyMsg, prc != null ? prc.getSession() : null, isSoap(), getReplySoapHeaderSessionKey(), soapWrapper);
} finally {
if (mc != null) {
try {
mc.close();
} catch (JMSException e) {
log.warn("JmsSender [" + getName() + "] got exception closing message consumer for reply", e);
}
}
}
}
return msg.getJMSMessageID();
} catch (JMSException e) {
throw new SenderException(e);
} catch (IOException e) {
throw new SenderException(e);
} catch (NamingException e) {
throw new SenderException(e);
} catch (DomBuilderException e) {
throw new SenderException(e);
} catch (TransformerException e) {
throw new SenderException(e);
} catch (JmsException e) {
throw new SenderException(e);
} finally {
if (mp != null) {
try {
mp.close();
} catch (JMSException e) {
log.warn("JmsSender [" + getName() + "] got exception closing message producer", e);
}
}
closeSession(s);
}
}
use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class CmisHttpSender method invoke.
public Response invoke(String url, Map<String, String> headers, Output writer, BindingSession session, BigInteger offset, BigInteger length) throws SenderException, TimeOutException {
// Prepare the message. We will overwrite things later...
this.headers = headers;
int responseCode = -1;
IPipeLineSession pls = new PipeLineSessionBase();
pls.put("writer", writer);
pls.put("url", url);
ParameterResolutionContext prc = new ParameterResolutionContext("", pls);
try {
sendMessageWithTimeoutGuarded(null, null, prc);
return (Response) pls.get("response");
} catch (Exception e) {
throw new CmisConnectionException(getUrl(), responseCode, e);
}
}
use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class FtpSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
try {
IPipeLineSession session = null;
if (prc != null) {
session = prc.getSession();
}
ftpSession.put(paramList, session, message, remoteDirectory, remoteFilenamePattern, true);
} catch (SenderException e) {
throw e;
} catch (Exception e) {
throw new SenderException("Error during ftp-ing " + message, e);
}
return message;
}
Aggregations