Search in sources :

Example 1 with ServerInfo

use of com.tibco.tibjms.admin.ServerInfo in project iaf by ibissource.

the class GetTibcoQueues method getQueueMessage.

private String getQueueMessage(Session jSession, TibjmsAdmin admin, String queueName, int queueItem, LdapSender ldapSender) throws TibjmsAdminException, JMSException {
    QueueInfo qInfo = admin.getQueue(queueName);
    if (qInfo == null) {
        throw new JMSException(" queue [" + queueName + "] does not exist");
    }
    XmlBuilder qMessageXml = new XmlBuilder("qMessage");
    ServerInfo serverInfo = admin.getInfo();
    String url = serverInfo.getURL();
    qMessageXml.addAttribute("url", url);
    String resolvedUrl = getResolvedUrl(url);
    if (resolvedUrl != null) {
        qMessageXml.addAttribute("resolvedUrl", resolvedUrl);
    }
    qMessageXml.addAttribute("timestamp", DateUtils.getIsoTimeStamp());
    qMessageXml.addAttribute("startTime", DateUtils.format(serverInfo.getStartTime(), DateUtils.fullIsoFormat));
    XmlBuilder qNameXml = new XmlBuilder("qName");
    qNameXml.setCdataValue(queueName);
    Queue queue = jSession.createQueue(queueName);
    QueueBrowser queueBrowser = null;
    try {
        queueBrowser = jSession.createBrowser(queue);
        Enumeration enm = queueBrowser.getEnumeration();
        int count = 0;
        boolean found = false;
        String chompCharSizeString = AppConstants.getInstance().getString("browseQueue.chompCharSize", null);
        int chompCharSize = (int) Misc.toFileSize(chompCharSizeString, -1);
        while (enm.hasMoreElements() && !found) {
            count++;
            if (count == queueItem) {
                qNameXml.addAttribute("item", count);
                Object o = enm.nextElement();
                if (o instanceof Message) {
                    Message msg = (Message) o;
                    XmlBuilder qMessageId = new XmlBuilder("qMessageId");
                    qMessageId.setCdataValue(msg.getJMSMessageID());
                    qMessageXml.addSubElement(qMessageId);
                    XmlBuilder qTimestamp = new XmlBuilder("qTimestamp");
                    qTimestamp.setCdataValue(DateUtils.format(msg.getJMSTimestamp(), DateUtils.fullIsoFormat));
                    qMessageXml.addSubElement(qTimestamp);
                    StringBuffer sb = new StringBuffer("");
                    Enumeration propertyNames = msg.getPropertyNames();
                    while (propertyNames.hasMoreElements()) {
                        String propertyName = (String) propertyNames.nextElement();
                        Object object = msg.getObjectProperty(propertyName);
                        if (sb.length() > 0) {
                            sb.append("; ");
                        }
                        sb.append(propertyName);
                        sb.append("=");
                        sb.append(object);
                    }
                    XmlBuilder qPropsXml = new XmlBuilder("qProps");
                    qPropsXml.setCdataValue(sb.toString());
                    qMessageXml.addSubElement(qPropsXml);
                    XmlBuilder qTextXml = new XmlBuilder("qText");
                    String msgText;
                    try {
                        TextMessage textMessage = (TextMessage) msg;
                        msgText = textMessage.getText();
                    } catch (ClassCastException e) {
                        msgText = msg.toString();
                        qTextXml.addAttribute("text", false);
                    }
                    int msgSize = msgText.length();
                    if (isHideMessage()) {
                        qTextXml.setCdataValue("***HIDDEN***");
                    } else {
                        if (chompCharSize >= 0 && msgSize > chompCharSize) {
                            qTextXml.setCdataValue(msgText.substring(0, chompCharSize) + "...");
                            qTextXml.addAttribute("chomped", true);
                        } else {
                            qTextXml.setCdataValue(msgText);
                        }
                    }
                    qMessageXml.addSubElement(qTextXml);
                    XmlBuilder qTextSizeXml = new XmlBuilder("qTextSize");
                    qTextSizeXml.setValue(Misc.toFileSize(msgSize));
                    qMessageXml.addSubElement(qTextSizeXml);
                }
                found = true;
            } else {
                enm.nextElement();
            }
        }
    } finally {
        if (queueBrowser != null) {
            try {
                queueBrowser.close();
            } catch (JMSException e) {
                log.warn(getLogPrefix(null) + "exception on closing queue browser", e);
            }
        }
    }
    qMessageXml.addSubElement(qNameXml);
    Map aclMap = getAclMap(admin, ldapSender);
    XmlBuilder aclXml = new XmlBuilder("acl");
    XmlBuilder qInfoXml = qInfoToXml(qInfo);
    aclXml.setValue((String) aclMap.get(qInfo.getName()));
    qInfoXml.addSubElement(aclXml);
    qMessageXml.addSubElement(qInfoXml);
    Map consumersMap = getConnectedConsumersMap(admin);
    XmlBuilder consumerXml = new XmlBuilder("connectedConsumers");
    if (consumersMap.containsKey(qInfo.getName())) {
        LinkedList<String> consumers = (LinkedList<String>) consumersMap.get(qInfo.getName());
        String consumersString = listToString(consumers);
        if (consumersString != null) {
            consumerXml.setCdataValue(consumersString);
        }
    }
    qInfoXml.addSubElement(consumerXml);
    return qMessageXml.toXML();
}
Also used : QueueInfo(com.tibco.tibjms.admin.QueueInfo) Enumeration(java.util.Enumeration) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) ServerInfo(com.tibco.tibjms.admin.ServerInfo) JMSException(javax.jms.JMSException) LinkedList(java.util.LinkedList) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) Queue(javax.jms.Queue) HashMap(java.util.HashMap) Map(java.util.Map) QueueBrowser(javax.jms.QueueBrowser) TextMessage(javax.jms.TextMessage)

