use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class TestTool method closeQueues.
public static boolean closeQueues(Map queues, Properties properties, Map writers) {
boolean remainingMessagesFound = false;
Iterator 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");
String postResult = prePostFixedQuerySender.sendMessage(TESTTOOL_CORRELATIONID, TESTTOOL_DUMMY_MESSAGE);
if (!preResult.equals(postResult)) {
String message = null;
FixedQuerySender readQueryFixedQuerySender = (FixedQuerySender) querySendersInfo.get("readQueryQueryFixedQuerySender");
try {
message = readQueryFixedQuerySender.sendMessage(TESTTOOL_CORRELATIONID, TESTTOOL_DUMMY_MESSAGE);
} catch (TimeOutException e) {
errorMessage("Time out on execute query for '" + name + "': " + e.getMessage(), e, writers);
} catch (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 (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);
}
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);
}
}
webServiceSender.close();
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(0);
while (listenerMessage != null) {
String message = listenerMessage.getMessage();
wrongPipelineMessage("Found remaining request message on '" + queueName + "'", message, writers);
remainingMessagesFound = true;
listenerMessage = listenerMessageHandler.getRequestMessage(0);
}
listenerMessage = listenerMessageHandler.getResponseMessage(0);
while (listenerMessage != null) {
String message = listenerMessage.getMessage();
wrongPipelineMessage("Found remaining response message on '" + queueName + "'", message, writers);
remainingMessagesFound = true;
listenerMessage = listenerMessageHandler.getResponseMessage(0);
}
}
}
}
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(0);
while (listenerMessage != null) {
String message = listenerMessage.getMessage();
wrongPipelineMessage("Found remaining request message on '" + queueName + "'", message, writers);
remainingMessagesFound = true;
listenerMessage = listenerMessageHandler.getRequestMessage(0);
}
listenerMessage = listenerMessageHandler.getResponseMessage(0);
while (listenerMessage != null) {
String message = listenerMessage.getMessage();
wrongPipelineMessage("Found remaining response message on '" + queueName + "'", message, writers);
remainingMessagesFound = true;
listenerMessage = listenerMessageHandler.getResponseMessage(0);
}
}
}
}
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 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
* @throws TimeOutException
* @throws SenderException
*/
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 + "'.");
}
}
}
}
}
use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class SapSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String tid = null;
try {
ParameterValueList pvl = null;
if (prc != null) {
pvl = prc.getValues(paramList);
}
SapSystem sapSystem = getSystem(pvl);
JCoFunction function = getFunction(sapSystem, pvl);
if (StringUtils.isEmpty(getSapSystemName())) {
pvl.removeParameterValue(getSapSystemNameParam());
}
if (StringUtils.isEmpty(getFunctionName())) {
pvl.removeParameterValue(getFunctionNameParam());
}
message2FunctionCall(function, message, correlationID, pvl);
if (log.isDebugEnabled())
log.debug(getLogPrefix() + " function call [" + functionCall2message(function) + "]");
JCoDestination destination = getDestination(prc.getSession(), sapSystem);
tid = getTid(destination, sapSystem);
if (StringUtils.isEmpty(tid)) {
function.execute(destination);
} else {
function.execute(destination, tid);
}
if (isSynchronous()) {
return functionResult2message(function);
} else {
return tid;
}
} catch (Exception e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class IbisJavaSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String result = null;
HashMap context = null;
try {
if (paramList != null) {
context = (HashMap) prc.getValueMap(paramList);
} else {
context = new HashMap();
}
DispatcherManager dm = null;
Class c = Class.forName("nl.nn.adapterframework.dispatcher.DispatcherManagerFactory");
if (getDispatchType().equalsIgnoreCase("DLL")) {
String version = nl.nn.adapterframework.dispatcher.Version.version;
if (version.contains("IbisServiceDispatcher 1.3"))
throw new SenderException("IBIS-ServiceDispatcher out of date! Please update to version 1.4 or higher");
Method getDispatcherManager = c.getMethod("getDispatcherManager", String.class);
dm = (DispatcherManager) getDispatcherManager.invoke(null, getDispatchType());
} else {
Method getDispatcherManager = c.getMethod("getDispatcherManager");
dm = (DispatcherManager) getDispatcherManager.invoke(null, (Object[]) null);
}
result = dm.processRequest(getServiceName(), correlationID, message, context);
if (isMultipartResponse()) {
return HttpSender.handleMultipartResponse(multipartResponseContentType, new ByteArrayInputStream(result.getBytes(multipartResponseCharset)), prc, null);
}
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "exception processing message using request processor [" + getServiceName() + "]", e);
} finally {
if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
}
if (prc != null) {
Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
}
}
return result;
}
use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class IbisLocalSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String result = null;
HashMap context = null;
if (paramList != null) {
try {
context = (HashMap) prc.getValueMap(paramList);
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
}
} else {
if (StringUtils.isNotEmpty(getReturnedSessionKeys())) {
context = new HashMap();
}
}
if (StringUtils.isNotEmpty(getServiceName())) {
try {
if (isIsolated()) {
if (isSynchronous()) {
log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in separate Thread");
result = isolatedServiceCaller.callServiceIsolated(getServiceName(), correlationID, message, context, false);
} else {
log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in asynchronously");
isolatedServiceCaller.callServiceAsynchronous(getServiceName(), correlationID, message, context, false);
result = message;
}
} else {
log.debug(getLogPrefix() + "calling service [" + getServiceName() + "] in same Thread");
result = ServiceDispatcher.getInstance().dispatchRequest(getServiceName(), correlationID, message, context);
}
} catch (ListenerException e) {
if (ExceptionUtils.getRootCause(e) instanceof TimeOutException) {
throw new TimeOutException(getLogPrefix() + "timeout calling service [" + getServiceName() + "]", e);
} else {
throw new SenderException(getLogPrefix() + "exception calling service [" + getServiceName() + "]", e);
}
} finally {
if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
}
if (prc != null) {
Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
}
}
} else {
String javaListener;
if (StringUtils.isNotEmpty(getJavaListenerSessionKey())) {
javaListener = (String) prc.getSession().get(getJavaListenerSessionKey());
} else {
javaListener = getJavaListener();
}
try {
JavaListener listener = JavaListener.getListener(javaListener);
if (listener == null) {
String msg = "could not find JavaListener [" + javaListener + "]";
if (isThrowJavaListenerNotFoundException()) {
throw new SenderException(msg);
} else {
log.info(getLogPrefix() + msg);
return "<error>" + msg + "</error>";
}
}
if (isIsolated()) {
if (isSynchronous()) {
log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in separate Thread");
result = isolatedServiceCaller.callServiceIsolated(javaListener, correlationID, message, context, true);
} else {
log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in asynchronously");
isolatedServiceCaller.callServiceAsynchronous(javaListener, correlationID, message, context, true);
result = message;
}
} else {
log.debug(getLogPrefix() + "calling JavaListener [" + javaListener + "] in same Thread");
result = listener.processRequest(correlationID, message, context);
}
} catch (ListenerException e) {
if (ExceptionUtils.getRootCause(e) instanceof TimeOutException) {
throw new TimeOutException(getLogPrefix() + "timeout calling JavaListener [" + javaListener + "]", e);
} else {
throw new SenderException(getLogPrefix() + "exception calling JavaListener [" + javaListener + "]", e);
}
} finally {
if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
}
if (prc != null) {
Misc.copyContext(getReturnedSessionKeys(), context, prc.getSession());
}
}
}
return result;
}
Aggregations