Example usage for javax.jms Message getJMSTimestamp

List of usage examples for javax.jms Message getJMSTimestamp

Introduction

In this page you can find the example usage for javax.jms Message getJMSTimestamp.

Prototype


long getJMSTimestamp() throws JMSException;

Source Link

Document

Gets the message timestamp.

Usage

From source file:jms.ConsumerThread.java

@Override
public void run() {

    long messageCount = jmsConsumer.getConfigs().getMessageCount();
    String consumerID = jmsConsumer.getConfigs().getId();

    log.info("Starting consumer to receive " + messageCount + " messages. Consumer ID: " + consumerID);
    Message message = null;

    try {/*from   w w w . j  ava2s. c o  m*/
        long latency;
        for (int i = 1; i <= messageCount; i++) {

            message = jmsConsumer.receive();

            latency = System.currentTimeMillis() - message.getJMSTimestamp();
            latencyHist.update(latency);
            globalLatencyHist.update(latency);
            receivedCount.incrementAndGet();

            consumerRate.mark();
            globalConsumerRate.mark();
            if (log.isTraceEnabled()) {
                log.trace("message received: " + message);
            }

            //logs the messages that are received
            log.debug(((TextMessage) message).getText());
        }

        log.info("Stopping consumer. [ Consumer ID: " + consumerID + "  ]");
        jmsConsumer.close();
    } catch (JMSException e) {
        log.error("Exception occurred while consuming. " + "\n\tconsumer ID: " + consumerID + "\n\tMessage: "
                + message, e);
    }

    log.info("Stopped consumer. [ Consumer ID: " + consumerID + "  ]");
}

From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java

public void testMoveJmsHeadersAdaptrisMessageToJmsMessage() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MessageTypeTranslatorImp trans = createTranslator();
    try {/*from w w  w. j  ava 2 s.com*/
        broker.start();
        Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);

        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        addMetadata(msg);
        addRedundantJmsHeaders(msg);

        trans.setMoveJmsHeaders(true);
        start(trans, session);

        Message jmsMsg = trans.translate(msg);
        assertEquals(msg.getMetadataValue(JMS_TYPE), jmsMsg.getJMSType());
        assertNotSame(msg.getMetadataValue(JMS_CORRELATION_ID), jmsMsg.getJMSCorrelationID());
        assertNotSame(msg.getMetadataValue(JMS_TIMESTAMP), jmsMsg.getJMSTimestamp());
        assertNotSame(msg.getMetadataValue(JMS_REDELIVERED), jmsMsg.getJMSPriority());
        assertNotSame(msg.getMetadataValue(JMS_MESSAGE_ID), jmsMsg.getJMSMessageID());
        assertNotSame(msg.getMetadataValue(JMS_EXPIRATION), jmsMsg.getJMSExpiration());
        assertNotSame(msg.getMetadataValue(JMS_DELIVERY_MODE), jmsMsg.getJMSDeliveryMode());
        assertJmsProperties(jmsMsg);
    } finally {
        stop(trans);
        broker.destroy();
    }

}

From source file:com.jmstoolkit.beans.MessageTableModel.java

/**
 *
 * @param message/* w w  w.j  a v  a  2  s  .c  o  m*/
 */
@Override
public void onMessage(Message message) {
    LOGGER.log(Level.FINE, "Message Received");
    messagesReceived++;
    try {
        MessageTableRecord qRecord = new MessageTableRecord();
        qRecord.setJMSCorrelationID(message.getJMSCorrelationID());
        qRecord.setJMSDeliveryMode(message.getJMSDeliveryMode());
        qRecord.setJMSExpiration(message.getJMSExpiration());
        qRecord.setJMSMessageID(message.getJMSMessageID());
        qRecord.setJMSTimestamp(message.getJMSTimestamp());
        qRecord.setJMSType(message.getJMSType());
        qRecord.setJMSDestination(message.getJMSDestination());
        qRecord.setJMSCorrelationIDAsBytes(message.getJMSCorrelationIDAsBytes());
        qRecord.setJMSPriority(message.getJMSPriority());
        qRecord.setJMSType(message.getJMSType());
        qRecord.setJMSReplyTo(message.getJMSReplyTo());
        qRecord.setJMSRedelivered(message.getJMSRedelivered());
        Enumeration pEnumerator = message.getPropertyNames();
        Properties props = new Properties();
        while (pEnumerator.hasMoreElements()) {
            String pElement = (String) pEnumerator.nextElement();
            props.put(pElement, message.getStringProperty(pElement));
        }
        qRecord.setProperties(props);

        if (message instanceof TextMessage) {
            qRecord.setText(((TextMessage) message).getText());
        }
        if (message instanceof ObjectMessage) {
            qRecord.setObject(((ObjectMessage) message).getObject());
        }

        List newData = data;
        newData.add(qRecord);
        this.setData(newData);
    } catch (JMSException e) {
        LOGGER.log(Level.WARNING, "JMS problem", e);
    }
}

