Search in sources :

Example 16 with FixedQuerySender

use of nl.nn.adapterframework.jdbc.FixedQuerySender in project iaf by ibissource.

the class TestTool method openQueues.

public static Map<String, Map<String, Object>> openQueues(String scenarioDirectory, List<String> steps, Properties properties, IbisContext ibisContext, AppConstants appConstants, Map<String, Object> writers, int parameterTimeout) {
    Map<String, Map<String, Object>> queues = new HashMap<String, Map<String, Object>>();
    debugMessage("Get all queue names", writers);
    List<String> jmsSenders = new ArrayList<String>();
    List<String> jmsListeners = new ArrayList<String>();
    List<String> jdbcFixedQuerySenders = new ArrayList<String>();
    List<String> ibisWebServiceSenders = new ArrayList<String>();
    List<String> webServiceSenders = new ArrayList<String>();
    List<String> webServiceListeners = new ArrayList<String>();
    List<String> httpSenders = new ArrayList<String>();
    List<String> ibisJavaSenders = new ArrayList<String>();
    List<String> delaySenders = new ArrayList<String>();
    List<String> javaListeners = new ArrayList<String>();
    List<String> fileSenders = new ArrayList<String>();
    List<String> fileListeners = new ArrayList<String>();
    List<String> xsltProviderListeners = new ArrayList<String>();
    Iterator iterator = properties.keySet().iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        int i = key.indexOf('.');
        if (i != -1) {
            int j = key.indexOf('.', i + 1);
            if (j != -1) {
                String queueName = key.substring(0, j);
                debugMessage("queuename openqueue: " + queueName, writers);
                if ("nl.nn.adapterframework.jms.JmsSender".equals(properties.get(queueName + ".className")) && !jmsSenders.contains(queueName)) {
                    debugMessage("Adding jmsSender queue: " + queueName, writers);
                    jmsSenders.add(queueName);
                } else if ("nl.nn.adapterframework.jms.JmsListener".equals(properties.get(queueName + ".className")) && !jmsListeners.contains(queueName)) {
                    debugMessage("Adding jmsListener queue: " + queueName, writers);
                    jmsListeners.add(queueName);
                } else if ("nl.nn.adapterframework.jdbc.FixedQuerySender".equals(properties.get(queueName + ".className")) && !jdbcFixedQuerySenders.contains(queueName)) {
                    debugMessage("Adding jdbcFixedQuerySender queue: " + queueName, writers);
                    jdbcFixedQuerySenders.add(queueName);
                } else if ("nl.nn.adapterframework.http.IbisWebServiceSender".equals(properties.get(queueName + ".className")) && !ibisWebServiceSenders.contains(queueName)) {
                    debugMessage("Adding ibisWebServiceSender queue: " + queueName, writers);
                    ibisWebServiceSenders.add(queueName);
                } else if ("nl.nn.adapterframework.http.WebServiceSender".equals(properties.get(queueName + ".className")) && !webServiceSenders.contains(queueName)) {
                    debugMessage("Adding webServiceSender queue: " + queueName, writers);
                    webServiceSenders.add(queueName);
                } else if ("nl.nn.adapterframework.http.WebServiceListener".equals(properties.get(queueName + ".className")) && !webServiceListeners.contains(queueName)) {
                    debugMessage("Adding webServiceListener queue: " + queueName, writers);
                    webServiceListeners.add(queueName);
                } else if ("nl.nn.adapterframework.http.HttpSender".equals(properties.get(queueName + ".className")) && !httpSenders.contains(queueName)) {
                    debugMessage("Adding httpSender queue: " + queueName, writers);
                    httpSenders.add(queueName);
                } else if ("nl.nn.adapterframework.senders.IbisJavaSender".equals(properties.get(queueName + ".className")) && !ibisJavaSenders.contains(queueName)) {
                    debugMessage("Adding ibisJavaSender queue: " + queueName, writers);
                    ibisJavaSenders.add(queueName);
                } else if ("nl.nn.adapterframework.senders.DelaySender".equals(properties.get(queueName + ".className")) && !delaySenders.contains(queueName)) {
                    debugMessage("Adding delaySender queue: " + queueName, writers);
                    delaySenders.add(queueName);
                } else if ("nl.nn.adapterframework.receivers.JavaListener".equals(properties.get(queueName + ".className")) && !javaListeners.contains(queueName)) {
                    debugMessage("Adding javaListener queue: " + queueName, writers);
                    javaListeners.add(queueName);
                } else if ("nl.nn.adapterframework.testtool.FileSender".equals(properties.get(queueName + ".className")) && !fileSenders.contains(queueName)) {
                    debugMessage("Adding fileSender queue: " + queueName, writers);
                    fileSenders.add(queueName);
                } else if ("nl.nn.adapterframework.testtool.FileListener".equals(properties.get(queueName + ".className")) && !fileListeners.contains(queueName)) {
                    debugMessage("Adding fileListener queue: " + queueName, writers);
                    fileListeners.add(queueName);
                } else if ("nl.nn.adapterframework.testtool.XsltProviderListener".equals(properties.get(queueName + ".className")) && !xsltProviderListeners.contains(queueName)) {
                    debugMessage("Adding xsltProviderListeners queue: " + queueName, writers);
                    xsltProviderListeners.add(queueName);
                }
            }
        }
    }
    debugMessage("Initialize jms senders", writers);
    iterator = jmsSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String queueName = (String) iterator.next();
        String queue = (String) properties.get(queueName + ".queue");
        if (queue == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find property '" + queueName + ".queue'", writers);
        } else {
            JmsSender jmsSender = (JmsSender) ibisContext.createBeanAutowireByName(JmsSender.class);
            jmsSender.setName("Test Tool JmsSender");
            jmsSender.setDestinationName(queue);
            jmsSender.setDestinationType(DestinationType.QUEUE);
            jmsSender.setAcknowledgeMode("auto");
            String jmsRealm = (String) properties.get(queueName + ".jmsRealm");
            if (jmsRealm != null) {
                jmsSender.setJmsRealm(jmsRealm);
            } else {
                jmsSender.setJmsRealm("default");
            }
            String deliveryMode = properties.getProperty(queueName + ".deliveryMode");
            debugMessage("Property '" + queueName + ".deliveryMode': " + deliveryMode, writers);
            String persistent = properties.getProperty(queueName + ".persistent");
            debugMessage("Property '" + queueName + ".persistent': " + persistent, writers);
            String useCorrelationIdFrom = properties.getProperty(queueName + ".useCorrelationIdFrom");
            debugMessage("Property '" + queueName + ".useCorrelationIdFrom': " + useCorrelationIdFrom, writers);
            String replyToName = properties.getProperty(queueName + ".replyToName");
            debugMessage("Property '" + queueName + ".replyToName': " + replyToName, writers);
            if (deliveryMode != null) {
                debugMessage("Set deliveryMode to " + deliveryMode, writers);
                jmsSender.setDeliveryMode(EnumUtils.parse(DeliveryMode.class, deliveryMode));
            }
            if ("true".equals(persistent)) {
                debugMessage("Set persistent to true", writers);
                jmsSender.setPersistent(true);
            } else {
                debugMessage("Set persistent to false", writers);
                jmsSender.setPersistent(false);
            }
            if (replyToName != null) {
                debugMessage("Set replyToName to " + replyToName, writers);
                jmsSender.setReplyToName(replyToName);
            }
            try {
                jmsSender.configure();
            } catch (ConfigurationException e) {
                throw new RuntimeException(e);
            }
            Map<String, Object> jmsSenderInfo = new HashMap<String, Object>();
            jmsSenderInfo.put("jmsSender", jmsSender);
            jmsSenderInfo.put("useCorrelationIdFrom", useCorrelationIdFrom);
            String correlationId = properties.getProperty(queueName + ".jmsCorrelationId");
            if (correlationId != null) {
                jmsSenderInfo.put("jmsCorrelationId", correlationId);
                debugMessage("Property '" + queueName + ".jmsCorrelationId': " + correlationId, writers);
            }
            queues.put(queueName, jmsSenderInfo);
            debugMessage("Opened jms sender '" + queueName + "'", writers);
        }
    }
    debugMessage("Initialize jms listeners", writers);
    iterator = jmsListeners.iterator();
    while (queues != null && iterator.hasNext()) {
        String queueName = (String) iterator.next();
        String queue = (String) properties.get(queueName + ".queue");
        String timeout = (String) properties.get(queueName + ".timeout");
        int nTimeout = parameterTimeout;
        if (timeout != null && timeout.length() > 0) {
            nTimeout = Integer.parseInt(timeout);
            debugMessage("Overriding default timeout setting of " + parameterTimeout + " with " + nTimeout, writers);
        }
        if (queue == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find property '" + queueName + ".queue'", writers);
        } else {
            PullingJmsListener pullingJmsListener = (PullingJmsListener) ibisContext.createBeanAutowireByName(PullingJmsListener.class);
            pullingJmsListener.setName("Test Tool JmsListener");
            pullingJmsListener.setDestinationName(queue);
            pullingJmsListener.setDestinationType(DestinationType.QUEUE);
            pullingJmsListener.setAcknowledgeMode("auto");
            String jmsRealm = (String) properties.get(queueName + ".jmsRealm");
            if (jmsRealm != null) {
                pullingJmsListener.setJmsRealm(jmsRealm);
            } else {
                pullingJmsListener.setJmsRealm("default");
            }
            // Call setJmsRealm twice as a workaround for a strange bug
            // where we get a java.lang.NullPointerException in a class of
            // the commons-beanutils.jar on the first call to setJmsRealm
            // after starting the Test Tool ear:
            // at org.apache.commons.beanutils.MappedPropertyDescriptor.internalFindMethod(MappedPropertyDescriptor.java(Compiled Code))
            // at org.apache.commons.beanutils.MappedPropertyDescriptor.internalFindMethod(MappedPropertyDescriptor.java:413)
            // ...
            // Looks like some sort of classloader problem where
            // internalFindMethod on another class is called (last line in
            // stacktrace has "Compiled Code" while other lines have
            // linenumbers).
            // Can be reproduced with for example:
            // - WebSphere Studio Application Developer (Windows) Version: 5.1.2
            // - Ibis4Juice build 20051104-1351
            // - y01\rr\getAgent1003\scenario01.properties
            pullingJmsListener.setTimeOut(nTimeout);
            String setForceMessageIdAsCorrelationId = (String) properties.get(queueName + ".setForceMessageIdAsCorrelationId");
            if ("true".equals(setForceMessageIdAsCorrelationId)) {
                pullingJmsListener.setForceMessageIdAsCorrelationId(true);
            }
            try {
                pullingJmsListener.configure();
            } catch (ConfigurationException e) {
                throw new RuntimeException(e);
            }
            Map<String, Object> jmsListenerInfo = new HashMap<String, Object>();
            jmsListenerInfo.put("jmsListener", pullingJmsListener);
            queues.put(queueName, jmsListenerInfo);
            debugMessage("Opened jms listener '" + queueName + "'", writers);
            if (jmsCleanUp(queueName, pullingJmsListener, writers)) {
                errorMessage("Found one or more old messages on queue '" + queueName + "', you might want to run your tests with a higher 'wait before clean up' value", writers);
            }
        }
    }
    debugMessage("Initialize jdbc fixed query senders", writers);
    iterator = jdbcFixedQuerySenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        String datasourceName = (String) properties.get(name + ".datasourceName");
        String username = (String) properties.get(name + ".username");
        String password = (String) properties.get(name + ".password");
        boolean allFound = false;
        String preDelete = "";
        int preDeleteIndex = 1;
        String queryType = (String) properties.get(name + ".queryType");
        String getBlobSmartString = (String) properties.get(name + ".getBlobSmart");
        boolean getBlobSmart = false;
        if (getBlobSmartString != null) {
            getBlobSmart = Boolean.valueOf(getBlobSmartString).booleanValue();
        }
        if (datasourceName == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find datasourceName property for " + name, writers);
        } else {
            Map<String, Object> querySendersInfo = new HashMap<String, Object>();
            while (!allFound && queues != null) {
                preDelete = (String) properties.get(name + ".preDel" + preDeleteIndex);
                if (preDelete != null) {
                    FixedQuerySender deleteQuerySender = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
                    deleteQuerySender.setName("Test Tool pre delete query sender");
                    deleteQuerySender.setDatasourceName(datasourceName);
                    deleteQuerySender.setQueryType("delete");
                    deleteQuerySender.setQuery("delete from " + preDelete);
                    try {
                        deleteQuerySender.configure();
                        deleteQuerySender.open();
                        deleteQuerySender.sendMessage(TESTTOOL_DUMMY_MESSAGE, null);
                        deleteQuerySender.close();
                    } catch (ConfigurationException e) {
                        closeQueues(queues, properties, writers);
                        queues = null;
                        errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                    } catch (TimeoutException e) {
                        closeQueues(queues, properties, writers);
                        queues = null;
                        errorMessage("Time out on execute pre delete query for '" + name + "': " + e.getMessage(), e, writers);
                    } catch (SenderException e) {
                        closeQueues(queues, properties, writers);
                        queues = null;
                        errorMessage("Could not execute pre delete query for '" + name + "': " + e.getMessage(), e, writers);
                    }
                    preDeleteIndex++;
                } else {
                    allFound = true;
                }
            }
            if (queues != null) {
                String prePostQuery = (String) properties.get(name + ".prePostQuery");
                if (prePostQuery != null) {
                    FixedQuerySender prePostFixedQuerySender = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
                    prePostFixedQuerySender.setName("Test Tool query sender");
                    prePostFixedQuerySender.setDatasourceName(datasourceName);
                    // prePostFixedQuerySender.setUsername(username);
                    // prePostFixedQuerySender.setPassword(password);
                    prePostFixedQuerySender.setQueryType("select");
                    prePostFixedQuerySender.setQuery(prePostQuery);
                    try {
                        prePostFixedQuerySender.configure();
                    } catch (ConfigurationException e) {
                        closeQueues(queues, properties, writers);
                        queues = null;
                        errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                    }
                    if (queues != null) {
                        try {
                            prePostFixedQuerySender.open();
                        } catch (SenderException e) {
                            closeQueues(queues, properties, writers);
                            queues = null;
                            errorMessage("Could not open (pre/post) '" + name + "': " + e.getMessage(), e, writers);
                        }
                    }
                    if (queues != null) {
                        try {
                            PipeLineSession session = new PipeLineSession();
                            session.put(PipeLineSession.businessCorrelationIdKey, TestTool.TESTTOOL_CORRELATIONID);
                            String result = prePostFixedQuerySender.sendMessage(TESTTOOL_DUMMY_MESSAGE, session).asString();
                            querySendersInfo.put("prePostQueryFixedQuerySender", prePostFixedQuerySender);
                            querySendersInfo.put("prePostQueryResult", result);
                        } catch (TimeoutException e) {
                            closeQueues(queues, properties, writers);
                            queues = null;
                            errorMessage("Time out on execute query for '" + name + "': " + e.getMessage(), e, writers);
                        } catch (IOException | SenderException e) {
                            closeQueues(queues, properties, writers);
                            queues = null;
                            errorMessage("Could not execute query for '" + name + "': " + e.getMessage(), e, writers);
                        }
                    }
                }
            }
            if (queues != null) {
                String readQuery = (String) properties.get(name + ".readQuery");
                if (readQuery != null) {
                    FixedQuerySender readQueryFixedQuerySender = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
                    readQueryFixedQuerySender.setName("Test Tool query sender");
                    readQueryFixedQuerySender.setDatasourceName(datasourceName);
                    if ((queryType != null) && (!queryType.equals(""))) {
                        readQueryFixedQuerySender.setQueryType(queryType);
                    } else {
                        readQueryFixedQuerySender.setQueryType("select");
                    }
                    readQueryFixedQuerySender.setQuery(readQuery);
                    readQueryFixedQuerySender.setBlobSmartGet(getBlobSmart);
                    try {
                        readQueryFixedQuerySender.configure();
                    } catch (ConfigurationException e) {
                        closeQueues(queues, properties, writers);
                        queues = null;
                        errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                    }
                    if (queues != null) {
                        try {
                            readQueryFixedQuerySender.open();
                            querySendersInfo.put("readQueryQueryFixedQuerySender", readQueryFixedQuerySender);
                        } catch (SenderException e) {
                            closeQueues(queues, properties, writers);
                            queues = null;
                            errorMessage("Could not open '" + name + "': " + e.getMessage(), e, writers);
                        }
                    }
                }
            }
            if (queues != null) {
                String waitBeforeRead = (String) properties.get(name + ".waitBeforeRead");
                if (waitBeforeRead != null) {
                    try {
                        querySendersInfo.put("readQueryWaitBeforeRead", new Integer(waitBeforeRead));
                    } catch (NumberFormatException e) {
                        errorMessage("Value of '" + name + ".waitBeforeRead' not a number: " + e.getMessage(), e, writers);
                    }
                }
                queues.put(name, querySendersInfo);
                debugMessage("Opened jdbc connection '" + name + "'", writers);
            }
        }
    }
    debugMessage("Initialize ibis web service senders", writers);
    iterator = ibisWebServiceSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        String ibisHost = (String) properties.get(name + ".ibisHost");
        String ibisInstance = (String) properties.get(name + ".ibisInstance");
        String serviceName = (String) properties.get(name + ".serviceName");
        Boolean convertExceptionToMessage = new Boolean((String) properties.get(name + ".convertExceptionToMessage"));
        if (ibisHost == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find ibisHost property for " + name, writers);
        } else if (ibisInstance == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find ibisInstance property for " + name, writers);
        } else if (serviceName == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find serviceName property for " + name, writers);
        } else {
            IbisWebServiceSender ibisWebServiceSender = new IbisWebServiceSender();
            ibisWebServiceSender.setName("Test Tool IbisWebServiceSender");
            ibisWebServiceSender.setIbisHost(ibisHost);
            ibisWebServiceSender.setIbisInstance(ibisInstance);
            ibisWebServiceSender.setServiceName(serviceName);
            try {
                ibisWebServiceSender.configure();
            } catch (ConfigurationException e) {
                errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                closeQueues(queues, properties, writers);
                queues = null;
            }
            try {
                ibisWebServiceSender.open();
            } catch (SenderException e) {
                closeQueues(queues, properties, writers);
                queues = null;
                errorMessage("Could not open '" + name + "': " + e.getMessage(), e, writers);
            }
            if (queues != null) {
                Map<String, Object> ibisWebServiceSenderInfo = new HashMap<String, Object>();
                ibisWebServiceSenderInfo.put("ibisWebServiceSender", ibisWebServiceSender);
                ibisWebServiceSenderInfo.put("convertExceptionToMessage", convertExceptionToMessage);
                queues.put(name, ibisWebServiceSenderInfo);
                debugMessage("Opened ibis web service sender '" + name + "'", writers);
            }
        }
    }
    debugMessage("Initialize web service senders", writers);
    iterator = webServiceSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        Boolean convertExceptionToMessage = new Boolean((String) properties.get(name + ".convertExceptionToMessage"));
        String url = (String) properties.get(name + ".url");
        String userName = (String) properties.get(name + ".userName");
        String password = (String) properties.get(name + ".password");
        String authAlias = (String) properties.get(name + ".authAlias");
        String soap = (String) properties.get(name + ".soap");
        String allowSelfSignedCertificates = properties.getProperty(name + ".allowSelfSignedCertificates", "true");
        String verifyHostname = properties.getProperty(name + ".verifyHostname", "false");
        if (url == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find url property for " + name, writers);
        } else {
            WebServiceSender webServiceSender = new WebServiceSender();
            webServiceSender.setName("Test Tool WebServiceSender");
            webServiceSender.setUrl(url);
            webServiceSender.setUsername(userName);
            webServiceSender.setPassword(password);
            webServiceSender.setAuthAlias(authAlias);
            if (soap != null) {
                webServiceSender.setSoap(new Boolean(soap));
            }
            webServiceSender.setAllowSelfSignedCertificates(new Boolean(allowSelfSignedCertificates));
            webServiceSender.setVerifyHostname(new Boolean(verifyHostname));
            String serviceNamespaceURI = (String) properties.get(name + ".serviceNamespaceURI");
            if (serviceNamespaceURI != null) {
                webServiceSender.setServiceNamespaceURI(serviceNamespaceURI);
            }
            String serviceNamespace = (String) properties.get(name + ".serviceNamespace");
            if (serviceNamespace != null) {
                webServiceSender.setServiceNamespace(serviceNamespace);
            }
            try {
                webServiceSender.configure();
            } catch (ConfigurationException e) {
                errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                closeQueues(queues, properties, writers);
                queues = null;
            }
            if (queues != null) {
                try {
                    webServiceSender.open();
                } catch (SenderException e) {
                    closeQueues(queues, properties, writers);
                    queues = null;
                    errorMessage("Could not open '" + name + "': " + e.getMessage(), e, writers);
                }
                if (queues != null) {
                    Map<String, Object> webServiceSenderInfo = new HashMap<String, Object>();
                    webServiceSenderInfo.put("webServiceSender", webServiceSender);
                    webServiceSenderInfo.put("convertExceptionToMessage", convertExceptionToMessage);
                    queues.put(name, webServiceSenderInfo);
                    debugMessage("Opened web service sender '" + name + "'", writers);
                }
            }
        }
    }
    debugMessage("Initialize web service listeners", writers);
    iterator = webServiceListeners.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        String serviceNamespaceURI = (String) properties.get(name + ".serviceNamespaceURI");
        if (serviceNamespaceURI == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find property '" + name + ".serviceNamespaceURI'", writers);
        } else {
            ListenerMessageHandler listenerMessageHandler = new ListenerMessageHandler();
            listenerMessageHandler.setTimeout(parameterTimeout);
            if (properties.contains(name + ".requestTimeOut") || properties.contains(name + ".responseTimeOut")) {
                errorMessage("properties " + name + ".requestTimeOut/" + name + ".responseTimeOut have been replaced with " + name + ".timeout", writers);
            }
            try {
                long timeout = Long.parseLong((String) properties.get(name + ".timeout"));
                listenerMessageHandler.setTimeout(timeout);
                debugMessage("Timeout set to '" + timeout + "'", writers);
            } catch (Exception e) {
            }
            WebServiceListener webServiceListener = new WebServiceListener();
            webServiceListener.setName("Test Tool WebServiceListener");
            webServiceListener.setServiceNamespaceURI(serviceNamespaceURI);
            webServiceListener.setHandler(listenerMessageHandler);
            try {
                webServiceListener.open();
            } catch (ListenerException e) {
                closeQueues(queues, properties, writers);
                queues = null;
                errorMessage("Could not open web service listener '" + name + "': " + e.getMessage(), e, writers);
            }
            Map<String, Object> webServiceListenerInfo = new HashMap<String, Object>();
            webServiceListenerInfo.put("webServiceListener", webServiceListener);
            webServiceListenerInfo.put("listenerMessageHandler", listenerMessageHandler);
            queues.put(name, webServiceListenerInfo);
            ServiceDispatcher serviceDispatcher = ServiceDispatcher.getInstance();
            try {
                serviceDispatcher.registerServiceClient(serviceNamespaceURI, webServiceListener);
                debugMessage("Opened web service listener '" + name + "'", writers);
            } catch (ListenerException e) {
                closeQueues(queues, properties, writers);
                queues = null;
                errorMessage("Could not open web service listener '" + name + "': " + e.getMessage(), e, writers);
            }
        }
    }
    debugMessage("Initialize http senders", writers);
    iterator = httpSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        Boolean convertExceptionToMessage = new Boolean((String) properties.get(name + ".convertExceptionToMessage"));
        String url = (String) properties.get(name + ".url");
        String userName = (String) properties.get(name + ".userName");
        String password = (String) properties.get(name + ".password");
        String authAlias = (String) properties.get(name + ".authAlias");
        String headerParams = (String) properties.get(name + ".headersParams");
        String xhtmlString = (String) properties.get(name + ".xhtml");
        String methodtype = (String) properties.get(name + ".methodType");
        String paramsInUrlString = (String) properties.get(name + ".paramsInUrl");
        String inputMessageParam = (String) properties.get(name + ".inputMessageParam");
        String multipartString = (String) properties.get(name + ".multipart");
        String styleSheetName = (String) properties.get(name + ".styleSheetName");
        String allowSelfSignedCertificates = properties.getProperty(name + ".allowSelfSignedCertificates", "true");
        String verifyHostname = properties.getProperty(name + ".verifyHostname", "false");
        if (url == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find url property for " + name, writers);
        } else {
            HttpSender httpSender = null;
            PipeLineSession session = null;
            ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
            try {
                // Use directoryClassLoader to make it possible to specify
                // styleSheetName relative to the scenarioDirectory.
                // TODO create larva classloader without basepath
                DirectoryClassLoader directoryClassLoader = new DirectoryClassLoader(originalClassLoader);
                directoryClassLoader.setDirectory(scenarioDirectory);
                directoryClassLoader.setBasePath(".");
                directoryClassLoader.configure(ibisContext, "dummy");
                Thread.currentThread().setContextClassLoader(directoryClassLoader);
                httpSender = new HttpSender();
                httpSender.setName("Test Tool HttpSender");
                httpSender.setUrl(url);
                httpSender.setUsername(userName);
                httpSender.setPassword(password);
                httpSender.setAuthAlias(authAlias);
                httpSender.setHeadersParams(headerParams);
                if (StringUtils.isNotEmpty(xhtmlString)) {
                    httpSender.setXhtml(Boolean.valueOf(xhtmlString).booleanValue());
                }
                if (StringUtils.isNotEmpty(methodtype)) {
                    HttpMethod method = EnumUtils.parse(HttpMethod.class, methodtype);
                    httpSender.setMethodType(method);
                }
                if (StringUtils.isNotEmpty(paramsInUrlString)) {
                    httpSender.setParamsInUrl(Boolean.valueOf(paramsInUrlString).booleanValue());
                }
                if (StringUtils.isNotEmpty(inputMessageParam)) {
                    httpSender.setInputMessageParam(inputMessageParam);
                }
                if (StringUtils.isNotEmpty(multipartString)) {
                    httpSender.setMultipart(Boolean.valueOf(multipartString).booleanValue());
                }
                if (StringUtils.isNotEmpty(styleSheetName)) {
                    httpSender.setStyleSheetName(styleSheetName);
                }
                httpSender.setAllowSelfSignedCertificates(new Boolean(allowSelfSignedCertificates));
                httpSender.setVerifyHostname(new Boolean(verifyHostname));
                session = new PipeLineSession();
                Map<String, Object> paramPropertiesMap = createParametersMapFromParamProperties(properties, name, writers, true, session);
                Iterator<String> parameterNameIterator = paramPropertiesMap.keySet().iterator();
                while (parameterNameIterator.hasNext()) {
                    String parameterName = (String) parameterNameIterator.next();
                    Parameter parameter = (Parameter) paramPropertiesMap.get(parameterName);
                    httpSender.addParameter(parameter);
                }
                httpSender.configure();
            } catch (ClassLoaderException e) {
                errorMessage("Could not create classloader: " + e.getMessage(), e, writers);
                closeQueues(queues, properties, writers);
                queues = null;
            } catch (ConfigurationException e) {
                errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                closeQueues(queues, properties, writers);
                queues = null;
            } finally {
                if (originalClassLoader != null) {
                    Thread.currentThread().setContextClassLoader(originalClassLoader);
                }
            }
            if (queues != null) {
                try {
                    httpSender.open();
                } catch (SenderException e) {
                    closeQueues(queues, properties, writers);
                    queues = null;
                    errorMessage("Could not open '" + name + "': " + e.getMessage(), e, writers);
                }
                if (queues != null) {
                    Map<String, Object> httpSenderInfo = new HashMap<String, Object>();
                    httpSenderInfo.put("httpSender", httpSender);
                    httpSenderInfo.put("session", session);
                    httpSenderInfo.put("convertExceptionToMessage", convertExceptionToMessage);
                    queues.put(name, httpSenderInfo);
                    debugMessage("Opened http sender '" + name + "'", writers);
                }
            }
        }
    }
    debugMessage("Initialize ibis java senders", writers);
    iterator = ibisJavaSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        String serviceName = (String) properties.get(name + ".serviceName");
        Boolean convertExceptionToMessage = new Boolean((String) properties.get(name + ".convertExceptionToMessage"));
        if (serviceName == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find serviceName property for " + name, writers);
        } else {
            IbisJavaSender ibisJavaSender = new IbisJavaSender();
            ibisJavaSender.setName("Test Tool IbisJavaSender");
            ibisJavaSender.setServiceName(serviceName);
            PipeLineSession session = new PipeLineSession();
            Map<String, Object> paramPropertiesMap = createParametersMapFromParamProperties(properties, name, writers, true, session);
            Iterator<String> parameterNameIterator = paramPropertiesMap.keySet().iterator();
            while (parameterNameIterator.hasNext()) {
                String parameterName = (String) parameterNameIterator.next();
                Parameter parameter = (Parameter) paramPropertiesMap.get(parameterName);
                ibisJavaSender.addParameter(parameter);
            }
            try {
                ibisJavaSender.configure();
            } catch (ConfigurationException e) {
                errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                closeQueues(queues, properties, writers);
                queues = null;
            }
            if (queues != null) {
                try {
                    ibisJavaSender.open();
                } catch (SenderException e) {
                    closeQueues(queues, properties, writers);
                    queues = null;
                    errorMessage("Could not open '" + name + "': " + e.getMessage(), e, writers);
                }
                if (queues != null) {
                    Map<String, Object> ibisJavaSenderInfo = new HashMap<String, Object>();
                    ibisJavaSenderInfo.put("ibisJavaSender", ibisJavaSender);
                    ibisJavaSenderInfo.put("session", session);
                    ibisJavaSenderInfo.put("convertExceptionToMessage", convertExceptionToMessage);
                    queues.put(name, ibisJavaSenderInfo);
                    debugMessage("Opened ibis java sender '" + name + "'", writers);
                }
            }
        }
    }
    debugMessage("Initialize delay senders", writers);
    iterator = delaySenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        Boolean convertExceptionToMessage = new Boolean((String) properties.get(name + ".convertExceptionToMessage"));
        String delayTime = (String) properties.get(name + ".delayTime");
        DelaySender delaySender = new DelaySender();
        if (delayTime != null) {
            delaySender.setDelayTime(Long.parseLong(delayTime));
        }
        delaySender.setName("Test Tool DelaySender");
        Map<String, Object> delaySenderInfo = new HashMap<String, Object>();
        delaySenderInfo.put("delaySender", delaySender);
        delaySenderInfo.put("convertExceptionToMessage", convertExceptionToMessage);
        queues.put(name, delaySenderInfo);
        debugMessage("Opened delay sender '" + name + "'", writers);
    }
    debugMessage("Initialize java listeners", writers);
    iterator = javaListeners.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        String serviceName = (String) properties.get(name + ".serviceName");
        if (serviceName == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find property '" + name + ".serviceName'", writers);
        } else {
            ListenerMessageHandler<String> listenerMessageHandler = new ListenerMessageHandler<>();
            if (properties.contains(name + ".requestTimeOut") || properties.contains(name + ".responseTimeOut")) {
                errorMessage("properties " + name + ".requestTimeOut/" + name + ".responseTimeOut have been replaced with " + name + ".timeout", writers);
            }
            try {
                long timeout = Long.parseLong((String) properties.get(name + ".timeout"));
                listenerMessageHandler.setTimeout(timeout);
                debugMessage("Timeout set to '" + timeout + "'", writers);
            } catch (Exception e) {
            }
            JavaListener javaListener = new JavaListener();
            javaListener.setName("Test Tool JavaListener");
            javaListener.setServiceName(serviceName);
            javaListener.setHandler(listenerMessageHandler);
            try {
                javaListener.open();
                Map<String, Object> javaListenerInfo = new HashMap<String, Object>();
                javaListenerInfo.put("javaListener", javaListener);
                javaListenerInfo.put("listenerMessageHandler", listenerMessageHandler);
                queues.put(name, javaListenerInfo);
                debugMessage("Opened java listener '" + name + "'", writers);
            } catch (ListenerException e) {
                closeQueues(queues, properties, writers);
                queues = null;
                errorMessage("Could not open java listener '" + name + "': " + e.getMessage(), e, writers);
            }
        }
    }
    debugMessage("Initialize file senders", writers);
    iterator = fileSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String queueName = (String) iterator.next();
        String filename = (String) properties.get(queueName + ".filename");
        if (filename == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find filename property for " + queueName, writers);
        } else {
            FileSender fileSender = new FileSender();
            String filenameAbsolutePath = (String) properties.get(queueName + ".filename.absolutepath");
            fileSender.setFilename(filenameAbsolutePath);
            String encoding = (String) properties.get(queueName + ".encoding");
            if (encoding != null) {
                fileSender.setEncoding(encoding);
                debugMessage("Encoding set to '" + encoding + "'", writers);
            }
            String deletePathString = (String) properties.get(queueName + ".deletePath");
            if (deletePathString != null) {
                boolean deletePath = Boolean.valueOf(deletePathString).booleanValue();
                fileSender.setDeletePath(deletePath);
                debugMessage("Delete path set to '" + deletePath + "'", writers);
            }
            String createPathString = (String) properties.get(queueName + ".createPath");
            if (createPathString != null) {
                boolean createPath = Boolean.valueOf(createPathString).booleanValue();
                fileSender.setCreatePath(createPath);
                debugMessage("Create path set to '" + createPath + "'", writers);
            }
            try {
                String checkDeleteString = (String) properties.get(queueName + ".checkDelete");
                if (checkDeleteString != null) {
                    boolean checkDelete = Boolean.valueOf(checkDeleteString).booleanValue();
                    fileSender.setCheckDelete(checkDelete);
                    debugMessage("Check delete set to '" + checkDelete + "'", writers);
                }
            } catch (Exception e) {
            }
            try {
                String runAntString = (String) properties.get(queueName + ".runAnt");
                if (runAntString != null) {
                    boolean runAnt = Boolean.valueOf(runAntString).booleanValue();
                    fileSender.setRunAnt(runAnt);
                    debugMessage("Run ant set to '" + runAnt + "'", writers);
                }
            } catch (Exception e) {
            }
            try {
                long timeOut = Long.parseLong((String) properties.get(queueName + ".timeOut"));
                fileSender.setTimeOut(timeOut);
                debugMessage("Time out set to '" + timeOut + "'", writers);
            } catch (Exception e) {
            }
            try {
                long interval = Long.parseLong((String) properties.get(queueName + ".interval"));
                fileSender.setInterval(interval);
                debugMessage("Interval set to '" + interval + "'", writers);
            } catch (Exception e) {
            }
            try {
                String overwriteString = (String) properties.get(queueName + ".overwrite");
                if (overwriteString != null) {
                    debugMessage("OverwriteString = " + overwriteString, writers);
                    boolean overwrite = Boolean.valueOf(overwriteString).booleanValue();
                    fileSender.setOverwrite(overwrite);
                    debugMessage("Overwrite set to '" + overwrite + "'", writers);
                }
            } catch (Exception e) {
            }
            Map<String, Object> fileSenderInfo = new HashMap<String, Object>();
            fileSenderInfo.put("fileSender", fileSender);
            queues.put(queueName, fileSenderInfo);
            debugMessage("Opened file sender '" + queueName + "'", writers);
        }
    }
    debugMessage("Initialize file listeners", writers);
    iterator = fileListeners.iterator();
    while (queues != null && iterator.hasNext()) {
        String queueName = (String) iterator.next();
        String filename = (String) properties.get(queueName + ".filename");
        String filename2 = (String) properties.get(queueName + ".filename2");
        String directory = null;
        String wildcard = null;
        if (filename == null) {
            directory = (String) properties.get(queueName + ".directory");
            wildcard = (String) properties.get(queueName + ".wildcard");
        }
        if (filename == null && directory == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find filename or directory property for " + queueName, writers);
        } else if (directory != null && wildcard == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find wildcard property for " + queueName, writers);
        } else {
            FileListener fileListener = new FileListener();
            if (filename == null) {
                String directoryAbsolutePath = (String) properties.get(queueName + ".directory.absolutepath");
                ;
                fileListener.setDirectory(directoryAbsolutePath);
                fileListener.setWildcard(wildcard);
            } else {
                String filenameAbsolutePath = (String) properties.get(queueName + ".filename.absolutepath");
                ;
                fileListener.setFilename(filenameAbsolutePath);
            }
            try {
                long waitBeforeRead = Long.parseLong((String) properties.get(queueName + ".waitBeforeRead"));
                fileListener.setWaitBeforeRead(waitBeforeRead);
                debugMessage("Wait before read set to '" + waitBeforeRead + "'", writers);
            } catch (Exception e) {
            }
            try {
                long timeOut = Long.parseLong((String) properties.get(queueName + ".timeOut"));
                fileListener.setTimeOut(timeOut);
                debugMessage("Time out set to '" + timeOut + "'", writers);
            } catch (Exception e) {
            }
            try {
                long interval = Long.parseLong((String) properties.get(queueName + ".interval"));
                fileListener.setInterval(interval);
                debugMessage("Interval set to '" + interval + "'", writers);
            } catch (Exception e) {
            }
            if (filename2 != null) {
                fileListener.setFilename2(filename2);
            }
            Map<String, Object> fileListenerInfo = new HashMap<String, Object>();
            fileListenerInfo.put("fileListener", fileListener);
            queues.put(queueName, fileListenerInfo);
            debugMessage("Opened file listener '" + queueName + "'", writers);
            if (fileListenerCleanUp(queueName, fileListener, writers)) {
                errorMessage("Found old messages on '" + queueName + "'", writers);
            }
        }
    }
    debugMessage("Initialize xslt provider listeners", writers);
    iterator = xsltProviderListeners.iterator();
    while (queues != null && iterator.hasNext()) {
        String queueName = (String) iterator.next();
        String filename = (String) properties.get(queueName + ".filename");
        if (filename == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find filename property for " + queueName, writers);
        } else {
            Boolean fromClasspath = new Boolean((String) properties.get(queueName + ".fromClasspath"));
            if (!fromClasspath) {
                filename = (String) properties.get(queueName + ".filename.absolutepath");
            }
            XsltProviderListener xsltProviderListener = new XsltProviderListener();
            xsltProviderListener.setFromClasspath(fromClasspath);
            xsltProviderListener.setFilename(filename);
            String xsltVersionString = (String) properties.get(queueName + ".xsltVersion");
            if (xsltVersionString != null) {
                try {
                    int xsltVersion = Integer.valueOf(xsltVersionString).intValue();
                    xsltProviderListener.setXsltVersion(xsltVersion);
                    debugMessage("XsltVersion set to '" + xsltVersion + "'", writers);
                } catch (Exception e) {
                }
            }
            String xslt2String = (String) properties.get(queueName + ".xslt2");
            if (xslt2String != null) {
                try {
                    boolean xslt2 = Boolean.valueOf(xslt2String).booleanValue();
                    xsltProviderListener.setXslt2(xslt2);
                    debugMessage("Xslt2 set to '" + xslt2 + "'", writers);
                } catch (Exception e) {
                }
            }
            String namespaceAwareString = (String) properties.get(queueName + ".namespaceAware");
            if (namespaceAwareString != null) {
                try {
                    boolean namespaceAware = Boolean.valueOf(namespaceAwareString).booleanValue();
                    xsltProviderListener.setNamespaceAware(namespaceAware);
                    debugMessage("Namespace aware set to '" + namespaceAware + "'", writers);
                } catch (Exception e) {
                }
            }
            try {
                xsltProviderListener.init();
                Map<String, Object> xsltProviderListenerInfo = new HashMap<String, Object>();
                xsltProviderListenerInfo.put("xsltProviderListener", xsltProviderListener);
                queues.put(queueName, xsltProviderListenerInfo);
                debugMessage("Opened xslt provider listener '" + queueName + "'", writers);
            } catch (ListenerException e) {
                closeQueues(queues, properties, writers);
                queues = null;
                errorMessage("Could not create xslt provider listener for '" + queueName + "': " + e.getMessage(), e, writers);
            }
        }
    }
    return queues;
}
Also used : PullingJmsListener(nl.nn.adapterframework.jms.PullingJmsListener) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Iterator(java.util.Iterator) DelaySender(nl.nn.adapterframework.senders.DelaySender) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) ServiceDispatcher(nl.nn.adapterframework.receivers.ServiceDispatcher) IbisWebServiceSender(nl.nn.adapterframework.http.IbisWebServiceSender) WebServiceSender(nl.nn.adapterframework.http.WebServiceSender) TimeoutException(nl.nn.adapterframework.core.TimeoutException) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) ClassLoaderException(nl.nn.adapterframework.configuration.ClassLoaderException) IbisWebServiceSender(nl.nn.adapterframework.http.IbisWebServiceSender) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IOException(java.io.IOException) WebServiceListener(nl.nn.adapterframework.http.WebServiceListener) HttpSender(nl.nn.adapterframework.http.HttpSender) ClassLoaderException(nl.nn.adapterframework.configuration.ClassLoaderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) ParseException(java.text.ParseException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) FileNotFoundException(java.io.FileNotFoundException) SenderException(nl.nn.adapterframework.core.SenderException) ListenerException(nl.nn.adapterframework.core.ListenerException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) IbisJavaSender(nl.nn.adapterframework.senders.IbisJavaSender) JavaListener(nl.nn.adapterframework.receivers.JavaListener) DeliveryMode(nl.nn.adapterframework.jms.JMSFacade.DeliveryMode) Parameter(nl.nn.adapterframework.parameters.Parameter) JmsSender(nl.nn.adapterframework.jms.JmsSender) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender) HttpMethod(nl.nn.adapterframework.http.HttpSenderBase.HttpMethod)

