Example usage for javax.jms Message setJMSDeliveryMode

List of usage examples for javax.jms Message setJMSDeliveryMode

Introduction

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

Prototype


void setJMSDeliveryMode(int deliveryMode) throws JMSException;

Source Link

Document

Sets the DeliveryMode value for this message.

Usage

From source file:com.adaptris.core.jms.activemq.BlobMessageTranslatorTest.java

public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    EmbeddedActiveMq activeMqBroker = new EmbeddedActiveMq();
    JmsConnection conn = null;/* w  w  w.  j a va 2 s  .com*/
    try {
        activeMqBroker.start();
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);

        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Message jmsMsg = createMessage(session);
        jmsMsg.setJMSCorrelationID("ABC");
        jmsMsg.setJMSDeliveryMode(1);
        jmsMsg.setJMSPriority(4);
        addProperties(jmsMsg);
        long timestamp = System.currentTimeMillis();
        jmsMsg.setJMSTimestamp(timestamp);

        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        trans.setMoveJmsHeaders(true);
        start(trans);

        AdaptrisMessage msg = trans.translate(jmsMsg);
        assertMetadata(msg);
        assertEquals("ABC", msg.getMetadataValue(JmsConstants.JMS_CORRELATION_ID));
        assertEquals("1", msg.getMetadataValue(JmsConstants.JMS_DELIVERY_MODE));
        assertEquals("4", msg.getMetadataValue(JmsConstants.JMS_PRIORITY));
        assertEquals(String.valueOf(timestamp), msg.getMetadataValue(JmsConstants.JMS_TIMESTAMP));
    } finally {
        stop(trans);
        stop(conn);
        activeMqBroker.destroy();
    }

}

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

public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MessageTypeTranslatorImp trans = createTranslator();
    try {/*www.jav a 2 s .  c o  m*/
        Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Message jmsMsg = createMessage(session);
        jmsMsg.setJMSCorrelationID("ABC");
        jmsMsg.setJMSDeliveryMode(1);
        jmsMsg.setJMSPriority(4);
        addProperties(jmsMsg);
        long timestamp = System.currentTimeMillis();
        jmsMsg.setJMSTimestamp(timestamp);

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

        AdaptrisMessage msg = trans.translate(jmsMsg);
        assertMetadata(msg);
        assertEquals("ABC", msg.getMetadataValue(JmsConstants.JMS_CORRELATION_ID));
        assertEquals("1", msg.getMetadataValue(JmsConstants.JMS_DELIVERY_MODE));
        assertEquals("4", msg.getMetadataValue(JmsConstants.JMS_PRIORITY));
        assertEquals(String.valueOf(timestamp), msg.getMetadataValue(JmsConstants.JMS_TIMESTAMP));
    } finally {
        stop(trans);
        broker.destroy();
    }

}

From source file:hermes.impl.DefaultXMLHelper.java

