Example usage for javax.jms Message setJMSExpiration

List of usage examples for javax.jms Message setJMSExpiration

Introduction

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

Prototype


void setJMSExpiration(long expiration) throws JMSException;

Source Link

Document

Sets the message's expiration value.

Usage

From source file:org.logicblaze.lingo.jms.JmsClientInterceptor.java

protected void populateHeaders(Message requestMessage) throws JMSException {
    if (correlationID != null) {
        requestMessage.setJMSCorrelationID(correlationID);
    }//from w  ww.  ja v  a  2s  .c  om
    if (jmsType != null) {
        requestMessage.setJMSType(jmsType);
    }
    if (jmsExpiration >= 0) {
        requestMessage.setJMSExpiration(jmsExpiration);
    }
    int jmsPriority = getJmsPriority();
    if (jmsPriority >= 0) {
        requestMessage.setJMSPriority(jmsPriority);
    }
    if (messageProperties != null) {
        for (Iterator iter = messageProperties.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry) iter.next();
            String name = entry.getKey().toString();
            Object value = entry.getValue();
            requestMessage.setObjectProperty(name, value);
        }
    }
}

From source file:hermes.impl.DefaultXMLHelper.java

public Message createMessage(MessageFactory hermes, XMLMessage message)
        throws JMSException, IOException, ClassNotFoundException, DecoderException {
    try {/*from ww  w.  ja v  a2 s  . c om*/
        Message rval = hermes.createMessage();

        if (message instanceof XMLTextMessage) {
            rval = hermes.createTextMessage();

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

            if (BASE64_CODEC.equals(textMessage.getCodec())) {
                byte[] bytes = base64EncoderTL.get().decode(textMessage.getText().getBytes());
                textRval.setText(new String(bytes, "ASCII"));
            } else {
                textRval.setText(textMessage.getText());
            }
        } else if (message instanceof XMLMapMessage) {
            rval = hermes.createMapMessage();

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

            for (Iterator iter = mapMessage.getBodyProperty().iterator(); iter.hasNext();) {
                final Property property = (Property) iter.next();

                if (property.getValue() == null) {
                    mapRval.setObject(property.getName(), null);
                } else if (property.getType().equals(String.class.getName())) {
                    mapRval.setString(property.getName(), property.getValue());
                } else if (property.getType().equals(Long.class.getName())) {
                    mapRval.setLong(property.getName(), Long.parseLong(property.getValue()));
                } else if (property.getType().equals(Double.class.getName())) {
                    mapRval.setDouble(property.getName(), Double.parseDouble(property.getValue()));
                } else if (property.getType().equals(Boolean.class.getName())) {
                    mapRval.setBoolean(property.getName(), Boolean.getBoolean(property.getValue()));
                } else if (property.getType().equals(Character.class.getName())) {
                    mapRval.setChar(property.getName(), property.getValue().charAt(0));
                } else if (property.getType().equals(Short.class.getName())) {
                    mapRval.setShort(property.getName(), Short.parseShort(property.getValue()));
                } else if (property.getType().equals(Integer.class.getName())) {
                    mapRval.setInt(property.getName(), Integer.parseInt(property.getValue()));
                }
            }
        } else if (message instanceof XMLBytesMessage) {
            rval = hermes.createBytesMessage();

            XMLBytesMessage bytesMessage = (XMLBytesMessage) message;
            BytesMessage bytesRval = (BytesMessage) rval;

            bytesRval.writeBytes(base64EncoderTL.get().decode(bytesMessage.getBytes().getBytes()));
        } else if (message instanceof XMLObjectMessage) {
            rval = hermes.createObjectMessage();

            XMLObjectMessage objectMessage = (XMLObjectMessage) message;
            ObjectMessage objectRval = (ObjectMessage) rval;
            ByteArrayInputStream bistream = new ByteArrayInputStream(
                    base64EncoderTL.get().decode(objectMessage.getObject().getBytes()));

            ObjectInputStream oistream = new ObjectInputStream(bistream);

            objectRval.setObject((Serializable) oistream.readObject());
        }

        //
        // JMS Header properties

        try {
            rval.setJMSDeliveryMode(message.getJMSDeliveryMode());
        } catch (JMSException ex) {
            log.error("unable to set JMSDeliveryMode to " + message.getJMSDeliveryMode() + ": "
                    + ex.getMessage());
        }

        try {
            rval.setJMSMessageID(message.getJMSMessageID());
        } catch (JMSException ex) {
            log.error("unable to set JMSMessageID: " + ex.getMessage(), ex);
        }

        try {
            if (message.getJMSExpiration() != null) {
                rval.setJMSExpiration(message.getJMSExpiration());
            }
        } catch (JMSException ex) {
            log.error("unable to set JMSExpiration: " + ex.getMessage(), ex);
        }

        try {
            if (message.getJMSPriority() != null) {
                rval.setJMSPriority(message.getJMSPriority());
            }
        } catch (JMSException ex) {
            log.error("unable to set JMSPriority: " + ex.getMessage(), ex);
        }

        try {
            if (message.getJMSTimestamp() != null) {
                rval.setJMSTimestamp(message.getJMSTimestamp());
            }
        } catch (JMSException ex) {
            log.error("unable to set JMSTimestamp:" + ex.getMessage(), ex);
        }

        if (message.getJMSCorrelationID() != null) {
            rval.setJMSCorrelationID(message.getJMSCorrelationID());
        }

        if (message.getJMSReplyTo() != null && !message.getJMSReplyTo().equals("null")) {
            rval.setJMSReplyTo(hermes.getDestination(message.getJMSReplyTo(),
                    Domain.getDomain(message.getJMSReplyToDomain())));
        }

        if (message.getJMSType() != null) {
            rval.setJMSType(message.getJMSType());
        }

        if (message.getJMSDestination() != null) {
            if (message.isFromQueue()) {
                rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.QUEUE));
            } else {
                rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.TOPIC));
            }
        }

        for (Iterator iter = message.getHeaderProperty().iterator(); iter.hasNext();) {
            Property property = (Property) iter.next();

            if (property.getValue() == null) {
                rval.setObjectProperty(property.getName(), null);
            } else if (property.getType().equals(String.class.getName())) {
                rval.setStringProperty(property.getName(), StringEscapeUtils.unescapeXml(property.getValue()));
            } else if (property.getType().equals(Long.class.getName())) {
                rval.setLongProperty(property.getName(), Long.parseLong(property.getValue()));
            } else if (property.getType().equals(Double.class.getName())) {
                rval.setDoubleProperty(property.getName(), Double.parseDouble(property.getValue()));
            } else if (property.getType().equals(Boolean.class.getName())) {
                rval.setBooleanProperty(property.getName(), Boolean.parseBoolean(property.getValue()));
            } else if (property.getType().equals(Short.class.getName())) {
                rval.setShortProperty(property.getName(), Short.parseShort(property.getValue()));
            } else if (property.getType().equals(Integer.class.getName())) {
                rval.setIntProperty(property.getName(), Integer.parseInt(property.getValue()));
            }
        }

        return rval;
    } catch (NamingException e) {
        throw new HermesException(e);
    }

}