Example 17 with FixedQuerySender

use of nl.nn.adapterframework.jdbc.FixedQuerySender 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;
}
Also used : PullingJmsListener(nl.nn.adapterframework.jms.PullingJmsListener) ListenerException(nl.nn.adapterframework.core.ListenerException) DelaySender(nl.nn.adapterframework.senders.DelaySender) IbisWebServiceSender(nl.nn.adapterframework.http.IbisWebServiceSender) WebServiceSender(nl.nn.adapterframework.http.WebServiceSender) TimeoutException(nl.nn.adapterframework.core.TimeoutException) IbisWebServiceSender(nl.nn.adapterframework.http.IbisWebServiceSender) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IOException(java.io.IOException) WebServiceListener(nl.nn.adapterframework.http.WebServiceListener) IbisJavaSender(nl.nn.adapterframework.senders.IbisJavaSender) JavaListener(nl.nn.adapterframework.receivers.JavaListener) JmsSender(nl.nn.adapterframework.jms.JmsSender) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Example 18 with FixedQuerySender

use of nl.nn.adapterframework.jdbc.FixedQuerySender in project iaf by ibissource.

the class ConfigurationUtils method makeConfigActive.

public static boolean makeConfigActive(IbisContext ibisContext, String name, String version, String jmsRealm) throws ConfigurationException {
    if (StringUtils.isEmpty(jmsRealm)) {
        jmsRealm = JmsRealmFactory.getInstance().getFirstDatasourceJmsRealm();
        if (StringUtils.isEmpty(jmsRealm)) {
            return false;
        }
    }
    Connection conn = null;
    ResultSet rs = null;
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    qs.setJmsRealm(jmsRealm);
    qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG");
    qs.configure();
    try {
        qs.open();
        conn = qs.getConnection();
        int updated = 0;
        String selectQuery = "SELECT NAME FROM IBISCONFIG WHERE NAME=? AND VERSION=?";
        PreparedStatement selectStmt = conn.prepareStatement(selectQuery);
        selectStmt.setString(1, name);
        selectStmt.setString(2, version);
        rs = selectStmt.executeQuery();
        if (rs.next()) {
            String query = ("UPDATE IBISCONFIG SET ACTIVECONFIG = '" + (qs.getDbmsSupport().getBooleanValue(false)) + "' WHERE NAME=?");
            PreparedStatement stmt = conn.prepareStatement(query);
            stmt.setString(1, name);
            updated = stmt.executeUpdate();
            if (updated > 0) {
                String query2 = ("UPDATE IBISCONFIG SET ACTIVECONFIG = '" + (qs.getDbmsSupport().getBooleanValue(true)) + "' WHERE NAME=? AND VERSION=?");
                PreparedStatement stmt2 = conn.prepareStatement(query2);
                stmt2.setString(1, name);
                stmt2.setString(2, version);
                return (stmt2.executeUpdate() > 0) ? true : false;
            }
        }
    } catch (SenderException e) {
        throw new ConfigurationException(e);
    } catch (JdbcException e) {
        throw new ConfigurationException(e);
    } catch (SQLException e) {
        throw new ConfigurationException(e);
    } finally {
        qs.close();
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                log.warn("Could not close resultset", e);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                log.warn("Could not close connection", e);
            }
        }
    }
    return false;
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SenderException(nl.nn.adapterframework.core.SenderException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Example 19 with FixedQuerySender

use of nl.nn.adapterframework.jdbc.FixedQuerySender in project iaf by ibissource.

the class TestTool method openQueues.

public static Map openQueues(String scenarioDirectory, List steps, Properties properties, IbisContext ibisContext, Map writers) {
    Map queues = new HashMap();
    debugMessage("Get all queue names", writers);
    List jmsSenders = new ArrayList();
    List jmsListeners = new ArrayList();
    List jdbcFixedQuerySenders = new ArrayList();
    List ibisWebServiceSenders = new ArrayList();
    List webServiceSenders = new ArrayList();
    List webServiceListeners = new ArrayList();
    List httpSenders = new ArrayList();
    List ibisJavaSenders = new ArrayList();
    List delaySenders = new ArrayList();
    List javaListeners = new ArrayList();
    List fileSenders = new ArrayList();
    List fileListeners = new ArrayList();
    List xsltProviderListeners = new ArrayList();
    Iterator iterator = properties.keySet().iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        int i = key.indexOf('.');
        if (i != -1) {
            int j = key.indexOf('.', i + 1);
            if (j != -1) {
                String queueName = key.substring(0, j);
                debugMessage("queuename openqueue: " + queueName, writers);
                if ("nl.nn.adapterframework.jms.JmsSender".equals(properties.get(queueName + ".className")) && !jmsSenders.contains(queueName)) {
                    debugMessage("Adding jmsSender queue: " + queueName, writers);
                    jmsSenders.add(queueName);
                } else if ("nl.nn.adapterframework.jms.JmsListener".equals(properties.get(queueName + ".className")) && !jmsListeners.contains(queueName)) {
                    debugMessage("Adding jmsListener queue: " + queueName, writers);
                    jmsListeners.add(queueName);
                } else if ("nl.nn.adapterframework.jdbc.FixedQuerySender".equals(properties.get(queueName + ".className")) && !jdbcFixedQuerySenders.contains(queueName)) {
                    debugMessage("Adding jdbcFixedQuerySender queue: " + queueName, writers);
                    jdbcFixedQuerySenders.add(queueName);
                } else if ("nl.nn.adapterframework.http.IbisWebServiceSender".equals(properties.get(queueName + ".className")) && !ibisWebServiceSenders.contains(queueName)) {
                    debugMessage("Adding ibisWebServiceSender queue: " + queueName, writers);
                    ibisWebServiceSenders.add(queueName);
                } else if ("nl.nn.adapterframework.http.WebServiceSender".equals(properties.get(queueName + ".className")) && !webServiceSenders.contains(queueName)) {
                    debugMessage("Adding webServiceSender queue: " + queueName, writers);
                    webServiceSenders.add(queueName);
                } else if ("nl.nn.adapterframework.http.WebServiceListener".equals(properties.get(queueName + ".className")) && !webServiceListeners.contains(queueName)) {
                    debugMessage("Adding webServiceListener queue: " + queueName, writers);
                    webServiceListeners.add(queueName);
                } else if ("nl.nn.adapterframework.http.HttpSender".equals(properties.get(queueName + ".className")) && !httpSenders.contains(queueName)) {
                    debugMessage("Adding httpSender queue: " + queueName, writers);
                    httpSenders.add(queueName);
                } else if ("nl.nn.adapterframework.senders.IbisJavaSender".equals(properties.get(queueName + ".className")) && !ibisJavaSenders.contains(queueName)) {
                    debugMessage("Adding ibisJavaSender queue: " + queueName, writers);
                    ibisJavaSenders.add(queueName);
                } else if ("nl.nn.adapterframework.senders.DelaySender".equals(properties.get(queueName + ".className")) && !delaySenders.contains(queueName)) {
                    debugMessage("Adding delaySender queue: " + queueName, writers);
                    delaySenders.add(queueName);
                } else if ("nl.nn.adapterframework.receivers.JavaListener".equals(properties.get(queueName + ".className")) && !javaListeners.contains(queueName)) {
                    debugMessage("Adding javaListener queue: " + queueName, writers);
                    javaListeners.add(queueName);
                } else if ("nl.nn.adapterframework.testtool.FileSender".equals(properties.get(queueName + ".className")) && !fileSenders.contains(queueName)) {
                    debugMessage("Adding fileSender queue: " + queueName, writers);
                    fileSenders.add(queueName);
                } else if ("nl.nn.adapterframework.testtool.FileListener".equals(properties.get(queueName + ".className")) && !fileListeners.contains(queueName)) {
                    debugMessage("Adding fileListener queue: " + queueName, writers);
                    fileListeners.add(queueName);
                } else if ("nl.nn.adapterframework.testtool.XsltProviderListener".equals(properties.get(queueName + ".className")) && !xsltProviderListeners.contains(queueName)) {
                    debugMessage("Adding xsltProviderListeners queue: " + queueName, writers);
                    xsltProviderListeners.add(queueName);
                }
            }
        }
    }
    debugMessage("Initialize jms senders", writers);
    iterator = jmsSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String queueName = (String) iterator.next();
        String queue = (String) properties.get(queueName + ".queue");
        if (queue == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find property '" + queueName + ".queue'", writers);
        } else {
            JmsSender jmsSender = (JmsSender) ibisContext.createBeanAutowireByName(JmsSender.class);
            jmsSender.setName("Test Tool JmsSender");
            jmsSender.setDestinationName(queue);
            jmsSender.setDestinationType("QUEUE");
            jmsSender.setAcknowledgeMode("auto");
            String jmsRealm = (String) properties.get(queueName + ".jmsRealm");
            if (jmsRealm != null) {
                jmsSender.setJmsRealm(jmsRealm);
            } else {
                jmsSender.setJmsRealm("default");
            }
            String deliveryMode = properties.getProperty(queueName + ".deliveryMode");
            debugMessage("Property '" + queueName + ".deliveryMode': " + deliveryMode, writers);
            String persistent = properties.getProperty(queueName + ".persistent");
            debugMessage("Property '" + queueName + ".persistent': " + persistent, writers);
            String useCorrelationIdFrom = properties.getProperty(queueName + ".useCorrelationIdFrom");
            debugMessage("Property '" + queueName + ".useCorrelationIdFrom': " + useCorrelationIdFrom, writers);
            String replyToName = properties.getProperty(queueName + ".replyToName");
            debugMessage("Property '" + queueName + ".replyToName': " + replyToName, writers);
            if (deliveryMode != null) {
                debugMessage("Set deliveryMode to " + deliveryMode, writers);
                jmsSender.setDeliveryMode(deliveryMode);
            }
            if ("true".equals(persistent)) {
                debugMessage("Set persistent to true", writers);
                jmsSender.setPersistent(true);
            } else {
                debugMessage("Set persistent to false", writers);
                jmsSender.setPersistent(false);
            }
            if (replyToName != null) {
                debugMessage("Set replyToName to " + replyToName, writers);
                jmsSender.setReplyToName(replyToName);
            }
            Map jmsSenderInfo = new HashMap();
            jmsSenderInfo.put("jmsSender", jmsSender);
            jmsSenderInfo.put("useCorrelationIdFrom", useCorrelationIdFrom);
            String correlationId = properties.getProperty(queueName + ".jmsCorrelationId");
            if (correlationId != null) {
                jmsSenderInfo.put("jmsCorrelationId", correlationId);
                debugMessage("Property '" + queueName + ".jmsCorrelationId': " + correlationId, writers);
            }
            queues.put(queueName, jmsSenderInfo);
            debugMessage("Opened jms sender '" + queueName + "'", writers);
        }
    }
    debugMessage("Initialize jms listeners", writers);
    iterator = jmsListeners.iterator();
    while (queues != null && iterator.hasNext()) {
        String queueName = (String) iterator.next();
        String queue = (String) properties.get(queueName + ".queue");
        String timeout = (String) properties.get(queueName + ".timeout");
        int nTimeout = DEFAULT_TIMEOUT;
        if (timeout != null && timeout.length() > 0) {
            nTimeout = Integer.parseInt(timeout);
            debugMessage("Overriding default timeout setting of " + DEFAULT_TIMEOUT + " with " + nTimeout, writers);
        }
        if (queue == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find property '" + queueName + ".queue'", writers);
        } else {
            PullingJmsListener pullingJmsListener = (PullingJmsListener) ibisContext.createBeanAutowireByName(PullingJmsListener.class);
            pullingJmsListener.setName("Test Tool JmsListener");
            pullingJmsListener.setDestinationName(queue);
            pullingJmsListener.setDestinationType("QUEUE");
            pullingJmsListener.setAcknowledgeMode("auto");
            String jmsRealm = (String) properties.get(queueName + ".jmsRealm");
            if (jmsRealm != null) {
                pullingJmsListener.setJmsRealm(jmsRealm);
            } else {
                pullingJmsListener.setJmsRealm("default");
            }
            // Call setJmsRealm twice as a workaround for a strange bug
            // where we get a java.lang.NullPointerException in a class of
            // the commons-beanutils.jar on the first call to setJmsRealm
            // after starting the Test Tool ear:
            // at org.apache.commons.beanutils.MappedPropertyDescriptor.internalFindMethod(MappedPropertyDescriptor.java(Compiled Code))
            // at org.apache.commons.beanutils.MappedPropertyDescriptor.internalFindMethod(MappedPropertyDescriptor.java:413)
            // ...
            // Looks like some sort of classloader problem where
            // internalFindMethod on another class is called (last line in
            // stacktrace has "Compiled Code" while other lines have
            // linenumbers).
            // Can be reproduced with for example:
            // - WebSphere Studio Application Developer (Windows) Version: 5.1.2
            // - Ibis4Juice build 20051104-1351
            // - y01\rr\getAgent1003\scenario01.properties
            pullingJmsListener.setTimeOut(nTimeout);
            String setForceMessageIdAsCorrelationId = (String) properties.get(queueName + ".setForceMessageIdAsCorrelationId");
            if ("true".equals(setForceMessageIdAsCorrelationId)) {
                pullingJmsListener.setForceMessageIdAsCorrelationId(true);
            }
            Map jmsListenerInfo = new HashMap();
            jmsListenerInfo.put("jmsListener", pullingJmsListener);
            queues.put(queueName, jmsListenerInfo);
            debugMessage("Opened jms listener '" + queueName + "'", writers);
            if (jmsCleanUp(queueName, pullingJmsListener, writers)) {
                errorMessage("Found one or more old messages on queue '" + queueName + "', you might want to run your tests with a higher 'wait before clean up' value", writers);
            }
        }
    }
    debugMessage("Initialize jdbc fixed query senders", writers);
    iterator = jdbcFixedQuerySenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        String datasourceName = (String) properties.get(name + ".datasourceName");
        String username = (String) properties.get(name + ".username");
        String password = (String) properties.get(name + ".password");
        boolean allFound = false;
        String preDelete = "";
        int preDeleteIndex = 1;
        String queryType = (String) properties.get(name + ".queryType");
        String getBlobSmartString = (String) properties.get(name + ".getBlobSmart");
        boolean getBlobSmart = false;
        if (getBlobSmartString != null) {
            getBlobSmart = Boolean.valueOf(getBlobSmartString).booleanValue();
        }
        if (datasourceName == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find datasourceName property for " + name, writers);
        } else {
            Map querySendersInfo = new HashMap();
            while (!allFound && queues != null) {
                preDelete = (String) properties.get(name + ".preDel" + preDeleteIndex);
                if (preDelete != null) {
                    FixedQuerySender deleteQuerySender = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
                    deleteQuerySender.setName("Test Tool pre delete query sender");
                    deleteQuerySender.setDatasourceName(AppConstants.getInstance().getResolvedProperty("jndiContextPrefix") + datasourceName);
                    deleteQuerySender.setQueryType("delete");
                    deleteQuerySender.setQuery("delete from " + preDelete);
                    try {
                        deleteQuerySender.configure();
                        deleteQuerySender.open();
                        deleteQuerySender.sendMessage(TESTTOOL_CORRELATIONID, TESTTOOL_DUMMY_MESSAGE);
                        deleteQuerySender.close();
                    } catch (ConfigurationException e) {
                        closeQueues(queues, properties, writers);
                        queues = null;
                        errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                    } catch (TimeOutException e) {
                        closeQueues(queues, properties, writers);
                        queues = null;
                        errorMessage("Time out on execute pre delete query for '" + name + "': " + e.getMessage(), e, writers);
                    } catch (SenderException e) {
                        closeQueues(queues, properties, writers);
                        queues = null;
                        errorMessage("Could not execute pre delete query for '" + name + "': " + e.getMessage(), e, writers);
                    }
                    preDeleteIndex++;
                } else {
                    allFound = true;
                }
            }
            if (queues != null) {
                String prePostQuery = (String) properties.get(name + ".prePostQuery");
                if (prePostQuery != null) {
                    FixedQuerySender prePostFixedQuerySender = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
                    prePostFixedQuerySender.setName("Test Tool query sender");
                    prePostFixedQuerySender.setDatasourceName(AppConstants.getInstance().getResolvedProperty("jndiContextPrefix") + datasourceName);
                    // prePostFixedQuerySender.setUsername(username);
                    // prePostFixedQuerySender.setPassword(password);
                    prePostFixedQuerySender.setQueryType("select");
                    prePostFixedQuerySender.setQuery(prePostQuery);
                    try {
                        prePostFixedQuerySender.configure();
                    } catch (ConfigurationException e) {
                        closeQueues(queues, properties, writers);
                        queues = null;
                        errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                    }
                    if (queues != null) {
                        try {
                            prePostFixedQuerySender.open();
                        } catch (SenderException e) {
                            closeQueues(queues, properties, writers);
                            queues = null;
                            errorMessage("Could not open (pre/post) '" + name + "': " + e.getMessage(), e, writers);
                        }
                    }
                    if (queues != null) {
                        try {
                            String result = prePostFixedQuerySender.sendMessage(TESTTOOL_CORRELATIONID, TESTTOOL_DUMMY_MESSAGE);
                            querySendersInfo.put("prePostQueryFixedQuerySender", prePostFixedQuerySender);
                            querySendersInfo.put("prePostQueryResult", result);
                        } catch (TimeOutException e) {
                            closeQueues(queues, properties, writers);
                            queues = null;
                            errorMessage("Time out on execute query for '" + name + "': " + e.getMessage(), e, writers);
                        } catch (SenderException e) {
                            closeQueues(queues, properties, writers);
                            queues = null;
                            errorMessage("Could not execute query for '" + name + "': " + e.getMessage(), e, writers);
                        }
                    }
                }
            }
            if (queues != null) {
                String readQuery = (String) properties.get(name + ".readQuery");
                if (readQuery != null) {
                    FixedQuerySender readQueryFixedQuerySender = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
                    readQueryFixedQuerySender.setName("Test Tool query sender");
                    readQueryFixedQuerySender.setDatasourceName(AppConstants.getInstance().getResolvedProperty("jndiContextPrefix") + datasourceName);
                    if ((queryType != null) && (!queryType.equals(""))) {
                        readQueryFixedQuerySender.setQueryType(queryType);
                    } else {
                        readQueryFixedQuerySender.setQueryType("select");
                    }
                    readQueryFixedQuerySender.setQuery(readQuery);
                    readQueryFixedQuerySender.setBlobSmartGet(getBlobSmart);
                    try {
                        readQueryFixedQuerySender.configure();
                    } catch (ConfigurationException e) {
                        closeQueues(queues, properties, writers);
                        queues = null;
                        errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                    }
                    if (queues != null) {
                        try {
                            readQueryFixedQuerySender.open();
                            querySendersInfo.put("readQueryQueryFixedQuerySender", readQueryFixedQuerySender);
                        } catch (SenderException e) {
                            closeQueues(queues, properties, writers);
                            queues = null;
                            errorMessage("Could not open '" + name + "': " + e.getMessage(), e, writers);
                        }
                    }
                }
            }
            if (queues != null) {
                String waitBeforeRead = (String) properties.get(name + ".waitBeforeRead");
                if (waitBeforeRead != null) {
                    try {
                        querySendersInfo.put("readQueryWaitBeforeRead", new Integer(waitBeforeRead));
                    } catch (NumberFormatException e) {
                        errorMessage("Value of '" + name + ".waitBeforeRead' not a number: " + e.getMessage(), e, writers);
                    }
                }
                queues.put(name, querySendersInfo);
                debugMessage("Opened jdbc connection '" + name + "'", writers);
            }
        }
    }
    debugMessage("Initialize ibis web service senders", writers);
    iterator = ibisWebServiceSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        String ibisHost = (String) properties.get(name + ".ibisHost");
        String ibisInstance = (String) properties.get(name + ".ibisInstance");
        String serviceName = (String) properties.get(name + ".serviceName");
        Boolean convertExceptionToMessage = new Boolean((String) properties.get(name + ".convertExceptionToMessage"));
        if (ibisHost == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find ibisHost property for " + name, writers);
        } else if (ibisInstance == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find ibisInstance property for " + name, writers);
        } else if (serviceName == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find serviceName property for " + name, writers);
        } else {
            IbisWebServiceSender ibisWebServiceSender = new IbisWebServiceSender();
            ibisWebServiceSender.setName("Test Tool IbisWebServiceSender");
            ibisWebServiceSender.setIbisHost(ibisHost);
            ibisWebServiceSender.setIbisInstance(ibisInstance);
            ibisWebServiceSender.setServiceName(serviceName);
            try {
                ibisWebServiceSender.configure();
            } catch (ConfigurationException e) {
                errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                closeQueues(queues, properties, writers);
                queues = null;
            }
            try {
                ibisWebServiceSender.open();
            } catch (SenderException e) {
                closeQueues(queues, properties, writers);
                queues = null;
                errorMessage("Could not open '" + name + "': " + e.getMessage(), e, writers);
            }
            if (queues != null) {
                Map ibisWebServiceSenderInfo = new HashMap();
                ibisWebServiceSenderInfo.put("ibisWebServiceSender", ibisWebServiceSender);
                ibisWebServiceSenderInfo.put("convertExceptionToMessage", convertExceptionToMessage);
                queues.put(name, ibisWebServiceSenderInfo);
                debugMessage("Opened ibis web service sender '" + name + "'", writers);
            }
        }
    }
    debugMessage("Initialize web service senders", writers);
    iterator = webServiceSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        Boolean convertExceptionToMessage = new Boolean((String) properties.get(name + ".convertExceptionToMessage"));
        String url = (String) properties.get(name + ".url");
        String userName = (String) properties.get(name + ".userName");
        String password = (String) properties.get(name + ".password");
        String soap = (String) properties.get(name + ".soap");
        String allowSelfSignedCertificates = (String) properties.get(name + ".allowSelfSignedCertificates");
        if (url == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find url property for " + name, writers);
        } else {
            WebServiceSender webServiceSender = new WebServiceSender();
            webServiceSender.setName("Test Tool WebServiceSender");
            webServiceSender.setUrl(url);
            webServiceSender.setUserName(userName);
            webServiceSender.setPassword(password);
            if (soap != null) {
                webServiceSender.setSoap(new Boolean(soap));
            }
            if (allowSelfSignedCertificates != null) {
                webServiceSender.setAllowSelfSignedCertificates(new Boolean(allowSelfSignedCertificates));
            }
            String serviceNamespaceURI = (String) properties.get(name + ".serviceNamespaceURI");
            if (serviceNamespaceURI != null) {
                webServiceSender.setServiceNamespaceURI(serviceNamespaceURI);
            }
            String serviceNamespace = (String) properties.get(name + ".serviceNamespace");
            if (serviceNamespace != null) {
                webServiceSender.setServiceNamespace(serviceNamespace);
            }
            try {
                webServiceSender.configure();
            } catch (ConfigurationException e) {
                errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                closeQueues(queues, properties, writers);
                queues = null;
            }
            if (queues != null) {
                try {
                    webServiceSender.open();
                } catch (SenderException e) {
                    closeQueues(queues, properties, writers);
                    queues = null;
                    errorMessage("Could not open '" + name + "': " + e.getMessage(), e, writers);
                }
                if (queues != null) {
                    Map webServiceSenderInfo = new HashMap();
                    webServiceSenderInfo.put("webServiceSender", webServiceSender);
                    webServiceSenderInfo.put("convertExceptionToMessage", convertExceptionToMessage);
                    queues.put(name, webServiceSenderInfo);
                    debugMessage("Opened web service sender '" + name + "'", writers);
                }
            }
        }
    }
    debugMessage("Initialize web service listeners", writers);
    iterator = webServiceListeners.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        String serviceNamespaceURI = (String) properties.get(name + ".serviceNamespaceURI");
        if (serviceNamespaceURI == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find property '" + name + ".serviceNamespaceURI'", writers);
        } else {
            ListenerMessageHandler listenerMessageHandler = new ListenerMessageHandler();
            try {
                long requestTimeOut = Long.parseLong((String) properties.get(name + ".requestTimeOut"));
                listenerMessageHandler.setRequestTimeOut(requestTimeOut);
                debugMessage("Request time out set to '" + requestTimeOut + "'", writers);
            } catch (Exception e) {
            }
            try {
                long responseTimeOut = Long.parseLong((String) properties.get(name + ".responseTimeOut"));
                listenerMessageHandler.setResponseTimeOut(responseTimeOut);
                debugMessage("Response time out set to '" + responseTimeOut + "'", writers);
            } catch (Exception e) {
            }
            WebServiceListener webServiceListener = new WebServiceListener();
            webServiceListener.setName("Test Tool WebServiceListener");
            webServiceListener.setServiceNamespaceURI(serviceNamespaceURI);
            webServiceListener.setHandler(listenerMessageHandler);
            try {
                webServiceListener.open();
            } catch (ListenerException e) {
                closeQueues(queues, properties, writers);
                queues = null;
                errorMessage("Could not open web service listener '" + name + "': " + e.getMessage(), e, writers);
            }
            Map webServiceListenerInfo = new HashMap();
            webServiceListenerInfo.put("webServiceListener", webServiceListener);
            webServiceListenerInfo.put("listenerMessageHandler", listenerMessageHandler);
            queues.put(name, webServiceListenerInfo);
            ServiceDispatcher serviceDispatcher = ServiceDispatcher.getInstance();
            try {
                serviceDispatcher.registerServiceClient(serviceNamespaceURI, webServiceListener);
                debugMessage("Opened web service listener '" + name + "'", writers);
            } catch (ListenerException e) {
                closeQueues(queues, properties, writers);
                queues = null;
                errorMessage("Could not open web service listener '" + name + "': " + e.getMessage(), e, writers);
            }
        }
    }
    debugMessage("Initialize http senders", writers);
    iterator = httpSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        Boolean convertExceptionToMessage = new Boolean((String) properties.get(name + ".convertExceptionToMessage"));
        String url = (String) properties.get(name + ".url");
        String userName = (String) properties.get(name + ".userName");
        String password = (String) properties.get(name + ".password");
        String headerParams = (String) properties.get(name + ".headersParams");
        String xhtmlString = (String) properties.get(name + ".xhtml");
        String methodtype = (String) properties.get(name + ".methodType");
        String paramsInUrlString = (String) properties.get(name + ".paramsInUrl");
        String inputMessageParam = (String) properties.get(name + ".inputMessageParam");
        String multipartString = (String) properties.get(name + ".multipart");
        String styleSheetName = (String) properties.get(name + ".styleSheetName");
        if (url == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find url property for " + name, writers);
        } else {
            HttpSender httpSender = null;
            ParameterResolutionContext parameterResolutionContext = null;
            ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
            try {
                // Use directoryClassLoader to make it possible to specify
                // styleSheetName relative to the scenarioDirectory.
                DirectoryClassLoader directoryClassLoader = new DirectoryClassLoader(scenarioDirectory);
                Thread.currentThread().setContextClassLoader(directoryClassLoader);
                httpSender = new HttpSender();
                httpSender.setName("Test Tool HttpSender");
                httpSender.setUrl(url);
                httpSender.setUserName(userName);
                httpSender.setPassword(password);
                httpSender.setHeadersParams(headerParams);
                if (StringUtils.isNotEmpty(xhtmlString)) {
                    httpSender.setXhtml(Boolean.valueOf(xhtmlString).booleanValue());
                }
                if (StringUtils.isNotEmpty(methodtype)) {
                    httpSender.setMethodType(methodtype);
                }
                if (StringUtils.isNotEmpty(paramsInUrlString)) {
                    httpSender.setParamsInUrl(Boolean.valueOf(paramsInUrlString).booleanValue());
                }
                if (StringUtils.isNotEmpty(inputMessageParam)) {
                    httpSender.setInputMessageParam(inputMessageParam);
                }
                if (StringUtils.isNotEmpty(multipartString)) {
                    httpSender.setMultipart(Boolean.valueOf(multipartString).booleanValue());
                }
                if (StringUtils.isNotEmpty(styleSheetName)) {
                    httpSender.setStyleSheetName(styleSheetName);
                }
                parameterResolutionContext = new ParameterResolutionContext();
                parameterResolutionContext.setSession(new PipeLineSessionBase());
                Map paramPropertiesMap = createParametersMapFromParamProperties(properties, name, writers, true, parameterResolutionContext);
                Iterator parameterNameIterator = paramPropertiesMap.keySet().iterator();
                while (parameterNameIterator.hasNext()) {
                    String parameterName = (String) parameterNameIterator.next();
                    Parameter parameter = (Parameter) paramPropertiesMap.get(parameterName);
                    httpSender.addParameter(parameter);
                }
                httpSender.configure();
            } catch (ConfigurationException e) {
                errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                closeQueues(queues, properties, writers);
                queues = null;
            } finally {
                if (originalClassLoader != null) {
                    Thread.currentThread().setContextClassLoader(originalClassLoader);
                }
            }
            if (queues != null) {
                try {
                    httpSender.open();
                } catch (SenderException e) {
                    closeQueues(queues, properties, writers);
                    queues = null;
                    errorMessage("Could not open '" + name + "': " + e.getMessage(), e, writers);
                }
                if (queues != null) {
                    Map httpSenderInfo = new HashMap();
                    httpSenderInfo.put("httpSender", httpSender);
                    httpSenderInfo.put("parameterResolutionContext", parameterResolutionContext);
                    httpSenderInfo.put("convertExceptionToMessage", convertExceptionToMessage);
                    queues.put(name, httpSenderInfo);
                    debugMessage("Opened http sender '" + name + "'", writers);
                }
            }
        }
    }
    debugMessage("Initialize ibis java senders", writers);
    iterator = ibisJavaSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        String serviceName = (String) properties.get(name + ".serviceName");
        Boolean convertExceptionToMessage = new Boolean((String) properties.get(name + ".convertExceptionToMessage"));
        if (serviceName == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find serviceName property for " + name, writers);
        } else {
            IbisJavaSender ibisJavaSender = new IbisJavaSender();
            ibisJavaSender.setName("Test Tool IbisJavaSender");
            ibisJavaSender.setServiceName(serviceName);
            ParameterResolutionContext parameterResolutionContext = new ParameterResolutionContext();
            parameterResolutionContext.setSession(new PipeLineSessionBase());
            Map paramPropertiesMap = createParametersMapFromParamProperties(properties, name, writers, true, parameterResolutionContext);
            Iterator parameterNameIterator = paramPropertiesMap.keySet().iterator();
            while (parameterNameIterator.hasNext()) {
                String parameterName = (String) parameterNameIterator.next();
                Parameter parameter = (Parameter) paramPropertiesMap.get(parameterName);
                ibisJavaSender.addParameter(parameter);
            }
            try {
                ibisJavaSender.configure();
            } catch (ConfigurationException e) {
                errorMessage("Could not configure '" + name + "': " + e.getMessage(), e, writers);
                closeQueues(queues, properties, writers);
                queues = null;
            }
            if (queues != null) {
                try {
                    ibisJavaSender.open();
                } catch (SenderException e) {
                    closeQueues(queues, properties, writers);
                    queues = null;
                    errorMessage("Could not open '" + name + "': " + e.getMessage(), e, writers);
                }
                if (queues != null) {
                    Map ibisJavaSenderInfo = new HashMap();
                    ibisJavaSenderInfo.put("ibisJavaSender", ibisJavaSender);
                    ibisJavaSenderInfo.put("parameterResolutionContext", parameterResolutionContext);
                    ibisJavaSenderInfo.put("convertExceptionToMessage", convertExceptionToMessage);
                    queues.put(name, ibisJavaSenderInfo);
                    debugMessage("Opened ibis java sender '" + name + "'", writers);
                }
            }
        }
    }
    debugMessage("Initialize delay senders", writers);
    iterator = delaySenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        Boolean convertExceptionToMessage = new Boolean((String) properties.get(name + ".convertExceptionToMessage"));
        String delayTime = (String) properties.get(name + ".delayTime");
        DelaySender delaySender = new DelaySender();
        if (delayTime != null) {
            delaySender.setDelayTime(Long.parseLong(delayTime));
        }
        delaySender.setName("Test Tool DelaySender");
        Map delaySenderInfo = new HashMap();
        delaySenderInfo.put("delaySender", delaySender);
        delaySenderInfo.put("convertExceptionToMessage", convertExceptionToMessage);
        queues.put(name, delaySenderInfo);
        debugMessage("Opened delay sender '" + name + "'", writers);
    }
    debugMessage("Initialize java listeners", writers);
    iterator = javaListeners.iterator();
    while (queues != null && iterator.hasNext()) {
        String name = (String) iterator.next();
        String serviceName = (String) properties.get(name + ".serviceName");
        if (serviceName == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find property '" + name + ".serviceName'", writers);
        } else {
            ListenerMessageHandler listenerMessageHandler = new ListenerMessageHandler();
            try {
                long requestTimeOut = Long.parseLong((String) properties.get(name + ".requestTimeOut"));
                listenerMessageHandler.setRequestTimeOut(requestTimeOut);
                debugMessage("Request time out set to '" + requestTimeOut + "'", writers);
            } catch (Exception e) {
            }
            try {
                long responseTimeOut = Long.parseLong((String) properties.get(name + ".responseTimeOut"));
                listenerMessageHandler.setResponseTimeOut(responseTimeOut);
                debugMessage("Response time out set to '" + responseTimeOut + "'", writers);
            } catch (Exception e) {
            }
            JavaListener javaListener = new JavaListener();
            javaListener.setName("Test Tool JavaListener");
            javaListener.setServiceName(serviceName);
            javaListener.setHandler(listenerMessageHandler);
            try {
                javaListener.open();
                Map javaListenerInfo = new HashMap();
                javaListenerInfo.put("javaListener", javaListener);
                javaListenerInfo.put("listenerMessageHandler", listenerMessageHandler);
                queues.put(name, javaListenerInfo);
                debugMessage("Opened java listener '" + name + "'", writers);
            } catch (ListenerException e) {
                closeQueues(queues, properties, writers);
                queues = null;
                errorMessage("Could not open java listener '" + name + "': " + e.getMessage(), e, writers);
            }
        }
    }
    debugMessage("Initialize file senders", writers);
    iterator = fileSenders.iterator();
    while (queues != null && iterator.hasNext()) {
        String queueName = (String) iterator.next();
        String filename = (String) properties.get(queueName + ".filename");
        if (filename == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find filename property for " + queueName, writers);
        } else {
            FileSender fileSender = new FileSender();
            String filenameAbsolutePath = (String) properties.get(queueName + ".filename.absolutepath");
            fileSender.setFilename(filenameAbsolutePath);
            String encoding = (String) properties.get(queueName + ".encoding");
            if (encoding != null) {
                fileSender.setEncoding(encoding);
                debugMessage("Encoding set to '" + encoding + "'", writers);
            }
            String deletePathString = (String) properties.get(queueName + ".deletePath");
            if (deletePathString != null) {
                boolean deletePath = Boolean.valueOf(deletePathString).booleanValue();
                fileSender.setDeletePath(deletePath);
                debugMessage("Delete path set to '" + deletePath + "'", writers);
            }
            String createPathString = (String) properties.get(queueName + ".createPath");
            if (createPathString != null) {
                boolean createPath = Boolean.valueOf(createPathString).booleanValue();
                fileSender.setCreatePath(createPath);
                debugMessage("Create path set to '" + createPath + "'", writers);
            }
            try {
                String checkDeleteString = (String) properties.get(queueName + ".checkDelete");
                if (checkDeleteString != null) {
                    boolean checkDelete = Boolean.valueOf(checkDeleteString).booleanValue();
                    fileSender.setCheckDelete(checkDelete);
                    debugMessage("Check delete set to '" + checkDelete + "'", writers);
                }
            } catch (Exception e) {
            }
            try {
                String runAntString = (String) properties.get(queueName + ".runAnt");
                if (runAntString != null) {
                    boolean runAnt = Boolean.valueOf(runAntString).booleanValue();
                    fileSender.setRunAnt(runAnt);
                    debugMessage("Run ant set to '" + runAnt + "'", writers);
                }
            } catch (Exception e) {
            }
            try {
                long timeOut = Long.parseLong((String) properties.get(queueName + ".timeOut"));
                fileSender.setTimeOut(timeOut);
                debugMessage("Time out set to '" + timeOut + "'", writers);
            } catch (Exception e) {
            }
            try {
                long interval = Long.parseLong((String) properties.get(queueName + ".interval"));
                fileSender.setInterval(interval);
                debugMessage("Interval set to '" + interval + "'", writers);
            } catch (Exception e) {
            }
            try {
                String overwriteString = (String) properties.get(queueName + ".overwrite");
                if (overwriteString != null) {
                    debugMessage("OverwriteString = " + overwriteString, writers);
                    boolean overwrite = Boolean.valueOf(overwriteString).booleanValue();
                    fileSender.setOverwrite(overwrite);
                    debugMessage("Overwrite set to '" + overwrite + "'", writers);
                }
            } catch (Exception e) {
            }
            Map fileSenderInfo = new HashMap();
            fileSenderInfo.put("fileSender", fileSender);
            queues.put(queueName, fileSenderInfo);
            debugMessage("Opened file sender '" + queueName + "'", writers);
        }
    }
    debugMessage("Initialize file listeners", writers);
    iterator = fileListeners.iterator();
    while (queues != null && iterator.hasNext()) {
        String queueName = (String) iterator.next();
        String filename = (String) properties.get(queueName + ".filename");
        String filename2 = (String) properties.get(queueName + ".filename2");
        String directory = null;
        String wildcard = null;
        if (filename == null) {
            directory = (String) properties.get(queueName + ".directory");
            wildcard = (String) properties.get(queueName + ".wildcard");
        }
        if (filename == null && directory == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find filename or directory property for " + queueName, writers);
        } else if (directory != null && wildcard == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find wildcard property for " + queueName, writers);
        } else {
            FileListener fileListener = new FileListener();
            if (filename == null) {
                String directoryAbsolutePath = (String) properties.get(queueName + ".directory.absolutepath");
                ;
                fileListener.setDirectory(directoryAbsolutePath);
                fileListener.setWildcard(wildcard);
            } else {
                String filenameAbsolutePath = (String) properties.get(queueName + ".filename.absolutepath");
                ;
                fileListener.setFilename(filenameAbsolutePath);
            }
            try {
                long waitBeforeRead = Long.parseLong((String) properties.get(queueName + ".waitBeforeRead"));
                fileListener.setWaitBeforeRead(waitBeforeRead);
                debugMessage("Wait before read set to '" + waitBeforeRead + "'", writers);
            } catch (Exception e) {
            }
            try {
                long timeOut = Long.parseLong((String) properties.get(queueName + ".timeOut"));
                fileListener.setTimeOut(timeOut);
                debugMessage("Time out set to '" + timeOut + "'", writers);
            } catch (Exception e) {
            }
            try {
                long interval = Long.parseLong((String) properties.get(queueName + ".interval"));
                fileListener.setInterval(interval);
                debugMessage("Interval set to '" + interval + "'", writers);
            } catch (Exception e) {
            }
            if (filename2 != null) {
                fileListener.setFilename2(filename2);
            }
            Map fileListenerInfo = new HashMap();
            fileListenerInfo.put("fileListener", fileListener);
            queues.put(queueName, fileListenerInfo);
            debugMessage("Opened file listener '" + queueName + "'", writers);
            if (fileListenerCleanUp(queueName, fileListener, writers)) {
                errorMessage("Found old messages on '" + queueName + "'", writers);
            }
        }
    }
    debugMessage("Initialize xslt provider listeners", writers);
    iterator = xsltProviderListeners.iterator();
    while (queues != null && iterator.hasNext()) {
        String queueName = (String) iterator.next();
        String filename = (String) properties.get(queueName + ".filename");
        if (filename == null) {
            closeQueues(queues, properties, writers);
            queues = null;
            errorMessage("Could not find filename property for " + queueName, writers);
        } else {
            Boolean fromClasspath = new Boolean((String) properties.get(queueName + ".fromClasspath"));
            if (!fromClasspath) {
                filename = (String) properties.get(queueName + ".filename.absolutepath");
            }
            XsltProviderListener xsltProviderListener = new XsltProviderListener();
            xsltProviderListener.setFromClasspath(fromClasspath);
            xsltProviderListener.setFilename(filename);
            String xslt2String = (String) properties.get(queueName + ".xslt2");
            if (xslt2String != null) {
                try {
                    boolean xslt2 = Boolean.valueOf(xslt2String).booleanValue();
                    xsltProviderListener.setXslt2(xslt2);
                    debugMessage("Xslt2 set to '" + xslt2 + "'", writers);
                } catch (Exception e) {
                }
            }
            String namespaceAwareString = (String) properties.get(queueName + ".namespaceAware");
            if (namespaceAwareString != null) {
                try {
                    boolean namespaceAware = Boolean.valueOf(namespaceAwareString).booleanValue();
                    xsltProviderListener.setNamespaceAware(namespaceAware);
                    debugMessage("Namespace aware set to '" + namespaceAware + "'", writers);
                } catch (Exception e) {
                }
            }
            try {
                xsltProviderListener.init();
                Map xsltProviderListenerInfo = new HashMap();
                xsltProviderListenerInfo.put("xsltProviderListener", xsltProviderListener);
                queues.put(queueName, xsltProviderListenerInfo);
                debugMessage("Opened xslt provider listener '" + queueName + "'", writers);
            } catch (ListenerException e) {
                closeQueues(queues, properties, writers);
                queues = null;
                errorMessage("Could not create xslt provider listener for '" + queueName + "': " + e.getMessage(), e, writers);
            }
        }
    }
    return queues;
}
Also used : PullingJmsListener(nl.nn.adapterframework.jms.PullingJmsListener) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Iterator(java.util.Iterator) DelaySender(nl.nn.adapterframework.senders.DelaySender) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ServiceDispatcher(nl.nn.adapterframework.receivers.ServiceDispatcher) IbisWebServiceSender(nl.nn.adapterframework.http.IbisWebServiceSender) WebServiceSender(nl.nn.adapterframework.http.WebServiceSender) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) IbisWebServiceSender(nl.nn.adapterframework.http.IbisWebServiceSender) WebServiceListener(nl.nn.adapterframework.http.WebServiceListener) HttpSender(nl.nn.adapterframework.http.HttpSender) ParseException(java.text.ParseException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) FileNotFoundException(java.io.FileNotFoundException) SenderException(nl.nn.adapterframework.core.SenderException) DocumentException(org.dom4j.DocumentException) ListenerException(nl.nn.adapterframework.core.ListenerException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) IbisJavaSender(nl.nn.adapterframework.senders.IbisJavaSender) TimeOutException(nl.nn.adapterframework.core.TimeOutException) JavaListener(nl.nn.adapterframework.receivers.JavaListener) Parameter(nl.nn.adapterframework.parameters.Parameter) JmsSender(nl.nn.adapterframework.jms.JmsSender) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 20 with FixedQuerySender

