protected JBossMessage(final Message foreign, final byte type, final ClientSession session)
      throws JMSException {
    this(type, session);

    setJMSTimestamp(foreign.getJMSTimestamp());

    try {
      byte[] corrIDBytes = foreign.getJMSCorrelationIDAsBytes();
      setJMSCorrelationIDAsBytes(corrIDBytes);
    } catch (JMSException e) {
      // specified as String
      String corrIDString = foreign.getJMSCorrelationID();
      if (corrIDString != null) {
        setJMSCorrelationID(corrIDString);
      }
    }

    setJMSReplyTo(foreign.getJMSReplyTo());
    setJMSDestination(foreign.getJMSDestination());
    setJMSDeliveryMode(foreign.getJMSDeliveryMode());
    setJMSExpiration(foreign.getJMSExpiration());
    setJMSPriority(foreign.getJMSPriority());
    setJMSType(foreign.getJMSType());

    // We can't avoid a cast warning here since getPropertyNames() is on the JMS API
    for (Enumeration<String> props = foreign.getPropertyNames(); props.hasMoreElements(); ) {
      String name = (String) props.nextElement();

      Object prop = foreign.getObjectProperty(name);

      this.setObjectProperty(name, prop);
    }
  }
  /**
   * Get timestamp
   *
   * @return The value
   * @throws JMSException Thrown if an error occurs
   */
  @Override
  public long getJMSTimestamp() throws JMSException {
    if (ActiveMQRAMessage.trace) {
      ActiveMQRALogger.LOGGER.trace("getJMSTimestamp()");
    }

    return message.getJMSTimestamp();
  }
예제 #3
0
  protected HornetQMessage(final Message foreign, final byte type, final ClientSession session)
      throws JMSException {
    this(type, session);

    setJMSTimestamp(foreign.getJMSTimestamp());

    String value =
        System.getProperty(
            HornetQJMSConstants.JMS_HORNETQ_ENABLE_BYTE_ARRAY_JMS_CORRELATION_ID_PROPERTY_NAME);

    boolean supportBytesId = !"false".equals(value);

    if (supportBytesId) {
      try {
        byte[] corrIDBytes = foreign.getJMSCorrelationIDAsBytes();
        setJMSCorrelationIDAsBytes(corrIDBytes);
      } catch (JMSException e) {
        // specified as String
        String corrIDString = foreign.getJMSCorrelationID();
        if (corrIDString != null) {
          setJMSCorrelationID(corrIDString);
        }
      }
    } else {
      // Some providers, like WSMQ do automatic conversions between native byte[] correlation id
      // and String correlation id. This makes it impossible for HQ to guarantee to return the
      // correct
      // type as set by the user
      // So we allow the behaviour to be overridden by a system property
      // https://jira.jboss.org/jira/browse/HORNETQ-356
      // https://jira.jboss.org/jira/browse/HORNETQ-332
      String corrIDString = foreign.getJMSCorrelationID();
      if (corrIDString != null) {
        setJMSCorrelationID(corrIDString);
      }
    }

    setJMSReplyTo(foreign.getJMSReplyTo());
    setJMSDestination(foreign.getJMSDestination());
    setJMSDeliveryMode(foreign.getJMSDeliveryMode());
    setJMSExpiration(foreign.getJMSExpiration());
    setJMSPriority(foreign.getJMSPriority());
    setJMSType(foreign.getJMSType());

    // We can't avoid a cast warning here since getPropertyNames() is on the JMS API
    for (Enumeration<String> props = foreign.getPropertyNames(); props.hasMoreElements(); ) {
      String name = props.nextElement();

      Object prop = foreign.getObjectProperty(name);

      setObjectProperty(name, prop);
    }
  }