From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java

private static String formatHeaders(Message message) {
    Destination dest = null;/*ww w.  j a  v a  2 s .  co m*/
    int delMode = 0;
    long expiration = 0;
    Time expTime = null;
    int priority = 0;
    String msgID = null;
    long timestamp = 0;
    Time timestampTime = null;
    String correlID = null;
    Destination replyTo = null;
    boolean redelivered = false;
    String type = null;

    StringBuilder sb = new StringBuilder();
    try {

        try {
            dest = message.getJMSDestination();
            sb.append("  JMSDestination: ");
            sb.append(dest);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSDestination header\n", e);
        }

        try {
            delMode = message.getJMSDeliveryMode();
            if (delMode == DeliveryMode.NON_PERSISTENT) {
                sb.append("  JMSDeliveryMode: non-persistent\n");
            } else if (delMode == DeliveryMode.PERSISTENT) {
                sb.append("  JMSDeliveryMode: persistent\n");
            } else {
                sb.append("  JMSDeliveryMode: neither persistent nor non-persistent; error\n");
            }
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSDeliveryMode header\n", e);
        }

        try {
            expiration = message.getJMSExpiration();
            if (expiration != 0) {
                expTime = new Time(expiration);
                sb.append("  JMSExpiration: ");
                sb.append(expTime);
                sb.append("\n");
            } else {
                sb.append("  JMSExpiration: 0\n");
            }
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSExpiration header\n", e);
        }

        try {
            priority = message.getJMSPriority();
            sb.append("  JMSPriority: ");
            sb.append(priority);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSPriority header\n", e);
        }

        try {
            msgID = message.getJMSMessageID();
            sb.append("  JMSMessageID: ");
            sb.append(msgID);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSMessageID header\n", e);
        }

        try {
            timestamp = message.getJMSTimestamp();
            if (timestamp != 0) {
                timestampTime = new Time(timestamp);
                sb.append("  JMSTimestamp: ");
                sb.append(timestampTime);
                sb.append("\n");
            } else {
                sb.append("  JMSTimestamp: 0\n");
            }
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSTimestamp header\n", e);
        }

        try {
            correlID = message.getJMSCorrelationID();
            sb.append("  JMSCorrelationID: ");
            sb.append(correlID);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSCorrelationID header\n", e);
        }

        try {
            replyTo = message.getJMSReplyTo();
            sb.append("  JMSReplyTo: ");
            sb.append(replyTo);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSReplyTo header\n", e);
        }

        try {
            redelivered = message.getJMSRedelivered();
            sb.append("  JMSRedelivered: ");
            sb.append(redelivered);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSRedelivered header\n", e);
        }

        try {
            type = message.getJMSType();
            sb.append("  JMSType: ");
            sb.append(type);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSType header\n", e);
        }

    } catch (Exception e) {
        log.log(Level.WARNING, "Unable to generate JMS headers\n", e);
    }
    return sb.toString();
}

From source file:hermes.impl.DefaultXMLHelper.java

