protected Message createMessage() throws JMSException { Message message = createMessage("FOO.BAR"); message.setJMSType("selector-test"); message.setJMSMessageID("connection:1:1:1:1"); message.setObjectProperty("name", "James"); message.setObjectProperty("location", "London"); message.setByteProperty("byteProp", (byte) 123); message.setByteProperty("byteProp2", (byte) 33); message.setShortProperty("shortProp", (short) 123); message.setIntProperty("intProp", 123); message.setLongProperty("longProp", 123); message.setFloatProperty("floatProp", 123); message.setDoubleProperty("doubleProp", 123); message.setIntProperty("rank", 123); message.setIntProperty("version", 2); message.setStringProperty("quote", "'In God We Trust'"); message.setStringProperty("foo", "_foo"); message.setStringProperty("punctuation", "!#$&()*+,-./:;<=>?@[\\]^`{|}~"); message.setStringProperty("endingUnderScore", "XD7xlJIQn_"); message.setBooleanProperty("trueProp", true); message.setBooleanProperty("falseProp", false); return message; }
@Override public JMSProducer send(Destination destination, Message message) { if (message == null) { throw new MessageFormatRuntimeException("null message"); } try { if (jmsHeaderCorrelationID != null) { message.setJMSCorrelationID(jmsHeaderCorrelationID); } if (jmsHeaderCorrelationIDAsBytes != null && jmsHeaderCorrelationIDAsBytes.length > 0) { message.setJMSCorrelationIDAsBytes(jmsHeaderCorrelationIDAsBytes); } if (jmsHeaderReplyTo != null) { message.setJMSReplyTo(jmsHeaderReplyTo); } if (jmsHeaderType != null) { message.setJMSType(jmsHeaderType); } // XXX HORNETQ-1209 "JMS 2.0" can this be a foreign msg? // if so, then "SimpleString" properties will trigger an error. setProperties(message); if (completionListener != null) { CompletionListener wrapped = new CompletionListenerWrapper(completionListener); producer.send(destination, message, wrapped); } else { producer.send(destination, message); } } catch (JMSException e) { throw JmsExceptionUtils.convertToRuntimeException(e); } return this; }
/** * Set type * * @param type The value * @throws JMSException Thrown if an error occurs */ @Override public void setJMSType(final String type) throws JMSException { if (ActiveMQRAMessage.trace) { ActiveMQRALogger.LOGGER.trace("setJMSType(" + type + ")"); } message.setJMSType(type); }
public void testJMSPropertySelectors() throws Exception { Message message = createMessage(); message.setJMSType("selector-test"); message.setJMSMessageID("id:test:1:1:1:1"); assertSelector(message, "JMSType = 'selector-test'", true); assertSelector(message, "JMSType = 'crap'", false); assertSelector(message, "JMSMessageID = 'id:test:1:1:1:1'", true); assertSelector(message, "JMSMessageID = 'id:not-test:1:1:1:1'", false); message = createMessage(); message.setJMSType("1001"); assertSelector(message, "JMSType='1001'", true); assertSelector(message, "JMSType='1001' OR JMSType='1002'", true); assertSelector(message, "JMSType = 'crap'", false); }
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, and must include the prefix // as ActiveMQ requires that when converting the String to a javax.jms.Destination type headerValue = normalizeDestinationName((String) headerValue, true); } Destination replyTo = ExchangeHelper.convertToType(exchange, Destination.class, headerValue); JmsMessageHelper.setJMSReplyTo(jmsMessage, replyTo); } 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")) { JmsMessageHelper.setJMSDeliveryMode(exchange, jmsMessage, headerValue); } else if (headerName.equals("JMSExpiration")) { jmsMessage.setJMSExpiration( ExchangeHelper.convertToType(exchange, Long.class, headerValue)); } else { // 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: {} with value: {}", headerName, 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: {} of class: {} with value: {}", new Object[] {headerName, headerValue.getClass().getName(), headerValue}); } } }
/** {@inheritDoc} */ @Override public void mapTo(Context context, JMSBindingData target) throws Exception { super.mapTo(context, target); Message message = target.getMessage(); for (Property property : context.getProperties()) { String name = property.getName(); if (matches(name)) { Object value = property.getValue(); if (value == null) { continue; } try { // process JMS headers if (name.equals(HEADER_JMS_DESTINATION)) { message.setJMSDestination(Destination.class.cast(value)); } else if (name.equals(HEADER_JMS_DELIVERY_MODE)) { message.setJMSDeliveryMode(Integer.parseInt(value.toString())); } else if (name.equals(HEADER_JMS_EXPIRATION)) { message.setJMSExpiration(Long.parseLong(value.toString())); } else if (name.equals(HEADER_JMS_PRIORITY)) { message.setJMSPriority(Integer.parseInt(value.toString())); } else if (name.equals(HEADER_JMS_MESSAGE_ID)) { message.setJMSMessageID(value.toString()); } else if (name.equals(HEADER_JMS_TIMESTAMP)) { message.setJMSTimestamp(Long.parseLong(value.toString())); } else if (name.equals(HEADER_JMS_CORRELATION_ID)) { message.setJMSCorrelationID(value.toString()); } else if (name.equals(HEADER_JMS_REPLY_TO)) { message.setJMSReplyTo(Destination.class.cast(value)); } else if (name.equals(HEADER_JMS_TYPE)) { message.setJMSType(value.toString()); } else if (name.equals(HEADER_JMS_REDELIVERED)) { message.setJMSRedelivered(Boolean.parseBoolean(value.toString())); // process JMS properties } else { message.setObjectProperty(name, value); } } catch (Throwable t) { continue; } } else if (matches(name, getIncludeRegexes(), new ArrayList<Pattern>())) { Object value = property.getValue(); if (value == null) { continue; } message.setObjectProperty(name, value); } } }
public static void constructMessageHeaders( Message jmsMsg, MessageHeaders msgHeaders, Destination destination) throws JMSException { jmsMsg.setJMSCorrelationID(msgHeaders.getJMSCorrelationID()); jmsMsg.setJMSDeliveryMode(msgHeaders.getJMSDeliveryMode()); jmsMsg.setJMSExpiration(msgHeaders.getJMSExpiration()); jmsMsg.setJMSMessageID(msgHeaders.getJMSMessageID()); jmsMsg.setJMSPriority(msgHeaders.getJMSPriority()); jmsMsg.setJMSRedelivered(msgHeaders.isJMSRedelivered()); // currently we are setting the replyTo destination as null jmsMsg.setJMSReplyTo(null); jmsMsg.setJMSTimestamp(msgHeaders.getJMSTimestamp()); jmsMsg.setJMSType(msgHeaders.getJMSType()); jmsMsg.setJMSDestination(destination); }