Search in sources :

Example 51 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class ExchangeMailListener method addEmailInfoSimple.

private void addEmailInfoSimple(EmailMessage emailMessage, XmlBuilder emailXml) throws Exception {
    XmlBuilder subjectXml = new XmlBuilder("subject");
    subjectXml.setCdataValue(emailMessage.getSubject());
    emailXml.addSubElement(subjectXml);
}
Also used : XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Example 52 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder 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 53 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class GetTibcoQueues method qInfoToXml.

private XmlBuilder qInfoToXml(QueueInfo qInfo) {
    XmlBuilder qInfoXml = new XmlBuilder("qInfo");
    XmlBuilder qNameXml = new XmlBuilder("qName");
    String qName = qInfo.getName();
    qNameXml.setCdataValue(qName);
    qInfoXml.addSubElement(qNameXml);
    String qNameEncoded = XmlUtils.encodeURL(qName);
    if (!qNameEncoded.equals(qName)) {
        XmlBuilder qNameEncodedXml = new XmlBuilder("qNameEncoded");
        qNameEncodedXml.setCdataValue(qNameEncoded);
        qInfoXml.addSubElement(qNameEncodedXml);
    }
    XmlBuilder pendingMsgCountXml = new XmlBuilder("pendingMsgCount");
    long pendingMsgCount = qInfo.getPendingMessageCount();
    pendingMsgCountXml.setValue(Long.toString(pendingMsgCount));
    qInfoXml.addSubElement(pendingMsgCountXml);
    XmlBuilder pendingMsgSizeXml = new XmlBuilder("pendingMsgSize");
    long pendingMsgSize = qInfo.getPendingMessageSize();
    pendingMsgSizeXml.setValue(Misc.toFileSize(pendingMsgSize));
    qInfoXml.addSubElement(pendingMsgSizeXml);
    XmlBuilder receiverCountXml = new XmlBuilder("receiverCount");
    int receiverCount = qInfo.getReceiverCount();
    receiverCountXml.setValue(Integer.toString(receiverCount));
    qInfoXml.addSubElement(receiverCountXml);
    XmlBuilder inTotalMsgsXml = new XmlBuilder("inTotalMsgs");
    long inTotalMsgs = qInfo.getInboundStatistics().getTotalMessages();
    inTotalMsgsXml.setValue(Long.toString(inTotalMsgs));
    qInfoXml.addSubElement(inTotalMsgsXml);
    XmlBuilder outTotalMsgsXml = new XmlBuilder("outTotalMsgs");
    long outTotalMsgs = qInfo.getOutboundStatistics().getTotalMessages();
    outTotalMsgsXml.setValue(Long.toString(outTotalMsgs));
    qInfoXml.addSubElement(outTotalMsgsXml);
    XmlBuilder isStaticXml = new XmlBuilder("isStatic");
    isStaticXml.setValue(qInfo.isStatic() ? "true" : "false");
    qInfoXml.addSubElement(isStaticXml);
    XmlBuilder prefetchXml = new XmlBuilder("prefetch");
    int prefetch = qInfo.getPrefetch();
    prefetchXml.setValue(Integer.toString(prefetch));
    qInfoXml.addSubElement(prefetchXml);
    XmlBuilder isBridgedXml = new XmlBuilder("isBridged");
    BridgeTarget[] bta = qInfo.getBridgeTargets();
    isBridgedXml.setValue(bta.length == 0 ? "false" : "true");
    qInfoXml.addSubElement(isBridgedXml);
    if (bta.length != 0) {
        XmlBuilder bridgeTargetsXml = new XmlBuilder("bridgeTargets");
        String btaString = null;
        for (int j = 0; j < bta.length; j++) {
            BridgeTarget bridgeTarget = bta[j];
            if (btaString == null) {
                btaString = bridgeTarget.toString();
            } else {
                btaString = btaString + "; " + bridgeTarget.toString();
            }
        }
        bridgeTargetsXml.setCdataValue(btaString);
        qInfoXml.addSubElement(bridgeTargetsXml);
    }
    return qInfoXml;
}
Also used : XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) BridgeTarget(com.tibco.tibjms.admin.BridgeTarget)

Example 54 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder 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)