public XMLMessage createXMLMessage(ObjectFactory factory, Message message)
        throws JMSException, IOException, EncoderException {
    try {//from  w w  w  .ja  v  a2  s. c  om
        XMLMessage rval = factory.createXMLMessage();

        if (message instanceof TextMessage) {
            rval = factory.createXMLTextMessage();

            XMLTextMessage textRval = (XMLTextMessage) rval;
            TextMessage textMessage = (TextMessage) message;

            if (isBase64EncodeTextMessages()) {
                byte[] bytes = base64EncoderTL.get().encode(textMessage.getText().getBytes());
                textRval.setText(new String(bytes, "ASCII"));
                textRval.setCodec(BASE64_CODEC);
            } else {
                textRval.setText(textMessage.getText());
            }
        } else if (message instanceof MapMessage) {
            rval = factory.createXMLMapMessage();

            XMLMapMessage mapRval = (XMLMapMessage) rval;
            MapMessage mapMessage = (MapMessage) message;

            for (Enumeration iter = mapMessage.getMapNames(); iter.hasMoreElements();) {
                String propertyName = (String) iter.nextElement();
                Object propertyValue = mapMessage.getObject(propertyName);
                Property xmlProperty = factory.createProperty();

                if (propertyValue != null) {
                    xmlProperty.setValue(propertyValue.toString());
                    xmlProperty.setType(propertyValue.getClass().getName());
                }
                xmlProperty.setName(propertyName);

                mapRval.getBodyProperty().add(xmlProperty);
            }
        } else if (message instanceof BytesMessage) {
            rval = factory.createXMLBytesMessage();

            XMLBytesMessage bytesRval = (XMLBytesMessage) rval;
            BytesMessage bytesMessage = (BytesMessage) message;
            ByteArrayOutputStream bosream = new ByteArrayOutputStream();

            bytesMessage.reset();

            try {
                for (;;) {
                    bosream.write(bytesMessage.readByte());
                }
            } catch (MessageEOFException ex) {
                // NOP
            }

            bytesRval.setBytes(new String(base64EncoderTL.get().encode(bosream.toByteArray())));
        } else if (message instanceof ObjectMessage) {
            rval = factory.createXMLObjectMessage();

            XMLObjectMessage objectRval = (XMLObjectMessage) rval;
            ObjectMessage objectMessage = (ObjectMessage) message;

            ByteArrayOutputStream bostream = new ByteArrayOutputStream();
            ObjectOutputStream oostream = new ObjectOutputStream(bostream);

            oostream.writeObject(objectMessage.getObject());
            oostream.flush();
            byte b[] = base64EncoderTL.get().encode(bostream.toByteArray());
            String s = new String(b, "ASCII");
            objectRval.setObject(s);
        }

        if (message.getJMSReplyTo() != null) {
            rval.setJMSReplyTo(JMSUtils.getDestinationName(message.getJMSReplyTo()));
            rval.setJMSReplyToDomain(Domain.getDomain(message.getJMSReplyTo()).getId());
        }

        // try/catch each individually as we sometime find some JMS
        // providers
        // can barf
        try {
            rval.setJMSDeliveryMode(message.getJMSDeliveryMode());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSExpiration(message.getJMSExpiration());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSMessageID(message.getJMSMessageID());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSPriority(message.getJMSPriority());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSRedelivered(message.getJMSRedelivered());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        } catch (IllegalStateException ex) {
            // http://hermesjms.com/forum/viewtopic.php?f=4&t=346

            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSTimestamp(message.getJMSTimestamp());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSType(message.getJMSType());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSCorrelationID(message.getJMSCorrelationID());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            if (message.getJMSDestination() != null) {
                rval.setJMSDestination(JMSUtils.getDestinationName(message.getJMSDestination()));
                rval.setFromQueue(JMSUtils.isQueue(message.getJMSDestination()));
            }
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        for (final Enumeration iter = message.getPropertyNames(); iter.hasMoreElements();) {
            String propertyName = (String) iter.nextElement();

            if (!propertyName.startsWith("JMS")) {
                Object propertyValue = message.getObjectProperty(propertyName);
                Property property = factory.createProperty();

                property.setName(propertyName);

                if (propertyValue != null) {
                    property.setValue(StringEscapeUtils.escapeXml(propertyValue.toString()));
                    property.setType(propertyValue.getClass().getName());
                }

                rval.getHeaderProperty().add(property);
            }
        }

        return rval;
    } catch (Exception ex) {
        throw new HermesException(ex);
    }
}

From source file:nl.nn.adapterframework.extensions.ifsa.jms.IfsaRequesterSender.java

/**
 * Execute a request to the IFSA service.
 * @return in Request/Reply, the retrieved message or TIMEOUT, otherwise null
 *///from   w w  w .j  a v a  2s .c o m
public String sendMessage(String dummyCorrelationId, String message, Map params, String bifName, byte btcData[])
        throws SenderException, TimeOutException {
    String result = null;
    QueueSession session = null;
    QueueSender sender = null;
    Map udzMap = null;

    try {
        log.debug(getLogPrefix() + "creating session and sender");
        session = createSession();
        IFSAQueue queue;
        if (params != null && params.size() > 0) {
            // Use first param as serviceId
            String serviceId = (String) params.get("serviceId");
            if (serviceId == null) {
                serviceId = getServiceId();
            }
            String occurrence = (String) params.get("occurrence");
            if (occurrence != null) {
                int i = serviceId.indexOf('/',
                        serviceId.indexOf('/', serviceId.indexOf('/', serviceId.indexOf('/') + 1) + 1) + 1);
                int j = serviceId.indexOf('/', i + 1);
                serviceId = serviceId.substring(0, i + 1) + occurrence + serviceId.substring(j);
            }
            queue = getMessagingSource().lookupService(getMessagingSource().polishServiceId(serviceId));
            if (queue == null) {
                throw new SenderException(
                        getLogPrefix() + "got null as queue for serviceId [" + serviceId + "]");
            }
            if (log.isDebugEnabled()) {
                log.info(getLogPrefix() + "got Queue to send messages on [" + queue.getQueueName() + "]");
            }
            // Use remaining params as outgoing UDZs
            udzMap = new HashMap();
            udzMap.putAll(params);
            udzMap.remove("serviceId");
            udzMap.remove("occurrence");
        } else {
            queue = getServiceQueue();
        }
        sender = createSender(session, queue);

        log.debug(getLogPrefix() + "sending message with bifName [" + bifName + "]");

        TextMessage sentMessage = sendMessage(session, sender, message, udzMap, bifName, btcData);
        log.debug(getLogPrefix() + "message sent");

        if (isSynchronous()) {

            log.debug(getLogPrefix() + "waiting for reply");
            Message msg = getRawReplyMessage(session, queue, sentMessage);
            try {
                long tsReplyReceived = System.currentTimeMillis();
                long tsRequestSent = sentMessage.getJMSTimestamp();
                long tsReplySent = msg.getJMSTimestamp();
                //               long jmsTimestampRcvd = msg.getJMSTimestamp();
                ////                  long businessProcFinishSent=0;
                //               long businessProcStartRcvd=0;
                //               long businessProcStartSent=0;
                //               long businessProcFinishRcvd=0;
                //               if (sentMessage instanceof IFSAMessage) {
                //                  businessProcStartSent=((IFSAMessage)sentMessage).getBusinessProcessingStartTime();
                ////                     businessProcFinishSent=((IFSAMessage)sentMessage).getBusinessProcessingFinishTime();
                //               }
                //               if (msg instanceof IFSAMessage) {
                //                  businessProcStartRcvd=((IFSAMessage)msg).getBusinessProcessingStartTime();
                //                  businessProcFinishRcvd=((IFSAMessage)msg).getBusinessProcessingFinishTime();
                //               }
                if (log.isInfoEnabled()) {
                    log.info(getLogPrefix() + "A) RequestSent   [" + DateUtils.format(tsRequestSent) + "]");
                    log.info(getLogPrefix() + "B) ReplySent     [" + DateUtils.format(tsReplySent)
                            + "] diff (~queing + processing) [" + (tsReplySent - tsRequestSent) + "]");
                    log.info(getLogPrefix() + "C) ReplyReceived [" + DateUtils.format(tsReplyReceived)
                            + "] diff (transport of reply )[" + (tsReplyReceived - tsReplySent) + "]");
                    //                  log.info(getLogPrefix()+"C2) msgRcvd.businessProcStartRcvd  ["+DateUtils.format(businessProcStartRcvd) +"] ");
                    //                  log.info(getLogPrefix()+"D)  msgRcvd.jmsTimestamp           ["+DateUtils.format(jmsTimestampRcvd)      +"] diff ["+(jmsTimestampRcvd-businessProcStartSent)+"]");
                    //                  log.info(getLogPrefix()+"E)  msgRcvd.businessProcFinishRcvd ["+DateUtils.format(businessProcFinishRcvd)+"] diff ["+(businessProcFinishRcvd-jmsTimestampRcvd)+"] (=time spend on IFSA bus sending result?)");
                    //                  log.info(getLogPrefix()+"F)  timestampAfterRcvd             ["+DateUtils.format(timestampAfterRcvd)    +"] diff ["+(timestampAfterRcvd-businessProcFinishRcvd)+"] ");
                    //                  log.info(getLogPrefix()+"business processing time (E-C1) ["+(businessProcFinishRcvd-businessProcStartSent)+"] ");
                }
                //               if (businessProcessTimes!=null) {                  
                //                  businessProcessTimes.addValue(businessProcFinishRcvd-businessProcStartSent);
                //               }
            } catch (JMSException e) {
                log.warn(getLogPrefix() + "exception determining processing times", e);
            }
            if (msg instanceof TextMessage) {
                result = ((TextMessage) msg).getText();
            } else {
                if (msg.getClass().getName().endsWith("IFSAReportMessage")) {
                    if (msg instanceof IFSAReportMessage) {
                        IFSAReportMessage irm = (IFSAReportMessage) msg;
                        if (isThrowExceptions()) {
                            throw new SenderException(getLogPrefix() + "received IFSAReportMessage ["
                                    + ToStringBuilder.reflectionToString(irm) + "], NoReplyReason ["
                                    + irm.getNoReplyReason() + "]");
                        }
                        log.warn(getLogPrefix() + "received IFSAReportMessage ["
                                + ToStringBuilder.reflectionToString(irm) + "], NoReplyReason ["
                                + irm.getNoReplyReason() + "]");
                        result = "<IFSAReport>" + "<NoReplyReason>" + irm.getNoReplyReason()
                                + "</NoReplyReason>" + "</IFSAReport>";

                    }
                } else {
                    log.warn(getLogPrefix() + "received neither TextMessage nor IFSAReportMessage but ["
                            + msg.getClass().getName() + "]");
                    result = msg.toString();
                }
            }
            if (result == null) {
                log.info(getLogPrefix() + "received null reply");
            } else {
                if (log.isDebugEnabled()) {
                    if (AppConstants.getInstance().getBoolean("log.logIntermediaryResults", false)) {
                        log.debug(getLogPrefix() + "received reply [" + result + "]");
                    } else {
                        log.debug(getLogPrefix() + "received reply");
                    }
                } else {
                    log.info(getLogPrefix() + "received reply");
                }
            }
        } else {
            result = sentMessage.getJMSMessageID();
        }
    } catch (JMSException e) {
        throw new SenderException(getLogPrefix() + "caught JMSException in sendMessage()", e);
    } catch (IfsaException e) {
        throw new SenderException(getLogPrefix() + "caught IfsaException in sendMessage()", e);
    } finally {
        if (sender != null) {
            try {
                log.debug(getLogPrefix() + "closing sender");
                sender.close();
            } catch (JMSException e) {
                log.debug(getLogPrefix() + "Exception closing sender", e);
            }
        }
        closeSession(session);
    }
    if (isThrowExceptions() && result != null && result.startsWith("<exception>")) {
        throw new SenderException("Retrieved exception message from IFSA bus: " + result);
    }
    return result;
}

From source file:nl.nn.adapterframework.extensions.tibco.GetTibcoQueues.java

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");
    }/* www  .j av  a 2  s .c o m*/

    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();
}