use of nl.nn.adapterframework.jdbc.FixedQuerySender 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;
}
Also used : PullingJmsListener(nl.nn.adapterframework.jms.PullingJmsListener) IbisWebServiceSender(nl.nn.adapterframework.http.IbisWebServiceSender) WebServiceListener(nl.nn.adapterframework.http.WebServiceListener) IbisJavaSender(nl.nn.adapterframework.senders.IbisJavaSender) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ListenerException(nl.nn.adapterframework.core.ListenerException) JavaListener(nl.nn.adapterframework.receivers.JavaListener) Iterator(java.util.Iterator) DelaySender(nl.nn.adapterframework.senders.DelaySender) IbisWebServiceSender(nl.nn.adapterframework.http.IbisWebServiceSender) WebServiceSender(nl.nn.adapterframework.http.WebServiceSender) JmsSender(nl.nn.adapterframework.jms.JmsSender) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Aggregations

FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)32 Connection (java.sql.Connection)17 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)14 SenderException (nl.nn.adapterframework.core.SenderException)13 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)11 Parameter (nl.nn.adapterframework.parameters.Parameter)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 SQLException (java.sql.SQLException)8 LinkedHashMap (java.util.LinkedHashMap)8 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)8 Map (java.util.Map)7 PipeRunException (nl.nn.adapterframework.core.PipeRunException)7 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)7 ArrayList (java.util.ArrayList)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 ListenerException (nl.nn.adapterframework.core.ListenerException)4 IbisWebServiceSender (nl.nn.adapterframework.http.IbisWebServiceSender)4 WebServiceListener (nl.nn.adapterframework.http.WebServiceListener)4