Example 2 with ServerInfo

use of com.tibco.tibjms.admin.ServerInfo in project iaf by ibissource.

the class GetTibcoQueues method getQueuesInfo.

private String getQueuesInfo(Session jSession, TibjmsAdmin admin, boolean showAge, LdapSender ldapSender) throws TibjmsAdminException {
    XmlBuilder qInfosXml = new XmlBuilder("qInfos");
    ServerInfo serverInfo = admin.getInfo();
    String url = serverInfo.getURL();
    qInfosXml.addAttribute("url", url);
    String resolvedUrl = getResolvedUrl(url);
    if (resolvedUrl != null) {
        qInfosXml.addAttribute("resolvedUrl", resolvedUrl);
    }
    long currentTime = (new Date()).getTime();
    qInfosXml.addAttribute("timestamp", DateUtils.format(currentTime, DateUtils.fullIsoFormat));
    long startTime = serverInfo.getStartTime();
    qInfosXml.addAttribute("startTime", DateUtils.format(startTime, DateUtils.fullIsoFormat));
    qInfosXml.addAttribute("age", Misc.getAge(startTime));
    Map aclMap = getAclMap(admin, ldapSender);
    Map consumersMap = getConnectedConsumersMap(admin);
    QueueInfo[] qInfos = admin.getQueues();
    for (int i = 0; i < qInfos.length; i++) {
        QueueInfo qInfo = qInfos[i];
        if (skipTemporaryQueues && qInfo.isTemporary()) {
        // skip
        } else {
            XmlBuilder qInfoXml = qInfoToXml(qInfo);
            qInfosXml.addSubElement(qInfoXml);
            XmlBuilder aclXml = new XmlBuilder("acl");
            aclXml.setValue((String) aclMap.get(qInfo.getName()));
            qInfoXml.addSubElement(aclXml);
            XmlBuilder consumerXml = new XmlBuilder("connectedConsumers");
            if (consumersMap.containsKey(qInfo.getName())) {
                LinkedList<String> consumers = (LinkedList<String>) consumersMap.get(qInfo.getName());
                String consumersString = listToString(consumers);
                if (consumersString != null) {
                    consumerXml.setCdataValue(consumersString);
                }
            }
            qInfoXml.addSubElement(consumerXml);
            if (showAge) {
                if (qInfo.getReceiverCount() == 0 && qInfo.getPendingMessageCount() > 0) {
                    String qfmAge;
                    if (getQueueRegex() == null || qInfo.getName().matches(getQueueRegex())) {
                        qfmAge = TibcoUtils.getQueueFirstMessageAgeAsString(jSession, qInfo.getName(), currentTime);
                    } else {
                        qfmAge = "?";
                    }
                    if (qfmAge != null) {
                        XmlBuilder firstMsgAgeXml = new XmlBuilder("firstMsgAge");
                        firstMsgAgeXml.setCdataValue(qfmAge);
                        qInfoXml.addSubElement(firstMsgAgeXml);
                    }
                }
            }
        }
    }
    return qInfosXml.toXML();
}
Also used : QueueInfo(com.tibco.tibjms.admin.QueueInfo) ServerInfo(com.tibco.tibjms.admin.ServerInfo) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) LinkedList(java.util.LinkedList)

Aggregations

QueueInfo (com.tibco.tibjms.admin.QueueInfo)2 ServerInfo (com.tibco.tibjms.admin.ServerInfo)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)2 Date (java.util.Date)1 Enumeration (java.util.Enumeration)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 Queue (javax.jms.Queue)1 QueueBrowser (javax.jms.QueueBrowser)1 TextMessage (javax.jms.TextMessage)1