From source file:nl.nn.adapterframework.extensions.tibco.TibcoUtils.java

protected static long getQueueFirstMessageAge(Session jSession, String queueName, String messageSelector,
        long currentTime, boolean warn) throws JMSException {
    QueueBrowser queueBrowser = null;//from  w w w .  j  ava2 s .  co  m
    try {
        Queue queue = jSession.createQueue(queueName);
        if (messageSelector == null) {
            queueBrowser = jSession.createBrowser(queue);
        } else {
            queueBrowser = jSession.createBrowser(queue, messageSelector);
        }
        Enumeration enm = queueBrowser.getEnumeration();
        if (enm.hasMoreElements()) {
            Object o = enm.nextElement();
            if (o instanceof Message) {
                Message msg = (Message) o;
                long jmsTimestamp = msg.getJMSTimestamp();
                return currentTime - jmsTimestamp;
            } else {
                if (warn) {
                    log.warn("message was not of type Message, but [" + o.getClass().getName() + "]");
                }
                return -2;
            }
        } else {
            return -1;
        }
    } finally {
        if (queueBrowser != null) {
            try {
                queueBrowser.close();
            } catch (JMSException e) {
                log.warn("Exception on closing queueBrowser", e);
            }
        }
    }
}

From source file:nl.nn.adapterframework.jms.JMSFacade.java

