示例#1
0
  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;
  }
  /**
   * Set message id
   *
   * @param id The value
   * @throws JMSException Thrown if an error occurs
   */
  @Override
  public void setJMSMessageID(final String id) throws JMSException {
    if (ActiveMQRAMessage.trace) {
      ActiveMQRALogger.LOGGER.trace("setJMSMessageID(" + id + ")");
    }

    message.setJMSMessageID(id);
  }
示例#3
0
  /** {@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);
      }
    }
  }
示例#4
0
 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);
 }
示例#5
0
  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 static void copyJMSHeaders(Message inputMessage, Message outputMessage)
      throws JMSException {
    Object propValue;

    if (inputMessage == null || outputMessage == null) {
      return;
    }

    propValue = inputMessage.getJMSMessageID();
    if (propValue != null) {
      outputMessage.setJMSMessageID((String) propValue);
    }

    propValue = inputMessage.getJMSDestination();
    if (propValue != null) {
      outputMessage.setJMSDestination((Destination) propValue);
    }

    propValue = inputMessage.getJMSReplyTo();
    if (propValue != null) {
      outputMessage.setJMSReplyTo((Destination) propValue);
    }

    outputMessage.setJMSTimestamp(inputMessage.getJMSTimestamp());

    propValue = inputMessage.getJMSCorrelationID();
    if (!StringUtil.isEmpty((String) propValue)) {
      outputMessage.setJMSCorrelationID((String) propValue);
    }

    outputMessage.setJMSPriority(inputMessage.getJMSPriority());

    outputMessage.setJMSExpiration(inputMessage.getJMSExpiration());

    return;
  }