From source file:org.apache.axis2.transport.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   www. ja  v a2s  .  c o  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) {
                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.apache.camel.component.jms.JmsBinding.java

public void appendJmsProperty(Message jmsMessage, Exchange exchange, org.apache.camel.Message in,
        String headerName, Object headerValue) throws JMSException {
    if (isStandardJMSHeader(headerName)) {
        if (headerName.equals("JMSCorrelationID")) {
            jmsMessage.setJMSCorrelationID(ExchangeHelper.convertToType(exchange, String.class, headerValue));
        } else if (headerName.equals("JMSReplyTo") && headerValue != null) {
            if (headerValue instanceof String) {
                // if the value is a String we must normalize it first
                headerValue = normalizeDestinationName((String) headerValue);
            }//from   ww  w .j av  a 2  s . c  o m
            jmsMessage.setJMSReplyTo(ExchangeHelper.convertToType(exchange, Destination.class, headerValue));
        } else if (headerName.equals("JMSType")) {
            jmsMessage.setJMSType(ExchangeHelper.convertToType(exchange, String.class, headerValue));
        } else if (headerName.equals("JMSPriority")) {
            jmsMessage.setJMSPriority(ExchangeHelper.convertToType(exchange, Integer.class, headerValue));
        } else if (headerName.equals("JMSDeliveryMode")) {
            Integer deliveryMode = ExchangeHelper.convertToType(exchange, Integer.class, headerValue);
            jmsMessage.setJMSDeliveryMode(deliveryMode);
            jmsMessage.setIntProperty(JmsConstants.JMS_DELIVERY_MODE, deliveryMode);
        } else if (headerName.equals("JMSExpiration")) {
            jmsMessage.setJMSExpiration(ExchangeHelper.convertToType(exchange, Long.class, headerValue));
        } else if (LOG.isTraceEnabled()) {
            // The following properties are set by the MessageProducer:
            // JMSDestination
            // The following are set on the underlying JMS provider:
            // JMSMessageID, JMSTimestamp, JMSRedelivered
            // log at trace level to not spam log
            LOG.trace("Ignoring JMS header: " + headerName + " with value: " + headerValue);
        }
    } else if (shouldOutputHeader(in, headerName, headerValue, exchange)) {
        // only primitive headers and strings is allowed as properties
        // see message properties: http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html
        Object value = getValidJMSHeaderValue(headerName, headerValue);
        if (value != null) {
            // must encode to safe JMS header name before setting property on jmsMessage
            String key = jmsKeyFormatStrategy.encodeKey(headerName);
            // set the property
            JmsMessageHelper.setProperty(jmsMessage, key, value);
        } else if (LOG.isDebugEnabled()) {
            // okay the value is not a primitive or string so we cannot sent it over the wire
            LOG.debug("Ignoring non primitive header: " + headerName + " of class: "
                    + headerValue.getClass().getName() + " with value: " + headerValue);
        }
    }
}

From source file:org.apache.synapse.transport.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//w  w  w .  j  a v a2s.  c  o  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;
    }

    Iterator iter = headerMap.keySet().iterator();
    while (iter.hasNext()) {

        String name = (String) iter.next();

        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).intValue());
            } 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) {
                message.setStringProperty(name, (String) value);
            } else if (value instanceof Boolean) {
                message.setBooleanProperty(name, ((Boolean) value).booleanValue());
            } else if (value instanceof Integer) {
                message.setIntProperty(name, ((Integer) value).intValue());
            } else if (value instanceof Long) {
                message.setLongProperty(name, ((Long) value).longValue());
            } else if (value instanceof Double) {
                message.setDoubleProperty(name, ((Double) value).doubleValue());
            } else if (value instanceof Float) {
                message.setFloatProperty(name, ((Float) value).floatValue());
            }
        }
    }
}