public String send(MessageProducer messageProducer, Message message, boolean ignoreInvalidDestinationException)
        throws NamingException, JMSException {
    if (log.isDebugEnabled()) {
        log.debug(getLogPrefix() + "sender on [" + getDestinationName()
                + "] will send message with JMSDeliveryMode=[" + message.getJMSDeliveryMode()
                + "] \n  JMSMessageID=[" + message.getJMSMessageID() + "] \n  JMSCorrelationID=["
                + message.getJMSCorrelationID() + "] \n  JMSTimestamp=["
                + DateUtils.format(message.getJMSTimestamp()) + "] \n  JMSExpiration=["
                + message.getJMSExpiration() + "] \n  JMSPriority=[" + message.getJMSPriority()
                + "] \n Message=[" + message.toString() + "]");
    }//from   w  ww  .  j  av a 2  s . c o  m
    try {
        if (useJms102()) {
            if (messageProducer instanceof TopicPublisher) {
                ((TopicPublisher) messageProducer).publish(message);
            } else {
                ((QueueSender) messageProducer).send(message);
            }
            return message.getJMSMessageID();
        } else {
            messageProducer.send(message);
            return message.getJMSMessageID();
        }
    } catch (InvalidDestinationException e) {
        if (ignoreInvalidDestinationException) {
            log.warn("queue [" + messageProducer.getDestination() + "] doesn't exist");
            return null;
        } else {
            throw e;
        }
    }
}

