Example usage for javax.jms Message getJMSDestination

List of usage examples for javax.jms Message getJMSDestination

Introduction

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

Prototype


Destination getJMSDestination() throws JMSException;

Source Link

Document

Gets the Destination object for this message.

Usage

From source file:org.springframework.cloud.stream.binder.jms.utils.RepublishMessageRecoverer.java

@Override
public void recover(Message undeliveredMessage, Throwable cause) {
    String deadLetterQueueName = queueProvisioner.provisionDeadLetterQueue();

    final JmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
    MessageConverter converter = new SimpleMessageConverter();
    Object payload = null;// w ww  .j a  v a2  s.c  o  m

    try {
        payload = converter.fromMessage(undeliveredMessage);
    } catch (JMSException e) {
        logger.error("The message payload could not be retrieved. It will be lost.", e);
    }

    final Map<String, Object> headers = mapper.toHeaders(undeliveredMessage);
    headers.put(X_EXCEPTION_STACKTRACE, getStackTraceAsString(cause));
    headers.put(X_EXCEPTION_MESSAGE,
            cause.getCause() != null ? cause.getCause().getMessage() : cause.getMessage());
    try {
        headers.put(X_ORIGINAL_QUEUE, undeliveredMessage.getJMSDestination().toString());
    } catch (JMSException e) {
        logger.error("The message destination could not be retrieved", e);
    }
    Map<? extends String, ? extends Object> additionalHeaders = additionalHeaders(undeliveredMessage, cause);
    if (additionalHeaders != null) {
        headers.putAll(additionalHeaders);
    }

    jmsTemplate.convertAndSend(deadLetterQueueName, payload, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws JMSException {
            mapper.fromHeaders(new MessageHeaders(headers), message);
            return message;
        }
    });

}

From source file:org.springframework.jms.support.converter.SimpleJmsHeaderMapper.java

@Override
public Map<String, Object> toHeaders(javax.jms.Message jmsMessage) {
    Map<String, Object> headers = new HashMap<String, Object>();
    try {/*from   w  w w.  java 2  s.c  o  m*/
        try {
            String correlationId = jmsMessage.getJMSCorrelationID();
            if (correlationId != null) {
                headers.put(JmsHeaders.CORRELATION_ID, correlationId);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSCorrelationID property, skipping", e);
        }
        try {
            Destination destination = jmsMessage.getJMSDestination();
            if (destination != null) {
                headers.put(JmsHeaders.DESTINATION, destination);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSDestination property, skipping", e);
        }
        try {
            int deliveryMode = jmsMessage.getJMSDeliveryMode();
            headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode);
        } catch (Exception e) {
            logger.info("failed to read JMSDeliveryMode property, skipping", e);
        }
        try {
            long expiration = jmsMessage.getJMSExpiration();
            headers.put(JmsHeaders.EXPIRATION, expiration);
        } catch (Exception e) {
            logger.info("failed to read JMSExpiration property, skipping", e);
        }
        try {
            String messageId = jmsMessage.getJMSMessageID();
            if (messageId != null) {
                headers.put(JmsHeaders.MESSAGE_ID, messageId);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSMessageID property, skipping", e);
        }
        try {
            headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority());
        } catch (Exception e) {
            logger.info("failed to read JMSPriority property, skipping", e);
        }
        try {
            Destination replyTo = jmsMessage.getJMSReplyTo();
            if (replyTo != null) {
                headers.put(JmsHeaders.REPLY_TO, replyTo);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSReplyTo property, skipping", e);
        }
        try {
            headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered());
        } catch (Exception e) {
            logger.info("failed to read JMSRedelivered property, skipping", e);
        }
        try {
            String type = jmsMessage.getJMSType();
            if (type != null) {
                headers.put(JmsHeaders.TYPE, type);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSType property, skipping", e);
        }
        try {
            headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());
        } catch (Exception e) {
            logger.info("failed to read JMSTimestamp property, skipping", e);
        }

        Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames();
        if (jmsPropertyNames != null) {
            while (jmsPropertyNames.hasMoreElements()) {
                String propertyName = jmsPropertyNames.nextElement().toString();
                try {
                    String headerName = this.toHeaderName(propertyName);
                    headers.put(headerName, jmsMessage.getObjectProperty(propertyName));
                } catch (Exception e) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("error occurred while mapping JMS property '" + propertyName
                                + "' to Message header", e);
                    }
                }
            }
        }
    } catch (JMSException e) {
        if (logger.isWarnEnabled()) {
            logger.warn("error occurred while mapping from JMS properties to MessageHeaders", e);
        }
    }
    return headers;
}

