Example usage for javax.jms Message setJMSType

List of usage examples for javax.jms Message setJMSType

Introduction

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

Prototype


void setJMSType(String type) throws JMSException;

Source Link

Document

Sets the message type.

Usage

From source file:org.springframework.integration.jms.DefaultJmsHeaderMapper.java

public void fromHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) {
    try {/*from  w ww .  j  a  va  2 s .  c o m*/
        Object jmsCorrelationId = headers.get(JmsHeaders.CORRELATION_ID);
        if (jmsCorrelationId instanceof Number) {
            jmsCorrelationId = ((Number) jmsCorrelationId).toString();
        }
        if (jmsCorrelationId instanceof String) {
            try {
                jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
            } catch (Exception e) {
                logger.info("failed to set JMSCorrelationID, skipping", e);
            }
        }
        Object jmsReplyTo = headers.get(JmsHeaders.REPLY_TO);
        if (jmsReplyTo instanceof Destination) {
            try {
                jmsMessage.setJMSReplyTo((Destination) jmsReplyTo);
            } catch (Exception e) {
                logger.info("failed to set JMSReplyTo, skipping", e);
            }
        }
        Object jmsType = headers.get(JmsHeaders.TYPE);
        if (jmsType instanceof String) {
            try {
                jmsMessage.setJMSType((String) jmsType);
            } catch (Exception e) {
                logger.info("failed to set JMSType, skipping", e);
            }
        }
        Set<String> headerNames = headers.keySet();
        for (String headerName : headerNames) {
            if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) {
                Object value = headers.get(headerName);
                if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) {
                    try {
                        String propertyName = this.fromHeaderName(headerName);
                        jmsMessage.setObjectProperty(propertyName, value);
                    } catch (Exception e) {
                        if (headerName.startsWith("JMSX")) {
                            if (logger.isTraceEnabled()) {
                                logger.trace(
                                        "skipping reserved header, it cannot be set by client: " + headerName);
                            }
                        } else if (logger.isWarnEnabled()) {
                            logger.warn("failed to map Message header '" + headerName + "' to JMS property", e);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("error occurred while mapping from MessageHeaders to JMS properties", e);
        }
    }
}

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

@Override
public void fromHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) {
    try {//from  w  ww  .j  av a 2s  .c  o  m
        Object jmsCorrelationId = headers.get(JmsHeaders.CORRELATION_ID);
        if (jmsCorrelationId instanceof Number) {
            jmsCorrelationId = jmsCorrelationId.toString();
        }
        if (jmsCorrelationId instanceof String) {
            try {
                jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
            } catch (Exception e) {
                logger.info("failed to set JMSCorrelationID, skipping", e);
            }
        }
        Object jmsReplyTo = headers.get(JmsHeaders.REPLY_TO);
        if (jmsReplyTo instanceof Destination) {
            try {
                jmsMessage.setJMSReplyTo((Destination) jmsReplyTo);
            } catch (Exception e) {
                logger.info("failed to set JMSReplyTo, skipping", e);
            }
        }
        Object jmsType = headers.get(JmsHeaders.TYPE);
        if (jmsType instanceof String) {
            try {
                jmsMessage.setJMSType((String) jmsType);
            } catch (Exception e) {
                logger.info("failed to set JMSType, skipping", e);
            }
        }
        Set<String> headerNames = headers.keySet();
        for (String headerName : headerNames) {
            if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) {
                Object value = headers.get(headerName);
                if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) {
                    try {
                        String propertyName = this.fromHeaderName(headerName);
                        jmsMessage.setObjectProperty(propertyName, value);
                    } catch (Exception e) {
                        if (headerName.startsWith("JMSX")) {
                            if (logger.isTraceEnabled()) {
                                logger.trace(
                                        "skipping reserved header, it cannot be set by client: " + headerName);
                            }
                        } else if (logger.isWarnEnabled()) {
                            logger.warn("failed to map Message header '" + headerName + "' to JMS property", e);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("error occurred while mapping from MessageHeaders to JMS properties", e);
        }
    }
}

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

@Override
public void fromHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) {
    try {//from   ww w  .  j a va  2  s  . c o  m
        Object jmsCorrelationId = headers.get(JmsHeaders.CORRELATION_ID);
        if (jmsCorrelationId instanceof Number) {
            jmsCorrelationId = jmsCorrelationId.toString();
        }
        if (jmsCorrelationId instanceof String) {
            try {
                jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
            } catch (Exception e) {
                logger.info("failed to set JMSCorrelationID, skipping", e);
            }
        }
        Object jmsReplyTo = headers.get(JmsHeaders.REPLY_TO);
        if (jmsReplyTo instanceof Destination) {
            try {
                jmsMessage.setJMSReplyTo((Destination) jmsReplyTo);
            } catch (Exception e) {
                logger.info("failed to set JMSReplyTo, skipping", e);
            }
        }
        Object jmsType = headers.get(JmsHeaders.TYPE);
        if (jmsType instanceof String) {
            try {
                jmsMessage.setJMSType((String) jmsType);
            } catch (Exception e) {
                logger.info("failed to set JMSType, skipping", e);
            }
        }
        Set<String> headerNames = headers.keySet();
        for (String headerName : headerNames) {
            if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) {
                Object value = headers.get(headerName);
                if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) {
                    try {
                        String propertyName = this.fromHeaderName(headerName);
                        jmsMessage.setObjectProperty(propertyName, value);
                    } catch (Exception e) {
                        if (headerName.startsWith("JMSX")) {
                            if (logger.isTraceEnabled()) {
                                logger.trace(
                                        "skipping reserved header, it cannot be set by client: " + headerName);
                            }
                        } else if (logger.isWarnEnabled()) {
                            logger.warn("failed to map Message header '" + headerName + "' to JMS property", e);
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        if (logger.isWarnEnabled()) {
            logger.warn("error occurred while mapping from MessageHeaders to JMS properties", ex);
        }
    }
}

From source file:org.wso2.carbon.apimgt.jms.listener.utils.JMSUtils.java

/**
 * Set transport headers from the axis message context, into the JMS message
 *
 * @param messageConfiguration the adaptor message context
 * @param message              the JMS Message
 * @throws JMSException on exception//w  w w.j  a v  a  2  s. c o  m
 */
public static void setTransportHeaders(Map<String, String> messageConfiguration, Message message)
        throws JMSException {

    if (messageConfiguration == null) {
        return;
    }

    for (String name : messageConfiguration.keySet()) {

        if (name.startsWith(JMSConstants.JMSX_PREFIX)
                && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) {
            continue;
        }

        if (JMSConstants.JMS_COORELATION_ID.equals(name)) {
            message.setJMSCorrelationID(messageConfiguration.get(JMSConstants.JMS_COORELATION_ID));
        } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) {
            String mode = messageConfiguration.get(JMSConstants.JMS_DELIVERY_MODE);
            try {
                message.setJMSDeliveryMode(Integer.parseInt(mode));
            } catch (NumberFormatException nfe) {
                log.warn("Invalid delivery mode ignored : " + mode, nfe);
            }

        } else if (JMSConstants.JMS_EXPIRATION.equals(name)) {
            message.setJMSExpiration(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_EXPIRATION)));
        } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) {
            message.setJMSMessageID(messageConfiguration.get(JMSConstants.JMS_MESSAGE_ID));
        } else if (JMSConstants.JMS_PRIORITY.equals(name)) {
            message.setJMSPriority(Integer.parseInt(messageConfiguration.get(JMSConstants.JMS_PRIORITY)));
        } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) {
            message.setJMSTimestamp(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_TIMESTAMP)));
        } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) {
            message.setJMSType(messageConfiguration.get(JMSConstants.JMS_MESSAGE_TYPE));

        } else {

            //TODO currently only string is supported  in messageConfiguration
            Object value = messageConfiguration.get(name);
            if (value instanceof String) {
                message.setStringProperty(name, (String) value);
            } else if (value instanceof Boolean) {
                message.setBooleanProperty(name, (Boolean) value);
            } else if (value instanceof Integer) {
                message.setIntProperty(name, (Integer) value);
            } else if (value instanceof Long) {
                message.setLongProperty(name, (Long) value);
            } else if (value instanceof Double) {
                message.setDoubleProperty(name, (Double) value);
            } else if (value instanceof Float) {
                message.setFloatProperty(name, (Float) value);
            }
        }
    }
}

