예제 #1
0
  public void onMessage(Message message) {
    try {
      if (logger.isDebugEnabled()) {
        logger.debug("Message received it is of type: " + message.getClass().getName());
        if (message.getJMSDestination() != null) {
          logger.debug(
              "Message received on "
                  + message.getJMSDestination()
                  + " ("
                  + message.getJMSDestination().getClass().getName()
                  + ")");
        } else {
          logger.debug("Message received on unknown destination");
        }
        logger.debug("Message CorrelationId is: " + message.getJMSCorrelationID());
        logger.debug("Jms Message Id is: " + message.getJMSMessageID());
      }

      if (message.getJMSRedelivered()) {
        if (logger.isDebugEnabled()) {
          logger.debug(
              "Message with correlationId: "
                  + message.getJMSCorrelationID()
                  + " is redelivered. handing off to Exception Handler");
        }
        redeliveryHandler.handleRedelivery(message);
      }

      UMOMessageAdapter adapter = connector.getMessageAdapter(message);
      routeMessage(new MuleMessage(adapter));
    } catch (Exception e) {
      handleException(e);
    }
  }
예제 #2
0
  /**
   * Consumes a tuple and sends a JMS message.
   *
   * <p>If autoAck is true, the tuple will be acknowledged after the message is sent.
   *
   * <p>If JMS sending fails, the tuple will be failed.
   */
  @Override
  public void execute(Tuple input) {
    // write the tuple to a JMS destination...
    LOG.debug("Tuple received. Sending JMS message.");

    try {
      Message msg = this.producer.toMessage(this.session, input);
      if (msg != null) {
        if (msg.getJMSDestination() != null) {
          this.messageProducer.send(msg.getJMSDestination(), msg);
        } else {
          this.messageProducer.send(msg);
        }
      }
      if (this.autoAck) {
        LOG.debug("ACKing tuple: " + input);
        this.collector.ack(input);
      }
    } catch (JMSException e) {
      // failed to send the JMS message, fail the tuple fast
      LOG.warn("Failing tuple: " + input);
      LOG.warn("Exception: ", e);
      this.collector.fail(input);
    }
  }
  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 destination
   *
   * @return The value
   * @throws JMSException Thrown if an error occurs
   */
  @Override
  public Destination getJMSDestination() throws JMSException {
    if (ActiveMQRAMessage.trace) {
      ActiveMQRALogger.LOGGER.trace("getJMSDestination()");
    }

    return message.getJMSDestination();
  }
예제 #5
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);
    }
  }
예제 #6
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;
  }
예제 #7
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());
 }
예제 #8
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;
 }
예제 #9
0
 @Override
 protected String createMessageId() {
   if (jmsMessage == null) {
     if (LOG.isTraceEnabled()) {
       LOG.trace("No javax.jms.Message set so generating a new message id");
     }
     return super.createMessageId();
   }
   try {
     String id =
         getDestinationAsString(jmsMessage.getJMSDestination()) + jmsMessage.getJMSMessageID();
     return getSanitizedString(id);
   } catch (JMSException e) {
     throw new RuntimeExchangeException(
         "Unable to retrieve JMSMessageID from JMS Message", getExchange(), e);
   }
 }
  /** Waits for a message and checks to see if it is valid. */
  private void checkMessage(String clientId, String destination) throws JMSException {
    long startTime = System.currentTimeMillis();

    while (true) { // Wait for the message
      if (messageCount > 0) {
        assertNotNull(currentMessage);
        if (currentMessage instanceof TextMessage) {
          assertEquals(messageText, ((TextMessage) currentMessage).getText());
        } else {
          fail("Text Message expected.");
        }

        assertEquals(clientId, currentClientId);

        Destination messageDestination = currentMessage.getJMSDestination();
        if (messageDestination instanceof Topic) {
          String topic = ((Topic) messageDestination).getTopicName();
          assertEquals(topic, destination);
        } else if (messageDestination instanceof Queue) {
          String queue = ((Queue) messageDestination).getQueueName();
          assertEquals(queue, destination);
        }

        String propertyTest = currentMessage.getStringProperty(propertyName);
        assertEquals(propertyValue, propertyTest);
        break;
      } else { // Check for timeout
        long currentTime = System.currentTimeMillis();
        if (currentTime > (startTime + messageTimeout)) {
          fail("Timeout reached waiting for message.");
          break;
        } else {
          try {
            Thread.sleep(100);
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
      }
    }

    messageCount = 0;
    currentMessage = null;
    currentClientId = null;
  }
  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;
  }
예제 #12
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);
        }
      }
    }
  }