예제 #4
0
파일: JmsBinding.java 프로젝트: mnki/camel
  public Map<String, Object> extractHeadersFromJms(Message jmsMessage, Exchange exchange) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (jmsMessage != null) {
      // lets populate the standard JMS message headers
      try {
        map.put("JMSCorrelationID", jmsMessage.getJMSCorrelationID());
        map.put("JMSCorrelationIDAsBytes", JmsMessageHelper.getJMSCorrelationIDAsBytes(jmsMessage));
        map.put("JMSDeliveryMode", jmsMessage.getJMSDeliveryMode());
        map.put("JMSDestination", jmsMessage.getJMSDestination());
        map.put("JMSExpiration", jmsMessage.getJMSExpiration());
        map.put("JMSMessageID", jmsMessage.getJMSMessageID());
        map.put("JMSPriority", jmsMessage.getJMSPriority());
        map.put("JMSRedelivered", jmsMessage.getJMSRedelivered());
        map.put("JMSTimestamp", jmsMessage.getJMSTimestamp());

        map.put("JMSReplyTo", JmsMessageHelper.getJMSReplyTo(jmsMessage));
        map.put("JMSType", JmsMessageHelper.getJMSType(jmsMessage));

        // this works around a bug in the ActiveMQ property handling
        map.put(JMS_X_GROUP_ID, JmsMessageHelper.getStringProperty(jmsMessage, JMS_X_GROUP_ID));
        map.put("JMSXUserID", JmsMessageHelper.getStringProperty(jmsMessage, "JMSXUserID"));
      } catch (JMSException e) {
        throw new RuntimeCamelException(e);
      }

      Enumeration<?> names;
      try {
        names = jmsMessage.getPropertyNames();
      } catch (JMSException e) {
        throw new RuntimeCamelException(e);
      }
      while (names.hasMoreElements()) {
        String name = names.nextElement().toString();
        try {
          Object value = JmsMessageHelper.getProperty(jmsMessage, name);
          if (headerFilterStrategy != null
              && headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange)) {
            continue;
          }

          // must decode back from safe JMS header name to original header name
          // when storing on this Camel JmsMessage object.
          String key = jmsKeyFormatStrategy.decodeKey(name);
          map.put(key, value);
        } catch (JMSException e) {
          throw new RuntimeCamelException(name, e);
        }
      }
    }

    return map;
  }
예제 #5
0
파일: JMSUtil.java 프로젝트: krakhee20/jbit
 public static void constructConnectorMessageHeaders(Message jmsMsg, MessageHeaders msgHeaders)
     throws JMSException {
   msgHeaders.setJMSCorrelationID(jmsMsg.getJMSCorrelationID());
   msgHeaders.setJMSDeliveryMode(jmsMsg.getJMSDeliveryMode());
   msgHeaders.setJMSDestination(jmsMsg.getJMSDestination().toString());
   msgHeaders.setJMSExpiration(jmsMsg.getJMSExpiration());
   msgHeaders.setJMSMessageID(jmsMsg.getJMSMessageID());
   msgHeaders.setJMSPriority(jmsMsg.getJMSPriority());
   msgHeaders.setJMSRedelivered(jmsMsg.getJMSRedelivered());
   msgHeaders.setJMSReplyTo(jmsMsg.getJMSReplyTo().toString());
   msgHeaders.setJMSTimestamp(jmsMsg.getJMSTimestamp());
   msgHeaders.setJMSType(jmsMsg.getJMSType());
 }