From source file:org.wso2.carbon.event.output.adapter.jms.internal.util.JMSUtils.java

/**
 * Set transport headers from the axis message context, into the JMS message
 *
 * @param messageConfiguration the adaptor message context
 * @param message              the JMS Message
 * @throws javax.jms.JMSException on exception
 *///from   w  w  w  . ja  v a  2s.c o m
public static Message setTransportHeaders(Map<String, String> messageConfiguration, Message message)
        throws JMSException {

    if (messageConfiguration == null) {
        return message;
    }

    for (String name : messageConfiguration.keySet()) {

        if (name.startsWith(JMSConstants.JMSX_PREFIX)
                && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) {
            continue;
        }

        if (JMSConstants.JMS_COORELATION_ID.equals(name)) {
            message.setJMSCorrelationID(messageConfiguration.get(JMSConstants.JMS_COORELATION_ID));
        } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) {
            String mode = messageConfiguration.get(JMSConstants.JMS_DELIVERY_MODE);
            try {
                message.setJMSDeliveryMode(Integer.parseInt(mode));
            } catch (NumberFormatException nfe) {
                log.warn("Invalid delivery mode ignored : " + mode, nfe);
            }

        } else if (JMSConstants.JMS_EXPIRATION.equals(name)) {
            message.setJMSExpiration(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_EXPIRATION)));
        } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) {
            message.setJMSMessageID(messageConfiguration.get(JMSConstants.JMS_MESSAGE_ID));
        } else if (JMSConstants.JMS_PRIORITY.equals(name)) {
            message.setJMSPriority(Integer.parseInt(messageConfiguration.get(JMSConstants.JMS_PRIORITY)));
        } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) {
            message.setJMSTimestamp(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_TIMESTAMP)));
        } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) {
            message.setJMSType(messageConfiguration.get(JMSConstants.JMS_MESSAGE_TYPE));

        } else {

            //TODO currently only string is supported  in messageConfiguration
            Object value = messageConfiguration.get(name);
            if (value instanceof String) {
                message.setStringProperty(name, (String) value);
            } else if (value instanceof Boolean) {
                message.setBooleanProperty(name, (Boolean) value);
            } else if (value instanceof Integer) {
                message.setIntProperty(name, (Integer) value);
            } else if (value instanceof Long) {
                message.setLongProperty(name, (Long) value);
            } else if (value instanceof Double) {
                message.setDoubleProperty(name, (Double) value);
            } else if (value instanceof Float) {
                message.setFloatProperty(name, (Float) value);
            }
        }
    }

    return message;
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSUtils.java

