Search in sources :

Example 6 with JmsSender

use of nl.nn.adapterframework.jms.JmsSender 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)

Example 7 with JmsSender

use of nl.nn.adapterframework.jms.JmsSender in project iaf by ibissource.

the class ShowSecurityItems method addJmsRealms.

private ArrayList<Object> addJmsRealms() {
    List<String> jmsRealms = JmsRealmFactory.getInstance().getRegisteredRealmNamesAsList();
    ArrayList<Object> jmsRealmList = new ArrayList<Object>();
    String confResString;
    try {
        confResString = Misc.getConfigurationResources();
        if (confResString != null) {
            confResString = XmlUtils.removeNamespaces(confResString);
        }
    } catch (IOException e) {
        log.warn("error getting configuration resources [" + e + "]");
        confResString = null;
    }
    for (int j = 0; j < jmsRealms.size(); j++) {
        Map<String, Object> realm = new HashMap<String, Object>();
        String jmsRealm = (String) jmsRealms.get(j);
        String dsName = null;
        String qcfName = null;
        String tcfName = null;
        String dsInfo = null;
        String qcfInfo = null;
        DirectQuerySender qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(jmsRealm);
        try {
            dsName = qs.getDataSourceNameToUse();
            dsInfo = qs.getDatasourceInfo();
        } catch (JdbcException jdbce) {
        // no datasource
        }
        if (StringUtils.isNotEmpty(dsName)) {
            realm.put("name", jmsRealm);
            realm.put("datasourceName", dsName);
            realm.put("info", dsInfo);
            if (confResString != null) {
                String connectionPoolProperties = Misc.getConnectionPoolProperties(confResString, "JDBC", dsName);
                if (StringUtils.isNotEmpty(connectionPoolProperties)) {
                    realm.put("connectionPoolProperties", connectionPoolProperties);
                }
            }
        }
        JmsSender js = new JmsSender();
        js.setJmsRealm(jmsRealm);
        try {
            qcfName = js.getConnectionFactoryName();
            qcfInfo = js.getConnectionFactoryInfo();
        } catch (JmsException jmse) {
        // no connectionFactory
        }
        if (StringUtils.isNotEmpty(qcfName)) {
            realm.put("name", jmsRealm);
            realm.put("queueConnectionFactoryName", qcfName);
            realm.put("info", qcfInfo);
            if (confResString != null) {
                String connectionPoolProperties = Misc.getConnectionPoolProperties(confResString, "JMS", qcfName);
                if (StringUtils.isNotEmpty(connectionPoolProperties)) {
                    realm.put("connectionPoolProperties", connectionPoolProperties);
                }
            }
        }
        tcfName = js.getTopicConnectionFactoryName();
        if (StringUtils.isNotEmpty(tcfName)) {
            realm.put("name", jmsRealm);
            realm.put("topicConnectionFactoryName", tcfName);
        }
        jmsRealmList.add(realm);
    }
    return jmsRealmList;
}
Also used : HashMap(java.util.HashMap) JmsException(nl.nn.adapterframework.jms.JmsException) ArrayList(java.util.ArrayList) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) IOException(java.io.IOException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) JmsSender(nl.nn.adapterframework.jms.JmsSender)

Example 8 with JmsSender

use of nl.nn.adapterframework.jms.JmsSender in project iaf by ibissource.

the class ShowSecurityItems method addJmsRealms.