예제 #6
0
 private static Map<String, Object> headers(final javax.jms.Message message) throws JMSException {
   final Map<String, Object> result = new HashMap<>();
   putHeadedIfPresent(result, CorrelationID, message.getJMSCorrelationID());
   putHeadedIfPresent(result, CorrelationIDAsBytes, message.getJMSCorrelationIDAsBytes());
   putHeadedIfPresent(result, DeliveryMode, message.getJMSDeliveryMode());
   putHeadedIfPresent(result, Destination, message.getJMSDestination());
   putHeadedIfPresent(result, Expiration, message.getJMSExpiration());
   putHeadedIfPresent(result, MessageID, message.getJMSMessageID());
   putHeadedIfPresent(result, Priority, message.getJMSPriority());
   putHeadedIfPresent(result, Redelivered, message.getJMSRedelivered());
   putHeadedIfPresent(result, ReplyTo, message.getJMSReplyTo());
   putHeadedIfPresent(result, Timestamp, message.getJMSTimestamp());
   putHeadedIfPresent(result, Type, message.getJMSType());
   return result;
 }
  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;
  }
  protected void updateQueue(U bean) throws EventException {
    boolean resumeAfter = !awaitPaused;
    Session session = null;
    try {
      pause();

      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue queue = session.createQueue(getSubmitQueueName());
      QueueBrowser qb = session.createBrowser(queue);

      @SuppressWarnings("rawtypes")
      Enumeration e = qb.getEnumeration();
      while (e.hasMoreElements()) {

        Message msg = (Message) e.nextElement();
        TextMessage t = (TextMessage) msg;
        String json = t.getText();
        final StatusBean b = service.unmarshal(json, getBeanClass());

        MessageConsumer consumer =
            session.createConsumer(queue, "JMSMessageID = '" + msg.getJMSMessageID() + "'");
        Message rem = consumer.receive(Constants.getReceiveFrequency());

        consumer.close();

        if (rem == null && b.getUniqueId().equals(bean.getUniqueId())) {
          // Something went wrong, not sure why it does this, TODO investigate
          if (overrideMap == null) overrideMap = new Hashtable<>(7);
          overrideMap.put(b.getUniqueId(), bean);
          continue;
        }

        MessageProducer producer = session.createProducer(queue);
        if (b.getUniqueId().equals(bean.getUniqueId())) {

          b.setStatus(bean.getStatus());
          t = session.createTextMessage(service.marshal(b));
          t.setJMSMessageID(rem.getJMSMessageID());
          t.setJMSExpiration(rem.getJMSExpiration());
          t.setJMSTimestamp(rem.getJMSTimestamp());
          t.setJMSPriority(rem.getJMSPriority());
          t.setJMSCorrelationID(rem.getJMSCorrelationID());
        }
        producer.send(t);
        producer.close();
      }

    } catch (Exception ne) {
      throw new EventException("Cannot reorder queue!", ne);

    } finally {
      // Only resume if it wasn't in a paused state before this update
      if (resumeAfter) {
        resume();
      }
      try {
        if (session != null) session.close();
      } catch (JMSException e) {
        throw new EventException("Cannot close session!", e);
      }
    }
  }
예제 #9
0
  /** {@inheritDoc} */
  @Override
  public void mapFrom(JMSBindingData source, Context context) throws Exception {
    super.mapFrom(source, context);

    Message message = source.getMessage();

    // process JMS headers
    if (matches(HEADER_JMS_DESTINATION)) {
      context
          .setProperty(HEADER_JMS_DESTINATION, message.getJMSDestination())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_DELIVERY_MODE)) {
      context
          .setProperty(HEADER_JMS_DELIVERY_MODE, message.getJMSDeliveryMode())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_EXPIRATION)) {
      context
          .setProperty(HEADER_JMS_EXPIRATION, message.getJMSExpiration())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_PRIORITY)) {
      context
          .setProperty(HEADER_JMS_PRIORITY, message.getJMSPriority())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_MESSAGE_ID)) {
      context
          .setProperty(HEADER_JMS_MESSAGE_ID, message.getJMSMessageID())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_TIMESTAMP)) {
      context
          .setProperty(HEADER_JMS_TIMESTAMP, message.getJMSTimestamp())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_CORRELATION_ID)) {
      context
          .setProperty(HEADER_JMS_CORRELATION_ID, message.getJMSCorrelationID())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_REPLY_TO)) {
      context
          .setProperty(HEADER_JMS_REPLY_TO, message.getJMSReplyTo())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_TYPE)) {
      context.setProperty(HEADER_JMS_TYPE, message.getJMSType()).addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_REDELIVERED)) {
      context
          .setProperty(HEADER_JMS_REDELIVERED, message.getJMSRedelivered())
          .addLabels(JMS_HEADER_LABELS);
    }

    // process JMS properties
    Enumeration<?> e = message.getPropertyNames();
    while (e.hasMoreElements()) {
      String key = e.nextElement().toString();
      if (matches(key)) {
        Object value = null;
        try {
          value = message.getObjectProperty(key);
        } catch (JMSException pce) {
          // ignore and keep going (here just to keep checkstyle happy)
          pce.getMessage();
        }
        if (value != null) {
          context.setProperty(key, value).addLabels(JMS_PROPERTY_LABELS);
        }
      } else if (matches(key, getIncludeRegexes(), new ArrayList<Pattern>())) {
        Object value = null;
        try {
          value = message.getObjectProperty(key);
        } catch (JMSException pce) {
          // ignore and keep going (here just to keep checkstyle happy)
          pce.getMessage();
        }
        if (value != null) {
          context.setProperty(key, value).addLabels(JMS_PROPERTY_LABELS);
        }
      }
    }
  }