From source file:org.jwebsocket.jms.endpoint.JMSEndPointSender.java

/**
 *
 * @param aTargetId//ww w.ja v  a2s .  c o m
 * @param aCorrelationID
 * @param aText
 * @param aResponseListener
 * @param aTimeout
 */
public synchronized void sendText(String aTargetId, final String aCorrelationID, final String aText,
        IJMSResponseListener aResponseListener, long aTimeout) {
    Message lMsg;
    try {
        lMsg = mSession.createTextMessage(aText);
        if (null != aCorrelationID) {
            lMsg.setJMSCorrelationID(aCorrelationID);
        }
        lMsg.setStringProperty("targetId", aTargetId);
        lMsg.setStringProperty("sourceId", mEndPointId);

        if (mLog.isDebugEnabled()) {
            StringBuilder lPropStr = new StringBuilder();
            Enumeration lPropNames = lMsg.getPropertyNames();
            while (lPropNames.hasMoreElements()) {
                String lPropName = (String) lPropNames.nextElement();
                Object lValue = lMsg.getObjectProperty(lPropName);
                lPropStr.append(lPropName).append("=").append(lValue);
                if (lPropNames.hasMoreElements()) {
                    lPropStr.append(", ");
                }
            }
            mLog.debug("Sending text to '" + aTargetId + "': "
                    + (JMSLogging.isFullTextLogging() ? aText
                            : "[content suppressed, length: " + aText.length() + " bytes]")
                    + ", props: " + lPropStr + "...");
        }

        // processing callbacks
        if (null != aResponseListener) {
            Assert.notNull(aCorrelationID, "The 'correlationID' argument cannot be null!");
            Assert.isTrue(aTimeout > 0, "Invalid 'timeout' argument. Expecting 'timeout' > 0");
            // setting the expiration time
            lMsg.setJMSExpiration(aTimeout);

            // saving the callback 
            mResponseListeners.put(aCorrelationID, aResponseListener);

            // schedule the timer task
            Tools.getTimer().schedule(new JWSTimerTask() {
                @Override
                public void runTask() {
                    Thread lThread = new Thread() {
                        @Override
                        public void run() {
                            IJMSResponseListener lListener = mResponseListeners.remove(aCorrelationID);
                            if (null != lListener) {
                                lListener.onTimeout();
                            }
                        }
                    };
                    lThread.setName("JMSEndPointSender Timeout Thread");
                    Tools.getThreadPool().submit(lThread);
                }
            }, aTimeout);
        }

        mProducer.send(lMsg);

    } catch (JMSException lEx) {
        mLog.error(lEx.getClass().getSimpleName() + " sending message: " + lEx.getMessage() + " "
                + ExceptionUtils.getStackTrace(lEx));
    }
}