private void addJmsRealms(XmlBuilder securityItems, String confResString) {
    List jmsRealms = JmsRealmFactory.getInstance().getRegisteredRealmNamesAsList();
    XmlBuilder jrs = new XmlBuilder("jmsRealms");
    securityItems.addSubElement(jrs);
    for (int j = 0; j < jmsRealms.size(); j++) {
        String jmsRealm = (String) jmsRealms.get(j);
        String dsName = null;
        String qcfName = null;
        String tcfName = null;
        String dsInfo = null;
        String qcfInfo = null;
        DirectQuerySender qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(jmsRealm);
        try {
            dsName = qs.getDataSourceNameToUse();
            dsInfo = qs.getDatasourceInfo();
        } catch (JdbcException jdbce) {
        // no datasource
        }
        if (StringUtils.isNotEmpty(dsName)) {
            XmlBuilder jr = new XmlBuilder("jmsRealm");
            jrs.addSubElement(jr);
            jr.addAttribute("name", jmsRealm);
            jr.addAttribute("datasourceName", dsName);
            XmlBuilder infoElem = new XmlBuilder("info");
            infoElem.setValue(dsInfo);
            jr.addSubElement(infoElem);
            if (confResString != null) {
                String connectionPoolProperties;
                try {
                    connectionPoolProperties = Misc.getConnectionPoolProperties(confResString, "JDBC", dsName);
                } catch (Exception e) {
                    connectionPoolProperties = "*** ERROR ***";
                }
                if (StringUtils.isNotEmpty(connectionPoolProperties)) {
                    infoElem = new XmlBuilder("info");
                    infoElem.setValue(connectionPoolProperties);
                    jr.addSubElement(infoElem);
                }
            }
        }
        JmsSender js = new JmsSender();
        js.setJmsRealm(jmsRealm);
        try {
            qcfName = js.getConnectionFactoryName();
            qcfInfo = js.getConnectionFactoryInfo();
        } catch (JmsException jmse) {
        // no connectionFactory
        }
        if (StringUtils.isNotEmpty(qcfName)) {
            XmlBuilder jr = new XmlBuilder("jmsRealm");
            jrs.addSubElement(jr);
            jr.addAttribute("name", jmsRealm);
            jr.addAttribute("queueConnectionFactoryName", qcfName);
            XmlBuilder infoElem = new XmlBuilder("info");
            infoElem.setValue(qcfInfo);
            jr.addSubElement(infoElem);
            if (confResString != null) {
                String connectionPoolProperties;
                try {
                    connectionPoolProperties = Misc.getConnectionPoolProperties(confResString, "JMS", qcfName);
                } catch (Exception e) {
                    connectionPoolProperties = "*** ERROR ***";
                }
                if (StringUtils.isNotEmpty(connectionPoolProperties)) {
                    infoElem = new XmlBuilder("info");
                    infoElem.setValue(connectionPoolProperties);
                    jr.addSubElement(infoElem);
                }
            }
        }
        tcfName = js.getTopicConnectionFactoryName();
        if (StringUtils.isNotEmpty(tcfName)) {
            XmlBuilder jr = new XmlBuilder("jmsRealm");
            jrs.addSubElement(jr);
            jr.addAttribute("name", jmsRealm);
            jr.addAttribute("topicConnectionFactoryName", tcfName);
        }
    }
}
Also used : JmsException(nl.nn.adapterframework.jms.JmsException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) JmsSender(nl.nn.adapterframework.jms.JmsSender) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) ServletException(javax.servlet.ServletException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) TransformerException(javax.xml.transform.TransformerException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) JmsException(nl.nn.adapterframework.jms.JmsException) IOException(java.io.IOException)

Aggregations

JmsSender (nl.nn.adapterframework.jms.JmsSender)8 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 Map (java.util.Map)3 SenderException (nl.nn.adapterframework.core.SenderException)3 TimeOutException (nl.nn.adapterframework.core.TimeOutException)3 Iterator (java.util.Iterator)2 ZipInputStream (java.util.zip.ZipInputStream)2 ListenerException (nl.nn.adapterframework.core.ListenerException)2 IbisWebServiceSender (nl.nn.adapterframework.http.IbisWebServiceSender)2 WebServiceListener (nl.nn.adapterframework.http.WebServiceListener)2 WebServiceSender (nl.nn.adapterframework.http.WebServiceSender)2 DirectQuerySender (nl.nn.adapterframework.jdbc.DirectQuerySender)2 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)2 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)2 JmsException (nl.nn.adapterframework.jms.JmsException)2 PullingJmsListener (nl.nn.adapterframework.jms.PullingJmsListener)2