List of usage examples for javax.jms Message setObjectProperty
void setObjectProperty(String name, Object value) throws JMSException;
From source file:org.springframework.flex.messaging.jms.FlexMessageConverter.java
/** * // w ww .j av a 2s . c o m * {@inheritDoc} */ public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { Assert.state(object instanceof flex.messaging.messages.Message, "FlexMessageConverter can only handle Flex Messages"); flex.messaging.messages.Message flexMessage = (flex.messaging.messages.Message) object; Object messageBody = flexMessage.getBody(); Message jmsMessage = this.targetConverter.toMessage(messageBody, session); jmsMessage.setObjectProperty(FLEX_CLIENT_ID, flexMessage.getClientId()); jmsMessage.setLongProperty(FLEX_TIME_TO_LIVE, flexMessage.getTimeToLive()); Map<String, Object> headers = this.getFlexMessageHeaderMap(flexMessage); for (String key : headers.keySet()) { Object value = flexMessage.getHeader(key); try { jmsMessage.setObjectProperty(key, value); } catch (Exception e) { if (this.logger.isWarnEnabled()) { this.logger.warn("failed to copy Flex header '" + key + "'", e); } } } return jmsMessage; }
From source file:org.springframework.integration.jms.DefaultJmsHeaderMapper.java
public void fromHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) { try {/*w w w . j a v a2 s .com*/ 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 ww w . j a v a 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 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 va2 s . co 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); } } }