From source file:org.mule.transport.jms.JmsMessageUtils.java

public static Message copyJMSProperties(Message from, Message to, JmsConnector connector) throws JMSException {
    if (connector.supportsProperty(JmsConstants.JMS_CORRELATION_ID)) {
        to.setJMSCorrelationID(from.getJMSCorrelationID());
    }/*w  w  w  .  j  a  v a 2  s .co m*/
    if (connector.supportsProperty(JmsConstants.JMS_DELIVERY_MODE)) {
        to.setJMSDeliveryMode(from.getJMSDeliveryMode());
    }
    if (connector.supportsProperty(JmsConstants.JMS_DESTINATION)) {
        to.setJMSDestination(from.getJMSDestination());
    }
    if (connector.supportsProperty(JmsConstants.JMS_EXPIRATION)) {
        to.setJMSExpiration(from.getJMSExpiration());
    }
    if (connector.supportsProperty(JmsConstants.JMS_MESSAGE_ID)) {
        to.setJMSMessageID(from.getJMSMessageID());
    }
    if (connector.supportsProperty(JmsConstants.JMS_PRIORITY)) {
        to.setJMSPriority(from.getJMSPriority());
    }
    if (connector.supportsProperty(JmsConstants.JMS_REDELIVERED)) {
        to.setJMSRedelivered(from.getJMSRedelivered());
    }
    if (connector.supportsProperty(JmsConstants.JMS_REPLY_TO)) {
        to.setJMSReplyTo(from.getJMSReplyTo());
    }
    if (connector.supportsProperty(JmsConstants.JMS_TIMESTAMP)) {
        to.setJMSTimestamp(from.getJMSTimestamp());
    }
    if (connector.supportsProperty(JmsConstants.JMS_TYPE)) {
        to.setJMSType(from.getJMSType());
    }
    return to;
}

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/*from   w  ww. java 2  s .co  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
 *//*  www  .  java 2 s .  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   ww w .j  a v a 2 s .c o  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);
            }
        }
    }
}