/**
   * Clear properties
   *
   * @throws JMSException Thrown if an error occurs
   */
  @Override
  public void clearProperties() throws JMSException {
    if (ActiveMQRAMessage.trace) {
      ActiveMQRALogger.LOGGER.trace("clearProperties()");
    }

    message.clearProperties();
  }
  public static void makeMessageReadWrite(Message jmsMessage) throws JMSException {

    if (jmsMessage == null) {
      return;
    }

    String strMessage = getTextData(jmsMessage);

    if (strMessage != null) {
      jmsMessage.clearBody();
      setTextData(jmsMessage, strMessage);
    }

    HashMap propertyTable = getAllProperties(jmsMessage);

    jmsMessage.clearProperties();
    setAllProperties(jmsMessage, propertyTable);
  }
Beispiel #3
0
  /*
   * JMS does not let you add a property on received message without first
   * calling clearProperties, so we need to save and re-add all the old properties so we
   * don't lose them!!
   */
  private static void copyProperties(final Message msg) throws JMSException {
    @SuppressWarnings("unchecked")
    Enumeration<String> en = msg.getPropertyNames();

    Map<String, Object> oldProps = null;

    while (en.hasMoreElements()) {
      String propName = en.nextElement();

      if (oldProps == null) {
        oldProps = new HashMap<String, Object>();
      }

      oldProps.put(propName, msg.getObjectProperty(propName));
    }

    msg.clearProperties();

    if (oldProps != null) {
      Iterator<Entry<String, Object>> oldPropsIter = oldProps.entrySet().iterator();

      while (oldPropsIter.hasNext()) {
        Entry<String, Object> entry = oldPropsIter.next();

        String propName = entry.getKey();

        Object val = entry.getValue();

        if (val instanceof byte[] == false) {
          // Can't set byte[] array props through the JMS API - if we're bridging a HornetQ message
          // it might have such props
          msg.setObjectProperty(propName, entry.getValue());
        } else if (msg instanceof HornetQMessage) {
          ((HornetQMessage) msg).getCoreMessage().putBytesProperty(propName, (byte[]) val);
        }
      }
    }
  }