From source file:org.springframework.jms.support.SimpleJmsHeaderMapper.java

@Override
public MessageHeaders toHeaders(javax.jms.Message jmsMessage) {
    Map<String, Object> headers = new HashMap<String, Object>();
    try {/* ww  w. ja  v  a  2 s . c o  m*/
        try {
            String correlationId = jmsMessage.getJMSCorrelationID();
            if (correlationId != null) {
                headers.put(JmsHeaders.CORRELATION_ID, correlationId);
            }
        } catch (Exception ex) {
            logger.info("failed to read JMSCorrelationID property, skipping", ex);
        }
        try {
            Destination destination = jmsMessage.getJMSDestination();
            if (destination != null) {
                headers.put(JmsHeaders.DESTINATION, destination);
            }
        } catch (Exception ex) {
            logger.info("failed to read JMSDestination property, skipping", ex);
        }
        try {
            int deliveryMode = jmsMessage.getJMSDeliveryMode();
            headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode);
        } catch (Exception ex) {
            logger.info("failed to read JMSDeliveryMode property, skipping", ex);
        }
        try {
            long expiration = jmsMessage.getJMSExpiration();
            headers.put(JmsHeaders.EXPIRATION, expiration);
        } catch (Exception ex) {
            logger.info("failed to read JMSExpiration property, skipping", ex);
        }
        try {
            String messageId = jmsMessage.getJMSMessageID();
            if (messageId != null) {
                headers.put(JmsHeaders.MESSAGE_ID, messageId);
            }
        } catch (Exception ex) {
            logger.info("failed to read JMSMessageID property, skipping", ex);
        }
        try {
            headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority());
        } catch (Exception ex) {
            logger.info("failed to read JMSPriority property, skipping", ex);
        }
        try {
            Destination replyTo = jmsMessage.getJMSReplyTo();
            if (replyTo != null) {
                headers.put(JmsHeaders.REPLY_TO, replyTo);
            }
        } catch (Exception ex) {
            logger.info("failed to read JMSReplyTo property, skipping", ex);
        }
        try {
            headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered());
        } catch (Exception ex) {
            logger.info("failed to read JMSRedelivered property, skipping", ex);
        }
        try {
            String type = jmsMessage.getJMSType();
            if (type != null) {
                headers.put(JmsHeaders.TYPE, type);
            }
        } catch (Exception ex) {
            logger.info("failed to read JMSType property, skipping", ex);
        }
        try {
            headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());
        } catch (Exception ex) {
            logger.info("failed to read JMSTimestamp property, skipping", ex);
        }

        Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames();
        if (jmsPropertyNames != null) {
            while (jmsPropertyNames.hasMoreElements()) {
                String propertyName = jmsPropertyNames.nextElement().toString();
                try {
                    String headerName = this.toHeaderName(propertyName);
                    headers.put(headerName, jmsMessage.getObjectProperty(propertyName));
                } catch (Exception ex) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Error occurred while mapping JMS property '" + propertyName
                                + "' to Message header", ex);
                    }
                }
            }
        }
    } catch (JMSException ex) {
        if (logger.isWarnEnabled()) {
            logger.warn("Error occurred while mapping from JMS properties to MessageHeaders", ex);
        }
    }
    return new MessageHeaders(headers);
}