All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.undefinedlabs.scope.rules.propagation.carriers.JmsTextMapExtractAdapter Maven / Gradle / Ivy

package com.undefinedlabs.scope.rules.propagation.carriers;

import io.opentracing.propagation.TextMap;

import javax.jms.JMSException;
import javax.jms.Message;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class JmsTextMapExtractAdapter implements TextMap {

  private final Map map = new HashMap<>();

  public JmsTextMapExtractAdapter(Message message) {
    if (message == null) {
      return;
    }
    try {
      final Enumeration enumeration = message.getPropertyNames();
      if (enumeration != null) {
        while (enumeration.hasMoreElements()) {
          final String key = (String) enumeration.nextElement();
          final Object value = message.getObjectProperty(key);
          if (value instanceof String) {
            map.put(decodeDash(key), (String) value);
          }
        }
      }
    } catch (JMSException e) {
      throw new RuntimeException(e);
    }
  }

  @Override
  public Iterator> iterator() {
    return map.entrySet().iterator();
  }

  @Override
  public void put(String key, String value) {
    throw new UnsupportedOperationException(
        "JmsTextMapExtractAdapter should only be used with Tracer.extract()");
  }

  private String decodeDash(String key) {
    return key.replace(JmsTextMapInjectAdapter.DASH, "-");
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy