コード例 #1
0
ファイル: JmsBinding.java プロジェクト: mnki/camel
 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});
     }
   }
 }
コード例 #2
0
ファイル: JmsBinding.java プロジェクト: chicagozer/rheosoft
  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("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("JMSXGroupID", jmsMessage.getStringProperty("JMSXGroupID"));
      } 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 = jmsMessage.getObjectProperty(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;
  }
コード例 #3
0
ファイル: MessageCreatorImpl.java プロジェクト: JoergKe/camel
  void processReply(Session session, Message answer) throws JMSException {
    // when in InOnly mode the JMSReplyTo is a bit complicated
    // we only want to set the JMSReplyTo on the answer if
    // there is a JMSReplyTo from the header/endpoint and
    // we have been told to preserveMessageQos

    Object jmsReplyTo = JmsMessageHelper.getJMSReplyTo(answer);
    if (endpoint.isDisableReplyTo()) {
      // honor disable reply to configuration
      LOG.trace("ReplyTo is disabled on endpoint: {}", endpoint);
      JmsMessageHelper.setJMSReplyTo(answer, null);
    } else {
      // if the binding did not create the reply to then we have to try to create it here
      if (jmsReplyTo == null) {
        // prefer reply to from header over endpoint configured
        jmsReplyTo = exchange.getIn().getHeader("JMSReplyTo", String.class);
        if (jmsReplyTo == null) {
          jmsReplyTo = endpoint.getReplyTo();
        }
      }
    }

    // we must honor these special flags to preserve QoS
    // as we are not OUT capable and thus do not expect a reply, and therefore
    // the consumer of this message should not return a reply so we remove it
    // unless we use preserveMessageQos=true to tell that we still want to use JMSReplyTo
    if (jmsReplyTo != null
        && !(endpoint.isPreserveMessageQos() || endpoint.isExplicitQosEnabled())) {
      // log at debug what we are doing, as higher level may cause noise in production logs
      // this behavior is also documented at the camel website
      if (LOG.isDebugEnabled()) {
        LOG.debug(
            "Disabling JMSReplyTo: {} for destination: {}. Use preserveMessageQos=true to force Camel to keep the JMSReplyTo on endpoint: {}",
            new Object[] {jmsReplyTo, to, endpoint});
      }
      jmsReplyTo = null;
    }

    // the reply to is a String, so we need to look up its Destination instance
    // and if needed create the destination using the session if needed to
    if (jmsReplyTo != null && jmsReplyTo instanceof String) {
      String replyTo = (String) jmsReplyTo;
      // we need to null it as we use the String to resolve it as a Destination instance
      jmsReplyTo = resolveOrCreateDestination(replyTo, session);
    }

    // set the JMSReplyTo on the answer if we are to use it
    Destination replyTo = null;
    String replyToOverride = endpoint.getConfiguration().getReplyToOverride();
    if (replyToOverride != null) {
      replyTo = resolveOrCreateDestination(replyToOverride, session);
    } else if (jmsReplyTo instanceof Destination) {
      replyTo = (Destination) jmsReplyTo;
    }
    if (replyTo != null) {
      LOG.debug("Using JMSReplyTo destination: {}", replyTo);
      JmsMessageHelper.setJMSReplyTo(answer, replyTo);
    } else {
      // do not use JMSReplyTo
      log.trace("Not using JMSReplyTo");
      JmsMessageHelper.setJMSReplyTo(answer, null);
    }

    LOG.trace("Created javax.jms.Message: {}", answer);
  }