public Message createMessage(MessageFactory hermes, XMLMessage message)
        throws JMSException, IOException, ClassNotFoundException, DecoderException {
    try {/*from w ww .  j a  v  a 2s  .c  o  m*/
        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:nl.nn.adapterframework.jms.JmsSender.java

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc,
        String soapHeader) throws SenderException, TimeOutException {
    Session s = null;/*from ww w .j  a v  a  2s .  c  o  m*/
    MessageProducer mp = null;

    ParameterValueList pvl = null;
    if (prc != null && paramList != null) {
        try {
            pvl = prc.getValues(paramList);
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "cannot extract parameters", e);
        }
    }

    if (isSoap()) {
        if (soapHeader == null) {
            if (pvl != null && StringUtils.isNotEmpty(getSoapHeaderParam())) {
                ParameterValue soapHeaderParamValue = pvl.getParameterValue(getSoapHeaderParam());
                if (soapHeaderParamValue == null) {
                    log.warn("no SoapHeader found using parameter [" + getSoapHeaderParam() + "]");
                } else {
                    soapHeader = soapHeaderParamValue.asStringValue("");
                }
            }
        }
        message = soapWrapper.putInEnvelope(message, getEncodingStyleURI(), getServiceNamespaceURI(),
                soapHeader);
        if (log.isDebugEnabled())
            log.debug(getLogPrefix() + "correlationId [" + correlationID + "] soap message [" + message + "]");
    }
    try {
        s = createSession();
        mp = getMessageProducer(s, getDestination(prc));
        Destination replyQueue = null;

        // create message
        Message msg = createTextMessage(s, correlationID, message);

        if (getMessageType() != null) {
            msg.setJMSType(getMessageType());
        }
        if (getDeliveryModeInt() > 0) {
            msg.setJMSDeliveryMode(getDeliveryModeInt());
            mp.setDeliveryMode(getDeliveryModeInt());
        }
        if (getPriority() >= 0) {
            msg.setJMSPriority(getPriority());
            mp.setPriority(getPriority());
        }

        // set properties
        if (pvl != null) {
            setProperties(msg, pvl);
        }
        if (replyToName != null) {
            replyQueue = getDestination(replyToName);
        } else {
            if (isSynchronous()) {
                replyQueue = getMessagingSource().getDynamicReplyQueue(s);
            }
        }
        if (replyQueue != null) {
            msg.setJMSReplyTo(replyQueue);
            if (log.isDebugEnabled())
                log.debug("replyTo set to queue [" + replyQueue.toString() + "]");
        }

        // send message   
        send(mp, msg);
        if (log.isDebugEnabled()) {
            log.debug("[" + getName() + "] " + "sent message [" + message + "] " + "to [" + mp.getDestination()
                    + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID ["
                    + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] "
                    + ((replyToName != null) ? "replyTo [" + replyToName + "]" : ""));
        } else {
            if (log.isInfoEnabled()) {
                log.info("[" + getName() + "] " + "sent message to [" + mp.getDestination() + "] " + "msgID ["
                        + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] "
                        + "using deliveryMode [" + getDeliveryMode() + "] "
                        + ((replyToName != null) ? "replyTo [" + replyToName + "]" : ""));
            }
        }
        if (isSynchronous()) {
            String replyCorrelationId = null;
            if (replyToName != null) {
                if ("CORRELATIONID".equalsIgnoreCase(getLinkMethod())) {
                    replyCorrelationId = correlationID;
                } else if ("CORRELATIONID_FROM_MESSAGE".equalsIgnoreCase(getLinkMethod())) {
                    replyCorrelationId = msg.getJMSCorrelationID();
                } else {
                    replyCorrelationId = msg.getJMSMessageID();
                }
            }
            if (log.isDebugEnabled())
                log.debug("[" + getName() + "] start waiting for reply on [" + replyQueue + "] requestMsgId ["
                        + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] for ["
                        + getReplyTimeout() + "] ms");
            MessageConsumer mc = getMessageConsumerForCorrelationId(s, replyQueue, replyCorrelationId);
            try {
                Message rawReplyMsg = mc.receive(getReplyTimeout());
                if (rawReplyMsg == null) {
                    throw new TimeOutException("did not receive reply on [" + replyQueue + "] requestMsgId ["
                            + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId
                            + "] within [" + getReplyTimeout() + "] ms");
                }
                return getStringFromRawMessage(rawReplyMsg, prc != null ? prc.getSession() : null, isSoap(),
                        getReplySoapHeaderSessionKey(), soapWrapper);
            } finally {
                if (mc != null) {
                    try {
                        mc.close();
                    } catch (JMSException e) {
                        log.warn("JmsSender [" + getName()
                                + "] got exception closing message consumer for reply", e);
                    }
                }
            }
        }
        return msg.getJMSMessageID();
    } catch (JMSException e) {
        throw new SenderException(e);
    } catch (IOException e) {
        throw new SenderException(e);
    } catch (NamingException e) {
        throw new SenderException(e);
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    } catch (TransformerException e) {
        throw new SenderException(e);
    } catch (JmsException e) {
        throw new SenderException(e);
    } finally {
        if (mp != null) {
            try {
                mp.close();
            } catch (JMSException e) {
                log.warn("JmsSender [" + getName() + "] got exception closing message producer", e);
            }
        }
        closeSession(s);
    }
}

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 w w w. j av a  2 s .  com*/
 * @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 w  ww. j  a v a2s .  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/*from ww w .j ava  2  s  . c  om*/
 * @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.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());
    }//from 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  w w. j ava2 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
 *//* w w w. j a v a2  s .co 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;
}