/**
 * Set transport headers from the axis message context, into the JMS message
 *
 * @param msgContext the axis message context
 * @param message the JMS Message//from w  w w.  jav a2  s . co  m
 * @throws JMSException on exception
 */
public static void setTransportHeaders(MessageContext msgContext, Message message) throws JMSException {

    Map<?, ?> headerMap = (Map<?, ?>) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);

    if (headerMap == null) {
        return;
    }

    for (Object headerName : headerMap.keySet()) {

        String name = (String) headerName;

        if (name.startsWith(JMSConstants.JMSX_PREFIX)
                && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) {
            continue;
        }

        if (JMSConstants.JMS_COORELATION_ID.equals(name)) {
            message.setJMSCorrelationID((String) headerMap.get(JMSConstants.JMS_COORELATION_ID));
        } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) {
            Object o = headerMap.get(JMSConstants.JMS_DELIVERY_MODE);
            if (o instanceof Integer) {
                message.setJMSDeliveryMode((Integer) o);
            } else if (o instanceof String) {
                try {
                    message.setJMSDeliveryMode(Integer.parseInt((String) o));
                } catch (NumberFormatException nfe) {
                    log.warn("Invalid delivery mode ignored : " + o, nfe);
                }
            } else {
                log.warn("Invalid delivery mode ignored : " + o);
            }

        } else if (JMSConstants.JMS_EXPIRATION.equals(name)) {
            message.setJMSExpiration(Long.parseLong((String) headerMap.get(JMSConstants.JMS_EXPIRATION)));
        } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) {
            message.setJMSMessageID((String) headerMap.get(JMSConstants.JMS_MESSAGE_ID));
        } else if (JMSConstants.JMS_PRIORITY.equals(name)) {
            message.setJMSPriority(Integer.parseInt((String) headerMap.get(JMSConstants.JMS_PRIORITY)));
        } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) {
            message.setJMSTimestamp(Long.parseLong((String) headerMap.get(JMSConstants.JMS_TIMESTAMP)));
        } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) {
            message.setJMSType((String) headerMap.get(JMSConstants.JMS_MESSAGE_TYPE));

        } else {
            Object value = headerMap.get(name);
            if (value instanceof String) {
                if (name.contains("-")) {
                    if (isHyphenReplaceMode(msgContext)) { // we replace
                        message.setStringProperty(transformHyphenatedString(name), (String) value);
                    } else if (isHyphenDeleteMode(msgContext)) { // we skip
                        continue;
                    } else {
                        message.setStringProperty(name, (String) value);
                    }
                } else {
                    message.setStringProperty(name, (String) value);
                }
            } else if (value instanceof Boolean) {
                message.setBooleanProperty(name, (Boolean) value);
            } else if (value instanceof Integer) {
                message.setIntProperty(name, (Integer) value);
            } else if (value instanceof Long) {
                message.setLongProperty(name, (Long) value);
            } else if (value instanceof Double) {
                message.setDoubleProperty(name, (Double) value);
            } else if (value instanceof Float) {
                message.setFloatProperty(name, (Float) value);
            }
        }
    }
}