com.rabbitmq.client.LongString Java Examples

The following examples show how to use com.rabbitmq.client.LongString. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java    From vertx-rabbitmq-client with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the given object in case of a LongString or List including a LongString to String.
 *
 * @return consolidated object
 */
private static Object convertLongStringToString( Object value ) {

  if ( value instanceof Date ) {
    return ((Date) value).toInstant();
  }

  if ( value instanceof LongString ) {
    return value.toString();
  }

  if ( value instanceof List ) {
    List<Object> newList = new ArrayList<>();
    for ( Object item : (List<?>) value ) {
      newList.add( convertLongStringToString( item ) );
    }
    return newList;
  }

  if ( value instanceof Map) {
    return convertMapLongStringToString((Map<String, Object>) value);
  }

  return value;
}
 
Example #2
Source File: RabbitMqMessage.java    From beam with Apache License 2.0 5 votes vote down vote up
private static Map<String, Object> serializableHeaders(Map<String, Object> headers) {
  Map<String, Object> returned = new HashMap<>();
  if (headers != null) {
    for (Map.Entry<String, Object> h : headers.entrySet()) {
      Object value = h.getValue();
      if (!(value instanceof Serializable)) {
        try {
          if (value instanceof LongString) {
            LongString longString = (LongString) value;
            byte[] bytes = longString.getBytes();
            String s = new String(bytes, StandardCharsets.UTF_8);
            value = s;
          } else {
            throw new RuntimeException(String.format("no transformation defined for %s", value));
          }
        } catch (Throwable t) {
          throw new UnsupportedOperationException(
              String.format(
                  "can't make unserializable value %s a serializable value (which is mandatory for Apache Beam dataflow implementation)",
                  value),
              t);
        }
      }
      returned.put(h.getKey(), value);
    }
  }
  return returned;
}
 
Example #3
Source File: RabbitMQTestConstants.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public SaslMechanism getSaslMechanism(String[] mechanisms) {
    return new SaslMechanism() {
        public String getName() {
            return "ANONYMOUS";
        }

        public LongString handleChallenge(LongString challenge, String username, String password) {
            return LongStringHelper.asLongString("");
        }
    };
}
 
Example #4
Source File: TraceeMessagePropertiesConverterTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void parseMessageHeaderIntoBackend() throws Exception {
	final Map<String, LongString> rabbitTraceeHeader = new HashMap<>();
	rabbitTraceeHeader.put(INVOCATION_ID_KEY, new TestLongString("Crazy ID"));

	unit.toMessageProperties(createRabbitHeaderWith(TPIC_HEADER, rabbitTraceeHeader), mock(Envelope.class), CHARSET_UTF8);

	assertThat(backend.copyToMap(), hasEntry(INVOCATION_ID_KEY, "Crazy ID"));
}
 
Example #5
Source File: RabbitMQMessageScheme.java    From storm-rabbitmq with MIT License 5 votes vote down vote up
private Map<String, Object> serializableHeaders(Map<String, Object> headers) {
    if (headers == null) {
        return new HashMap<String, Object>();
    }

    Map<String, Object> headersSerializable = new HashMap<String, Object>(headers.size());
    for (Map.Entry<String, Object> entry : headers.entrySet()) {
        if (entry.getValue() instanceof Number ||
                entry.getValue() instanceof Boolean ||
                entry.getValue() instanceof Character ||
                entry.getValue() instanceof String ||
                entry.getValue() instanceof Date) {
            headersSerializable.put(entry.getKey(), entry.getValue());
        } else if (entry.getValue() instanceof LongString) {
            headersSerializable.put(entry.getKey(), entry.getValue().toString());
        } else if (entry.getValue() instanceof ArrayList) {
            ArrayList serializedList = new ArrayList();
            for (Object elm : ((ArrayList) entry.getValue())) {
                if (elm instanceof HashMap) {
                    serializedList.add(serializableHeaders((HashMap<String, Object>) elm));
                }
            }
            headersSerializable.put(entry.getKey(), serializedList);
        }
    }
    return headersSerializable;
}