Example 55 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class XmlJmsBrowserSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queueBrowserElement;
    String root = null;
    String jmsRealm = null;
    String queueConnectionFactoryName = null;
    String destinationName = null;
    String destinationType = null;
    try {
        queueBrowserElement = XmlUtils.buildElement(message);
        root = queueBrowserElement.getTagName();
        jmsRealm = XmlUtils.getChildTagAsString(queueBrowserElement, "jmsRealm");
        queueConnectionFactoryName = XmlUtils.getChildTagAsString(queueBrowserElement, "queueConnectionFactoryName");
        destinationName = XmlUtils.getChildTagAsString(queueBrowserElement, "destinationName");
        destinationType = XmlUtils.getChildTagAsString(queueBrowserElement, "destinationType");
    } catch (DomBuilderException e) {
        throw new SenderException(getLogPrefix() + "got exception parsing [" + message + "]", e);
    }
    JmsMessageBrowser jmsBrowser = new JmsMessageBrowser();
    jmsBrowser.setName("XmlQueueBrowserSender");
    if (jmsRealm != null) {
        jmsBrowser.setJmsRealm(jmsRealm);
    }
    if (queueConnectionFactoryName != null) {
        jmsBrowser.setQueueConnectionFactoryName(queueConnectionFactoryName);
    }
    jmsBrowser.setDestinationName(destinationName);
    jmsBrowser.setDestinationType(destinationType);
    IMessageBrowser browser = jmsBrowser;
    IMessageBrowsingIterator it = null;
    boolean remove = false;
    if (root.equalsIgnoreCase("browse")) {
    // OK
    } else {
        if (root.equalsIgnoreCase("remove")) {
            remove = true;
        } else {
            throw new SenderException(getLogPrefix() + "unknown root element [" + root + "]");
        }
    }
    XmlBuilder result = new XmlBuilder("result");
    XmlBuilder items;
    if (remove) {
        items = new XmlBuilder("itemsRemoved");
    } else {
        items = new XmlBuilder("items");
    }
    try {
        int count = 0;
        it = browser.getIterator();
        while (it.hasNext()) {
            count++;
            JmsMessageBrowserIteratorItem jmsMessageBrowserIteratorItem = (JmsMessageBrowserIteratorItem) it.next();
            if (remove) {
                jmsBrowser.deleteMessage(jmsMessageBrowserIteratorItem.getJMSMessageID());
            } else {
                // browse
                XmlBuilder item = new XmlBuilder("item");
                XmlBuilder timestamp = new XmlBuilder("timestamp");
                timestamp.setValue(new java.util.Date(jmsMessageBrowserIteratorItem.getJMSTimestamp()).toString());
                item.addSubElement(timestamp);
                XmlBuilder messageId = new XmlBuilder("messageId");
                messageId.setValue(jmsMessageBrowserIteratorItem.getJMSMessageID());
                item.addSubElement(messageId);
                XmlBuilder correlationId = new XmlBuilder("correlationId");
                correlationId.setValue(jmsMessageBrowserIteratorItem.getCorrelationId());
                item.addSubElement(correlationId);
                XmlBuilder msg = new XmlBuilder("message");
                msg.setCdataValue(jmsMessageBrowserIteratorItem.getText());
                item.addSubElement(msg);
                items.addSubElement(item);
            }
        }
        if (remove) {
            items.setValue(Integer.toString(count));
        } else {
            items.addAttribute("count", count);
        }
        result.addSubElement(items);
    } catch (ListenerException e) {
        throw new SenderException(getLogPrefix() + "got exception browsing messages", e);
    } finally {
        try {
            if (it != null) {
                it.close();
            }
        } catch (ListenerException e) {
            log.warn(getLogPrefix() + "exception on closing message browser iterator", e);
        }
    }
    return result.toXML();
}
Also used : Element(org.w3c.dom.Element) IMessageBrowser(nl.nn.adapterframework.core.IMessageBrowser) IMessageBrowsingIterator(nl.nn.adapterframework.core.IMessageBrowsingIterator) ListenerException(nl.nn.adapterframework.core.ListenerException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)108 IOException (java.io.IOException)18 Iterator (java.util.Iterator)17 ArrayList (java.util.ArrayList)12 Date (java.util.Date)12 SenderException (nl.nn.adapterframework.core.SenderException)12 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)10 Configuration (nl.nn.adapterframework.configuration.Configuration)9 SchedulerException (org.quartz.SchedulerException)8 ServletException (javax.servlet.ServletException)7 TransformerException (javax.xml.transform.TransformerException)7 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)6 PipeRunException (nl.nn.adapterframework.core.PipeRunException)6 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)6 JmsException (nl.nn.adapterframework.jms.JmsException)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Adapter (nl.nn.adapterframework.core.Adapter)5 SimpleDateFormat (java.text.SimpleDateFormat)4 Map (java.util.Map)4