From source file:nl.nn.adapterframework.jms.JmsListenerBase.java

protected String retrieveIdFromMessage(Message message, Map threadContext) throws ListenerException {
    String cid = "unset";
    String mode = "unknown";
    String id = "unset";
    Date tsSent = null;/*from  w  w w . j  av a  2s . com*/
    Destination replyTo = null;
    try {
        mode = deliveryModeToString(message.getJMSDeliveryMode());
    } catch (JMSException ignore) {
        log.debug("ignoring JMSException in getJMSDeliveryMode()", ignore);
    }
    // --------------------------
    // retrieve MessageID
    // --------------------------
    try {
        id = message.getJMSMessageID();
    } catch (JMSException ignore) {
        log.debug("ignoring JMSException in getJMSMessageID()", ignore);
    }
    // --------------------------
    // retrieve CorrelationID
    // --------------------------
    try {
        if (isForceMessageIdAsCorrelationId()) {
            if (log.isDebugEnabled())
                log.debug("forcing the messageID to be the correlationID");
            cid = id;
        } else {
            cid = message.getJMSCorrelationID();
            if (cid == null) {
                cid = id;
                log.debug("Setting correlation ID to MessageId");
            }
        }
    } catch (JMSException ignore) {
        log.debug("ignoring JMSException in getJMSCorrelationID()", ignore);
    }
    // --------------------------
    // retrieve TimeStamp
    // --------------------------
    try {
        long lTimeStamp = message.getJMSTimestamp();
        tsSent = new Date(lTimeStamp);

    } catch (JMSException ignore) {
        log.debug("ignoring JMSException in getJMSTimestamp()", ignore);
    }
    // --------------------------
    // retrieve ReplyTo address
    // --------------------------
    try {
        replyTo = message.getJMSReplyTo();

    } catch (JMSException ignore) {
        log.debug("ignoring JMSException in getJMSReplyTo()", ignore);
    }

    if (log.isDebugEnabled()) {
        log.debug(getLogPrefix() + "listener on [" + getDestinationName()
                + "] got message with JMSDeliveryMode=[" + mode + "] \n  JMSMessageID=[" + id
                + "] \n  JMSCorrelationID=[" + cid + "] \n  Timestamp Sent=[" + DateUtils.format(tsSent)
                + "] \n  ReplyTo=[" + ((replyTo == null) ? "none" : replyTo.toString()) + "] \n Message=["
                + message.toString() + "]");
    }
    PipeLineSessionBase.setListenerParameters(threadContext, id, cid, null, tsSent);
    threadContext.put("timestamp", tsSent);
    threadContext.put("replyTo", replyTo);
    try {
        if (getAckMode() == Session.CLIENT_ACKNOWLEDGE) {
            message.acknowledge();
            log.debug("Listener on [" + getDestinationName() + "] acknowledged message");
        }
    } catch (JMSException e) {
        log.error("Warning in ack", e);
    }
    return cid;
}